diff --git a/classes/Dynamic.php b/classes/Dynamic.php index 5804e15..98f0a24 100644 --- a/classes/Dynamic.php +++ b/classes/Dynamic.php @@ -150,17 +150,7 @@ class Dynamic extends Object { $reference = $original_reference; - /** - * Disabled the sanity checks because I'm using LESS's @import for - * some hackery and it's not validating as true due to the imported - * file not being interrogated. Should be okay as minifying is now - * a subjective action that's turned on in the config due to the - * issues I had in production with it. - * - * if (is_writable($path) - * && (!file_exists($minified_filename) || filemtime($original_filename) > filemtime($minified_filename)) - * && $this->config->pickles['minify'] === true) - */ + // @todo LESS and SASS compiling should happen regardless of minification if ($this->config->pickles['minify'] === true) { // Compiles LESS & SASS to CSS before minifying @@ -203,10 +193,6 @@ class Dynamic extends Object { $reference = $minified_reference; } - else - { - Log::warning('Unable to minify ' . $original_reference . ' and a minified copy does not already exist'); - } $reference = $this->reference($reference); } diff --git a/tests/TODO b/tests/TODO index f6f0cf2..d0ceec3 100644 --- a/tests/TODO +++ b/tests/TODO @@ -1,6 +1,3 @@ -Dynamic -Log - Cache Config Database diff --git a/tests/classes/DynamicTest.php b/tests/classes/DynamicTest.php index a2e7a0b..6ec87cc 100644 --- a/tests/classes/DynamicTest.php +++ b/tests/classes/DynamicTest.php @@ -2,54 +2,176 @@ class DynamicTest extends PHPUnit_Framework_TestCase { - public function testReferenceWithoutFailover() + private $dynamic; + + public static function setUpBeforeClass() + { + // Using actual filesystem because you can't chdir with vfs:// + $public_path = '/tmp/pickles-fs/public/'; + + foreach (['css', 'images', 'js'] as $directory) + { + mkdir($public_path . $directory, 0777, true); + } + + touch($public_path . 'images/image.png'); + touch($public_path . 'images/invalid'); + + $css = <<dynamic = new Dynamic(); + } + + public function tearDown() + { + $minified_file = '/tmp/pickles-fs/public/css/stylesheet.min.css'; + + if (file_exists($minified_file)) + { + unlink($minified_file); + } + } + + public static function tearDownAfterClass() + { + File::removeDirectory('/tmp/pickles-fs'); + } + + public function testReference() + { + $this->assertRegExp('/^\/images\/image\.\d{10}\.png$/', $this->dynamic->reference('/images/image.png')); + } + + /** + * @expectedException Exception + * @expectedExceptionMessage Supplied reference does not exist (/images/missing.png) + */ + public function testReferenceMissingFileWithoutFailover() + { + $this->dynamic->reference('/images/missing.png'); + } + + public function testReferenceMissingFileWithFailover() + { + $this->assertEquals( + '/images/failover.png', + $this->dynamic->reference('/images/missing.png', '/images/failover.png') + ); + } + + /** + * @expectedException Exception + * @expectedExceptionMessage Filename must have an extension (e.g. /path/to/file.png) + */ + public function testReferenceInvalidFilename() + { + $this->dynamic->reference('/images/invalid'); + } + + /** + * @expectedException Exception + * @expectedExceptionMessage Reference value must be absolute (e.g. /path/to/file.png) + */ + public function testReferenceNotAbsolute() + { + $this->dynamic->reference('../images/relative.png'); + } + + /** + * @expectedException Exception + * @expectedExceptionMessage Filename must have an extension (e.g. /path/to/file.css) + */ + public function testCSSMissingExtension() + { + $this->dynamic->css('/css/invalid'); + } + + // TODO May not be able to do these two as it would require lessc and sass to not be installed + // TODO Good chance will also fail on Travis due to missing dependencies, will need to work through that + // TODO will probably want to move to the composer available versions of these + public function testCSSCommandErrorLESS() { } - public function testReferenceWithFailover() + public function testCSSCommandErrorSASS() { } - public function testCSSWrongExtension() + public function testCSSWithoutMinify() { + $config = Config::getInstance(); + $config->data['pickles']['minify'] = false; + $this->assertRegExp('/^\/css\/stylesheet\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.css')); } - public function testCSSErrorLESS() + public function testCSSWithMinify() { + $config = Config::getInstance(); + $config->data['pickles']['minify'] = true; + $this->assertRegExp('/^\/css\/stylesheet\.min\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.css')); } - public function testCSSErrorSASS() + /** + * @expectedException Exception + * @expectedExceptionMessage Supplied reference does not exist + */ + public function testCSSReferenceDoesNotExist() { - + $this->dynamic->css('/css/missing.css'); } - public function testCSS() + public function testLESSWithoutMinify() { + $config = Config::getInstance(); + $config->data['pickles']['minify'] = false; + $this->assertRegExp('/^\/css\/stylesheet\.\d{10}\.less$/', $this->dynamic->css('/css/stylesheet.less')); } - public function testCSSWithLESS() + public function testLESSWithMinify() { + $config = Config::getInstance(); + $config->data['pickles']['minify'] = true; + $this->assertRegExp('/^\/css\/stylesheet\.min\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.less')); } - public function testCSSWithSASS() + public function testSCSSWithoutMinify() { + $config = Config::getInstance(); + $config->data['pickles']['minify'] = false; + $this->assertRegExp('/^\/css\/stylesheet\.\d{10}\.scss$/', $this->dynamic->css('/css/stylesheet.scss')); } - public function testCSSUnableToMinify() - { - - } - - public function testCSSDoesNotExist() + public function testSCSSWithMinify() { + $config = Config::getInstance(); + $config->data['pickles']['minify'] = true; + $this->assertRegExp('/^\/css\/stylesheet\.min\.\d{10}\.css$/', $this->dynamic->css('/css/stylesheet.scss')); } public function testJSWrongExtension() diff --git a/tests/classes/LogTest.php b/tests/classes/LogTest.php index 80d1a8b..d5e8bca 100644 --- a/tests/classes/LogTest.php +++ b/tests/classes/LogTest.php @@ -2,39 +2,92 @@ class LogTest extends PHPUnit_Framework_TestCase { + public static function setUpBeforeClass() + { + $config = Config::getInstance(); + $config->data['pickles']['logging'] = true; + } + + public static function tearDownAfterClass() + { + File::removeDirectory(LOG_PATH); + } + public function testInformation() { + Log::information('information'); + $file = LOG_PATH . date('Y/m/d/') . 'information.log'; + $data = file($file); + $line = $data[count($data) - 1]; + + $this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ information$/', $line); } public function testWarning() { + Log::warning('warning'); + $file = LOG_PATH . date('Y/m/d/') . 'warning.log'; + $data = file($file); + $line = $data[count($data) - 1]; + + $this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ warning$/', $line); } public function testError() { + Log::error('error'); + $file = LOG_PATH . date('Y/m/d/') . 'error.log'; + $data = file($file); + $line = $data[count($data) - 1]; + + $this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ error$/', $line); } public function testSlowQuery() { + Log::slowQuery('slow query'); + $file = LOG_PATH . date('Y/m/d/') . 'slow_query.log'; + $data = file($file); + $line = $data[count($data) - 1]; + + $this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ slow query$/', $line); } public function testTransaction() { + Log::transaction('transaction'); + $file = LOG_PATH . date('Y/m/d/') . 'transaction.log'; + $data = file($file); + $line = $data[count($data) - 1]; + + $this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ transaction$/', $line); } public function testPHPError() { + Log::phperror('php error'); + $file = LOG_PATH . date('Y/m/d/') . 'php_error.log'; + $data = file($file); + $line = $data[count($data) - 1]; + + $this->assertRegExp('/^php error$/', $line); } public function testQuery() { + Log::query('query'); + $file = LOG_PATH . date('Y/m/d/') . 'query.log'; + $data = file($file); + $line = $data[count($data) - 1]; + + $this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ query$/', $line); } }