From f46b41f437404900b9896520138e22ee53223729 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Thu, 28 Jan 2021 21:53:44 +0900 Subject: [PATCH] Update unit tests for latest codeception --- .github/workflows/ci.yml | 12 +- codeception.dist.yml | 2 +- common/framework/db.php | 10 + .../unit/classes/FrontEndFileHandlerTest.php | 481 +++++++++--------- tests/unit/classes/ValidatorTest.php | 33 +- tests/unit/framework/DBTest.php | 6 + tests/unit/framework/DebugTest.php | 2 +- tests/unit/framework/PaginationTest.php | 42 +- tests/unit/framework/StorageTest.php | 4 +- .../framework/parsers/DBTableParserTest.php | 28 +- .../parsers/ModuleActionParserTest.php | 4 +- tests/unit/functions/LegacyTest.php | 2 +- 12 files changed, 331 insertions(+), 295 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03b69a5b9..2afa98e15 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,16 +28,18 @@ jobs: - name: PHP Lint run: if find . -name "*.php" ! -path "./vendor/*" -print0 | xargs -0 -n 1 -P 8 php -l | grep -v "No syntax errors detected"; then exit 1; fi - - name: Download codeception - if: matrix.php != '8.0' - run: wget https://codeception.com/releases/2.3.9/codecept.phar + - name: Download codeception (PHP 7.2 and above) + if: matrix.php >= '7.2' + run: wget https://codeception.com/codecept.phar + + - name: Download codeception (PHP 7.1 and below) + if: matrix.php <= '7.1' + run: wget https://codeception.com/php56/codecept.phar - name: Run PHP development server - if: matrix.php != '8.0' run: php -S localhost:8000 & - name: Build and run codeception - if: matrix.php != '8.0' run: | php codecept.phar build php codecept.phar run --debug --fail-fast --env travis diff --git a/codeception.dist.yml b/codeception.dist.yml index de1999f25..66396a311 100644 --- a/codeception.dist.yml +++ b/codeception.dist.yml @@ -4,8 +4,8 @@ paths: log: tests/_output data: tests/_data helpers: tests/_support +bootstrap: _bootstrap.php settings: - bootstrap: _bootstrap.php colors: true memory_limit: 1024M error_level: "E_ALL & ~E_STRICT & ~E_DEPRECATED & ~E_NOTICE" diff --git a/common/framework/db.php b/common/framework/db.php index fa1035716..ee789f824 100644 --- a/common/framework/db.php +++ b/common/framework/db.php @@ -1196,6 +1196,16 @@ class DB return $this->_total_time; } + /** + * Enable or disable debug comments. + * + * @param bool $enabled + */ + public function setDebugComment(bool $enabled) + { + $this->_debug_comment = $enabled; + } + /** * ========================== DEPRECATED METHODS ========================== * ==================== KEPT FOR COMPATIBILITY WITH XE ==================== diff --git a/tests/unit/classes/FrontEndFileHandlerTest.php b/tests/unit/classes/FrontEndFileHandlerTest.php index ecf74b633..645257e94 100644 --- a/tests/unit/classes/FrontEndFileHandlerTest.php +++ b/tests/unit/classes/FrontEndFileHandlerTest.php @@ -2,267 +2,292 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test { - use \Codeception\Specify; - + private $reservedCSS; + private $reservedJS; private function _filemtime($file) { return '?' . date('YmdHis', filemtime(_XE_PATH_ . $file)); } - public function testFrontEndFileHandler() + public function _before() { - $reservedCSS = HTMLDisplayHandler::$reservedCSS; - $reservedJS = HTMLDisplayHandler::$reservedJS; + $this->reservedCSS = HTMLDisplayHandler::$reservedCSS; + $this->reservedJS = HTMLDisplayHandler::$reservedJS; HTMLDisplayHandler::$reservedCSS = '/xxx$/'; HTMLDisplayHandler::$reservedJS = '/xxx$/'; FrontEndFileHandler::$minify = 'none'; FrontEndFileHandler::$concat = 'none'; + } + + public function _after() + { + HTMLDisplayHandler::$reservedCSS = $this->reservedCSS; + HTMLDisplayHandler::$reservedJS = $this->reservedJS; + } + + public function _failed() + { + HTMLDisplayHandler::$reservedCSS = $this->reservedCSS; + HTMLDisplayHandler::$reservedJS = $this->reservedJS; + } + + public function testJsHead() + { + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('./common/js/js_app.js', 'head')); + $handler->loadFile(array('./common/js/common.js', 'body')); + $handler->loadFile(array('./common/js/common.js', 'head')); + $handler->loadFile(array('./common/js/xml_js_filter.js', 'body')); + $expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null); + $expected[] = array('file' => '/rhymix/common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); + $this->assertEquals($expected, $handler->getJsFileList()); + } + + public function testJsBody() + { + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('./common/js/xml_handler.js', 'body')); + $handler->loadFile(array('./common/js/xml_js_filter.js', 'head')); + $expected[] = array('file' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); + $this->assertEquals($expected, $handler->getJsFileList('body')); + } + + public function testCssLess() + { + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('./common/css/rhymix.less')); + $result = $handler->getCssFileList(true); + $this->assertRegexp('/\.rhymix\.less\.css\?\d+$/', $result[0]['file']); + $this->assertEquals('all', $result[0]['media']); + $this->assertEmpty($result[0]['targetie']); + } - $this->specify("js (head)", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('./common/js/js_app.js', 'head')); - $handler->loadFile(array('./common/js/common.js', 'body')); - $handler->loadFile(array('./common/js/common.js', 'head')); - $handler->loadFile(array('./common/js/xml_js_filter.js', 'body')); - $expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null); - $expected[] = array('file' => '/rhymix/common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); - $this->assertEquals($expected, $handler->getJsFileList()); - }); + public function testDuplicateOrder() + { + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000)); + $handler->loadFile(array('./common/js/common.js', 'head', '', -100000)); + $handler->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000)); + $handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000)); + $handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000)); + $handler->loadFile(array('./common/js/common.js', 'head', '', -100000)); + $handler->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000)); + $handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000)); + $expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null); + $expected[] = array('file' => '/rhymix/common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); + $expected[] = array('file' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); + $expected[] = array('file' => '/rhymix/common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null); + $this->assertEquals($expected, $handler->getJsFileList()); + } + + public function testRedefineOrder() + { + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('./common/js/xml_handler.js', 'head', '', 1)); + $handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000)); + $handler->loadFile(array('./common/js/common.js', 'head', '', -100000)); + $handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000)); + $expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null); + $expected[] = array('file' => '/rhymix/common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); + $expected[] = array('file' => '/rhymix/common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null); + $expected[] = array('file' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); + $this->assertEquals($expected, $handler->getJsFileList()); + } + + public function testUnload() + { + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000)); + $handler->loadFile(array('./common/js/common.js', 'head', '', -100000)); + $handler->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000)); + $handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000)); + $handler->unloadFile('./common/js/js_app.js', '', 'all'); + $expected[] = array('file' => '/rhymix/common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); + $expected[] = array('file' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); + $expected[] = array('file' => '/rhymix/common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null); + $this->assertEquals($expected, $handler->getJsFileList()); + } - $this->specify("js (body)", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('./common/js/xml_handler.js', 'body')); - $handler->loadFile(array('./common/js/xml_js_filter.js', 'head')); - $expected[] = array('file' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); - $this->assertEquals($expected, $handler->getJsFileList('body')); - }); + public function testExternalFile1() + { + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('http://external.host/js/script.js')); + $handler->loadFile(array('https://external.host/js/script.js')); + $handler->loadFile(array('//external.host/js/script1.js')); + $handler->loadFile(array('///external.host/js/script2.js')); - $this->specify("css and less", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('./common/css/rhymix.less')); - $result = $handler->getCssFileList(true); - $this->assertRegexp('/\.rhymix\.less\.css\?\d+$/', $result[0]['file']); - $this->assertEquals('all', $result[0]['media']); - $this->assertEmpty($result[0]['targetie']); - }); + $expected[] = array('file' => 'http://external.host/js/script.js', 'targetie' => null); + $expected[] = array('file' => 'https://external.host/js/script.js', 'targetie' => null); + $expected[] = array('file' => '//external.host/js/script1.js', 'targetie' => null); + $expected[] = array('file' => '//external.host/js/script2.js', 'targetie' => null); + $this->assertEquals($expected, $handler->getJsFileList()); + } + + public function testExternalFile2() + { + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('//external.host/js/script.js')); + $handler->loadFile(array('///external.host/js/script.js')); - $this->specify("order (duplicate)", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000)); - $handler->loadFile(array('./common/js/common.js', 'head', '', -100000)); - $handler->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000)); - $handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000)); - $handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000)); - $handler->loadFile(array('./common/js/common.js', 'head', '', -100000)); - $handler->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000)); - $handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000)); - $expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null); - $expected[] = array('file' => '/rhymix/common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); - $expected[] = array('file' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); - $expected[] = array('file' => '/rhymix/common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null); - $this->assertEquals($expected, $handler->getJsFileList()); - }); + $expected[] = array('file' => '//external.host/js/script.js', 'targetie' => null); + $this->assertEquals($expected, $handler->getJsFileList()); + } + + public function testExternalFile3() + { + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('http://external.host/css/style1.css')); + $handler->loadFile(array('https://external.host/css/style2.css')); + $handler->loadFile(array('https://external.host/css/style3.css?foo=bar&t=123')); - $this->specify("order (redefine)", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('./common/js/xml_handler.js', 'head', '', 1)); - $handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000)); - $handler->loadFile(array('./common/js/common.js', 'head', '', -100000)); - $handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000)); - $expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null); - $expected[] = array('file' => '/rhymix/common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); - $expected[] = array('file' => '/rhymix/common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null); - $expected[] = array('file' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); - $this->assertEquals($expected, $handler->getJsFileList()); - }); + $expected[] = array('file' => 'http://external.host/css/style1.css', 'media'=>'all', 'targetie' => null); + $expected[] = array('file' => 'https://external.host/css/style2.css', 'media'=>'all', 'targetie' => null); + $expected[] = array('file' => 'https://external.host/css/style3.css?foo=bar&t=123', 'media'=>'all', 'targetie' => null); + $this->assertEquals($expected, $handler->getCssFileList()); + } + + public function testExternalFile4() + { + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('//external.host/css/style.css')); + $handler->loadFile(array('///external.host/css2/style2.css')); + $handler->loadFile(array('//external.host/css/style3.css?foo=bar&t=123')); - $this->specify("unload", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000)); - $handler->loadFile(array('./common/js/common.js', 'head', '', -100000)); - $handler->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000)); - $handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000)); - $handler->unloadFile('./common/js/js_app.js', '', 'all'); - $expected[] = array('file' => '/rhymix/common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); - $expected[] = array('file' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); - $expected[] = array('file' => '/rhymix/common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null); - $this->assertEquals($expected, $handler->getJsFileList()); - }); + $expected[] = array('file' => '//external.host/css/style.css', 'media'=>'all', 'targetie' => null); + $expected[] = array('file' => '//external.host/css2/style2.css', 'media'=>'all', 'targetie' => null); + $expected[] = array('file' => '//external.host/css/style3.css?foo=bar&t=123', 'media'=>'all', 'targetie' => null); + $this->assertEquals($expected, $handler->getCssFileList()); + } - $this->specify("target IE (js)", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('./common/js/js_app.js', 'head', 'ie6')); - $handler->loadFile(array('./common/js/js_app.js', 'head', 'ie7')); - $handler->loadFile(array('./common/js/js_app.js', 'head', 'ie8')); - $expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie6'); - $expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie7'); - $expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie8'); - $this->assertEquals($expected, $handler->getJsFileList()); - }); + public function testPathConversion() + { + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('./common/xeicon/xeicon.min.css')); + $result = $handler->getCssFileList(); + $this->assertEquals('/rhymix/common/css/xeicon/xeicon.min.css' . $this->_filemtime('common/css/xeicon/xeicon.min.css'), $result[0]['file']); + $this->assertEquals('all', $result[0]['media']); + $this->assertEmpty($result[0]['targetie']); + } - $this->specify("external file - schemaless", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('http://external.host/js/script.js')); - $handler->loadFile(array('https://external.host/js/script.js')); - $handler->loadFile(array('//external.host/js/script1.js')); - $handler->loadFile(array('///external.host/js/script2.js')); + public function testTargetie1() + { + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('./common/js/js_app.js', 'head', 'ie6')); + $handler->loadFile(array('./common/js/js_app.js', 'head', 'ie7')); + $handler->loadFile(array('./common/js/js_app.js', 'head', 'ie8')); + $expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie6'); + $expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie7'); + $expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie8'); + $this->assertEquals($expected, $handler->getJsFileList()); + } - $expected[] = array('file' => 'http://external.host/js/script.js', 'targetie' => null); - $expected[] = array('file' => 'https://external.host/js/script.js', 'targetie' => null); - $expected[] = array('file' => '//external.host/js/script1.js', 'targetie' => null); - $expected[] = array('file' => '//external.host/js/script2.js', 'targetie' => null); - $this->assertEquals($expected, $handler->getJsFileList()); - }); + public function testTargetie2() + { + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('./common/css/common.css', null, 'ie6')); + $handler->loadFile(array('./common/css/common.css', null, 'ie7')); + $handler->loadFile(array('./common/css/common.css', null, 'ie8')); - $this->specify("external file - schemaless", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('//external.host/js/script.js')); - $handler->loadFile(array('///external.host/js/script.js')); + $expected[] = array('file' => '/rhymix/common/css/common.css', 'media' => 'all', 'targetie' => 'ie6'); + $expected[] = array('file' => '/rhymix/common/css/common.css', 'media' => 'all', 'targetie' => 'ie7'); + $expected[] = array('file' => '/rhymix/common/css/common.css', 'media' => 'all', 'targetie' => 'ie8'); + $this->assertEquals($expected, $handler->getCssFileList()); + } + + public function testMedia() + { + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('./common/css/common.css', 'all')); + $handler->loadFile(array('./common/css/common.css', 'screen')); + $handler->loadFile(array('./common/css/common.css', 'handled')); - $expected[] = array('file' => '//external.host/js/script.js', 'targetie' => null); - $this->assertEquals($expected, $handler->getJsFileList()); - }); - - $this->specify("target IE (css)", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('./common/css/common.css', null, 'ie6')); - $handler->loadFile(array('./common/css/common.css', null, 'ie7')); - $handler->loadFile(array('./common/css/common.css', null, 'ie8')); - - $expected[] = array('file' => '/rhymix/common/css/common.css', 'media'=>'all', 'targetie' => 'ie6'); - $expected[] = array('file' => '/rhymix/common/css/common.css','media'=>'all', 'targetie' => 'ie7'); - $expected[] = array('file' => '/rhymix/common/css/common.css', 'media'=>'all', 'targetie' => 'ie8'); - $this->assertEquals($expected, $handler->getCssFileList()); - }); - - $this->specify("media", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('./common/css/common.css', 'all')); - $handler->loadFile(array('./common/css/common.css', 'screen')); - $handler->loadFile(array('./common/css/common.css', 'handled')); - - $expected[] = array('file' => '/rhymix/common/css/common.css', 'media'=>'all', 'targetie' => null); - $expected[] = array('file' => '/rhymix/common/css/common.css','media'=>'screen', 'targetie' => null); - $expected[] = array('file' => '/rhymix/common/css/common.css', 'media'=>'handled', 'targetie' => null); - $this->assertEquals($expected, $handler->getCssFileList()); - }); + $expected[] = array('file' => '/rhymix/common/css/common.css', 'media'=>'all', 'targetie' => null); + $expected[] = array('file' => '/rhymix/common/css/common.css','media'=>'screen', 'targetie' => null); + $expected[] = array('file' => '/rhymix/common/css/common.css', 'media'=>'handled', 'targetie' => null); + $this->assertEquals($expected, $handler->getCssFileList()); + } + public function testMinify() + { FrontEndFileHandler::$minify = 'all'; - - $this->specify("minify (css)", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('./common/css/rhymix.less')); - $result = $handler->getCssFileList(true); - $this->assertRegexp('/\.rhymix\.less\.min\.css\b/', $result[0]['file']); - $this->assertEquals('all', $result[0]['media']); - $this->assertEmpty($result[0]['targetie']); - }); - $this->specify("minify (js)", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('./common/js/common.js', 'head')); - $result = $handler->getJsFileList('head', true); - $this->assertRegexp('/minified\/common\.js\.common\.min\.js\?\d+$/', $result[0]['file']); - $this->assertEmpty($result[0]['targetie']); - }); + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('./common/css/rhymix.less')); + $result = $handler->getCssFileList(true); + $this->assertRegexp('/\.rhymix\.less\.min\.css\b/', $result[0]['file']); + $this->assertEquals('all', $result[0]['media']); + $this->assertEmpty($result[0]['targetie']); + + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('./common/js/common.js', 'head')); + $result = $handler->getJsFileList('head', true); + $this->assertRegexp('/minified\/common\.js\.common\.min\.js\?\d+$/', $result[0]['file']); + $this->assertEmpty($result[0]['targetie']); FrontEndFileHandler::$minify = 'none'; - + } + + public function testConcat() + { FrontEndFileHandler::$concat = 'css'; - $this->specify("concat (css)", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('./common/css/rhymix.less')); - $handler->loadFile(array('./common/css/bootstrap-responsive.css')); - $handler->loadFile(array('http://external.host/style.css')); - $handler->loadFile(array('./common/css/bootstrap.css', null, 'IE')); - $handler->loadFile(array('./tests/_data/formatter/concat.source1.css')); - $handler->loadFile(array('./tests/_data/formatter/concat.source2.css')); - $handler->loadFile(array('./tests/_data/formatter/concat.target1.css')); - $handler->loadFile(array('./tests/_data/formatter/concat.target2.css')); - $result = $handler->getCssFileList(true); - $this->assertEquals(4, count($result)); - $this->assertRegexp('/combined\/[0-9a-f]+\.css\?\d+$/', $result[0]['file']); - $this->assertEquals('/rhymix/common/css/bootstrap.css' . $this->_filemtime('common/css/bootstrap.css'), $result[1]['file']); - $this->assertEquals('IE', $result[1]['targetie']); - $this->assertEquals('http://external.host/style.css', $result[2]['file']); - $this->assertRegexp('/combined\/[0-9a-f]+\.css\?\d+$/', $result[3]['file']); - }); + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('./common/css/rhymix.less')); + $handler->loadFile(array('./common/css/bootstrap-responsive.css')); + $handler->loadFile(array('http://external.host/style.css')); + $handler->loadFile(array('./common/css/bootstrap.css', null, 'IE')); + $handler->loadFile(array('./tests/_data/formatter/concat.source1.css')); + $handler->loadFile(array('./tests/_data/formatter/concat.source2.css')); + $handler->loadFile(array('./tests/_data/formatter/concat.target1.css')); + $handler->loadFile(array('./tests/_data/formatter/concat.target2.css')); + $result = $handler->getCssFileList(true); + $this->assertEquals(4, count($result)); + $this->assertRegexp('/combined\/[0-9a-f]+\.css\?\d+$/', $result[0]['file']); + $this->assertEquals('/rhymix/common/css/bootstrap.css' . $this->_filemtime('common/css/bootstrap.css'), $result[1]['file']); + $this->assertEquals('IE', $result[1]['targetie']); + $this->assertEquals('http://external.host/style.css', $result[2]['file']); + $this->assertRegexp('/combined\/[0-9a-f]+\.css\?\d+$/', $result[3]['file']); FrontEndFileHandler::$concat = 'js'; - $this->specify("concat (js)", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('./common/js/common.js', 'head')); - $handler->loadFile(array('./common/js/debug.js', 'head')); - $handler->loadFile(array('./common/js/html5.js', 'head')); - $handler->loadFile(array('///external.host/js/script.js')); - $handler->loadFile(array('./tests/_data/formatter/concat.source1.js', 'head', 'lt IE 8')); - $handler->loadFile(array('./tests/_data/formatter/concat.source2.js', 'head', 'gt IE 7')); - $handler->loadFile(array('./tests/_data/formatter/concat.target1.js')); - $handler->loadFile(array('./tests/_data/formatter/concat.target2.js')); - $result = $handler->getJsFileList('head', true); - $this->assertEquals(3, count($result)); - $this->assertRegexp('/combined\/[0-9a-f]+\.js\?\d+$/', $result[0]['file']); - $this->assertEquals('//external.host/js/script.js', $result[1]['file']); - $this->assertRegexp('/combined\/[0-9a-f]+\.js\?\d+$/', $result[2]['file']); - }); + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('./common/js/common.js', 'head')); + $handler->loadFile(array('./common/js/debug.js', 'head')); + $handler->loadFile(array('./common/js/html5.js', 'head')); + $handler->loadFile(array('///external.host/js/script.js')); + $handler->loadFile(array('./tests/_data/formatter/concat.source1.js', 'head', 'lt IE 8')); + $handler->loadFile(array('./tests/_data/formatter/concat.source2.js', 'head', 'gt IE 7')); + $handler->loadFile(array('./tests/_data/formatter/concat.target1.js')); + $handler->loadFile(array('./tests/_data/formatter/concat.target2.js')); + $result = $handler->getJsFileList('head', true); + $this->assertEquals(3, count($result)); + $this->assertRegexp('/combined\/[0-9a-f]+\.js\?\d+$/', $result[0]['file']); + $this->assertEquals('//external.host/js/script.js', $result[1]['file']); + $this->assertRegexp('/combined\/[0-9a-f]+\.js\?\d+$/', $result[2]['file']); FrontEndFileHandler::$concat = 'none'; + } + + public function testBlockedScripts() + { + HTMLDisplayHandler::$reservedCSS = $this->reservedCSS; + HTMLDisplayHandler::$reservedJS = $this->reservedJS; - $this->specify("external file", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('http://external.host/css/style1.css')); - $handler->loadFile(array('https://external.host/css/style2.css')); - $handler->loadFile(array('https://external.host/css/style3.css?foo=bar&t=123')); - - $expected[] = array('file' => 'http://external.host/css/style1.css', 'media'=>'all', 'targetie' => null); - $expected[] = array('file' => 'https://external.host/css/style2.css', 'media'=>'all', 'targetie' => null); - $expected[] = array('file' => 'https://external.host/css/style3.css?foo=bar&t=123', 'media'=>'all', 'targetie' => null); - $this->assertEquals($expected, $handler->getCssFileList()); - }); - - $this->specify("external file - schemaless", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('//external.host/css/style.css')); - $handler->loadFile(array('///external.host/css2/style2.css')); - $handler->loadFile(array('//external.host/css/style3.css?foo=bar&t=123')); - - $expected[] = array('file' => '//external.host/css/style.css', 'media'=>'all', 'targetie' => null); - $expected[] = array('file' => '//external.host/css2/style2.css', 'media'=>'all', 'targetie' => null); - $expected[] = array('file' => '//external.host/css/style3.css?foo=bar&t=123', 'media'=>'all', 'targetie' => null); - $this->assertEquals($expected, $handler->getCssFileList()); - }); - - $this->specify("path conversion", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('./common/xeicon/xeicon.min.css')); - $result = $handler->getCssFileList(); - $this->assertEquals('/rhymix/common/css/xeicon/xeicon.min.css' . $this->_filemtime('common/css/xeicon/xeicon.min.css'), $result[0]['file']); - $this->assertEquals('all', $result[0]['media']); - $this->assertEmpty($result[0]['targetie']); - }); - - HTMLDisplayHandler::$reservedCSS = $reservedCSS; - HTMLDisplayHandler::$reservedJS = $reservedJS; - - $this->specify("blocked scripts", function() { - $handler = new FrontEndFileHandler(); - $handler->loadFile(array('./common/css/xe.min.css')); - $handler->loadFile(array('./common/js/common.js')); - $handler->loadFile(array('./common/js/xe.js')); - $handler->loadFile(array('./common/js/xe.min.js')); - $handler->loadFile(array('./common/js/xml2json.js')); - $handler->loadFile(array('./common/js/jquery.js')); - $handler->loadFile(array('./common/js/jquery-1.x.min.js')); - $handler->loadFile(array('./common/js/jquery-2.0.0.js')); - $handler->loadFile(array('./common/js/jQuery.min.js')); - $handler->loadFile(array('http://code.jquery.com/jquery-latest.js')); - $result = $handler->getCssFileList(); - $this->assertEquals(0, count($result)); - $result = $handler->getJsFileList(); - $this->assertEquals(1, count($result)); - $this->assertEquals('/rhymix/common/js/xml2json.js' . $this->_filemtime('common/js/xml2json.js'), $result[0]['file']); - }); + $handler = new FrontEndFileHandler(); + $handler->loadFile(array('./common/css/xe.min.css')); + $handler->loadFile(array('./common/js/common.js')); + $handler->loadFile(array('./common/js/xe.js')); + $handler->loadFile(array('./common/js/xe.min.js')); + $handler->loadFile(array('./common/js/xml2json.js')); + $handler->loadFile(array('./common/js/jquery.js')); + $handler->loadFile(array('./common/js/jquery-1.x.min.js')); + $handler->loadFile(array('./common/js/jquery-2.0.0.js')); + $handler->loadFile(array('./common/js/jQuery.min.js')); + $handler->loadFile(array('http://code.jquery.com/jquery-latest.js')); + $result = $handler->getCssFileList(); + $this->assertEquals(0, count($result)); + $result = $handler->getJsFileList(); + $this->assertEquals(1, count($result)); + $this->assertEquals('/rhymix/common/js/xml2json.js' . $this->_filemtime('common/js/xml2json.js'), $result[0]['file']); } } diff --git a/tests/unit/classes/ValidatorTest.php b/tests/unit/classes/ValidatorTest.php index 0524985e2..d7e8d9912 100644 --- a/tests/unit/classes/ValidatorTest.php +++ b/tests/unit/classes/ValidatorTest.php @@ -4,17 +4,25 @@ class ValidatorTest extends \Codeception\TestCase\Test { public function _before() { - $ob_level = ob_get_level(); - - //$oContext = Context::getInstance(); - //$oContext->init(); - + $ob_level = ob_get_level(); + + Context::init(); while (ob_get_level() > $ob_level) { ob_end_clean(); } } + public function _after() + { + Rhymix\Framework\Storage::deleteDirectory(__DIR__ . '/validator/ruleset', true); + } + + public function _failed() + { + Rhymix\Framework\Storage::deleteDirectory(__DIR__ . '/validator/ruleset', true); + } + public function testRequired() { $vd = new Validator(); @@ -187,20 +195,5 @@ class ValidatorTest extends \Codeception\TestCase\Test $js = $vd->getJsPath(); $this->assertEquals(trim(file_get_contents(__DIR__ . '/validator/condition.en.js')), trim(file_get_contents($js))); } - - protected function tearDown() - { - // remove cache directory - $cache_dir = __DIR__ . '/validator/ruleset'; - if(is_dir($cache_dir)) - { - $files = (array)glob($cache_dir.'/*'); - foreach($files as $file) - { - unlink($file); - } - rmdir($cache_dir); - } - } } diff --git a/tests/unit/framework/DBTest.php b/tests/unit/framework/DBTest.php index e9bfbdb86..04bad598d 100644 --- a/tests/unit/framework/DBTest.php +++ b/tests/unit/framework/DBTest.php @@ -2,6 +2,12 @@ class DBTest extends \Codeception\TestCase\Test { + public function _before() + { + $oDB = Rhymix\Framework\DB::getInstance(); + $oDB->setDebugComment(false); + } + public function testGetInstance() { $oDB = Rhymix\Framework\DB::getInstance(); diff --git a/tests/unit/framework/DebugTest.php b/tests/unit/framework/DebugTest.php index a19f71bf2..99522147d 100644 --- a/tests/unit/framework/DebugTest.php +++ b/tests/unit/framework/DebugTest.php @@ -41,7 +41,7 @@ class DebugTest extends \Codeception\TestCase\Test $errors = Rhymix\Framework\Debug::getErrors(); $this->assertGreaterThanOrEqual(1, count($errors)); $error = array_pop($errors); - $this->assertContains('Rhymix', $error->message); + $this->assertStringContainsString('Rhymix', $error->message); $this->assertEquals($file, $error->file); $this->assertEquals($line, $error->line); Rhymix\Framework\Debug::clearErrors(); diff --git a/tests/unit/framework/PaginationTest.php b/tests/unit/framework/PaginationTest.php index 057c0b791..79d720afa 100644 --- a/tests/unit/framework/PaginationTest.php +++ b/tests/unit/framework/PaginationTest.php @@ -13,36 +13,36 @@ class PaginationTest extends \Codeception\TestCase\Test public function testCreateLinks() { $links = Rhymix\Framework\Pagination::createLinks('index.php?page=', 27, 3); - $this->assertContains('