Update unit tests for latest codeception

This commit is contained in:
Kijin Sung 2021-01-28 21:53:44 +09:00
parent 0db02281c9
commit f46b41f437
12 changed files with 331 additions and 295 deletions

View file

@ -28,16 +28,18 @@ jobs:
- name: PHP Lint - 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 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 - name: Download codeception (PHP 7.2 and above)
if: matrix.php != '8.0' if: matrix.php >= '7.2'
run: wget https://codeception.com/releases/2.3.9/codecept.phar 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 - name: Run PHP development server
if: matrix.php != '8.0'
run: php -S localhost:8000 & run: php -S localhost:8000 &
- name: Build and run codeception - name: Build and run codeception
if: matrix.php != '8.0'
run: | run: |
php codecept.phar build php codecept.phar build
php codecept.phar run --debug --fail-fast --env travis php codecept.phar run --debug --fail-fast --env travis

View file

@ -4,8 +4,8 @@ paths:
log: tests/_output log: tests/_output
data: tests/_data data: tests/_data
helpers: tests/_support helpers: tests/_support
bootstrap: _bootstrap.php
settings: settings:
bootstrap: _bootstrap.php
colors: true colors: true
memory_limit: 1024M memory_limit: 1024M
error_level: "E_ALL & ~E_STRICT & ~E_DEPRECATED & ~E_NOTICE" error_level: "E_ALL & ~E_STRICT & ~E_DEPRECATED & ~E_NOTICE"

View file

