diff --git a/classes/Browser.php b/classes/Browser.php
index 3194128..52e41ba 100644
--- a/classes/Browser.php
+++ b/classes/Browser.php
@@ -96,7 +96,7 @@ class Browser extends Object
*/
public static function goHome()
{
- Browser::redirect('/');
+ return Browser::redirect('/');
}
/**
@@ -134,15 +134,7 @@ class Browser extends Object
}
header('Location: ' . $destination);
-
- if (defined('UNIT_TESTING'))
- {
- throw new Exception();
- }
- else
- {
- exit;
- }
+ exit;
}
/**
@@ -197,7 +189,6 @@ class Browser extends Object
case 102: $message = '102 Processing'; break;
// }}}
// {{{ 2xx Success
- case 200: $message = '200 OK'; break;
case 201: $message = '201 Created'; break;
case 202: $message = '202 Accepted'; break;
case 203: $message = '203 Non-Authoritative Information'; break;
diff --git a/classes/Config.php b/classes/Config.php
index ed8b40a..91b23b7 100644
--- a/classes/Config.php
+++ b/classes/Config.php
@@ -53,7 +53,11 @@ class Config extends Object
if (file_exists($filename) && is_file($filename) && is_readable($filename))
{
require_once $filename;
+ }
+ // Checks that we have the config array
+ if (isset($config))
+ {
// Determines the environment
if (isset($config['environment']))
{
diff --git a/classes/Controller.php b/classes/Controller.php
index b8b498c..cde4f37 100644
--- a/classes/Controller.php
+++ b/classes/Controller.php
@@ -220,6 +220,11 @@ class Controller extends Object
// Redirect to login page
Browser::redirect('/login');
+
+ // header() updates are a bitch to test, returning
+ // halts execution so we don't have any output in our
+ // testing results.
+ return false;
}
}
}
diff --git a/classes/HTML.php b/classes/HTML.php
index 49e881f..c17ebc4 100644
--- a/classes/HTML.php
+++ b/classes/HTML.php
@@ -22,7 +22,7 @@
*/
class HTML extends Object
{
- private $self_closing = array('br', 'hr', 'img', 'input', 'link', 'meta');
+ private $self_closing = ['br', 'hr', 'img', 'input', 'link', 'meta'];
public function __call($method, $arguments)
{
@@ -58,7 +58,7 @@ class HTML extends Object
}
else
{
- $attributes = array('type' => $type);
+ $attributes = ['type' => $type];
}
}
@@ -66,14 +66,15 @@ class HTML extends Object
{
if (isset($attributes['name']))
{
- $label = $this->label(array('for' => $attributes['name']), $attributes['label']);
- unset($attributes['label']);
+ $label = $this->label(['for' => $attributes['name']], $attributes['label']);
}
else
{
$label = $this->label($attributes['label']);
}
+ unset($attributes['label']);
+
return $label . $this->$method($attributes, $contents);
}
else
diff --git a/classes/Log.php b/classes/Log.php
index 1836bf3..e97b2d0 100644
--- a/classes/Log.php
+++ b/classes/Log.php
@@ -122,33 +122,26 @@ class Log
{
$log_path = LOG_PATH . date('Y/m/d/', ($time == false ? time() : $time));
- try
+ if (!file_exists($log_path))
{
- if (!file_exists($log_path))
- {
- mkdir($log_path, 0755, true);
- }
-
- $log_file = $log_path . $log_type . '.log';
-
- $message .= "\n";
-
- if ($format == true)
- {
- $backtrace = debug_backtrace();
- rsort($backtrace);
- $frame = $backtrace[strpos($backtrace[0]['file'], 'index.php') === false ? 0 : 1];
-
- return file_put_contents($log_file, date('H:i:s') . ' ' . str_replace(getcwd(), '', $frame['file']) . ':' . $frame['line'] . ' ' . $message, FILE_APPEND);
- }
- else
- {
- return file_put_contents($log_file, $message, FILE_APPEND);
- }
+ mkdir($log_path, 0755, true);
}
- catch (ErrorException $exception)
+
+ $log_file = $log_path . $log_type . '.log';
+
+ $message .= "\n";
+
+ if ($format == true)
{
- return false;
+ $backtrace = debug_backtrace();
+ rsort($backtrace);
+ $frame = $backtrace[strpos($backtrace[0]['file'], 'index.php') === false ? 0 : 1];
+
+ return file_put_contents($log_file, date('H:i:s') . ' ' . str_replace(getcwd(), '', $frame['file']) . ':' . $frame['line'] . ' ' . $message, FILE_APPEND);
+ }
+ else
+ {
+ return file_put_contents($log_file, $message, FILE_APPEND);
}
}
diff --git a/classes/Number.php b/classes/Number.php
index 743ee93..d4f5659 100644
--- a/classes/Number.php
+++ b/classes/Number.php
@@ -37,15 +37,25 @@ class Number
*/
public static function ordinalIndicator($number, $superscript = false)
{
- $suffix = 'th';
-
if (!in_array(($number % 100), array(11, 12, 13)))
{
switch ($number % 10)
{
- case 1: $suffix = 'st'; break;
- case 2: $suffix = 'nd'; break;
- case 3: $suffix = 'rd'; break;
+ case 1:
+ $suffix = 'st';
+ break;
+
+ case 2:
+ $suffix = 'nd';
+ break;
+
+ case 3:
+ $suffix = 'rd';
+ break;
+
+ default:
+ $suffix = 'th';
+ break;
}
}
diff --git a/classes/Object.php b/classes/Object.php
index f5a744c..9ca1bb5 100644
--- a/classes/Object.php
+++ b/classes/Object.php
@@ -123,6 +123,7 @@ class Object
public static function getInstance($class = false)
{
// In < 5.3 arguments must match in child, hence defaulting $class
+ // @todo Remove this, as we're no longer supporting 5.3
if ($class == false)
{
return false;
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index eef8f84..71d4f6e 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -1,7 +1,9 @@
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';
diff --git a/tests/classes/ConfigTest.php b/tests/classes/ConfigTest.php
new file mode 100644
index 0000000..3d62b50
--- /dev/null
+++ b/tests/classes/ConfigTest.php
@@ -0,0 +1,13 @@
+assertTrue(PHPUnit_Framework_Assert::readAttribute($config, 'config'));
+ }
+}
+
+?>
diff --git a/tests/classes/ControllerTest.php b/tests/classes/ControllerTest.php
index 3cec8aa..10ac352 100644
--- a/tests/classes/ControllerTest.php
+++ b/tests/classes/ControllerTest.php
@@ -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()));
}
diff --git a/tests/classes/DynamicTest.php b/tests/classes/DynamicTest.php
index 0db4ad6..a682476 100644
--- a/tests/classes/DynamicTest.php
+++ b/tests/classes/DynamicTest.php
@@ -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');
+ }
}
?>
diff --git a/tests/classes/HTMLTest.php b/tests/classes/HTMLTest.php
index d5afb4e..7823dff 100644
--- a/tests/classes/HTMLTest.php
+++ b/tests/classes/HTMLTest.php
@@ -94,6 +94,16 @@ class HTMLTest extends PHPUnit_Framework_TestCase
$this->html->div('string', ['class' => 'fancy'])
);
}
+
+ public function testLabelWithInputWithoutName()
+ {
+ $this->assertEquals(
+ '',
+ $this->html->input([
+ 'label' => 'Label',
+ ])
+ );
+ }
}
?>
diff --git a/tests/classes/LogTest.php b/tests/classes/LogTest.php
index d5e8bca..f1689a2 100644
--- a/tests/classes/LogTest.php
+++ b/tests/classes/LogTest.php
@@ -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'));
+ }
}
?>
diff --git a/tests/classes/ObjectTest.php b/tests/classes/ObjectTest.php
index 649907c..fcd89c9 100644
--- a/tests/classes/ObjectTest.php
+++ b/tests/classes/ObjectTest.php
@@ -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());
+ }
}
?>