diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 1a4cfb6e7..2c7c223b5 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -2424,26 +2424,36 @@ class e_parse } $staticArray = $this->staticUrl; // e_HTTP_STATIC; + $path = $this->replaceConstants($path, 'abs'); // replace any {THEME} etc. + $key = ltrim(eHelper::dasherize($path), '/'); if (is_array($staticArray)) { - $cnt = count($staticArray); - $staticCount = $this->staticCount(); - if ($staticCount > ($cnt - 1)) + if(!empty($this->staticUrlMap[$key])) { - $staticCount = 0; - $this->staticCount(0); + $http = $this->staticUrlMap[$key]; } + else + { + $cnt = count($staticArray); + $staticCount = $this->staticCount(); + if ($staticCount > ($cnt - 1)) + { + $staticCount = 0; + $this->staticCount(0); + } - $http = !empty($staticArray[$staticCount]) ? $staticArray[$staticCount] : e_HTTP; - + $http = !empty($staticArray[$staticCount]) ? $staticArray[$staticCount] : e_HTTP; + $this->staticCount(1); + } } else { $http = $this->staticUrl; } - $this->staticCount(1); + $this->staticUrlMap[$key] = $http; + if (empty($path)) { @@ -2452,7 +2462,7 @@ class e_parse $base = ''; - $path = $this->replaceConstants($path, 'abs'); // replace any {THEME} etc. + $srch = array( e_PLUGIN_ABS, @@ -2480,8 +2490,7 @@ class e_parse $ret = str_replace(e_MEDIA_ABS, $http . $base . e107::getFolder('media'), $ret); } - $key = ltrim(eHelper::dasherize($path), '/'); - $this->staticUrlMap[$key] = $ret; + return $ret; diff --git a/e107_tests/tests/unit/e_jsmanagerTest.php b/e107_tests/tests/unit/e_jsmanagerTest.php index 11114fa3e..1c95ffad7 100644 --- a/e107_tests/tests/unit/e_jsmanagerTest.php +++ b/e107_tests/tests/unit/e_jsmanagerTest.php @@ -381,6 +381,60 @@ class e_jsmanagerTest extends \Codeception\Test\Unit $this->assertTrue($result, $var['expected'] . " was not found in the rendered links. Render links result:" . $actual . "\n\n"); } + // ----------------- + $static = [ + 'https://static.mydomain.com/', + 'https://static2.mydomain.com/', + 'https://static3.mydomain.com/', + ]; + + $tp->setStaticUrl(null); + e107::getParser()->setStaticUrl($static); + + $staticTests = [ + 0 => array( + 'expected' => '', + 'input' => array('rel' => 'preload', 'href' => '{e_WEB}script.js', 'as' => 'script'), + 'cacheid' => true, + 'static' => true, + ), + 1 => array( + 'expected' => '', + 'input' => ['rel'=>'preload', 'as'=>'image', 'type'=> "image/jpeg", 'href'=>THEME_ABS.'image/header.jpg', 'media'=>"(max-width: 415px)"], + 'cacheid' => false, + 'static' => true, + ), + 2 => array( + 'expected' => '', + 'input' => ['rel'=>'preload', 'as'=>'image', 'type'=> "image/jpeg", 'href'=>THEME_ABS.'image/header.jpg', 'media'=>"(max-width: 415px)"], + 'cacheid' => false, + 'static' => true, + ), + 3 => array( + 'expected' => '', + 'input' => ['rel'=>'preload', 'as'=>'image', 'type'=> "image/jpeg", 'href'=>THEME_ABS.'image/header.jpg', 'media'=>"(max-width: 415px)"], + 'cacheid' => false, + 'static' => true, + ), + + ]; + + + + foreach($staticTests as $var) + { + $this->js->addLink($var['input'], $var['cacheid']); + } + + $actual = $this->js->renderLinks(true); + + + foreach($staticTests as $var) + { + $result = (strpos($actual, $var['expected']) !== false); + self::assertTrue($result, $var['expected'] . " was not found in the rendered links. Render links result:" . $actual . "\n\n"); + } + $tp->setStaticUrl(null); diff --git a/e107_tests/tests/unit/e_parseTest.php b/e107_tests/tests/unit/e_parseTest.php index 759354e26..4c1db7878 100644 --- a/e107_tests/tests/unit/e_parseTest.php +++ b/e107_tests/tests/unit/e_parseTest.php @@ -1798,7 +1798,7 @@ EXPECTED; // Test with Static Array $static = [ - 'https://static.mydomain.com/', + 'https://static1.mydomain.com/', 'https://static2.mydomain.com/', 'https://static3.mydomain.com/', ]; @@ -1806,7 +1806,7 @@ EXPECTED; $this->tp->setStaticUrl($static); $tests = [ 1 => array( - 'expected' => 'https://static.mydomain.com/e107_themes/bootstrap3/images/myimage1.jpg', + 'expected' => 'https://static1.mydomain.com/e107_themes/bootstrap3/images/myimage1.jpg', 'input' => '{THEME}images/myimage1.jpg', 'static' => true, ), @@ -1820,9 +1820,14 @@ EXPECTED; 'input' => '{THEME}images/myimage3.jpg', 'static' => true, ), - 4 => array( - 'expected' => 'https://static.mydomain.com/e107_themes/bootstrap3/images/myimage4.jpg', - 'input' => '{THEME}images/myimage4.jpg', + 4 => array( // test that previously generated static URL retains the same static domain when called again. + 'expected' => 'https://static3.mydomain.com/e107_themes/bootstrap3/images/myimage3.jpg', + 'input' => '{THEME}images/myimage3.jpg', + 'static' => true, + ), + 5 => array( // test that previously generated static URL retains the same static domain when called again. + 'expected' => 'https://static2.mydomain.com/e107_themes/bootstrap3/images/myimage2.jpg', + 'input' => '{THEME}images/myimage2.jpg', 'static' => true, ), @@ -1835,7 +1840,7 @@ EXPECTED; } $map = $this->tp->getStaticUrlMap(); - self::assertStringContainsString('myimage2.jpg', $map['e107-themes/bootstrap3/images/myimage2.jpg'] ); + self::assertStringContainsString('https://static2.mydomain.com', $map['e107-themes/bootstrap3/images/myimage2.jpg'] ); $this->tp->setStaticUrl(null); }