1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-13 01:54:12 +02:00

Parser staticUrl() test and JS manager addLink() test added.

This commit is contained in:
Cameron
2020-12-03 14:20:34 -08:00
parent 066104f4c3
commit 86690cee65
6 changed files with 129 additions and 20 deletions

View File

@@ -618,8 +618,8 @@ class e107Test extends \Codeception\Test\Unit
public function testLink()
{
$res = null;
$this->assertTrue($res);
}
public function testCss()

View File

@@ -21,7 +21,8 @@
try
{
$this->js = $this->make('e_jsmanager');
} catch(Exception $e)
}
catch(Exception $e)
{
$this->assertTrue(false, "Couldn't load e_jsmanager object");
}
@@ -45,7 +46,7 @@
$this->assertFalse($result);
}
/*
public function testRequireCoreLib()
{
@@ -225,12 +226,60 @@
{
}
*/
public function testAddLink()
{
$tests = array(
0 => array(
'expected' => '<link rel="preload" href="https://fonts.googleapis.com/css?family=Nunito&display=swap" as="style" onload="this.onload=null;" />',
'input' => array('rel'=>'preload', 'href'=>'https://fonts.googleapis.com/css?family=Nunito&display=swap', 'as'=>'style', 'onload' => "this.onload=null;"),
'cacheid' => false,
),
1 => array(
'expected' => '<link rel="preload" href="'.e_THEME_ABS.'bootstrap3/assets/fonts/fontawesome-webfont.woff2?v=4.7.0" as="font" type="font/woff2" crossorigin />', // partial
'input' => 'rel="preload" href="{THEME}assets/fonts/fontawesome-webfont.woff2?v=4.7.0" as="font" type="font/woff2" crossorigin',
'cacheid' => false,
),
2 => array(
'expected' => '<link rel="preload" href="'.e_WEB_ABS.'script.js?0" as="script" />',
'input' => array('rel'=>'preload', 'href'=>'{e_WEB}script.js', 'as'=>'script'),
'cacheid' => true,
),
/* Static URLs enabled from this point. */
3 => 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,
),
);
$tp = e107::getParser();
foreach($tests as $var)
{
$static = !empty($var['static']) ? 'https://static.mydomain.com/' : null;
$tp->setStaticUrl($static);
$this->js->addLink($var['input'], $var['cacheid']);
// $this->assertSame($var['expected'],$actual);
}
$actual = $this->js->renderLinks(true);
foreach($tests as $var)
{
$result = (strpos($actual, $var['expected']) !== false);
$this->assertTrue($result, $var['expected']." was not found in the rendered links. Render links result:".$actual."\n\n");
}
}
/*
public function testLibDisabled()
{
@@ -250,7 +299,7 @@
{
}
*/
}

View File

@@ -625,12 +625,51 @@ while(&#036;row = &#036;sql-&gt;fetch())
{
}
*/
public function testStaticUrl()
{
}
$tests = array(
0 => array(
'expected' => 'https://static.mydomain.com/',
'input' => null,
'static' => true,
),
1 => array(
'expected' => 'https://static.mydomain.com/e107_web/lib/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0',
'input' => e_WEB_ABS.'lib/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0',
'static' => true,
),
2 => array(
'expected' => 'https://static.mydomain.com/e107_media/000000test/myimage.jpg',
'input' => e_MEDIA_ABS.'myimage.jpg',
'static' => true,
),
3 => array(
'expected' => 'https://static.mydomain.com/e107_themes/bootstrap3/images/myimage.jpg',
'input' => '{THEME}images/myimage.jpg',
'static' => true,
),
4 => array(
'expected' => e_WEB_ABS.'lib/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0',
'input' => '{e_WEB}lib/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0',
'static' => false,
),
);
foreach($tests as $val)
{
$static = !empty($val['static']) ? 'https://static.mydomain.com/' : null;
$this->tp->setStaticUrl($static);
$actual = $this->tp->staticUrl($val['input']);
$this->assertSame( $val['expected'], $actual);
}
}
/*
public function testGetUrlConstants()
{