diff --git a/classes/context/Context.class.php b/classes/context/Context.class.php index 68198b31b..1fbf807a4 100644 --- a/classes/context/Context.class.php +++ b/classes/context/Context.class.php @@ -984,13 +984,16 @@ class Context * @see arrayConvWalkCallback will replaced array_walk_recursive in >=PHP5 * @return object converted object */ - public static function doConvertEncoding(&$val, $key = null, $charset) + public static function doConvertEncoding(&$val, $key = null, $charset = 'CP949') { if (is_array($val)) { - array_walk($val,'Context::doConvertEncoding',$charset); + array_walk($val,'Context::doConvertEncoding', $charset); + } + else + { + $val = iconv($charset, 'UTF-8', $val); } - else $val = iconv($charset,'UTF-8',$val); } /** @@ -2074,12 +2077,12 @@ class Context * case js : * $args[0]: file name, * $args[1]: type (head | body), - * $args[2]: target IE, + * $args[2]: unused, * $args[3]: index * case css : * $args[0]: file name, * $args[1]: media, - * $args[2]: target IE, + * $args[2]: source type hint, * $args[3]: index * */ @@ -2097,13 +2100,13 @@ class Context * Unload front end file * * @param string $file File name with path - * @param string $targetIe Target IE + * @param string $unused * @param string $media Media query * @return void */ - public static function unloadFile($file, $targetIe = '', $media = 'all') + public static function unloadFile($file, $unused = '', $media = 'all') { - self::$_oFrontEndFileHandler->unloadFile($file, $targetIe, $media); + self::$_oFrontEndFileHandler->unloadFile($file, '', $media); } /** @@ -2122,15 +2125,15 @@ class Context * * @deprecated * @param string $file File name with path - * @param string $optimized optimized (That seems to not use) - * @param string $targetie target IE + * @param string $unused1 + * @param string $unused2 * @param string $index index * @param string $type Added position. (head:.., body:..) * @param bool $isRuleset Use ruleset * @param string $autoPath If path not readed, set the path automatically. * @return void */ - public static function addJsFile($file, $optimized = FALSE, $targetie = '', $index = 0, $type = 'head', $isRuleset = FALSE, $autoPath = null) + public static function addJsFile($file, $unused1 = '', $unused2 = '', $index = 0, $type = 'head', $isRuleset = FALSE, $autoPath = null) { if($isRuleset) { @@ -2147,7 +2150,7 @@ class Context $file = $validator->getJsPath(); } - self::$_oFrontEndFileHandler->loadFile(array($file, $type, $targetie, $index)); + self::$_oFrontEndFileHandler->loadFile(array($file, $type, '', $index)); } /** @@ -2155,13 +2158,11 @@ class Context * * @deprecated * @param string $file File name with path - * @param string $optimized optimized (That seems to not use) - * @param string $targetie target IE * @return void */ - public static function unloadJsFile($file, $optimized = FALSE, $targetie = '') + public static function unloadJsFile($file) { - self::$_oFrontEndFileHandler->unloadFile($file, $targetie); + self::$_oFrontEndFileHandler->unloadFile($file); } /** @@ -2216,7 +2217,7 @@ class Context * * @param string $type Added position. (head:.., body:..) * @param bool $finalize (optional) - * @return array Returns javascript file list. Array contains file, targetie. + * @return array Returns javascript file list. */ public static function getJsFile($type = 'head', $finalize = false) { @@ -2228,16 +2229,16 @@ class Context * * @deprecated * @param string $file File name with path - * @param string $optimized optimized (That seems to not use) + * @param string $unused1 * @param string $media Media query - * @param string $targetie target IE + * @param string $unused2 * @param string $index index * @return void * */ - public static function addCSSFile($file, $optimized = FALSE, $media = 'all', $targetie = '', $index = 0) + public static function addCSSFile($file, $unused1 = '', $media = 'all', $unused2 = '', $index = 0) { - self::$_oFrontEndFileHandler->loadFile(array($file, $media, $targetie, $index)); + self::$_oFrontEndFileHandler->loadFile(array($file, $media, '', $index)); } /** @@ -2245,14 +2246,13 @@ class Context * * @deprecated * @param string $file File name with path - * @param string $optimized optimized (That seems to not use) + * @param string $unused * @param string $media Media query - * @param string $targetie target IE * @return void */ - public static function unloadCSSFile($file, $optimized = FALSE, $media = 'all', $targetie = '') + public static function unloadCSSFile($file, $unused = '', $media = 'all') { - self::$_oFrontEndFileHandler->unloadFile($file, $targetie, $media); + self::$_oFrontEndFileHandler->unloadFile($file, '', $media); } /** @@ -2269,7 +2269,7 @@ class Context * Return a list of css files * * @param bool $finalize (optional) - * @return array Returns css file list. Array contains file, media, targetie. + * @return array Returns css file list. */ public static function getCSSFile($finalize = false) { diff --git a/classes/frontendfile/FrontEndFileHandler.class.php b/classes/frontendfile/FrontEndFileHandler.class.php index e21e55a46..72b594dab 100644 --- a/classes/frontendfile/FrontEndFileHandler.class.php +++ b/classes/frontendfile/FrontEndFileHandler.class.php @@ -74,12 +74,12 @@ class FrontEndFileHandler extends Handler * case js * $args[0]: file name * $args[1]: type (head | body) - * $args[2]: target IE + * $args[2]: unused (previously targetIe) * $args[3]: index * case css * $args[0]: file name * $args[1]: media - * $args[2]: target IE / source type hint + * $args[2]: source type hint * $args[3]: index * $args[4]: vars for LESS and SCSS * @@ -228,20 +228,18 @@ class FrontEndFileHandler extends Handler $file->isMinified = true; } - // Process targetIe and media attributes - $file->targetIe = $targetIe; + // Since Rhymix 2.1, targetIe is always empty + $file->targetIe = ''; + + // Process media attributes and generate the key if($file->fileExtension == 'css' || $file->fileExtension == 'less' || $file->fileExtension == 'scss') { - $file->media = $media; - if(!$file->media) - { - $file->media = 'all'; - } - $file->key = sprintf('%s/%s:%s:%s', $file->filePath, $file->keyName, $file->targetIe, $file->media); + $file->media = $media ?: 'all'; + $file->key = sprintf('%s/%s:%s', $file->filePath, $file->keyName, $file->media); } else if($file->fileExtension == 'js') { - $file->key = sprintf('%s/%s:%s', $file->filePath, $file->keyName, $file->targetIe); + $file->key = sprintf('%s/%s', $file->filePath, $file->keyName); } return $file; @@ -427,7 +425,7 @@ class FrontEndFileHandler extends Handler * Get css file list * * @param bool $finalize (optional) - * @return array Returns css file list. Array contains file, media, targetie. + * @return array Returns css file list. */ public function getCssFileList($finalize = false) { @@ -471,7 +469,7 @@ class FrontEndFileHandler extends Handler { $url .= '?' . date('YmdHis', filemtime($file->fileFullPath)); } - $result[] = array('file' => $url, 'media' => $file->media, 'targetie' => $file->targetIe); + $result[] = array('file' => $url, 'media' => $file->media); } else { @@ -490,7 +488,7 @@ class FrontEndFileHandler extends Handler Rhymix\Framework\Storage::write(\RX_BASEDIR . $concat_filename, $concat_content); } $concat_filename .= '?' . date('YmdHis', filemtime(\RX_BASEDIR . $concat_filename)); - $result[] = array('file' => \RX_BASEURL . $concat_filename, 'media' => 'all', 'targetie' => ''); + $result[] = array('file' => \RX_BASEURL . $concat_filename, 'media' => 'all'); } } } @@ -505,7 +503,7 @@ class FrontEndFileHandler extends Handler { $url .= '?' . date('YmdHis', filemtime($file->fileFullPath)); } - $result[] = array('file' => $url, 'media' => $file->media, 'targetie' => $file->targetIe); + $result[] = array('file' => $url, 'media' => $file->media); } } } @@ -529,7 +527,7 @@ class FrontEndFileHandler extends Handler * * @param string $type Type of javascript. head, body * @param bool $finalize (optional) - * @return array Returns javascript file list. Array contains file, targetie. + * @return array Returns javascript file list. */ public function getJsFileList($type = 'head', $finalize = false) { @@ -577,7 +575,7 @@ class FrontEndFileHandler extends Handler { $url .= '?' . date('YmdHis', filemtime($file->fileFullPath)); } - $result[] = array('file' => $url, 'targetie' => $file->targetIe); + $result[] = array('file' => $url); } else { @@ -585,7 +583,7 @@ class FrontEndFileHandler extends Handler $concat_max_timestamp = 0; foreach ($concat_fileset as $file) { - $concat_files[] = $file->targetIe ? array($file->fileFullPath, $file->targetIe) : $file->fileFullPath; + $concat_files[] = $file->fileFullPath; $concat_max_timestamp = max($concat_max_timestamp, filemtime($file->fileFullPath)); } $concat_filename = self::$assetdir . '/combined/' . sha1(serialize($concat_files)) . '.js'; @@ -594,7 +592,7 @@ class FrontEndFileHandler extends Handler Rhymix\Framework\Storage::write(\RX_BASEDIR . $concat_filename, Rhymix\Framework\Formatter::concatJS($concat_files, $concat_filename)); } $concat_filename .= '?' . date('YmdHis', filemtime(\RX_BASEDIR . $concat_filename)); - $result[] = array('file' => \RX_BASEURL . $concat_filename, 'targetie' => ''); + $result[] = array('file' => \RX_BASEURL . $concat_filename); } } } @@ -609,7 +607,7 @@ class FrontEndFileHandler extends Handler { $url .= '?' . date('YmdHis', filemtime($file->fileFullPath)); } - $result[] = array('file' => $url, 'targetie' => $file->targetIe); + $result[] = array('file' => $url); } } } @@ -642,7 +640,7 @@ class FrontEndFileHandler extends Handler { foreach ($indexedMap as $file) { - if ($file->isExternalURL || ($file->fileExtension === 'css' && $file->targetIe) || !is_readable($file->fileFullPath)) + if ($file->isExternalURL || !is_readable($file->fileFullPath)) { $concat_key++; $concat_list[$concat_key][] = $file; diff --git a/classes/template/TemplateHandler.class.php b/classes/template/TemplateHandler.class.php index b728c4e5f..9b3c8071d 100644 --- a/classes/template/TemplateHandler.class.php +++ b/classes/template/TemplateHandler.class.php @@ -913,13 +913,13 @@ class TemplateHandler case 'js': if($doUnload) { - $result = vsprintf("Context::unloadFile('%s', '%s');", [$attr['target'] ?? '', $attr['targetie'] ?? '']); + $result = vsprintf("Context::unloadFile('%s', '');", [$attr['target'] ?? '']); } else { $metafile = isset($attr['target']) ? $attr['target'] : ''; $result = vsprintf("Context::loadFile(['%s', '%s', '%s', '%s']);", [ - $attr['target'] ?? '', $attr['type'] ?? '', $attr['targetie'] ?? ($isRemote ? $this->source_type : ''), $attr['index'] ?? '', + $attr['target'] ?? '', $attr['type'] ?? '', $isRemote ? $this->source_type : '', $attr['index'] ?? '', ]); } break; @@ -928,8 +928,8 @@ class TemplateHandler case 'scss': if($doUnload) { - $result = vsprintf("Context::unloadFile('%s', '%s', '%s');", [ - $attr['target'] ?? '', $attr['targetie'] ?? '', $attr['media'] ?? '', + $result = vsprintf("Context::unloadFile('%s', '', '%s');", [ + $attr['target'] ?? '', $attr['media'] ?? '', ]); } else @@ -937,7 +937,7 @@ class TemplateHandler $metafile = isset($attr['target']) ? $attr['target'] : ''; $metavars = isset($attr['vars']) ? ($attr['vars'] ? self::_replaceVar($attr['vars']) : '') : ''; $result = vsprintf("Context::loadFile(['%s', '%s', '%s', '%s', %s]);", [ - $attr['target'] ?? '', $attr['media'] ?? '', $attr['targetie'] ?? ($isRemote ? $this->source_type : ''), $attr['index'] ?? '', + $attr['target'] ?? '', $attr['media'] ?? '', $isRemote ? $this->source_type : '', $attr['index'] ?? '', isset($attr['vars']) ? ($attr['vars'] ? self::_replaceVar($attr['vars']) : '[]') : '[]', ]); } diff --git a/common/framework/Formatter.php b/common/framework/Formatter.php index 90204a609..8f17d59a2 100644 --- a/common/framework/Formatter.php +++ b/common/framework/Formatter.php @@ -496,25 +496,15 @@ class Formatter foreach ($source_filename as $filename) { - // Get the IE condition. - if (is_array($filename) && count($filename) >= 2) + // Handle the array format, previously used for the targetIE attribute. + if (is_array($filename) && count($filename) >= 1) { - list($filename, $targetie) = $filename; - } - else - { - $targetie = null; + $filename = reset($filename); } // Clean the content. $content = utf8_clean(file_get_contents($filename)); - // Wrap the content in an IE condition if there is one. - if ($targetie !== null) - { - $content = 'if (' . self::convertIECondition($targetie) . ') {' . "\n\n" . trim($content) . ";\n\n" . '}'; - } - // Append to the result string. $original_filename = starts_with(\RX_BASEDIR, $filename) ? substr($filename, strlen(\RX_BASEDIR)) : $filename; $result .= '/* Original file: ' . $original_filename . ' */' . "\n\n" . trim($content) . ";\n\n"; @@ -526,62 +516,12 @@ class Formatter /** * Convert IE conditional comments to JS conditions. * + * @deprecated * @param string $condition * @return string */ public static function convertIECondition($condition) { - $conversions = array( - '/^true$/i' => 'true', - '/^false$/i' => 'false', - '/^IE$/i' => 'window.navigator.userAgent.match(/MSIE\s/)', - '/^IE\s*(\d+)$/i' => '(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] == %d)', - '/^gt IE\s*(\d+)$/i' => '(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] > %d)', - '/^gte IE\s*(\d+)$/i' => '(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] >= %d)', - '/^lt IE\s*(\d+)$/i' => '(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] < %d)', - '/^lte IE\s*(\d+)$/i' => '(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] <= %d)', - ); - - $result = array(); - $conditions = preg_split('/([\&\|])/', $condition, -1, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); - foreach ($conditions as $condition) - { - $condition = trim(preg_replace('/[\(\)]/', '', $condition)); - if ($condition === '') - { - continue; - } - - if ($condition === '&' || $condition === '|') - { - $result[] = $condition . $condition; - continue; - } - - $negation = $condition[0] === '!'; - if ($negation) - { - $condition = trim(substr($condition, 1)); - } - - foreach ($conversions as $regexp => $replacement) - { - if (preg_match($regexp, $condition, $matches)) - { - if (count($matches) > 1) - { - array_shift($matches); - $result[] = ($negation ? '!' : '') . vsprintf($replacement, $matches); - } - else - { - $result[] = ($negation ? '!' : '') . $replacement; - } - break; - } - } - } - - return count($result) ? implode(' ', $result) : 'false'; + throw new Exceptions\FeatureDisabled; } } diff --git a/common/tpl/common_layout.html b/common/tpl/common_layout.html index 6e9db6b82..b7eff76b1 100644 --- a/common/tpl/common_layout.html +++ b/common/tpl/common_layout.html @@ -17,16 +17,12 @@ - -{"\n"} - -{"\n"} diff --git a/tests/_data/formatter/concat.target2.js b/tests/_data/formatter/concat.target2.js index d7e8e3ba6..7ad72cf6c 100644 --- a/tests/_data/formatter/concat.target2.js +++ b/tests/_data/formatter/concat.target2.js @@ -9,10 +9,6 @@ /* Original file: tests/_data/formatter/concat.source2.js */ -if ((/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] >= 6) && (/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] <= 8)) { - (function($) { $(".xe").hide(); })(jQuery);; - -}; diff --git a/tests/unit/classes/FrontEndFileHandlerTest.php b/tests/unit/classes/FrontEndFileHandlerTest.php index fb9d8ce55..c420c0ef7 100644 --- a/tests/unit/classes/FrontEndFileHandlerTest.php +++ b/tests/unit/classes/FrontEndFileHandlerTest.php @@ -40,8 +40,8 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $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' => $this->baseurl . 'common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null); - $expected[] = array('file' => $this->baseurl . 'common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); + $expected[] = array('file' => $this->baseurl . 'common/js/js_app.js' . $this->_filemtime('common/js/js_app.js')); + $expected[] = array('file' => $this->baseurl . 'common/js/common.js' . $this->_filemtime('common/js/common.js')); $this->assertEquals($expected, $handler->getJsFileList()); } @@ -50,7 +50,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $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' => $this->baseurl . 'common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); + $expected[] = array('file' => $this->baseurl . 'common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js')); $this->assertEquals($expected, $handler->getJsFileList('body')); } @@ -75,10 +75,10 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $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' => $this->baseurl . 'common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null); - $expected[] = array('file' => $this->baseurl . 'common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); - $expected[] = array('file' => $this->baseurl . 'common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); - $expected[] = array('file' => $this->baseurl . 'common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null); + $expected[] = array('file' => $this->baseurl . 'common/js/js_app.js' . $this->_filemtime('common/js/js_app.js')); + $expected[] = array('file' => $this->baseurl . 'common/js/common.js' . $this->_filemtime('common/js/common.js')); + $expected[] = array('file' => $this->baseurl . 'common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js')); + $expected[] = array('file' => $this->baseurl . 'common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js')); $this->assertEquals($expected, $handler->getJsFileList()); } @@ -89,10 +89,10 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $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' => $this->baseurl . 'common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null); - $expected[] = array('file' => $this->baseurl . 'common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); - $expected[] = array('file' => $this->baseurl . 'common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null); - $expected[] = array('file' => $this->baseurl . 'common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); + $expected[] = array('file' => $this->baseurl . 'common/js/js_app.js' . $this->_filemtime('common/js/js_app.js')); + $expected[] = array('file' => $this->baseurl . 'common/js/common.js' . $this->_filemtime('common/js/common.js')); + $expected[] = array('file' => $this->baseurl . 'common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js')); + $expected[] = array('file' => $this->baseurl . 'common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js')); $this->assertEquals($expected, $handler->getJsFileList()); } @@ -104,9 +104,9 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $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' => $this->baseurl . 'common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); - $expected[] = array('file' => $this->baseurl . 'common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); - $expected[] = array('file' => $this->baseurl . 'common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null); + $expected[] = array('file' => $this->baseurl . 'common/js/common.js' . $this->_filemtime('common/js/common.js')); + $expected[] = array('file' => $this->baseurl . 'common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js')); + $expected[] = array('file' => $this->baseurl . 'common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js')); $this->assertEquals($expected, $handler->getJsFileList()); } @@ -118,10 +118,10 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $handler->loadFile(array('//external.host/js/script1.js')); $handler->loadFile(array('///external.host/js/script2.js')); - $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); + $expected[] = array('file' => 'http://external.host/js/script.js'); + $expected[] = array('file' => 'https://external.host/js/script.js'); + $expected[] = array('file' => '//external.host/js/script1.js'); + $expected[] = array('file' => '//external.host/js/script2.js'); $this->assertEquals($expected, $handler->getJsFileList()); } @@ -131,7 +131,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $handler->loadFile(array('//external.host/js/script.js')); $handler->loadFile(array('///external.host/js/script.js')); - $expected[] = array('file' => '//external.host/js/script.js', 'targetie' => null); + $expected[] = array('file' => '//external.host/js/script.js'); $this->assertEquals($expected, $handler->getJsFileList()); } @@ -142,9 +142,9 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $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); + $expected[] = array('file' => 'http://external.host/css/style1.css', 'media'=>'all'); + $expected[] = array('file' => 'https://external.host/css/style2.css', 'media'=>'all'); + $expected[] = array('file' => 'https://external.host/css/style3.css?foo=bar&t=123', 'media'=>'all'); $this->assertEquals($expected, $handler->getCssFileList()); } @@ -155,9 +155,9 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $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); + $expected[] = array('file' => '//external.host/css/style.css', 'media'=>'all'); + $expected[] = array('file' => '//external.host/css2/style2.css', 'media'=>'all'); + $expected[] = array('file' => '//external.host/css/style3.css?foo=bar&t=123', 'media'=>'all'); $this->assertEquals($expected, $handler->getCssFileList()); } @@ -177,9 +177,10 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $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' => $this->baseurl . 'common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie6'); - $expected[] = array('file' => $this->baseurl . 'common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie7'); - $expected[] = array('file' => $this->baseurl . 'common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie8'); + + // All targetie attributes should be ignored since Rhymix 2.1 + // Since the 3 loadFile() are otherwise the same, only 1 will remain. + $expected[] = array('file' => $this->baseurl . 'common/js/js_app.js' . $this->_filemtime('common/js/js_app.js')); $this->assertEquals($expected, $handler->getJsFileList()); } @@ -190,9 +191,9 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $handler->loadFile(array('./common/css/common.css', null, 'ie7')); $handler->loadFile(array('./common/css/common.css', null, 'ie8')); - $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media' => 'all', 'targetie' => 'ie6'); - $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media' => 'all', 'targetie' => 'ie7'); - $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media' => 'all', 'targetie' => 'ie8'); + // All targetie attributes should be ignored since Rhymix 2.1 + // Since the 3 loadFile() are otherwise the same, only 1 will remain. + $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media' => 'all'); $this->assertEquals($expected, $handler->getCssFileList()); } @@ -203,9 +204,9 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $handler->loadFile(array('./common/css/common.css', 'screen')); $handler->loadFile(array('./common/css/common.css', 'handled')); - $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media'=>'all', 'targetie' => null); - $expected[] = array('file' => $this->baseurl . 'common/css/common.css','media'=>'screen', 'targetie' => null); - $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media'=>'handled', 'targetie' => null); + $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media'=>'all'); + $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media'=>'screen'); + $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media'=>'handled'); $this->assertEquals($expected, $handler->getCssFileList()); } @@ -243,12 +244,12 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $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->assertEquals(3, count($result)); $this->assertRegexp('/combined\/[0-9a-f]+\.css\?\d+$/', $result[0]['file']); - $this->assertEquals($this->baseurl . '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']); + //$this->assertEquals($this->baseurl . '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[1]['file']); + $this->assertRegexp('/combined\/[0-9a-f]+\.css\?\d+$/', $result[2]['file']); FrontEndFileHandler::$concat = 'js'; diff --git a/tests/unit/framework/FormatterTest.php b/tests/unit/framework/FormatterTest.php index a8bc15626..3b36ec2ec 100644 --- a/tests/unit/framework/FormatterTest.php +++ b/tests/unit/framework/FormatterTest.php @@ -174,35 +174,6 @@ class FormatterTest extends \Codeception\TestCase\Test $this->assertEquals(trim(file_get_contents($real_target2)), trim($test_with_targetie)); } - public function testConvertIECondition() - { - $this->assertEquals('window.navigator.userAgent.match(/MSIE\s/)', Rhymix\Framework\Formatter::convertIECondition('IE')); - $this->assertEquals('!window.navigator.userAgent.match(/MSIE\s/)', Rhymix\Framework\Formatter::convertIECondition('!IE')); - $this->assertEquals('!window.navigator.userAgent.match(/MSIE\s/)', Rhymix\Framework\Formatter::convertIECondition('!(IE)')); - $this->assertEquals('true && false', Rhymix\Framework\Formatter::convertIECondition('true&false')); - $this->assertEquals('false', Rhymix\Framework\Formatter::convertIECondition('gobbledygook')); - - $source = 'gt IE 7'; - $target = '(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] > 7)'; - $this->assertEquals($target, Rhymix\Framework\Formatter::convertIECondition($source)); - - $source = 'lte IE 8'; - $target = '(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] <= 8)'; - $this->assertEquals($target, Rhymix\Framework\Formatter::convertIECondition($source)); - - $source = '(gte IE 6) & (lt IE 8)'; - $target = '(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] >= 6) && (/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] < 8)'; - $this->assertEquals($target, Rhymix\Framework\Formatter::convertIECondition($source)); - - $source = '!(gt IE 9)'; - $target = '!(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] > 9)'; - $this->assertEquals($target, Rhymix\Framework\Formatter::convertIECondition($source)); - - $source = '!lt IE 8|lt IE 6'; - $target = '!(/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] < 8) || (/MSIE (\d+)/.exec(window.navigator.userAgent) && /MSIE (\d+)/.exec(window.navigator.userAgent)[1] < 6)'; - $this->assertEquals($target, Rhymix\Framework\Formatter::convertIECondition($source)); - } - protected function _removeSpace($str) { return preg_replace('/\s+/', '', $str);