More tests and 100% coverage achievements!
Also fixed a few minor bugs and reworked Browser class to not use the constant UNIT_TESTING so I could get the class to 100% coverage. Adds a dependency of testing_helpers which I believe is available on Travis CI by default. Up to 75% coverage, w00t w00t!
This commit is contained in:
parent
faaefc1b82
commit
8db383601e
15 changed files with 136 additions and 62 deletions
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
|
||||
set_exit_overload(function(){ return false; });
|
||||
|
||||
ob_start();
|
||||
session_start();
|
||||
@session_start();
|
||||
|
||||
require_once 'vendors/composer/autoload.php';
|
||||
|
||||
|
@ -11,8 +13,6 @@ if (!defined('SITE_PATH'))
|
|||
{
|
||||
define('SECURITY_LEVEL_USER', 10);
|
||||
define('SITE_PATH', org\bovigo\vfs\vfsStream::url('site/'));
|
||||
// This isn't ideal but it helps a ton when testing the Browser class.
|
||||
define('UNIT_TESTING', true);
|
||||
}
|
||||
|
||||
require_once 'pickles.php';
|
||||
|
|
|
@ -13,17 +13,14 @@ class BrowserTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals('bar', Browser::get('foo'));
|
||||
}
|
||||
|
||||
public function testMissingVariable()
|
||||
{
|
||||
$this->assertFalse(Browser::get('missing'));
|
||||
}
|
||||
|
||||
public function testGoHome()
|
||||
{
|
||||
try
|
||||
{
|
||||
Browser::goHome();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Browser::goHome();
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/', xdebug_get_headers()));
|
||||
}
|
||||
|
||||
|
@ -34,7 +31,7 @@ class BrowserTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertTrue(Browser::isMobile());
|
||||
}
|
||||
|
||||
public function testRedirect()
|
||||
public function testIsNotMobile()
|
||||
{
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/7.0.1 Safari/537.73.11';
|
||||
|
||||
|
|
13
tests/classes/ConfigTest.php
Normal file
13
tests/classes/ConfigTest.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
class ConfigTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConfigProperty()
|
||||
{
|
||||
$config = new Config();
|
||||
|
||||
$this->assertTrue(PHPUnit_Framework_Assert::readAttribute($config, 'config'));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -100,7 +100,7 @@ class ControllerTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
file_put_contents(SITE_MODULE_PATH . 'notauth.php', $module);
|
||||
|
||||
new Controller();
|
||||
@new Controller();
|
||||
|
||||
$this->assertTrue(in_array('Location: http://testsite.com/login', xdebug_get_headers()));
|
||||
}
|
||||
|
|
|
@ -68,7 +68,10 @@ JS;
|
|||
|
||||
public function testReference()
|
||||
{
|
||||
$this->assertRegExp('/^\/images\/image\.\d{10}\.png$/', $this->dynamic->reference('/images/image.png'));
|
||||
$this->assertRegExp(
|
||||
'/^\/images\/image\.\d{10}\.png$/',
|
||||
$this->dynamic->reference('/images/image.png'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,6 +109,14 @@ JS;
|
|||
$this->dynamic->reference('../images/relative.png');
|
||||
}
|
||||
|
||||
public function testReferenceWithQueryString()
|
||||
{
|
||||
$this->assertRegExp(
|
||||
'/^\/images\/image\.\d{10}\.png\?foo=bar$/',
|
||||
$this->dynamic->reference('/images/image.png?foo=bar'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Filename must have an extension (e.g. /path/to/file.css)
|
||||
|
@ -123,6 +134,18 @@ JS;
|
|||
$this->assertRegExp('/^\/css\/stylesheet\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.css'));
|
||||
}
|
||||
|
||||
public function testCSSWithoutMinifyFileMinifiedFileExists()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = false;
|
||||
|
||||
touch('/tmp/pickles-fs/public/css/stylesheet.min.css');
|
||||
|
||||
$this->assertRegExp('/^\/css\/stylesheet\.min\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.css'));
|
||||
|
||||
unlink('/tmp/pickles-fs/public/css/stylesheet.min.css');
|
||||
}
|
||||
|
||||
public function testCSSWithMinify()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
|
@ -197,6 +220,18 @@ JS;
|
|||
|
||||
$this->assertRegExp('/^\/js\/script\.min\.\d{10}\.js$/', $this->dynamic->js('/js/script.js'));
|
||||
}
|
||||
|
||||
public function testJSWithoutMinifyFileMinifiedFileExists()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['minify'] = false;
|
||||
|
||||
touch('/tmp/pickles-fs/public/js/script.min.css');
|
||||
|
||||
$this->assertRegExp('/^\/js\/script\.min\.\d{10}\.js$/', $this->dynamic->js('/js/script.js'));
|
||||
|
||||
unlink('/tmp/pickles-fs/public/js/script.min.css');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -94,6 +94,16 @@ class HTMLTest extends PHPUnit_Framework_TestCase
|
|||
$this->html->div('string', ['class' => 'fancy'])
|
||||
);
|
||||
}
|
||||
|
||||
public function testLabelWithInputWithoutName()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<label>Label</label><input type="text">',
|
||||
$this->html->input([
|
||||
'label' => 'Label',
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
class LogTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
private $config;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$config->data['pickles']['logging'] = true;
|
||||
$this->config = Config::getInstance();
|
||||
$this->config->data['pickles']['logging'] = true;
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
|
@ -89,6 +91,13 @@ class LogTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ query$/', $line);
|
||||
}
|
||||
|
||||
public function testLoggingDisabled()
|
||||
{
|
||||
$this->config->data['pickles']['logging'] = false;
|
||||
|
||||
$this->assertFalse(Log::error('should return false'));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -15,6 +15,11 @@ class ObjectTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
$this->assertInstanceOf('Cache', PHPUnit_Framework_Assert::readAttribute($object, 'cache'));
|
||||
}
|
||||
|
||||
public function testGetInstanceWithoutClass()
|
||||
{
|
||||
$this->assertFalse(Object::getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue