1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 12:48:24 +01: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

@ -4468,10 +4468,8 @@ class e107
define('e_AVATAR_UPLOAD_ABS', $this->get_override_http('AVATARS_UPLOAD'));
define('e_AVATAR_DEFAULT_ABS', $this->get_override_http('AVATARS_DEFAULT'));
if(defined('e_MEDIA_STATIC')) // experimental - subject to change.
{
define('e_CACHE_IMAGE_ABS', $this->get_override_http('CACHE_IMAGE'));
}
define('e_CACHE_IMAGE_ABS', $this->get_override_http('CACHE_IMAGE'));
// Special

View File

@ -64,6 +64,9 @@ class e_parse extends e_parser
private $staticCount = 0;
protected $staticUrl = null;
// BBcode that contain preformatted code.
private $preformatted = array('html', 'markdown');
@ -2719,7 +2722,7 @@ class e_parse extends e_parser
*/
public function staticUrl($path=null, $opts=array())
{
if(!defined('e_HTTP_STATIC') || deftrue('e_ADMIN_AREA'))
if(empty($this->staticUrl) || deftrue('e_ADMIN_AREA'))
{
// e107::getDebug()->log("e_HTTP_STATIC not defined");
if($path === null)
@ -2732,7 +2735,7 @@ class e_parse extends e_parser
}
}
$staticArray = e_HTTP_STATIC;
$staticArray = $this->staticUrl; // e_HTTP_STATIC;
if(is_array($staticArray))
{
@ -2749,7 +2752,7 @@ class e_parse extends e_parser
}
else
{
$http = e_HTTP_STATIC;
$http = $this->staticUrl;
}
$this->staticCount(1);
@ -2789,6 +2792,14 @@ class e_parse extends e_parser
}
/**
* Used internally to store e_HTTP_STATIC.
* @param string|null $url The static URL ie. e_HTTP_STATIC
*/
public function setStaticUrl($url)
{
$this->staticUrl = $url;
}
/**
* Generate an auto-sized Image URL.
@ -2848,7 +2859,7 @@ class e_parse extends e_parser
$baseurl = ($full ? SITEURL : e_HTTP).'thumb.php?';
if(defined('e_HTTP_STATIC'))
if(!empty($this->staticUrl))
{
$baseurl = $this->staticUrl().'thumb.php?';
}
@ -3131,7 +3142,7 @@ class e_parse extends e_parser
$base = (!empty($options['ebase'])) ? '{e_BASE}' : e_HTTP;
}
if(defined('e_HTTP_STATIC'))
if(!empty($this->staticUrl))
{
$base = $this->staticUrl();
}
@ -3821,6 +3832,7 @@ class e_parser
protected $bootstrap = null;
protected $fontawesome = null;
protected $removedList = array();
protected $nodesToDelete = array();
protected $nodesToConvert = array();
@ -3924,6 +3936,11 @@ class e_parser
}
if(defined('e_HTTP_STATIC'))
{
$this->staticUrl = e_HTTP_STATIC;
}
}
/**

View File

@ -799,9 +799,10 @@ class e_jsmanager
/**
* Render all link tags. (other than css)
* @return null
* @param bool $return - when true will not echo the result, will return it instead.
* @return null|string
*/
public function renderLinks()
public function renderLinks($return = false)
{
if(empty($this->_e_link))
{
@ -853,6 +854,11 @@ class e_jsmanager
}
if(!empty($return))
{
return $text;
}
echo $text;
}

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()
{