1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-06 22:57:14 +02:00
This commit is contained in:
Cameron
2021-04-06 18:41:15 -07:00
parent 920a881898
commit 2862e18db9
6 changed files with 806 additions and 624 deletions

View File

@@ -1667,14 +1667,28 @@ class media_admin_ui extends e_admin_ui
private function mediaManagerPlaceholders() private function mediaManagerPlaceholders()
{ {
$type = (E107_DEBUG_LEVEL > 0) ? 'text' : 'hidden'; $type = (E107_DEBUG_LEVEL > 0) ? 'text' : 'hidden';
$br = (E107_DEBUG_LEVEL > 0) ? "<br style='clear:both' />" : '';
$text = '
' .$br."<input title='bbcode' type='{$type}' style=readonly='readonly' class='span11 col-md-11' id='bbcode_holder' name='bbcode_holder' value='' /> $valueHolders = [
".$br."<input title='html/wysiwyg' type='{$type}' class='span11 col-md-11' readonly='readonly' id='html_holder' name='html_holder' value='' /> 'bbcode_holder' => 'bbcode',
".$br."<input title='(preview) src' type='{$type}' class='span11 col-md-11' readonly='readonly' id='src' name='src' value='' /> 'html_holder' => 'html/wysiwyg',
".$br."<input title='path (saved to db)' type='{$type}' class='span11 col-md-11' readonly='readonly' id='path' name='path' value='' /> 'src' => '(preview) src',
"; 'path' => 'path (save to db)'
];
$text = '';
foreach($valueHolders as $name => $label)
{
$text .= (E107_DEBUG_LEVEL > 0) ? "<br /><span style='margin-left:20px;display:inline-block;width:150px'>".$label."&nbsp;</span>" : '';
$text .= "<input title='".$label."' type='{$type}' readonly style='width:800px' class='' id='".$name."' name='".$name."' value='' />\n";
}
if(E107_DEBUG_LEVEL > 0)
{
$text .= "<br /><span style='margin-left:20px;display:inline-block;width:150px'>FontAwesome</span>".e107::getTheme()->getFontAwesome();
}
return $text; return $text;
} }
@@ -2117,12 +2131,15 @@ class media_admin_ui extends e_admin_ui
} }
if($this->fontawesome === 4)
{
e107::getParser()->setFontAwesome(4);;
$fa4 = e107::getMedia()->getGlyphs('fa4'); $fa4 = e107::getMedia()->getGlyphs('fa4');
foreach($fa4 as $val) foreach($fa4 as $val)
{ {
$items[] = array( $items[] = array(
'previewHtml' => $md->previewTag('fa-'.$val,array('type'=>'glyph')), 'previewHtml' => $md->previewTag('fa-'.$val, array('type'=>'glyph')),
'previewUrl' => 'fa fa-'.$val, 'previewUrl' => 'fa fa-'.$val,
'saveValue' => 'fa-'.$val.'.glyph', 'saveValue' => 'fa-'.$val.'.glyph',
'thumbUrl' => 'fa-'.$val, 'thumbUrl' => 'fa-'.$val,
@@ -2131,7 +2148,7 @@ class media_admin_ui extends e_admin_ui
'slideCategory' => 'font-awesome' 'slideCategory' => 'font-awesome'
); );
} }
}
if($this->fontawesome === false || ($this->fontawesome < 4)) if($this->fontawesome === false || ($this->fontawesome < 4))
{ {

View File

@@ -1103,6 +1103,15 @@ class e_theme
unset($vars['libraries']); unset($vars['libraries']);
} }
else // detect defined constants in legacy theme.php file.
{
if($data = self::getLegacyBSFA($path))
{
$vars['library'] = $data;
}
}
if(!empty($vars['stylesheets']['css'])) if(!empty($vars['stylesheets']['css']))
{ {
@@ -1158,6 +1167,37 @@ class e_theme
return $vars; return $vars;
} }
/**
* Read legacy bootstrap/fontawesome constants from theme.php
* @param string $path theme directory
*/
public static function getLegacyBSFA($path)
{
if(!$content = file_get_contents(e_THEME.$path.'/theme.php'))
{
return false;
}
$ret = [];
if(preg_match('/define[ ]*?\([\'|"]BOOTSTRAP[\'|"],[ \t]*(\d)\);/', $content, $m))
{
$ret[] = array('name' => 'bootstrap',
'version' => $m[1],
'scope' => 'front,wysiwyg',
);
}
if(preg_match('/define[ ]*?\([\'|"]FONTAWESOME[\'|"],[ \t]*(\d)\);/', $content, $m))
{
$ret[] = array('name' => 'fontawesome',
'version' => $m[1],
'scope' => 'front,wysiwyg',
);
}
return $ret;
}
/** /**
* Validate and return the name of the categories. * Validate and return the name of the categories.

View File

@@ -114,7 +114,9 @@ TEMPL;
public function toHTML($content) public function toHTML($content)
{ {
$tp = e107::getParser(); $tp = e107::getParser();
// XXX @Cam possible fix - convert to BB first, see news admin AJAX request/response values for reference why $fa = e107::getTheme()->getFontAwesome(); // get the frontend theme's fontawesome version.
$tp->setFontAwesome($fa);
$content = stripslashes($content); $content = stripslashes($content);
// $content = e107::getBB()->htmltoBBcode($content); //XXX This breaks inserted images from media-manager. :/ // $content = e107::getBB()->htmltoBBcode($content); //XXX This breaks inserted images from media-manager. :/

View File

@@ -943,12 +943,12 @@ class wysiwyg
/** /**
* @return array * @return array
*/ */
public function getEditorCSS() public function getEditorCSS($theme = 'front')
{ {
$tp = e107::getParser(); $tp = e107::getParser();
$libraries = e107::getTheme('admin')->getThemeFiles('library', 'wysiwyg'); $libraries = e107::getTheme($theme)->getThemeFiles('library', 'wysiwyg');
$ret = []; $ret = [];
@@ -967,7 +967,7 @@ class wysiwyg
if($useThemeStyle) if($useThemeStyle)
{ {
$theme = e107::getTheme()->getThemeFiles('css', 'wysiwyg'); $theme = e107::getTheme($theme)->getThemeFiles('css', 'wysiwyg');
if(!empty($theme['css'])) if(!empty($theme['css']))
{ {
foreach($theme['css'] as $path) foreach($theme['css'] as $path)

View File

@@ -1,5 +1,5 @@
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: Wiz * User: Wiz
* Date: 1/24/2019 * Date: 1/24/2019
@@ -7,21 +7,21 @@
*/ */
class e_themeTest extends \Codeception\Test\Unit
class e_themeTest extends \Codeception\Test\Unit {
{
/** @var e_theme */ /** @var e_theme */
private $tm; private $tm;
protected function _before() protected function _before()
{ {
// require_once(e_HANDLER."e_marketplace.php"); // require_once(e_HANDLER."e_marketplace.php");
try try
{ {
$this->tm = $this->make('e_theme'); $this->tm = $this->make('e_theme');
} }
catch (Exception $e) catch(Exception $e)
{ {
$this->assertTrue(false, "Couldn't load e_theme object"); $this->assertTrue(false, "Couldn't load e_theme object");
} }
@@ -31,7 +31,7 @@
} }
/* /*
public function testCssAttribute() public function testCssAttribute()
{ {
@@ -46,22 +46,23 @@
{ {
} }
*/ */
public function testGetScope() public function testGetScope()
{ {
$tests = array( $tests = array(
0 => array( 0 => array(
'theme' => 'front', 'theme' => 'front',
'type' => 'library', 'type' => 'library',
'scope' => 'front', 'scope' => 'front',
'expected' => array ( 'expected' => array(
'bootstrap' => 'bootstrap' =>
array ( array(
'name' => 'bootstrap', 'name' => 'bootstrap',
'version' => '3', 'version' => '3',
), ),
'fontawesome' => 'fontawesome' =>
array ( array(
'name' => 'fontawesome', 'name' => 'fontawesome',
'version' => '5', 'version' => '5',
), ),
@@ -71,19 +72,19 @@
'theme' => 'front', 'theme' => 'front',
'type' => 'library', 'type' => 'library',
'scope' => 'all', 'scope' => 'all',
'expected' => array ( 'expected' => array(
'bootstrap' => 'bootstrap' =>
array ( array(
'name' => 'bootstrap', 'name' => 'bootstrap',
'version' => '3', 'version' => '3',
), ),
'fontawesome' => 'fontawesome' =>
array ( array(
'name' => 'fontawesome', 'name' => 'fontawesome',
'version' => '5', 'version' => '5',
), ),
'bootstrap.editable' => 'bootstrap.editable' =>
array ( array(
'name' => 'bootstrap.editable', 'name' => 'bootstrap.editable',
'version' => '', 'version' => '',
), ),
@@ -93,19 +94,19 @@
'theme' => 'front', 'theme' => 'front',
'type' => 'library', 'type' => 'library',
'scope' => 'admin', 'scope' => 'admin',
'expected' => array ( 'expected' => array(
'bootstrap' => 'bootstrap' =>
array ( array(
'name' => 'bootstrap', 'name' => 'bootstrap',
'version' => '3', 'version' => '3',
), ),
'fontawesome' => 'fontawesome' =>
array ( array(
'name' => 'fontawesome', 'name' => 'fontawesome',
'version' => '5', 'version' => '5',
), ),
'bootstrap.editable' => 'bootstrap.editable' =>
array ( array(
'name' => 'bootstrap.editable', 'name' => 'bootstrap.editable',
'version' => '', 'version' => '',
), ),
@@ -115,14 +116,14 @@
'theme' => '_blank', 'theme' => '_blank',
'type' => 'library', 'type' => 'library',
'scope' => 'front', 'scope' => 'front',
'expected' => array ( 'expected' => array(
'bootstrap' => 'bootstrap' =>
array ( array(
'name' => 'bootstrap', 'name' => 'bootstrap',
'version' => '3', 'version' => '3',
), ),
'fontawesome' => 'fontawesome' =>
array ( array(
'name' => 'fontawesome', 'name' => 'fontawesome',
'version' => '4', 'version' => '4',
), ),
@@ -132,9 +133,9 @@
'theme' => 'bootstrap3', 'theme' => 'bootstrap3',
'type' => 'css', 'type' => 'css',
'scope' => 'front', 'scope' => 'front',
'expected' => array ( 'expected' => array(
'style.css' => 'style.css' =>
array ( array(
'name' => 'style.css', 'name' => 'style.css',
'info' => 'Default', 'info' => 'Default',
'nonadmin' => true, 'nonadmin' => true,
@@ -142,7 +143,7 @@
'description' => '', 'description' => '',
'thumbnail' => '', 'thumbnail' => '',
), ),
'*' => array ( '*' => array(
'name' => '*', 'name' => '*',
'info' => '*', 'info' => '*',
'nonadmin' => true, 'nonadmin' => true,
@@ -156,9 +157,9 @@
'theme' => 'bootstrap3', 'theme' => 'bootstrap3',
'type' => 'css', 'type' => 'css',
'scope' => 'admin', 'scope' => 'admin',
'expected' => array ( 'expected' => array(
'css/modern-light.css' => 'css/modern-light.css' =>
array ( array(
'name' => 'css/modern-light.css', 'name' => 'css/modern-light.css',
'info' => 'Modern Light', 'info' => 'Modern Light',
'nonadmin' => false, 'nonadmin' => false,
@@ -167,7 +168,7 @@
'thumbnail' => 'images/admin_modern-light.webp', 'thumbnail' => 'images/admin_modern-light.webp',
), ),
'css/modern-dark.css' => 'css/modern-dark.css' =>
array ( array(
'name' => 'css/modern-dark.css', 'name' => 'css/modern-dark.css',
'info' => 'Modern Dark', 'info' => 'Modern Dark',
'nonadmin' => false, 'nonadmin' => false,
@@ -176,7 +177,7 @@
'thumbnail' => 'images/admin_modern-dark.webp', 'thumbnail' => 'images/admin_modern-dark.webp',
), ),
'css/bootstrap-dark.min.css' => 'css/bootstrap-dark.min.css' =>
array ( array(
'name' => 'css/bootstrap-dark.min.css', 'name' => 'css/bootstrap-dark.min.css',
'info' => 'Legacy Dark Admin', 'info' => 'Legacy Dark Admin',
'nonadmin' => false, 'nonadmin' => false,
@@ -185,7 +186,7 @@
'thumbnail' => 'images/admin_bootstrap-dark.webp', 'thumbnail' => 'images/admin_bootstrap-dark.webp',
), ),
'css/kadmin.css' => 'css/kadmin.css' =>
array ( array(
'name' => 'css/kadmin.css', 'name' => 'css/kadmin.css',
'info' => 'K-Admin Inspired', 'info' => 'K-Admin Inspired',
'nonadmin' => false, 'nonadmin' => false,
@@ -194,7 +195,7 @@
'thumbnail' => 'images/admin_kadmin.webp', 'thumbnail' => 'images/admin_kadmin.webp',
), ),
'css/corporate.css' => 'css/corporate.css' =>
array ( array(
'name' => 'css/corporate.css', 'name' => 'css/corporate.css',
'info' => 'Corporate', 'info' => 'Corporate',
'nonadmin' => false, 'nonadmin' => false,
@@ -203,7 +204,7 @@
'thumbnail' => 'images/admin_corporate.webp', 'thumbnail' => 'images/admin_corporate.webp',
), ),
'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css' =>
array ( array(
'name' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css', 'name' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css',
'info' => 'Flatly', 'info' => 'Flatly',
'nonadmin' => false, 'nonadmin' => false,
@@ -212,7 +213,7 @@
'thumbnail' => 'images/admin_flatly.webp', 'thumbnail' => 'images/admin_flatly.webp',
), ),
'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css' =>
array ( array(
'name' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css', 'name' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css',
'info' => 'Sandstone', 'info' => 'Sandstone',
'nonadmin' => false, 'nonadmin' => false,
@@ -221,7 +222,7 @@
'thumbnail' => 'images/admin_sandstone.webp', 'thumbnail' => 'images/admin_sandstone.webp',
), ),
'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css' =>
array ( array(
'name' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css', 'name' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css',
'info' => 'Superhero', 'info' => 'Superhero',
'nonadmin' => false, 'nonadmin' => false,
@@ -242,7 +243,7 @@
var_export($result); var_export($result);
continue; continue;
} }
$this->assertSame($var['expected'], $result, 'Test #'.$index.' failed.'); $this->assertSame($var['expected'], $result, 'Test #' . $index . ' failed.');
} }
@@ -252,22 +253,22 @@
public function testGetThemeFiles() public function testGetThemeFiles()
{ {
$expected = array ( $expected = array(
0 => 0 =>
array ( array(
'css' => 'css' =>
array ( array(
0 => '{e_WEB}lib/bootstrap/3/css/bootstrap.min.css', 0 => '{e_WEB}lib/bootstrap/3/css/bootstrap.min.css',
), ),
'js' => 'js' =>
array ( array(
0 => '{e_WEB}lib/bootstrap/3/js/bootstrap.min.js', 0 => '{e_WEB}lib/bootstrap/3/js/bootstrap.min.js',
), ),
), ),
1 => 1 =>
array ( array(
'css' => 'css' =>
array ( array(
0 => '{e_WEB}lib/font-awesome/5/css/all.min.css', 0 => '{e_WEB}lib/font-awesome/5/css/all.min.css',
1 => '{e_WEB}lib/font-awesome/5/css/v4-shims.min.css', 1 => '{e_WEB}lib/font-awesome/5/css/v4-shims.min.css',
), ),
@@ -279,22 +280,22 @@
$this->assertSame($expected, $result); $this->assertSame($expected, $result);
$expected = array ( $expected = array(
0 => 0 =>
array ( array(
'css' => 'css' =>
array ( array(
0 => '{e_WEB}lib/bootstrap/3/css/bootstrap.min.css', 0 => '{e_WEB}lib/bootstrap/3/css/bootstrap.min.css',
), ),
'js' => 'js' =>
array ( array(
0 => '{e_WEB}lib/bootstrap/3/js/bootstrap.min.js', 0 => '{e_WEB}lib/bootstrap/3/js/bootstrap.min.js',
), ),
), ),
1 => 1 =>
array ( array(
'css' => 'css' =>
array ( array(
0 => '{e_WEB}lib/font-awesome/5/css/all.min.css', 0 => '{e_WEB}lib/font-awesome/5/css/all.min.css',
1 => '{e_WEB}lib/font-awesome/5/css/v4-shims.min.css', 1 => '{e_WEB}lib/font-awesome/5/css/v4-shims.min.css',
), ),
@@ -304,10 +305,9 @@
$result = e107::getTheme('bootstrap3')->getThemeFiles('library', 'wysiwyg'); $result = e107::getTheme('bootstrap3')->getThemeFiles('library', 'wysiwyg');
$this->assertSame($expected, $result); $this->assertSame($expected, $result);
$expected = array ( $expected = array(
'css' => 'css' =>
array ( array(),
),
); );
$result = e107::getTheme('bootstrap3')->getThemeFiles('css', 'wysiwyg'); $result = e107::getTheme('bootstrap3')->getThemeFiles('css', 'wysiwyg');
@@ -318,9 +318,9 @@
} }
public function testLoadLibrary() public function testLoadLibrary()
{ {
$tests = array( $tests = array(
0 => array( 0 => array(
'theme' => 'front', 'theme' => 'front',
@@ -343,37 +343,36 @@
foreach($tests as $index => $var) foreach($tests as $index => $var)
{ {
$loaded = e107::getTheme($var['theme'])->loadLibrary($var['scope']); $loaded = e107::getTheme($var['theme'])->loadLibrary($var['scope']);
$this->assertSame($var['expected'], $loaded, 'Test #'.$index.' failed.'); $this->assertSame($var['expected'], $loaded, 'Test #' . $index . ' failed.');
} }
// var_export($loaded); // var_export($loaded);
} }
public function testGet() public function testGet()
{ {
$tests = array( $tests = array(
0 => array( 0 => array(
'theme' => 'front', 'theme' => 'front',
'type' => 'library', 'type' => 'library',
'expected' => array ( 'expected' => array(
0 => 0 =>
array ( array(
'name' => 'bootstrap', 'name' => 'bootstrap',
'version' => '3', 'version' => '3',
'scope' => 'front,admin,wysiwyg', 'scope' => 'front,admin,wysiwyg',
), ),
1 => 1 =>
array ( array(
'name' => 'fontawesome', 'name' => 'fontawesome',
'version' => '5', 'version' => '5',
'scope' => 'front,admin,wysiwyg', 'scope' => 'front,admin,wysiwyg',
), ),
2 => 2 =>
array ( array(
'name' => 'bootstrap.editable', 'name' => 'bootstrap.editable',
'version' => '', 'version' => '',
'scope' => 'admin', 'scope' => 'admin',
@@ -383,21 +382,21 @@
1 => array( 1 => array(
'theme' => 'bootstrap3', 'theme' => 'bootstrap3',
'type' => 'library', 'type' => 'library',
'expected' => array ( 'expected' => array(
0 => 0 =>
array ( array(
'name' => 'bootstrap', 'name' => 'bootstrap',
'version' => '3', 'version' => '3',
'scope' => 'front,admin,wysiwyg', 'scope' => 'front,admin,wysiwyg',
), ),
1 => 1 =>
array ( array(
'name' => 'fontawesome', 'name' => 'fontawesome',
'version' => '5', 'version' => '5',
'scope' => 'front,admin,wysiwyg', 'scope' => 'front,admin,wysiwyg',
), ),
2 => 2 =>
array ( array(
'name' => 'bootstrap.editable', 'name' => 'bootstrap.editable',
'version' => '', 'version' => '',
'scope' => 'admin', 'scope' => 'admin',
@@ -407,15 +406,15 @@
2 => array( 2 => array(
'theme' => '_blank', 'theme' => '_blank',
'type' => 'library', 'type' => 'library',
'expected' => array ( 'expected' => array(
0 => 0 =>
array ( array(
'name' => 'bootstrap', 'name' => 'bootstrap',
'version' => '3', 'version' => '3',
'scope' => 'front', 'scope' => 'front',
), ),
1 => 1 =>
array ( array(
'name' => 'fontawesome', 'name' => 'fontawesome',
'version' => '4', 'version' => '4',
'scope' => 'front', 'scope' => 'front',
@@ -429,12 +428,13 @@
foreach($tests as $index => $var) foreach($tests as $index => $var)
{ {
$result = e107::getTheme($var['theme'])->get($var['type']); $result = e107::getTheme($var['theme'])->get($var['type']);
$this->assertSame($var['expected'], $result, 'Test #'.$index.' failed'); $this->assertSame($var['expected'], $result, 'Test #' . $index . ' failed');
} }
} }
/*
/*
public function testParse_theme_php() public function testParse_theme_php()
{ {
@@ -448,16 +448,16 @@
public function testGetThemeLayout() public function testGetThemeLayout()
{ {
$pref = array ( $pref = array(
'jumbotron_home' => 'jumbotron_home' =>
array ( array(
0 => 'FRONTPAGE', 0 => 'FRONTPAGE',
1 => 'page.php?3!', 1 => 'page.php?3!',
2 => '/my-sef-url!', 2 => '/my-sef-url!',
3 => '/news/?page=', 3 => '/news/?page=',
), ),
'jumbotron_full' => 'jumbotron_full' =>
array ( array(
0 => 'forum', 0 => 'forum',
1 => 'user.php!', // <-- exact match of URL 1 => 'user.php!', // <-- exact match of URL
2 => ':forum/index', 2 => ':forum/index',
@@ -466,7 +466,7 @@
// 2 => '/user', // <-- Expecting URL to match both user and usersetting since it contains no "!" // 2 => '/user', // <-- Expecting URL to match both user and usersetting since it contains no "!"
), ),
'jumbotron_sidebar_right' => 'jumbotron_sidebar_right' =>
array ( array(
0 => '/news', 0 => '/news',
1 => '/user/', 1 => '/user/',
2 => 'user.php?id', 2 => 'user.php?id',
@@ -493,47 +493,47 @@
$tests = array( $tests = array(
0 => array('url' => SITEURL."index.php", 'expected' => 'jumbotron_home'), 0 => array('url' => SITEURL . "index.php", 'expected' => 'jumbotron_home'),
1 => array('url' => SITEURL."index.php?", 'expected' => 'jumbotron_home'), 1 => array('url' => SITEURL . "index.php?", 'expected' => 'jumbotron_home'),
2 => array('url' => SITEURL."index.php?fbclid=asdlkjasdlakjsdasd", 'expected' => 'jumbotron_home'), 2 => array('url' => SITEURL . "index.php?fbclid=asdlkjasdlakjsdasd", 'expected' => 'jumbotron_home'),
3 => array('url' => SITEURL."index.php?utm_source=asdd&utm_medium=asdsd", 'expected' => 'jumbotron_home'), 3 => array('url' => SITEURL . "index.php?utm_source=asdd&utm_medium=asdsd", 'expected' => 'jumbotron_home'),
4 => array('url' => SITEURL."news", 'expected' => 'jumbotron_sidebar_right'), 4 => array('url' => SITEURL . "news", 'expected' => 'jumbotron_sidebar_right'),
5 => array('url' => SITEURL."forum", 'script' => "/forum/index.php", 'expected' => 'jumbotron_full'), 5 => array('url' => SITEURL . "forum", 'script' => "/forum/index.php", 'expected' => 'jumbotron_full'),
6 => array('url' => SITEURL."other/page", 'script' => '/page.php', 'expected' => 'other_layout'), 6 => array('url' => SITEURL . "other/page", 'script' => '/page.php', 'expected' => 'other_layout'),
7 => array('url' => SITEURL."news.php?5.3", 'script' => '/news.php', 'expected' => 'jumbotron_sidebar_right'), 7 => array('url' => SITEURL . "news.php?5.3", 'script' => '/news.php', 'expected' => 'jumbotron_sidebar_right'),
8 => array('url' => SITEURL."usersettings.php", 'script' => '/usersettings.php', 'expected' => 'jumbotron_sidebar_right'), 8 => array('url' => SITEURL . "usersettings.php", 'script' => '/usersettings.php', 'expected' => 'jumbotron_sidebar_right'),
9 => array('url' => SITEURL."user.php", 'script' => '/user.php', 'expected' => 'jumbotron_full'), 9 => array('url' => SITEURL . "user.php", 'script' => '/user.php', 'expected' => 'jumbotron_full'),
10 => array('url' => SITEURL."page.php", 'script' => '/page.php', 'expected' => 'other_layout'), 10 => array('url' => SITEURL . "page.php", 'script' => '/page.php', 'expected' => 'other_layout'),
11 => array('url' => SITEURL."page.php?3", 'script' => '/page.php', 'expected' => 'jumbotron_home'), 11 => array('url' => SITEURL . "page.php?3", 'script' => '/page.php', 'expected' => 'jumbotron_home'),
12 => array('url' => SITEURL."somepage/", 'script' => "/script.php", 'expected' => 'other_layout'), 12 => array('url' => SITEURL . "somepage/", 'script' => "/script.php", 'expected' => 'other_layout'),
13 => array('url' => SITEURL."plugin/", 'script' => "/myplugin.php", 'expected' => 'other_layout'), 13 => array('url' => SITEURL . "plugin/", 'script' => "/myplugin.php", 'expected' => 'other_layout'),
14 => array('url' => SITEURL."forum/index.php", 'script' => "/index.php", 'expected' => 'other_layout'), 14 => array('url' => SITEURL . "forum/index.php", 'script' => "/index.php", 'expected' => 'other_layout'),
15 => array('url' => SITEURL."my-chapter/my-title", 'script' => "/page.php", 'expected' => 'other_layout'), 15 => array('url' => SITEURL . "my-chapter/my-title", 'script' => "/page.php", 'expected' => 'other_layout'),
16 => array('url' => SITEURL."my-sef-url", 'script' => '/index.php', 'expected' => 'jumbotron_home'), 16 => array('url' => SITEURL . "my-sef-url", 'script' => '/index.php', 'expected' => 'jumbotron_home'),
17 => array('url' => SITEURL."user/settings?id=1", 'script' => '/usersettings.php', 'expected' => 'other_layout'), 17 => array('url' => SITEURL . "user/settings?id=1", 'script' => '/usersettings.php', 'expected' => 'other_layout'),
18 => array('url' => SITEURL."user/Tijn", 'script' => '/user.php', 'expected' => 'jumbotron_sidebar_right'), 18 => array('url' => SITEURL . "user/Tijn", 'script' => '/user.php', 'expected' => 'jumbotron_sidebar_right'),
19 => array('url' => SITEURL."user.php?id.1", 'script' => '/user.php', 'expected' => 'jumbotron_sidebar_right'), 19 => array('url' => SITEURL . "user.php?id.1", 'script' => '/user.php', 'expected' => 'jumbotron_sidebar_right'),
20 => array('url' => SITEURL."pluginpage/", 'script' => '/myplugin/index.php', 'expected' => 'script_match'), 20 => array('url' => SITEURL . "pluginpage/", 'script' => '/myplugin/index.php', 'expected' => 'script_match'),
21 => array('url' => SITEURL."news/?page=", 'script' => '/news.php', 'expected' => 'jumbotron_home'), 21 => array('url' => SITEURL . "news/?page=", 'script' => '/news.php', 'expected' => 'jumbotron_home'),
22 => array('url' => SITEURL."news/my-news-title", 'script' => '/news.php', 'expected' => 'jumbotron_sidebar_right'), 22 => array('url' => SITEURL . "news/my-news-title", 'script' => '/news.php', 'expected' => 'jumbotron_sidebar_right'),
23 => array('url' => SITEURL."news/?bla", 'script' => '/news.php', 'expected' => 'other_layout'), 23 => array('url' => SITEURL . "news/?bla", 'script' => '/news.php', 'expected' => 'other_layout'),
// Using e_ROUTE; // Using e_ROUTE;
24 => array('url' => 'whatever.php', 'script'=>'whatever.php', 'route'=> 'news/view/index', 'expected'=> 'other_layout'), 24 => array('url' => 'whatever.php', 'script' => 'whatever.php', 'route' => 'news/view/index', 'expected' => 'other_layout'),
25 => array('url' => 'whatever.php', 'script'=>'whatever.php', 'route'=> 'forum/index', 'expected'=> 'jumbotron_full'), 25 => array('url' => 'whatever.php', 'script' => 'whatever.php', 'route' => 'forum/index', 'expected' => 'jumbotron_full'),
26 => array('url' => 'whatever.php', 'script'=>'whatever.php', 'route'=> 'myplugin/index', 'expected'=> 'jumbotron_full'), 26 => array('url' => 'whatever.php', 'script' => 'whatever.php', 'route' => 'myplugin/index', 'expected' => 'jumbotron_full'),
); );
$themeObj = $this->tm; $themeObj = $this->tm;
foreach($tests as $item=>$var) foreach($tests as $item => $var)
{ {
$var['script'] = isset($var['script']) ? $var['script'] : null; $var['script'] = isset($var['script']) ? $var['script'] : null;
$result = $themeObj::getThemeLayout($pref, $defaultLayout, $var); $result = $themeObj::getThemeLayout($pref, $defaultLayout, $var);
$diz = isset($var['route']) ? $var['route'] : $var['url']; $diz = isset($var['route']) ? $var['route'] : $var['url'];
$this->assertEquals($var['expected'],$result, "Wrong theme layout returned for item [".$item."] ".$diz); $this->assertEquals($var['expected'], $result, "Wrong theme layout returned for item [" . $item . "] " . $diz);
// echo $var['url']."\t\t\t".$result."\n\n"; // echo $var['url']."\t\t\t".$result."\n\n";
} }
@@ -541,7 +541,8 @@
// print_r($_SERVER); // print_r($_SERVER);
} }
/*
/*
public function testClearCache() public function testClearCache()
{ {
@@ -556,12 +557,110 @@
{ {
} }
*/
public function testParse_theme_xml() public function testParse_theme_xml()
{ {
$tests = array(
'bootstrap3' => array(
'library' => array (
0 =>
array (
'name' => 'bootstrap',
'version' => '3',
'scope' => 'front,admin,wysiwyg',
),
1 =>
array (
'name' => 'fontawesome',
'version' => '5',
'scope' => 'front,admin,wysiwyg',
),
2 =>
array (
'name' => 'bootstrap.editable',
'version' => '',
'scope' => 'admin',
),
)
),
'bootstrap5' => array(
'library' => array (
0 =>
array (
'name' => 'bootstrap',
'version' => '5',
'scope' => 'front',
),
1 =>
array (
'name' => 'fontawesome',
'version' => '5',
'scope' => 'front',
),
),
),
'voux' => array( // theme using defines for FONTAWESOME and BOOTSTRAP
'library' => array (
0 =>
array (
'name' => 'bootstrap',
'version' => '3',
'scope' => 'front,wysiwyg',
),
1 =>
array (
'name' => 'fontawesome',
'version' => '4',
'scope' => 'front,wysiwyg',
),
)
),
);
foreach($tests as $theme => $var)
{
$result = e_theme::parse_theme_xml($theme);
foreach($var as $att => $value)
{
if(empty($value))
{
var_export($result[$att]);
continue;
}
$this->assertSame($result[$att], $value);
}
} }
*/
}
public function testGetLegacyBSFA()
{
$result = e_theme::getLegacyBSFA('voux');
$expected = array (
0 =>
array (
'name' => 'bootstrap',
'version' => '3',
'scope' => 'front,wysiwyg',
),
1 =>
array (
'name' => 'fontawesome',
'version' => '4',
'scope' => 'front,wysiwyg',
),
);
$this->assertSame($expected, $result);
}
@@ -573,7 +672,7 @@
// } // }
/* /*
public function testGetThemesMigrations() public function testGetThemesMigrations()
{ {
$thm = e107::getSingleton('themeHandler'); $thm = e107::getSingleton('themeHandler');
@@ -592,9 +691,9 @@
} }
*/ */
/* /*
public function testThemeInfoMigration() public function testThemeInfoMigration()
{ {
$thm = e107::getSingleton('themeHandler'); $thm = e107::getSingleton('themeHandler');
@@ -614,6 +713,6 @@
$this->assertSame($old, $new); $this->assertSame($old, $new);
} }
*/ */
} }

View File

@@ -1,15 +1,16 @@
<?php <?php
class wysiwygTest extends \Codeception\Test\Unit class wysiwygTest extends \Codeception\Test\Unit
{ {
/** @var wysiwyg */ /** @var wysiwyg */
protected $tm; protected $tm;
protected function _before() protected function _before()
{ {
require_once(e_PLUGIN."tinymce4/wysiwyg_class.php");
require_once(e_PLUGIN . "tinymce4/wysiwyg_class.php");
try try
{ {
$this->tm = $this->make('wysiwyg'); $this->tm = $this->make('wysiwyg');
@@ -21,7 +22,8 @@
} }
} }
/*
/*
public function testGetExternalPlugins() public function testGetExternalPlugins()
{ {
@@ -39,19 +41,42 @@
public function testGetEditorCSS() public function testGetEditorCSS()
{ {
$expected = array (
$tests = array(
'bootstrap3' => array(
0 => '/e107_web/lib/bootstrap/3/css/bootstrap.min.css', 0 => '/e107_web/lib/bootstrap/3/css/bootstrap.min.css',
1 => '/e107_web/lib/font-awesome/5/css/all.min.css', 1 => '/e107_web/lib/font-awesome/5/css/all.min.css',
2 => '/e107_web/lib/font-awesome/5/css/v4-shims.min.css', 2 => '/e107_web/lib/font-awesome/5/css/v4-shims.min.css',
3 => '/e107_web/lib/animate.css/animate.min.css', 3 => '/e107_web/lib/animate.css/animate.min.css',
4 => '/e107_plugins/tinymce4/editor.css', 4 => '/e107_plugins/tinymce4/editor.css',
),
'voux' => array (
0 => '/e107_web/lib/bootstrap/3/css/bootstrap.min.css',
1 => '/e107_web/lib/font-awesome/4.7.0/css/font-awesome.min.css',
2 => '/e107_web/lib/animate.css/animate.min.css',
3 => '/e107_plugins/tinymce4/editor.css',
)
); );
$result = $this->tm->getEditorCSS();
foreach($tests as $themedir => $expected)
{
$result = $this->tm->getEditorCSS($themedir);
if(empty($expected))
{
var_export($result);
continue;
}
$this->assertSame($expected, $result); $this->assertSame($expected, $result);
}
} }
/* /*
public function testGetTemplates() public function testGetTemplates()
{ {
@@ -76,8 +101,7 @@
{ {
} }
*/ */
}
}