1
0
mirror of https://github.com/e107inc/e107.git synced 2025-03-14 01:19:44 +01:00

Added getScope() to theme handler. Added more theme handler tests. Fixed duplicate entry in _blank/theme.xml

This commit is contained in:
Cameron 2021-02-11 08:51:02 -08:00
parent 853cd70b88
commit b0d10199b7
5 changed files with 315 additions and 14 deletions

View File

@ -2353,6 +2353,27 @@ class e107
return $libraryHandler->info($library);
break;
case 'files':
$info = $libraryHandler->info($library);
$ret = [];
if(!empty($info['files']['css']))
{
foreach($info['files']['css'] as $path => $other)
{
$ret['css'][] = $info['library_path'].'/'.$info['path'].'/'.$path;
}
}
if(!empty($info['files']['js']))
{
foreach($info['files']['js'] as $path => $other)
{
$ret['js'][] = $info['library_path'].'/'.$info['path'].'/'.$path;
}
}
return $ret;
break;
case 'preload':
$info = $libraryHandler->info($library);

View File

@ -154,6 +154,71 @@ class e_theme
// $ns->tablerender(TPVLAN_2, $text);
}
/**
* @param string $type library | stylesheet (as defined in theme.xml)
* @param string $scope front | admin | all | auto (as defined in theme.xml)
*/
public function getScope($type, $scope)
{
if($scope === 'auto')
{
$scope = 'front';
if(deftrue('e_ADMIN_AREA', false))
{
$scope = 'admin';
}
}
if($type === 'library')
{
$themeXMLData = $this->get('library');
}
if($type === 'stylesheet')
{
$themeXMLData = $this->get('css');
}
$ret = [];
foreach($themeXMLData as $info)
{
$tmp = explode(',', $info['scope']);
foreach($tmp as $scp)
{
$scp = trim($scp);
if($scp === $scope || $scp === 'all')
{
$name = $info['name'];
unset($info['name']);
unset($info['scope']);
$ret[$name] = $info;
// $ret[$name] = e107::library('files', $name);
}
}
}
return $ret;
/**
* if($name === 'bootstrap' && !empty($info['version']) && (intval($info['version']) > 3))
{
$name .= (string) $info['version'];
}
elseif($name === 'fontawesome' && !empty($info['version']) && (intval($info['version']) > 4))
{
$name .= (string) $info['version'];
}
*/
}
/**
* Load library dependencies.
@ -180,6 +245,7 @@ class e_theme
return;
}
$loaded = [];
foreach($libraries as $library)
{
@ -223,6 +289,7 @@ class e_theme
e107::library('load', $library['name']);
e107::library('preload', $library['name']);
$loaded[] = $library['name'];
continue;
}
@ -231,10 +298,12 @@ class e_theme
{
e107::library('load', $library['name']);
e107::library('preload', $library['name']);
$loaded[] = $library['name'];
continue;
}
}
return $loaded;
}
/**

View File

@ -729,13 +729,38 @@ class e107Test extends \Codeception\Test\Unit
$res = null;
$this->assertTrue($res);
}
*/
public function testLibrary()
{
$res = null;
$this->assertTrue($res);
}
$e107 = $this->e107;
$expected = array (
'css' =>
array (
0 => '{e_WEB}lib/font-awesome/5/css/all.min.css',
1 => '{e_WEB}lib/font-awesome/5/css/v4-shims.min.css',
),
);
$result = $e107::library('files', 'fontawesome5');
$this->assertSame($expected, $result);
$expected = array (
'css' =>
array (
0 => '{e_WEB}lib/bootstrap/5/css/bootstrap.min.css',
),
'js' =>
array (
0 => '{e_WEB}lib/bootstrap/5/js/bootstrap.bundle.min.js',
),
);
$result = $e107::library('files', 'bootstrap5');
$this->assertSame($expected, $result);
}
/*
public function testGetJs()
{
$res = null;

View File

@ -44,12 +44,202 @@
{
}
public function testLoadLibrary()
*/
public function testGetScope()
{
$tests = array(
0 => array(
'theme' => 'front',
'type' => 'library',
'scope' => 'front',
'expected' => array (
'bootstrap' =>
array (
'version' => '3',
),
'fontawesome' =>
array (
'version' => '5',
),
)
),
1 => array(
'theme' => 'front',
'type' => 'library',
'scope' => 'all',
'expected' => array (
'bootstrap' =>
array (
'version' => '3',
),
'fontawesome' =>
array (
'version' => '5',
),
)
),
2 => array(
'theme' => 'front',
'type' => 'library',
'scope' => 'admin',
'expected' => array (
'bootstrap' =>
array (
'version' => '3',
),
'fontawesome' =>
array (
'version' => '5',
),
'bootstrap.editable' =>
array (
'version' => '',
),
)
),
3 => array(
'theme' => '_blank',
'type' => 'library',
'scope' => 'front',
'expected' => array (
'bootstrap' =>
array (
'version' => '3',
),
'fontawesome' =>
array (
'version' => '4',
),
)
),
);
foreach($tests as $index => $var)
{
$result = e107::getTheme($var['theme'])->getScope($var['type'], $var['scope']);
$this->assertSame($var['expected'], $result, 'Test #'.$index.' failed.');
}
}
public function testLoadLibrary()
{
$tests = array(
0 => array(
'theme' => 'front',
'scope' => 'front',
'expected' => ['bootstrap', 'fontawesome5']
),
1 => array(
'theme' => 'front',
'scope' => 'admin',
'expected' => ['bootstrap', 'fontawesome5', 'bootstrap.editable']
),
2 => array(
'theme' => '_blank',
'scope' => 'front',
'expected' => ['bootstrap', 'fontawesome']
),
);
foreach($tests as $index => $var)
{
$loaded = e107::getTheme($var['theme'],true)->loadLibrary($var['scope']);
$this->assertSame($var['expected'], $loaded, 'Test #'.$index.' failed.');
}
// var_export($loaded);
}
public function testGet()
{
$tests = array(
0 => array(
'theme' => 'front',
'type' => 'library',
'expected' => array (
0 =>
array (
'name' => 'bootstrap',
'version' => '3',
'scope' => 'all',
),
1 =>
array (
'name' => 'fontawesome',
'version' => '5',
'scope' => 'all',
),
2 =>
array (
'name' => 'bootstrap.editable',
'version' => '',
'scope' => 'admin',
),
)
),
1 => array(
'theme' => 'bootstrap3',
'type' => 'library',
'expected' => array (
0 =>
array (
'name' => 'bootstrap',
'version' => '3',
'scope' => 'all',
),
1 =>
array (
'name' => 'fontawesome',
'version' => '5',
'scope' => 'all',
),
2 =>
array (
'name' => 'bootstrap.editable',
'version' => '',
'scope' => 'admin',
),
)
),
2 => array(
'theme' => '_blank',
'type' => 'library',
'expected' => array (
0 =>
array (
'name' => 'bootstrap',
'version' => '3',
'scope' => 'all',
),
1 =>
array (
'name' => 'fontawesome',
'version' => '4',
'scope' => 'all',
),
)
),
);
foreach($tests as $index => $var)
{
$result = e107::getTheme($var['theme'])->get($var['type']);
$this->assertSame($var['expected'], $result, 'Test #'.$index.' failed');
}
}
/*
public function testParse_theme_php()
{
@ -168,14 +358,14 @@
public function testLoadLayout()
{
// public function testLoadLayout()
// {
// $res = e_theme::loadLayout('full', 'bootstrap4');
// var_dump($res);
}
// }
/*
public function testGetThemesMigrations()
{

View File

@ -20,10 +20,6 @@
<word>empty</word>
<word>template</word>
</keywords>
<libraries>
<library name="bootstrap" version="3" scope="all"/>
<library name="fontawesome" scope="all"/>
</libraries>
<layouts>
<layout name='default' title='Default' default='true' />
<layout name='home' title='Home'>