mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 19:21:40 +09:00
Update unit tests to check for minification
This commit is contained in:
parent
bfaa2c170b
commit
22910608a2
2 changed files with 41 additions and 23 deletions
|
|
@ -9,6 +9,7 @@ class FrontEndFileHandler extends Handler
|
||||||
{
|
{
|
||||||
|
|
||||||
static $isSSL = null;
|
static $isSSL = null;
|
||||||
|
static $minify = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map for css
|
* Map for css
|
||||||
|
|
@ -143,11 +144,10 @@ class FrontEndFileHandler extends Handler
|
||||||
private function getFileInfo($fileName, $targetIe = '', $media = 'all')
|
private function getFileInfo($fileName, $targetIe = '', $media = 'all')
|
||||||
{
|
{
|
||||||
static $existsInfo = array();
|
static $existsInfo = array();
|
||||||
static $autoMinify = null;
|
|
||||||
|
|
||||||
if($autoMinify === null)
|
if(self::$minify === null)
|
||||||
{
|
{
|
||||||
$autoMinify = Context::getDBInfo()->minify_scripts === 'N' ? false : true;
|
self::$minify = Context::getDBInfo()->minify_scripts === 'N' ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($existsInfo[$existsKey]))
|
if(isset($existsInfo[$existsKey]))
|
||||||
|
|
@ -175,7 +175,7 @@ class FrontEndFileHandler extends Handler
|
||||||
$file->cdnPath = $this->_normalizeFilePath($pathInfo['dirname']);
|
$file->cdnPath = $this->_normalizeFilePath($pathInfo['dirname']);
|
||||||
|
|
||||||
// Minify file
|
// Minify file
|
||||||
if($autoMinify && !$file->isMinified && strpos($file->filePath, '://') === false && strpos($file->filePath, 'common/js/plugins') === false)
|
if(self::$minify && !$file->isMinified && strpos($file->filePath, '://') === false && strpos($file->filePath, 'common/js/plugins') === false)
|
||||||
{
|
{
|
||||||
$originalFilePath = $file->fileRealPath . '/' . $pathInfo['basename'];
|
$originalFilePath = $file->fileRealPath . '/' . $pathInfo['basename'];
|
||||||
if(($file->fileExtension === 'css' || $file->fileExtension === 'js') && file_exists($originalFilePath))
|
if(($file->fileExtension === 'css' || $file->fileExtension === 'js') && file_exists($originalFilePath))
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,11 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
|
||||||
public function testFrontEndFileHandler()
|
public function testFrontEndFileHandler()
|
||||||
{
|
{
|
||||||
$handler = new FrontEndFileHandler();
|
$handler = new FrontEndFileHandler();
|
||||||
|
$db_info = Context::getDBInfo();
|
||||||
|
$db_info->minify_scripts = 'N';
|
||||||
|
Context::setDBInfo($db_info);
|
||||||
|
|
||||||
$this->specify("js(head)", function() {
|
$this->specify("js(head)", function() use($db_info) {
|
||||||
$handler = new FrontEndFileHandler();
|
$handler = new FrontEndFileHandler();
|
||||||
$handler->loadFile(array('./common/js/jquery.js'));
|
$handler->loadFile(array('./common/js/jquery.js'));
|
||||||
$handler->loadFile(array('./common/js/js_app.js', 'head'));
|
$handler->loadFile(array('./common/js/js_app.js', 'head'));
|
||||||
|
|
@ -22,10 +25,12 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
|
||||||
$handler->loadFile(array('./common/js/common.js', 'head'));
|
$handler->loadFile(array('./common/js/common.js', 'head'));
|
||||||
$handler->loadFile(array('./common/js/xml_js_filter.js', 'body'));
|
$handler->loadFile(array('./common/js/xml_js_filter.js', 'body'));
|
||||||
|
|
||||||
if(__DEBUG__ || !__XE_VERSION_STABLE__)
|
if($db_info->minify_scripts === 'N')
|
||||||
{
|
{
|
||||||
$expected[] = array('file' => '/xe/common/js/jquery.js' . $this->_filemtime('common/js/jquery.js'), 'targetie' => null);
|
$expected[] = array('file' => '/xe/common/js/jquery.js' . $this->_filemtime('common/js/jquery.js'), 'targetie' => null);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$expected[] = array('file' => '/xe/common/js/jquery.min.js' . $this->_filemtime('common/js/jquery.min.js'), 'targetie' => null);
|
$expected[] = array('file' => '/xe/common/js/jquery.min.js' . $this->_filemtime('common/js/jquery.min.js'), 'targetie' => null);
|
||||||
}
|
}
|
||||||
$expected[] = array('file' => '/xe/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null);
|
$expected[] = array('file' => '/xe/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null);
|
||||||
|
|
@ -33,12 +38,12 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
|
||||||
$this->assertEquals($handler->getJsFileList(), $expected);
|
$this->assertEquals($handler->getJsFileList(), $expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->specify("js(body)", function() {
|
$this->specify("js(body)", function() use($db_info) {
|
||||||
$handler = new FrontEndFileHandler();
|
$handler = new FrontEndFileHandler();
|
||||||
$handler->loadFile(array('./common/js/jquery.js', 'body'));
|
$handler->loadFile(array('./common/js/jquery.js', 'body'));
|
||||||
$handler->loadFile(array('./common/js/xml_js_filter.js', 'head'));
|
$handler->loadFile(array('./common/js/xml_js_filter.js', 'head'));
|
||||||
|
|
||||||
if(__DEBUG__ || !__XE_VERSION_STABLE__)
|
if($db_info->minify_scripts === 'N')
|
||||||
{
|
{
|
||||||
$expected[] = array('file' => '/xe/common/js/jquery.js' . $this->_filemtime('common/js/jquery.js'), 'targetie' => null);
|
$expected[] = array('file' => '/xe/common/js/jquery.js' . $this->_filemtime('common/js/jquery.js'), 'targetie' => null);
|
||||||
}
|
}
|
||||||
|
|
@ -49,7 +54,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
|
||||||
$this->assertEquals($handler->getJsFileList('body'), $expected);
|
$this->assertEquals($handler->getJsFileList('body'), $expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->specify("css", function() {
|
$this->specify("css", function() use($db_info) {
|
||||||
$handler = new FrontEndFileHandler();
|
$handler = new FrontEndFileHandler();
|
||||||
$handler->loadFile(array('./common/css/xe.css'));
|
$handler->loadFile(array('./common/css/xe.css'));
|
||||||
$handler->loadFile(array('./common/css/mobile.css'));
|
$handler->loadFile(array('./common/css/mobile.css'));
|
||||||
|
|
@ -58,7 +63,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
|
||||||
$this->assertEquals($handler->getCssFileList(), $expected);
|
$this->assertEquals($handler->getCssFileList(), $expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->specify("order (duplicate)", function() {
|
$this->specify("order (duplicate)", function() use($db_info) {
|
||||||
$handler = new FrontEndFileHandler();
|
$handler = new FrontEndFileHandler();
|
||||||
$handler->loadFile(array('./common/js/jquery.js', 'head', '', -100000));
|
$handler->loadFile(array('./common/js/jquery.js', 'head', '', -100000));
|
||||||
$handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000));
|
$handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000));
|
||||||
|
|
@ -71,7 +76,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
|
||||||
$handler->loadFile(array('./common/js/xml_handler.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/xml_js_filter.js', 'head', '', -100000));
|
||||||
|
|
||||||
if(__DEBUG__ || !__XE_VERSION_STABLE__)
|
if($db_info->minify_scripts === 'N')
|
||||||
{
|
{
|
||||||
$expected[] = array('file' => '/xe/common/js/jquery.js' . $this->_filemtime('common/js/jquery.js'), 'targetie' => null);
|
$expected[] = array('file' => '/xe/common/js/jquery.js' . $this->_filemtime('common/js/jquery.js'), 'targetie' => null);
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +91,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
|
||||||
$this->assertEquals($handler->getJsFileList(), $expected);
|
$this->assertEquals($handler->getJsFileList(), $expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->specify("order (redefine)", function() {
|
$this->specify("order (redefine)", function() use($db_info) {
|
||||||
$handler = new FrontEndFileHandler();
|
$handler = new FrontEndFileHandler();
|
||||||
$handler->loadFile(array('./common/js/xml_handler.js', 'head', '', 1));
|
$handler->loadFile(array('./common/js/xml_handler.js', 'head', '', 1));
|
||||||
$handler->loadFile(array('./common/js/jquery.js', 'head', '', -100000));
|
$handler->loadFile(array('./common/js/jquery.js', 'head', '', -100000));
|
||||||
|
|
@ -94,7 +99,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
|
||||||
$handler->loadFile(array('./common/js/common.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_js_filter.js', 'head', '', -100000));
|
||||||
|
|
||||||
if(__DEBUG__ || !__XE_VERSION_STABLE__)
|
if($db_info->minify_scripts === 'N')
|
||||||
{
|
{
|
||||||
$expected[] = array('file' => '/xe/common/js/jquery.js' . $this->_filemtime('common/js/jquery.js'), 'targetie' => null);
|
$expected[] = array('file' => '/xe/common/js/jquery.js' . $this->_filemtime('common/js/jquery.js'), 'targetie' => null);
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +114,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
|
||||||
$this->assertEquals($handler->getJsFileList(), $expected);
|
$this->assertEquals($handler->getJsFileList(), $expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->specify("unload", function() {
|
$this->specify("unload", function() use($db_info) {
|
||||||
$handler = new FrontEndFileHandler();
|
$handler = new FrontEndFileHandler();
|
||||||
$handler->loadFile(array('./common/js/jquery.js', 'head', '', -100000));
|
$handler->loadFile(array('./common/js/jquery.js', 'head', '', -100000));
|
||||||
$handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000));
|
$handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000));
|
||||||
|
|
@ -125,13 +130,13 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
|
||||||
$this->assertEquals($handler->getJsFileList(), $expected);
|
$this->assertEquals($handler->getJsFileList(), $expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->specify("target IE(js)", function() {
|
$this->specify("target IE(js)", function() use($db_info) {
|
||||||
$handler = new FrontEndFileHandler();
|
$handler = new FrontEndFileHandler();
|
||||||
$handler->loadFile(array('./common/js/jquery.js', 'head', 'ie6'));
|
$handler->loadFile(array('./common/js/jquery.js', 'head', 'ie6'));
|
||||||
$handler->loadFile(array('./common/js/jquery.js', 'head', 'ie7'));
|
$handler->loadFile(array('./common/js/jquery.js', 'head', 'ie7'));
|
||||||
$handler->loadFile(array('./common/js/jquery.js', 'head', 'ie8'));
|
$handler->loadFile(array('./common/js/jquery.js', 'head', 'ie8'));
|
||||||
|
|
||||||
if(__DEBUG__ || !__XE_VERSION_STABLE__)
|
if($db_info->minify_scripts === 'N')
|
||||||
{
|
{
|
||||||
$expected[] = array('file' => '/xe/common/js/jquery.js' . $this->_filemtime('common/js/jquery.js'), 'targetie' => 'ie6');
|
$expected[] = array('file' => '/xe/common/js/jquery.js' . $this->_filemtime('common/js/jquery.js'), 'targetie' => 'ie6');
|
||||||
$expected[] = array('file' => '/xe/common/js/jquery.js' . $this->_filemtime('common/js/jquery.js'), 'targetie' => 'ie7');
|
$expected[] = array('file' => '/xe/common/js/jquery.js' . $this->_filemtime('common/js/jquery.js'), 'targetie' => 'ie7');
|
||||||
|
|
@ -146,7 +151,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
|
||||||
$this->assertEquals($handler->getJsFileList(), $expected);
|
$this->assertEquals($handler->getJsFileList(), $expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->specify("external file - schemaless", function() {
|
$this->specify("external file - schemaless", function() use($db_info) {
|
||||||
$handler = new FrontEndFileHandler();
|
$handler = new FrontEndFileHandler();
|
||||||
$handler->loadFile(array('http://external.host/js/script.js'));
|
$handler->loadFile(array('http://external.host/js/script.js'));
|
||||||
$handler->loadFile(array('https://external.host/js/script.js'));
|
$handler->loadFile(array('https://external.host/js/script.js'));
|
||||||
|
|
@ -160,7 +165,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
|
||||||
$this->assertEquals($handler->getJsFileList(), $expected);
|
$this->assertEquals($handler->getJsFileList(), $expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->specify("external file - schemaless", function() {
|
$this->specify("external file - schemaless", function() use($db_info) {
|
||||||
$handler = new FrontEndFileHandler();
|
$handler = new FrontEndFileHandler();
|
||||||
$handler->loadFile(array('//external.host/js/script.js'));
|
$handler->loadFile(array('//external.host/js/script.js'));
|
||||||
$handler->loadFile(array('///external.host/js/script.js'));
|
$handler->loadFile(array('///external.host/js/script.js'));
|
||||||
|
|
@ -169,7 +174,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
|
||||||
$this->assertEquals($handler->getJsFileList(), $expected);
|
$this->assertEquals($handler->getJsFileList(), $expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->specify("target IE(css)", function() {
|
$this->specify("target IE(css)", function() use($db_info) {
|
||||||
$handler = new FrontEndFileHandler();
|
$handler = new FrontEndFileHandler();
|
||||||
$handler->loadFile(array('./common/css/common.css', null, 'ie6'));
|
$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, 'ie7'));
|
||||||
|
|
@ -181,7 +186,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
|
||||||
$this->assertEquals($handler->getCssFileList(), $expected);
|
$this->assertEquals($handler->getCssFileList(), $expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->specify("media", function() {
|
$this->specify("media", function() use($db_info) {
|
||||||
$handler = new FrontEndFileHandler();
|
$handler = new FrontEndFileHandler();
|
||||||
$handler->loadFile(array('./common/css/common.css', 'all'));
|
$handler->loadFile(array('./common/css/common.css', 'all'));
|
||||||
$handler->loadFile(array('./common/css/common.css', 'screen'));
|
$handler->loadFile(array('./common/css/common.css', 'screen'));
|
||||||
|
|
@ -193,7 +198,20 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
|
||||||
$this->assertEquals($handler->getCssFileList(), $expected);
|
$this->assertEquals($handler->getCssFileList(), $expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->specify("external file", function() {
|
$db_info->minify_scripts = 'Y';
|
||||||
|
Context::setDBInfo($db_info);
|
||||||
|
FrontEndFileHandler::$minify = null;
|
||||||
|
|
||||||
|
$this->specify("minify", function() use($db_info) {
|
||||||
|
$handler = new FrontEndFileHandler();
|
||||||
|
$handler->loadFile(array('./common/css/xe.css'));
|
||||||
|
$handler->loadFile(array('./common/css/mobile.css'));
|
||||||
|
$expected[] = array('file' => '/xe/files/cache/minify/common.css.xe.min.css' . '?' . date('YmdHis'), 'media' => 'all', 'targetie' => null);
|
||||||
|
$expected[] = array('file' => '/xe/files/cache/minify/common.css.mobile.min.css' . '?' . date('YmdHis'), 'media' => 'all', 'targetie' => null);
|
||||||
|
$this->assertEquals($handler->getCssFileList(), $expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->specify("external file", function() use($db_info) {
|
||||||
$handler = new FrontEndFileHandler();
|
$handler = new FrontEndFileHandler();
|
||||||
$handler->loadFile(array('http://external.host/css/style1.css'));
|
$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/style2.css'));
|
||||||
|
|
@ -203,7 +221,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
|
||||||
$this->assertEquals($handler->getCssFileList(), $expected);
|
$this->assertEquals($handler->getCssFileList(), $expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->specify("external file - schemaless", function() {
|
$this->specify("external file - schemaless", function() use($db_info) {
|
||||||
$handler = new FrontEndFileHandler();
|
$handler = new FrontEndFileHandler();
|
||||||
$handler->loadFile(array('//external.host/css/style.css'));
|
$handler->loadFile(array('//external.host/css/style.css'));
|
||||||
$handler->loadFile(array('///external.host/css2/style2.css'));
|
$handler->loadFile(array('///external.host/css2/style2.css'));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue