mirror of
https://github.com/e107inc/e107.git
synced 2025-07-25 00:41:52 +02:00
Closes #5191 - Match static URL to previously called/generated static url when present.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
@@ -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' => '<link rel="preload" href="https://static.mydomain.com/e107_web/script.js?0" as="script" />',
|
||||
'input' => array('rel' => 'preload', 'href' => '{e_WEB}script.js', 'as' => 'script'),
|
||||
'cacheid' => true,
|
||||
'static' => true,
|
||||
),
|
||||
1 => array(
|
||||
'expected' => '<link rel="preload" as="image" type="image/jpeg" href="https://static.mydomain.com/e107_themes/bootstrap3/image/header.jpg" media="(max-width: 415px)" />',
|
||||
'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' => '<link rel="preload" as="image" type="image/jpeg" href="https://static.mydomain.com/e107_themes/bootstrap3/image/header.jpg" media="(max-width: 415px)" />',
|
||||
'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' => '<link rel="preload" as="image" type="image/jpeg" href="https://static.mydomain.com/e107_themes/bootstrap3/image/header.jpg" media="(max-width: 415px)" />',
|
||||
'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);
|
||||
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user