@ -1196,6 +1196,16 @@ class DB
return $this->_total_time; return $this->_total_time;
} }
/**
* Enable or disable debug comments.
*
* @param bool $enabled
*/
public function setDebugComment(bool $enabled)
{
$this->_debug_comment = $enabled;
}
/** /**
* ========================== DEPRECATED METHODS ========================== * ========================== DEPRECATED METHODS ==========================
* ==================== KEPT FOR COMPATIBILITY WITH XE ==================== * ==================== KEPT FOR COMPATIBILITY WITH XE ====================

View file

@ -2,267 +2,292 @@
class FrontEndFileHandlerTest extends \Codeception\TestCase\Test class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
{ {
use \Codeception\Specify; private $reservedCSS;
private $reservedJS;
private function _filemtime($file) private function _filemtime($file)
{ {
return '?' . date('YmdHis', filemtime(_XE_PATH_ . $file)); return '?' . date('YmdHis', filemtime(_XE_PATH_ . $file));
} }
public function testFrontEndFileHandler() public function _before()
{ {
$reservedCSS = HTMLDisplayHandler::$reservedCSS; $this->reservedCSS = HTMLDisplayHandler::$reservedCSS;
$reservedJS = HTMLDisplayHandler::$reservedJS; $this->reservedJS = HTMLDisplayHandler::$reservedJS;
HTMLDisplayHandler::$reservedCSS = '/xxx$/'; HTMLDisplayHandler::$reservedCSS = '/xxx$/';
HTMLDisplayHandler::$reservedJS = '/xxx$/'; HTMLDisplayHandler::$reservedJS = '/xxx$/';
FrontEndFileHandler::$minify = 'none'; FrontEndFileHandler::$minify = 'none';
FrontEndFileHandler::$concat = 'none'; FrontEndFileHandler::$concat = 'none';
}
$this->specify("js (head)", function() { public function _after()
$handler = new FrontEndFileHandler(); {
$handler->loadFile(array('./common/js/js_app.js', 'head')); HTMLDisplayHandler::$reservedCSS = $this->reservedCSS;
$handler->loadFile(array('./common/js/common.js', 'body')); HTMLDisplayHandler::$reservedJS = $this->reservedJS;
$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());
});
$this->specify("js (body)", function() { public function _failed()
$handler = new FrontEndFileHandler(); {
$handler->loadFile(array('./common/js/xml_handler.js', 'body')); HTMLDisplayHandler::$reservedCSS = $this->reservedCSS;
$handler->loadFile(array('./common/js/xml_js_filter.js', 'head')); HTMLDisplayHandler::$reservedJS = $this->reservedJS;
$expected[] = array('file' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); }
$this->assertEquals($expected, $handler->getJsFileList('body'));
});
$this->specify("css and less", function() { public function testJsHead()
$handler = new FrontEndFileHandler(); {
$handler->loadFile(array('./common/css/rhymix.less')); $handler = new FrontEndFileHandler();
$result = $handler->getCssFileList(true); $handler->loadFile(array('./common/js/js_app.js', 'head'));
$this->assertRegexp('/\.rhymix\.less\.css\?\d+$/', $result[0]['file']); $handler->loadFile(array('./common/js/common.js', 'body'));
$this->assertEquals('all', $result[0]['media']); $handler->loadFile(array('./common/js/common.js', 'head'));
$this->assertEmpty($result[0]['targetie']); $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());
}
$this->specify("order (duplicate)", function() { public function testJsBody()
$handler = new FrontEndFileHandler(); {
$handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000)); $handler = new FrontEndFileHandler();
$handler->loadFile(array('./common/js/common.js', 'head', '', -100000)); $handler->loadFile(array('./common/js/xml_handler.js', 'body'));
$handler->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000)); $handler->loadFile(array('./common/js/xml_js_filter.js', 'head'));
$handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000)); $expected[] = array('file' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null);
$handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000)); $this->assertEquals($expected, $handler->getJsFileList('body'));
$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());
});
$this->specify("order (redefine)", function() { public function testCssLess()
$handler = new FrontEndFileHandler(); {
$handler->loadFile(array('./common/js/xml_handler.js', 'head', '', 1)); $handler = new FrontEndFileHandler();
$handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000)); $handler->loadFile(array('./common/css/rhymix.less'));
$handler->loadFile(array('./common/js/common.js', 'head', '', -100000)); $result = $handler->getCssFileList(true);
$handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000)); $this->assertRegexp('/\.rhymix\.less\.css\?\d+$/', $result[0]['file']);
$expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null); $this->assertEquals('all', $result[0]['media']);
$expected[] = array('file' => '/rhymix/common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); $this->assertEmpty($result[0]['targetie']);
$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());
});
$this->specify("unload", function() { public function testDuplicateOrder()
$handler = new FrontEndFileHandler(); {
$handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000)); $handler = new FrontEndFileHandler();
$handler->loadFile(array('./common/js/common.js', 'head', '', -100000)); $handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000));
$handler->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000)); $handler->loadFile(array('./common/js/common.js', 'head', '', -100000));
$handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000)); $handler->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000));
$handler->unloadFile('./common/js/js_app.js', '', 'all'); $handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000));
$expected[] = array('file' => '/rhymix/common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); $handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000));
$expected[] = array('file' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); $handler->loadFile(array('./common/js/common.js', 'head', '', -100000));
$expected[] = array('file' => '/rhymix/common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null); $handler->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000));
$this->assertEquals($expected, $handler->getJsFileList()); $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());
}
$this->specify("target IE (js)", function() { public function testRedefineOrder()
$handler = new FrontEndFileHandler(); {
$handler->loadFile(array('./common/js/js_app.js', 'head', 'ie6')); $handler = new FrontEndFileHandler();
$handler->loadFile(array('./common/js/js_app.js', 'head', 'ie7')); $handler->loadFile(array('./common/js/xml_handler.js', 'head', '', 1));
$handler->loadFile(array('./common/js/js_app.js', 'head', 'ie8')); $handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000));
$expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie6'); $handler->loadFile(array('./common/js/common.js', 'head', '', -100000));
$expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie7'); $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' => 'ie8'); $expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null);
$this->assertEquals($expected, $handler->getJsFileList()); $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());
}
$this->specify("external file - schemaless", function() { public function testUnload()
$handler = new FrontEndFileHandler(); {
$handler->loadFile(array('http://external.host/js/script.js')); $handler = new FrontEndFileHandler();
$handler->loadFile(array('https://external.host/js/script.js')); $handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000));
$handler->loadFile(array('//external.host/js/script1.js')); $handler->loadFile(array('./common/js/common.js', 'head', '', -100000));
$handler->loadFile(array('///external.host/js/script2.js')); $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' => 'http://external.host/js/script.js', 'targetie' => null); public function testExternalFile1()
$expected[] = array('file' => 'https://external.host/js/script.js', 'targetie' => null); {
$expected[] = array('file' => '//external.host/js/script1.js', 'targetie' => null); $handler = new FrontEndFileHandler();
$expected[] = array('file' => '//external.host/js/script2.js', 'targetie' => null); $handler->loadFile(array('http://external.host/js/script.js'));
$this->assertEquals($expected, $handler->getJsFileList()); $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("external file - schemaless", function() { $expected[] = array('file' => 'http://external.host/js/script.js', 'targetie' => null);
$handler = new FrontEndFileHandler(); $expected[] = array('file' => 'https://external.host/js/script.js', 'targetie' => null);
$handler->loadFile(array('//external.host/js/script.js')); $expected[] = array('file' => '//external.host/js/script1.js', 'targetie' => null);
$handler->loadFile(array('///external.host/js/script.js')); $expected[] = array('file' => '//external.host/js/script2.js', 'targetie' => null);
$this->assertEquals($expected, $handler->getJsFileList());
}
$expected[] = array('file' => '//external.host/js/script.js', 'targetie' => null); public function testExternalFile2()
$this->assertEquals($expected, $handler->getJsFileList()); {
}); $handler = new FrontEndFileHandler();
$handler->loadFile(array('//external.host/js/script.js'));
$handler->loadFile(array('///external.host/js/script.js'));
$this->specify("target IE (css)", function() { $expected[] = array('file' => '//external.host/js/script.js', 'targetie' => null);
$handler = new FrontEndFileHandler(); $this->assertEquals($expected, $handler->getJsFileList());
$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'); public function testExternalFile3()
$expected[] = array('file' => '/rhymix/common/css/common.css','media'=>'all', 'targetie' => 'ie7'); {
$expected[] = array('file' => '/rhymix/common/css/common.css', 'media'=>'all', 'targetie' => 'ie8'); $handler = new FrontEndFileHandler();
$this->assertEquals($expected, $handler->getCssFileList()); $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("media", function() { $expected[] = array('file' => 'http://external.host/css/style1.css', 'media'=>'all', 'targetie' => null);
$handler = new FrontEndFileHandler(); $expected[] = array('file' => 'https://external.host/css/style2.css', 'media'=>'all', 'targetie' => null);
$handler->loadFile(array('./common/css/common.css', 'all')); $expected[] = array('file' => 'https://external.host/css/style3.css?foo=bar&t=123', 'media'=>'all', 'targetie' => null);
$handler->loadFile(array('./common/css/common.css', 'screen')); $this->assertEquals($expected, $handler->getCssFileList());
$handler->loadFile(array('./common/css/common.css', 'handled')); }
$expected[] = array('file' => '/rhymix/common/css/common.css', 'media'=>'all', 'targetie' => null); public function testExternalFile4()
$expected[] = array('file' => '/rhymix/common/css/common.css','media'=>'screen', 'targetie' => null); {
$expected[] = array('file' => '/rhymix/common/css/common.css', 'media'=>'handled', 'targetie' => null); $handler = new FrontEndFileHandler();
$this->assertEquals($expected, $handler->getCssFileList()); $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());
}
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']);
}
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());
}
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'));
$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' => '/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'; FrontEndFileHandler::$minify = 'all';
$this->specify("minify (css)", function() { $handler = new FrontEndFileHandler();
$handler = new FrontEndFileHandler(); $handler->loadFile(array('./common/css/rhymix.less'));
$handler->loadFile(array('./common/css/rhymix.less')); $result = $handler->getCssFileList(true);
$result = $handler->getCssFileList(true); $this->assertRegexp('/\.rhymix\.less\.min\.css\b/', $result[0]['file']);
$this->assertRegexp('/\.rhymix\.less\.min\.css\b/', $result[0]['file']); $this->assertEquals('all', $result[0]['media']);
$this->assertEquals('all', $result[0]['media']); $this->assertEmpty($result[0]['targetie']);
$this->assertEmpty($result[0]['targetie']);
});
$this->specify("minify (js)", function() { $handler = new FrontEndFileHandler();
$handler = new FrontEndFileHandler(); $handler->loadFile(array('./common/js/common.js', 'head'));
$handler->loadFile(array('./common/js/common.js', 'head')); $result = $handler->getJsFileList('head', true);
$result = $handler->getJsFileList('head', true); $this->assertRegexp('/minified\/common\.js\.common\.min\.js\?\d+$/', $result[0]['file']);
$this->assertRegexp('/minified\/common\.js\.common\.min\.js\?\d+$/', $result[0]['file']); $this->assertEmpty($result[0]['targetie']);
$this->assertEmpty($result[0]['targetie']);
});
FrontEndFileHandler::$minify = 'none'; FrontEndFileHandler::$minify = 'none';
}
public function testConcat()
{
FrontEndFileHandler::$concat = 'css'; FrontEndFileHandler::$concat = 'css';
$this->specify("concat (css)", function() { $handler = new FrontEndFileHandler();
$handler = new FrontEndFileHandler(); $handler->loadFile(array('./common/css/rhymix.less'));
$handler->loadFile(array('./common/css/rhymix.less')); $handler->loadFile(array('./common/css/bootstrap-responsive.css'));
$handler->loadFile(array('./common/css/bootstrap-responsive.css')); $handler->loadFile(array('http://external.host/style.css'));
$handler->loadFile(array('http://external.host/style.css')); $handler->loadFile(array('./common/css/bootstrap.css', null, 'IE'));
$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.source1.css')); $handler->loadFile(array('./tests/_data/formatter/concat.source2.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.target1.css')); $handler->loadFile(array('./tests/_data/formatter/concat.target2.css'));
$handler->loadFile(array('./tests/_data/formatter/concat.target2.css')); $result = $handler->getCssFileList(true);
$result = $handler->getCssFileList(true); $this->assertEquals(4, count($result));
$this->assertEquals(4, count($result)); $this->assertRegexp('/combined\/[0-9a-f]+\.css\?\d+$/', $result[0]['file']);
$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('/rhymix/common/css/bootstrap.css' . $this->_filemtime('common/css/bootstrap.css'), $result[1]['file']); $this->assertEquals('IE', $result[1]['targetie']);
$this->assertEquals('IE', $result[1]['targetie']); $this->assertEquals('http://external.host/style.css', $result[2]['file']);
$this->assertEquals('http://external.host/style.css', $result[2]['file']); $this->assertRegexp('/combined\/[0-9a-f]+\.css\?\d+$/', $result[3]['file']);
$this->assertRegexp('/combined\/[0-9a-f]+\.css\?\d+$/', $result[3]['file']);
});
FrontEndFileHandler::$concat = 'js'; FrontEndFileHandler::$concat = 'js';
$this->specify("concat (js)", function() { $handler = new FrontEndFileHandler();
$handler = new FrontEndFileHandler(); $handler->loadFile(array('./common/js/common.js', 'head'));
$handler->loadFile(array('./common/js/common.js', 'head')); $handler->loadFile(array('./common/js/debug.js', 'head'));
$handler->loadFile(array('./common/js/debug.js', 'head')); $handler->loadFile(array('./common/js/html5.js', 'head'));
$handler->loadFile(array('./common/js/html5.js', 'head')); $handler->loadFile(array('///external.host/js/script.js'));
$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.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.source2.js', 'head', 'gt IE 7')); $handler->loadFile(array('./tests/_data/formatter/concat.target1.js'));
$handler->loadFile(array('./tests/_data/formatter/concat.target1.js')); $handler->loadFile(array('./tests/_data/formatter/concat.target2.js'));
$handler->loadFile(array('./tests/_data/formatter/concat.target2.js')); $result = $handler->getJsFileList('head', true);
$result = $handler->getJsFileList('head', true); $this->assertEquals(3, count($result));
$this->assertEquals(3, count($result)); $this->assertRegexp('/combined\/[0-9a-f]+\.js\?\d+$/', $result[0]['file']);
$this->assertRegexp('/combined\/[0-9a-f]+\.js\?\d+$/', $result[0]['file']); $this->assertEquals('//external.host/js/script.js', $result[1]['file']);
$this->assertEquals('//external.host/js/script.js', $result[1]['file']); $this->assertRegexp('/combined\/[0-9a-f]+\.js\?\d+$/', $result[2]['file']);
$this->assertRegexp('/combined\/[0-9a-f]+\.js\?\d+$/', $result[2]['file']);
});
FrontEndFileHandler::$concat = 'none'; FrontEndFileHandler::$concat = 'none';
}
$this->specify("external file", function() { public function testBlockedScripts()
$handler = new FrontEndFileHandler(); {
$handler->loadFile(array('http://external.host/css/style1.css')); HTMLDisplayHandler::$reservedCSS = $this->reservedCSS;
$handler->loadFile(array('https://external.host/css/style2.css')); HTMLDisplayHandler::$reservedJS = $this->reservedJS;
$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); $handler = new FrontEndFileHandler();
$expected[] = array('file' => 'https://external.host/css/style2.css', 'media'=>'all', 'targetie' => null); $handler->loadFile(array('./common/css/xe.min.css'));
$expected[] = array('file' => 'https://external.host/css/style3.css?foo=bar&t=123', 'media'=>'all', 'targetie' => null); $handler->loadFile(array('./common/js/common.js'));
$this->assertEquals($expected, $handler->getCssFileList()); $handler->loadFile(array('./common/js/xe.js'));
}); $handler->loadFile(array('./common/js/xe.min.js'));
$handler->loadFile(array('./common/js/xml2json.js'));
$this->specify("external file - schemaless", function() { $handler->loadFile(array('./common/js/jquery.js'));
$handler = new FrontEndFileHandler(); $handler->loadFile(array('./common/js/jquery-1.x.min.js'));
$handler->loadFile(array('//external.host/css/style.css')); $handler->loadFile(array('./common/js/jquery-2.0.0.js'));
$handler->loadFile(array('///external.host/css2/style2.css')); $handler->loadFile(array('./common/js/jQuery.min.js'));
$handler->loadFile(array('//external.host/css/style3.css?foo=bar&t=123')); $handler->loadFile(array('http://code.jquery.com/jquery-latest.js'));
$result = $handler->getCssFileList();
$expected[] = array('file' => '//external.host/css/style.css', 'media'=>'all', 'targetie' => null); $this->assertEquals(0, count($result));
$expected[] = array('file' => '//external.host/css2/style2.css', 'media'=>'all', 'targetie' => null); $result = $handler->getJsFileList();
$expected[] = array('file' => '//external.host/css/style3.css?foo=bar&t=123', 'media'=>'all', 'targetie' => null); $this->assertEquals(1, count($result));
$this->assertEquals($expected, $handler->getCssFileList()); $this->assertEquals('/rhymix/common/js/xml2json.js' . $this->_filemtime('common/js/xml2json.js'), $result[0]['file']);
});
$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']);
});
} }
} }

View file

@ -4,17 +4,25 @@ class ValidatorTest extends \Codeception\TestCase\Test
{ {
public function _before() public function _before()
{ {
$ob_level = ob_get_level(); $ob_level = ob_get_level();
//$oContext = Context::getInstance();
//$oContext->init();
Context::init();
while (ob_get_level() > $ob_level) while (ob_get_level() > $ob_level)
{ {
ob_end_clean(); 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() public function testRequired()
{ {
$vd = new Validator(); $vd = new Validator();
@ -187,20 +195,5 @@ class ValidatorTest extends \Codeception\TestCase\Test
$js = $vd->getJsPath(); $js = $vd->getJsPath();
$this->assertEquals(trim(file_get_contents(__DIR__ . '/validator/condition.en.js')), trim(file_get_contents($js))); $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);
}
}
} }

View file

@ -2,6 +2,12 @@
class DBTest extends \Codeception\TestCase\Test class DBTest extends \Codeception\TestCase\Test
{ {
public function _before()
{
$oDB = Rhymix\Framework\DB::getInstance();
$oDB->setDebugComment(false);
}
public function testGetInstance() public function testGetInstance()
{ {
$oDB = Rhymix\Framework\DB::getInstance(); $oDB = Rhymix\Framework\DB::getInstance();

View file

@ -41,7 +41,7 @@ class DebugTest extends \Codeception\TestCase\Test
$errors = Rhymix\Framework\Debug::getErrors(); $errors = Rhymix\Framework\Debug::getErrors();
$this->assertGreaterThanOrEqual(1, count($errors)); $this->assertGreaterThanOrEqual(1, count($errors));
$error = array_pop($errors); $error = array_pop($errors);
$this->assertContains('Rhymix', $error->message); $this->assertStringContainsString('Rhymix', $error->message);
$this->assertEquals($file, $error->file); $this->assertEquals($file, $error->file);
$this->assertEquals($line, $error->line); $this->assertEquals($line, $error->line);
Rhymix\Framework\Debug::clearErrors(); Rhymix\Framework\Debug::clearErrors();

View file

@ -13,36 +13,36 @@ class PaginationTest extends \Codeception\TestCase\Test
public function testCreateLinks() public function testCreateLinks()
{ {
$links = Rhymix\Framework\Pagination::createLinks('index.php?page=', 27, 3); $links = Rhymix\Framework\Pagination::createLinks('index.php?page=', 27, 3);
$this->assertContains('<div class="pagination">', $links); $this->assertStringContainsString('<div class="pagination">', $links);
$this->assertContains('<a href="index.php?page=3">', $links); $this->assertStringContainsString('<a href="index.php?page=3">', $links);
$this->assertContains('<span class="page_number">1</span>', $links); $this->assertStringContainsString('<span class="page_number">1</span>', $links);
$this->assertContains('<span class="page_number">10</span>', $links); $this->assertStringContainsString('<span class="page_number">10</span>', $links);
$links = Rhymix\Framework\Pagination::createLinks('/foo/bar/page/', 27, 13); $links = Rhymix\Framework\Pagination::createLinks('/foo/bar/page/', 27, 13);
$this->assertContains('<div class="pagination">', $links); $this->assertStringContainsString('<div class="pagination">', $links);
$this->assertContains('<a href="/foo/bar/page/13">', $links); $this->assertStringContainsString('<a href="/foo/bar/page/13">', $links);
$this->assertContains('<span class="page_number">11</span>', $links); $this->assertStringContainsString('<span class="page_number">11</span>', $links);
$this->assertContains('<span class="page_number">20</span>', $links); $this->assertStringContainsString('<span class="page_number">20</span>', $links);
$links = Rhymix\Framework\Pagination::createLinks('/rhymix?page=$PAGE&foo=bar', 27, 25); $links = Rhymix\Framework\Pagination::createLinks('/rhymix?page=$PAGE&foo=bar', 27, 25);
$this->assertContains('<div class="pagination">', $links); $this->assertStringContainsString('<div class="pagination">', $links);
$this->assertContains('<a href="/rhymix?page=27&amp;foo=bar">', $links); $this->assertStringContainsString('<a href="/rhymix?page=27&amp;foo=bar">', $links);
$this->assertContains('<span class="page_number">21</span>', $links); $this->assertStringContainsString('<span class="page_number">21</span>', $links);
$this->assertContains('<span class="page_number">27</span>', $links); $this->assertStringContainsString('<span class="page_number">27</span>', $links);
$links = Rhymix\Framework\Pagination::createLinks('p', 27, 3, 10, Rhymix\Framework\Pagination::COUNT_STYLE_CONTINUOUS); $links = Rhymix\Framework\Pagination::createLinks('p', 27, 3, 10, Rhymix\Framework\Pagination::COUNT_STYLE_CONTINUOUS);
$this->assertContains('<div class="pagination">', $links); $this->assertStringContainsString('<div class="pagination">', $links);
$this->assertContains('<span class="page_number">1</span>', $links); $this->assertStringContainsString('<span class="page_number">1</span>', $links);
$this->assertContains('<span class="page_number">10</span>', $links); $this->assertStringContainsString('<span class="page_number">10</span>', $links);
$links = Rhymix\Framework\Pagination::createLinks('p', 27, 13, 10, Rhymix\Framework\Pagination::COUNT_STYLE_CONTINUOUS); $links = Rhymix\Framework\Pagination::createLinks('p', 27, 13, 10, Rhymix\Framework\Pagination::COUNT_STYLE_CONTINUOUS);
$this->assertContains('<div class="pagination">', $links); $this->assertStringContainsString('<div class="pagination">', $links);
$this->assertContains('<span class="page_number">9</span>', $links); $this->assertStringContainsString('<span class="page_number">9</span>', $links);
$this->assertContains('<span class="page_number">18</span>', $links); $this->assertStringContainsString('<span class="page_number">18</span>', $links);
$links = Rhymix\Framework\Pagination::createLinks('p', 27, 25, 10, Rhymix\Framework\Pagination::COUNT_STYLE_CONTINUOUS); $links = Rhymix\Framework\Pagination::createLinks('p', 27, 25, 10, Rhymix\Framework\Pagination::COUNT_STYLE_CONTINUOUS);
$this->assertContains('<div class="pagination">', $links); $this->assertStringContainsString('<div class="pagination">', $links);
$this->assertContains('<span class="page_number">18</span>', $links); $this->assertStringContainsString('<span class="page_number">18</span>', $links);
$this->assertContains('<span class="page_number">27</span>', $links); $this->assertStringContainsString('<span class="page_number">27</span>', $links);
} }
} }

View file

@ -171,14 +171,14 @@ class StorageTest extends \Codeception\TestCase\Test
$this->assertTrue(Rhymix\Framework\Storage::write($testfile . '1', '')); $this->assertTrue(Rhymix\Framework\Storage::write($testfile . '1', ''));
$this->assertTrue(file_exists($testfile . '1')); $this->assertTrue(file_exists($testfile . '1'));
$this->assertEquals(0, filesize($testfile . '1')); $this->assertEquals(0, filesize($testfile . '1'));
$this->assertEmpty(0, glob($testfile . '1.tmp.*')); $this->assertEmpty(glob($testfile . '1.tmp.*'));
// Empty stream copy test // Empty stream copy test
$stream = fopen('php://temp', 'r'); $stream = fopen('php://temp', 'r');
$this->assertTrue(Rhymix\Framework\Storage::write($testfile . '2', $stream)); $this->assertTrue(Rhymix\Framework\Storage::write($testfile . '2', $stream));
$this->assertTrue(file_exists($testfile . '2')); $this->assertTrue(file_exists($testfile . '2'));
$this->assertEquals(0, filesize($testfile . '2')); $this->assertEquals(0, filesize($testfile . '2'));
$this->assertEmpty(0, glob($testfile . '2.tmp.*')); $this->assertEmpty(glob($testfile . '2.tmp.*'));
fclose($stream); fclose($stream);
// Umask test // Umask test

View file

@ -45,19 +45,19 @@ class DBTableParserTest extends \Codeception\TestCase\Test
{ {
$table = Rhymix\Framework\Parsers\DBTableParser::loadXML(\RX_BASEDIR . 'tests/_data/dbtable/example.xml'); $table = Rhymix\Framework\Parsers\DBTableParser::loadXML(\RX_BASEDIR . 'tests/_data/dbtable/example.xml');
$sql = $table->getCreateQuery('rx_'); $sql = $table->getCreateQuery('rx_');
$this->assertContains('CREATE TABLE `rx_example` (', $sql); $this->assertStringContainsString('CREATE TABLE `rx_example` (', $sql);
$this->assertContains('`comment_srl` BIGINT NOT NULL,', $sql); $this->assertStringContainsString('`comment_srl` BIGINT NOT NULL,', $sql);
$this->assertContains('`status` VARCHAR(20) DEFAULT \'PUBLIC\',', $sql); $this->assertStringContainsString('`status` VARCHAR(20) DEFAULT \'PUBLIC\',', $sql);
$this->assertContains('PRIMARY KEY (`example_srl`),', $sql); $this->assertStringContainsString('PRIMARY KEY (`example_srl`),', $sql);
$this->assertContains('INDEX `idx_document_srl` (`document_srl`),', $sql); $this->assertStringContainsString('INDEX `idx_document_srl` (`document_srl`),', $sql);
$this->assertContains('INDEX `idx_module_document_srl` (`module_srl`, `document_srl`),', $sql); $this->assertStringContainsString('INDEX `idx_module_document_srl` (`module_srl`, `document_srl`),', $sql);
$this->assertContains('INDEX `idx_status` (`status`(6)),', $sql); $this->assertStringContainsString('INDEX `idx_status` (`status`(6)),', $sql);
$this->assertContains('UNIQUE INDEX `unique_list_order` (`list_order`),', $sql); $this->assertStringContainsString('UNIQUE INDEX `unique_list_order` (`list_order`),', $sql);
$this->assertContains('SPATIAL INDEX `spatial_geometry` (`geometry`),', $sql); $this->assertStringContainsString('SPATIAL INDEX `spatial_geometry` (`geometry`),', $sql);
$this->assertContains('FULLTEXT INDEX `fulltext_description` (`description`) WITH PARSER ngram,', $sql); $this->assertStringContainsString('FULLTEXT INDEX `fulltext_description` (`description`) WITH PARSER ngram,', $sql);
$this->assertContains('FOREIGN KEY (`module_srl`) REFERENCES `rx_module` (`module_srl`) ON DELETE CASCADE ON UPDATE RESTRICT', $sql); $this->assertStringContainsString('FOREIGN KEY (`module_srl`) REFERENCES `rx_module` (`module_srl`) ON DELETE CASCADE ON UPDATE RESTRICT', $sql);
$this->assertContains('CHECK (list_order < 0)', $sql); $this->assertStringContainsString('CHECK (list_order < 0)', $sql);
$this->assertContains('CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci', $sql); $this->assertStringContainsString('CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci', $sql);
$this->assertContains('ENGINE = InnoDB', $sql); $this->assertStringContainsString('ENGINE = InnoDB', $sql);
} }
} }

View file

@ -45,12 +45,12 @@ class ModuleActionParserTest extends \Codeception\TestCase\Test
// Grant // Grant
$this->assertEquals(['view'], array_keys(get_object_vars($info->grant))); $this->assertEquals(['view'], array_keys(get_object_vars($info->grant)));
$this->assertEquals('View', $info->grant->view->title); $this->assertContains($info->grant->view->title, ['View', '열람']);
$this->assertEquals('guest', $info->grant->view->default); $this->assertEquals('guest', $info->grant->view->default);
// Menu // Menu
$this->assertEquals(['test'], array_keys(get_object_vars($info->menu))); $this->assertEquals(['test'], array_keys(get_object_vars($info->menu)));
$this->assertEquals('Test Menu', $info->menu->test->title); $this->assertContains($info->menu->test->title, ['Test Menu', '테스트 메뉴']);
$this->assertEquals('dispTestAdminIndex', $info->menu->test->index); $this->assertEquals('dispTestAdminIndex', $info->menu->test->index);
$this->assertEquals(['dispTestAdminIndex'], $info->menu->test->acts); $this->assertEquals(['dispTestAdminIndex'], $info->menu->test->acts);
$this->assertEquals('all', $info->menu->test->type); $this->assertEquals('all', $info->menu->test->type);

View file

@ -95,7 +95,7 @@ class LegacyTest extends \Codeception\TestCase\Test
public function testGetEncodedEmailAddress() public function testGetEncodedEmailAddress()
{ {
$this->assertNotEquals('devops@rhymix.org', getEncodeEmailAddress('devops@rhymix.org')); $this->assertNotEquals('devops@rhymix.org', getEncodeEmailAddress('devops@rhymix.org'));
$this->assertContains('&#X', getEncodeEmailAddress('devops@rhymix.org')); $this->assertStringContainsString('&#X', getEncodeEmailAddress('devops@rhymix.org'));
} }
public function testGetMicrotime() public function testGetMicrotime()