From 2862e18db94899361a4d5be20c3e2d990b79e67a Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 6 Apr 2021 18:41:15 -0700 Subject: [PATCH] Issue #4471 --- e107_admin/image.php | 59 +- e107_handlers/theme_handler.php | 40 + e107_plugins/tinymce4/plugins/e107/parser.php | 4 +- e107_plugins/tinymce4/wysiwyg_class.php | 6 +- e107_tests/tests/unit/e_themeTest.php | 1171 +++++++++-------- .../unit/plugins/tinymce4/wysiwygTest.php | 150 ++- 6 files changed, 806 insertions(+), 624 deletions(-) diff --git a/e107_admin/image.php b/e107_admin/image.php index 63abf5c7a..4a6b55500 100644 --- a/e107_admin/image.php +++ b/e107_admin/image.php @@ -1666,15 +1666,29 @@ class media_admin_ui extends e_admin_ui private function mediaManagerPlaceholders() { - $type = (E107_DEBUG_LEVEL > 0) ? 'text' : 'hidden'; - $br = (E107_DEBUG_LEVEL > 0) ? "
" : ''; + $type = (E107_DEBUG_LEVEL > 0) ? 'text' : 'hidden'; + + + $valueHolders = [ + 'bbcode_holder' => 'bbcode', + 'html_holder' => 'html/wysiwyg', + 'src' => '(preview) src', + 'path' => 'path (save to db)' + ]; + + $text = ''; + foreach($valueHolders as $name => $label) + { + $text .= (E107_DEBUG_LEVEL > 0) ? "
".$label." " : ''; + $text .= "\n"; + + } + + if(E107_DEBUG_LEVEL > 0) + { + $text .= "
FontAwesome".e107::getTheme()->getFontAwesome(); + } - $text = ' - ' .$br." - ".$br." - ".$br." - ".$br." - "; return $text; } @@ -2117,21 +2131,24 @@ class media_admin_ui extends e_admin_ui } - $fa4 = e107::getMedia()->getGlyphs('fa4'); - - foreach($fa4 as $val) + if($this->fontawesome === 4) { - $items[] = array( - 'previewHtml' => $md->previewTag('fa-'.$val,array('type'=>'glyph')), - 'previewUrl' => 'fa fa-'.$val, - 'saveValue' => 'fa-'.$val.'.glyph', - 'thumbUrl' => 'fa-'.$val, - 'title' => 'FA4 '.$val, - 'slideCaption' => 'Font-Awesome 4', - 'slideCategory' => 'font-awesome' - ); - } + e107::getParser()->setFontAwesome(4);; + $fa4 = e107::getMedia()->getGlyphs('fa4'); + foreach($fa4 as $val) + { + $items[] = array( + 'previewHtml' => $md->previewTag('fa-'.$val, array('type'=>'glyph')), + 'previewUrl' => 'fa fa-'.$val, + 'saveValue' => 'fa-'.$val.'.glyph', + 'thumbUrl' => 'fa-'.$val, + 'title' => 'FA4 '.$val, + 'slideCaption' => 'Font-Awesome 4', + 'slideCategory' => 'font-awesome' + ); + } + } if($this->fontawesome === false || ($this->fontawesome < 4)) { diff --git a/e107_handlers/theme_handler.php b/e107_handlers/theme_handler.php index be48efa89..daceb5e06 100644 --- a/e107_handlers/theme_handler.php +++ b/e107_handlers/theme_handler.php @@ -1103,6 +1103,15 @@ class e_theme 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'])) { @@ -1158,6 +1167,37 @@ class e_theme 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. diff --git a/e107_plugins/tinymce4/plugins/e107/parser.php b/e107_plugins/tinymce4/plugins/e107/parser.php index d2f725c61..440616182 100644 --- a/e107_plugins/tinymce4/plugins/e107/parser.php +++ b/e107_plugins/tinymce4/plugins/e107/parser.php @@ -114,7 +114,9 @@ TEMPL; public function toHTML($content) { $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 = e107::getBB()->htmltoBBcode($content); //XXX This breaks inserted images from media-manager. :/ diff --git a/e107_plugins/tinymce4/wysiwyg_class.php b/e107_plugins/tinymce4/wysiwyg_class.php index 0159b349b..b34d903cb 100644 --- a/e107_plugins/tinymce4/wysiwyg_class.php +++ b/e107_plugins/tinymce4/wysiwyg_class.php @@ -943,12 +943,12 @@ class wysiwyg /** * @return array */ - public function getEditorCSS() + public function getEditorCSS($theme = 'front') { $tp = e107::getParser(); - $libraries = e107::getTheme('admin')->getThemeFiles('library', 'wysiwyg'); + $libraries = e107::getTheme($theme)->getThemeFiles('library', 'wysiwyg'); $ret = []; @@ -967,7 +967,7 @@ class wysiwyg if($useThemeStyle) { - $theme = e107::getTheme()->getThemeFiles('css', 'wysiwyg'); + $theme = e107::getTheme($theme)->getThemeFiles('css', 'wysiwyg'); if(!empty($theme['css'])) { foreach($theme['css'] as $path) diff --git a/e107_tests/tests/unit/e_themeTest.php b/e107_tests/tests/unit/e_themeTest.php index 5433f8620..7036a1f98 100644 --- a/e107_tests/tests/unit/e_themeTest.php +++ b/e107_tests/tests/unit/e_themeTest.php @@ -1,619 +1,718 @@ tm = $this->make('e_theme'); + } + catch(Exception $e) + { + $this->assertTrue(false, "Couldn't load e_theme object"); + } + + $this->tm->clearCache(); + e107::getTheme()->clearCache(); + } + + + /* + public function testCssAttribute() { - $this->tm = $this->make('e_theme'); - } - catch (Exception $e) - { - $this->assertTrue(false, "Couldn't load e_theme object"); + } - $this->tm->clearCache(); - e107::getTheme()->clearCache(); - } + public function testUpgradeThemeCode() + { + } -/* - public function testCssAttribute() - { + public function testGetThemeList() + { - } + } + */ + public function testGetScope() + { - public function testUpgradeThemeCode() - { - - } - - public function testGetThemeList() - { - - } -*/ - public function testGetScope() - { - $tests = array( - 0 => array( - 'theme' => 'front', - 'type' => 'library', - 'scope' => 'front', - 'expected' => array ( - 'bootstrap' => - array ( - 'name' => 'bootstrap', - 'version' => '3', - ), - 'fontawesome' => - array ( - 'name' => 'fontawesome', - 'version' => '5', - ), - ) - ), - 1 => array( - 'theme' => 'front', - 'type' => 'library', - 'scope' => 'all', - 'expected' => array ( - 'bootstrap' => - array ( - 'name' => 'bootstrap', - 'version' => '3', - ), - 'fontawesome' => - array ( - 'name' => 'fontawesome', - 'version' => '5', - ), - 'bootstrap.editable' => - array ( - 'name' => 'bootstrap.editable', - 'version' => '', - ), - ) - ), - 2 => array( - 'theme' => 'front', - 'type' => 'library', - 'scope' => 'admin', - 'expected' => array ( - 'bootstrap' => - array ( - 'name' => 'bootstrap', - 'version' => '3', - ), - 'fontawesome' => - array ( - 'name' => 'fontawesome', - 'version' => '5', - ), - 'bootstrap.editable' => - array ( - 'name' => 'bootstrap.editable', - 'version' => '', - ), - ) - ), - 3 => array( - 'theme' => '_blank', - 'type' => 'library', - 'scope' => 'front', - 'expected' => array ( - 'bootstrap' => - array ( - 'name' => 'bootstrap', - 'version' => '3', - ), - 'fontawesome' => - array ( - 'name' => 'fontawesome', - 'version' => '4', - ), - ) - ), - 4 => array( - 'theme' => 'bootstrap3', - 'type' => 'css', - 'scope' => 'front', - 'expected' => array ( - 'style.css' => - array ( - 'name' => 'style.css', - 'info' => 'Default', - 'nonadmin' => true, - 'exclude' => '', - 'description' => '', - 'thumbnail' => '', - ), - '*' => array ( - 'name' => '*', - 'info' => '*', - 'nonadmin' => true, - 'exclude' => '', - 'description' => '', - 'thumbnail' => '', - ), + $tests = array( + 0 => array( + 'theme' => 'front', + 'type' => 'library', + 'scope' => 'front', + 'expected' => array( + 'bootstrap' => + array( + 'name' => 'bootstrap', + 'version' => '3', ), - ), - 5 => array( - 'theme' => 'bootstrap3', - 'type' => 'css', - 'scope' => 'admin', - 'expected' => array ( - 'css/modern-light.css' => - array ( - 'name' => 'css/modern-light.css', - 'info' => 'Modern Light', - 'nonadmin' => false, - 'exclude' => 'bootstrap', - 'description' => 'A high-contrast light skin', - 'thumbnail' => 'images/admin_modern-light.webp', - ), - 'css/modern-dark.css' => - array ( - 'name' => 'css/modern-dark.css', - 'info' => 'Modern Dark', - 'nonadmin' => false, - 'exclude' => 'bootstrap', - 'description' => 'A high-contrast dark skin', - 'thumbnail' => 'images/admin_modern-dark.webp', - ), - 'css/bootstrap-dark.min.css' => - array ( - 'name' => 'css/bootstrap-dark.min.css', - 'info' => 'Legacy Dark Admin', - 'nonadmin' => false, - 'exclude' => 'bootstrap', - 'description' => 'A dark admin area skin', - 'thumbnail' => 'images/admin_bootstrap-dark.webp', - ), - 'css/kadmin.css' => - array ( - 'name' => 'css/kadmin.css', - 'info' => 'K-Admin Inspired', - 'nonadmin' => false, - 'exclude' => '', - 'description' => 'A light admin area skin', - 'thumbnail' => 'images/admin_kadmin.webp', - ), - 'css/corporate.css' => - array ( - 'name' => 'css/corporate.css', - 'info' => 'Corporate', - 'nonadmin' => false, - 'exclude' => 'bootstrap', - 'description' => '', - 'thumbnail' => 'images/admin_corporate.webp', - ), - 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css' => - array ( - 'name' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css', - 'info' => 'Flatly', - 'nonadmin' => false, - 'exclude' => 'bootstrap', - 'description' => '', - 'thumbnail' => 'images/admin_flatly.webp', - ), - 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css' => - array ( - 'name' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css', - 'info' => 'Sandstone', - 'nonadmin' => false, - 'exclude' => 'bootstrap', - 'description' => '', - 'thumbnail' => 'images/admin_sandstone.webp', - ), - 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css' => - array ( - 'name' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css', - 'info' => 'Superhero', - 'nonadmin' => false, - 'exclude' => 'bootstrap', - 'description' => '', - 'thumbnail' => 'images/admin_superhero.webp', - ), + 'fontawesome' => + array( + 'name' => 'fontawesome', + 'version' => '5', ), + ) + ), + 1 => array( + 'theme' => 'front', + 'type' => 'library', + 'scope' => 'all', + 'expected' => array( + 'bootstrap' => + array( + 'name' => 'bootstrap', + 'version' => '3', + ), + 'fontawesome' => + array( + 'name' => 'fontawesome', + 'version' => '5', + ), + 'bootstrap.editable' => + array( + 'name' => 'bootstrap.editable', + 'version' => '', + ), + ) + ), + 2 => array( + 'theme' => 'front', + 'type' => 'library', + 'scope' => 'admin', + 'expected' => array( + 'bootstrap' => + array( + 'name' => 'bootstrap', + 'version' => '3', + ), + 'fontawesome' => + array( + 'name' => 'fontawesome', + 'version' => '5', + ), + 'bootstrap.editable' => + array( + 'name' => 'bootstrap.editable', + 'version' => '', + ), + ) + ), + 3 => array( + 'theme' => '_blank', + 'type' => 'library', + 'scope' => 'front', + 'expected' => array( + 'bootstrap' => + array( + 'name' => 'bootstrap', + 'version' => '3', + ), + 'fontawesome' => + array( + 'name' => 'fontawesome', + 'version' => '4', + ), + ) + ), + 4 => array( + 'theme' => 'bootstrap3', + 'type' => 'css', + 'scope' => 'front', + 'expected' => array( + 'style.css' => + array( + 'name' => 'style.css', + 'info' => 'Default', + 'nonadmin' => true, + 'exclude' => '', + 'description' => '', + 'thumbnail' => '', + ), + '*' => array( + 'name' => '*', + 'info' => '*', + 'nonadmin' => true, + 'exclude' => '', + 'description' => '', + 'thumbnail' => '', ), + ), + ), + 5 => array( + 'theme' => 'bootstrap3', + 'type' => 'css', + 'scope' => 'admin', + 'expected' => array( + 'css/modern-light.css' => + array( + 'name' => 'css/modern-light.css', + 'info' => 'Modern Light', + 'nonadmin' => false, + 'exclude' => 'bootstrap', + 'description' => 'A high-contrast light skin', + 'thumbnail' => 'images/admin_modern-light.webp', + ), + 'css/modern-dark.css' => + array( + 'name' => 'css/modern-dark.css', + 'info' => 'Modern Dark', + 'nonadmin' => false, + 'exclude' => 'bootstrap', + 'description' => 'A high-contrast dark skin', + 'thumbnail' => 'images/admin_modern-dark.webp', + ), + 'css/bootstrap-dark.min.css' => + array( + 'name' => 'css/bootstrap-dark.min.css', + 'info' => 'Legacy Dark Admin', + 'nonadmin' => false, + 'exclude' => 'bootstrap', + 'description' => 'A dark admin area skin', + 'thumbnail' => 'images/admin_bootstrap-dark.webp', + ), + 'css/kadmin.css' => + array( + 'name' => 'css/kadmin.css', + 'info' => 'K-Admin Inspired', + 'nonadmin' => false, + 'exclude' => '', + 'description' => 'A light admin area skin', + 'thumbnail' => 'images/admin_kadmin.webp', + ), + 'css/corporate.css' => + array( + 'name' => 'css/corporate.css', + 'info' => 'Corporate', + 'nonadmin' => false, + 'exclude' => 'bootstrap', + 'description' => '', + 'thumbnail' => 'images/admin_corporate.webp', + ), + 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css' => + array( + 'name' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css', + 'info' => 'Flatly', + 'nonadmin' => false, + 'exclude' => 'bootstrap', + 'description' => '', + 'thumbnail' => 'images/admin_flatly.webp', + ), + 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css' => + array( + 'name' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css', + 'info' => 'Sandstone', + 'nonadmin' => false, + 'exclude' => 'bootstrap', + 'description' => '', + 'thumbnail' => 'images/admin_sandstone.webp', + ), + 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css' => + array( + 'name' => 'https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css', + 'info' => 'Superhero', + 'nonadmin' => false, + 'exclude' => 'bootstrap', + 'description' => '', + 'thumbnail' => 'images/admin_superhero.webp', + ), + ), + ), - ); + ); - foreach($tests as $index => $var) + foreach($tests as $index => $var) + { + $result = e107::getTheme($var['theme'])->getScope($var['type'], $var['scope']); + if(empty($var['expected'])) { - $result = e107::getTheme($var['theme'])->getScope($var['type'], $var['scope']); - if(empty($var['expected'])) - { - var_export($result); - continue; - } - $this->assertSame($var['expected'], $result, 'Test #'.$index.' failed.'); + var_export($result); + continue; } - - + $this->assertSame($var['expected'], $result, 'Test #' . $index . ' failed.'); } - public function testGetThemeFiles() - { - - $expected = array ( - 0 => - array ( - 'css' => - array ( - 0 => '{e_WEB}lib/bootstrap/3/css/bootstrap.min.css', - ), - 'js' => - array ( - 0 => '{e_WEB}lib/bootstrap/3/js/bootstrap.min.js', - ), - ), - 1 => - 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', - ), - ), - ); - - /** Expecting bootstrap 3 files fontawesome 5 files */ - $result = e107::getTheme('bootstrap3')->getThemeFiles('library', 'front'); - $this->assertSame($expected, $result); + } - $expected = array ( - 0 => - array ( - 'css' => - array ( - 0 => '{e_WEB}lib/bootstrap/3/css/bootstrap.min.css', - ), - 'js' => - array ( - 0 => '{e_WEB}lib/bootstrap/3/js/bootstrap.min.js', - ), - ), - 1 => - 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', - ), - ), - ); + public function testGetThemeFiles() + { - $result = e107::getTheme('bootstrap3')->getThemeFiles('library', 'wysiwyg'); - $this->assertSame($expected, $result); + $expected = array( + 0 => + array( + 'css' => + array( + 0 => '{e_WEB}lib/bootstrap/3/css/bootstrap.min.css', + ), + 'js' => + array( + 0 => '{e_WEB}lib/bootstrap/3/js/bootstrap.min.js', + ), + ), + 1 => + 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', + ), + ), + ); - $expected = array ( - 'css' => - array ( - ), - ); + /** Expecting bootstrap 3 files fontawesome 5 files */ + $result = e107::getTheme('bootstrap3')->getThemeFiles('library', 'front'); + $this->assertSame($expected, $result); - $result = e107::getTheme('bootstrap3')->getThemeFiles('css', 'wysiwyg'); - $this->assertSame($expected, $result); + + $expected = array( + 0 => + array( + 'css' => + array( + 0 => '{e_WEB}lib/bootstrap/3/css/bootstrap.min.css', + ), + 'js' => + array( + 0 => '{e_WEB}lib/bootstrap/3/js/bootstrap.min.js', + ), + ), + 1 => + 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::getTheme('bootstrap3')->getThemeFiles('library', 'wysiwyg'); + $this->assertSame($expected, $result); + + $expected = array( + 'css' => + array(), + ); + + $result = e107::getTheme('bootstrap3')->getThemeFiles('css', 'wysiwyg'); + $this->assertSame($expected, $result); // $result = e107::getTheme('bootstrap5')->getThemeFiles('css', 'wysiwyg'); - } + } + public function testLoadLibrary() + { - 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) { - $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'])->loadLibrary($var['scope']); - $this->assertSame($var['expected'], $loaded, 'Test #'.$index.' failed.'); - } + $loaded = e107::getTheme($var['theme'])->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' => 'front,admin,wysiwyg', + ), + 1 => + array( + 'name' => 'fontawesome', + 'version' => '5', + 'scope' => 'front,admin,wysiwyg', + ), + 2 => + array( + 'name' => 'bootstrap.editable', + 'version' => '', + 'scope' => 'admin', + ), + ) + ), + 1 => array( + 'theme' => 'bootstrap3', + 'type' => 'library', + 'expected' => 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', + ), + ) + ), + 2 => array( + 'theme' => '_blank', + 'type' => 'library', + 'expected' => array( + 0 => + array( + 'name' => 'bootstrap', + 'version' => '3', + 'scope' => 'front', + ), + 1 => + array( + 'name' => 'fontawesome', + 'version' => '4', + 'scope' => 'front', + ), + ) + ), + + ); + foreach($tests as $index => $var) + { + $result = e107::getTheme($var['theme'])->get($var['type']); + $this->assertSame($var['expected'], $result, 'Test #' . $index . ' failed'); } - public function testGet() - { - $tests = array( - 0 => array( - 'theme' => 'front', - 'type' => 'library', - 'expected' => 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', - ), - ) - ), - 1 => array( - 'theme' => 'bootstrap3', - 'type' => 'library', - 'expected' => 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', - ), - ) - ), - 2 => array( - 'theme' => '_blank', - 'type' => 'library', - 'expected' => array ( - 0 => - array ( - 'name' => 'bootstrap', - 'version' => '3', - 'scope' => 'front', - ), - 1 => - array ( - 'name' => 'fontawesome', - 'version' => '4', - 'scope' => 'front', - ), - ) - ), - ); + } - - foreach($tests as $index => $var) + /* + public function testParse_theme_php() { - $result = e107::getTheme($var['theme'])->get($var['type']); - $this->assertSame($var['expected'], $result, 'Test #'.$index.' failed'); + } - - } -/* - public function testParse_theme_php() - { - - } - - public function testGetThemeInfo() - { - - }*/ - - public function testGetThemeLayout() - { - - $pref = array ( - 'jumbotron_home' => - array ( - 0 => 'FRONTPAGE', - 1 => 'page.php?3!', - 2 => '/my-sef-url!', - 3 => '/news/?page=', - ), - 'jumbotron_full' => - array ( - 0 => 'forum', - 1 => 'user.php!', // <-- exact match of URL - 2 => ':forum/index', - 3 => ':myplugin/', - - // 2 => '/user', // <-- Expecting URL to match both user and usersetting since it contains no "!" - ), - 'jumbotron_sidebar_right' => - array ( - 0 => '/news', - 1 => '/user/', - 2 => 'user.php?id', - // 1 => '/usersettings.php' - ), - 'other_layout' => - array( - 0 => 'myplugin.php$', // <-- $ = script name match - 1 => 'forum/index.php', - 2 => 'page.php$', // <-- $ = script name match - 3 => '/user/settings?', - 4 => 'script.php$', - 5 => '/news/?bla', - 6 => ':news/view/index', - ), - 'script_match' => - array( - 0 => 'myplugin/index.php$', // <-- $ = script name match - - ), - ); - - $defaultLayout = "jumbotron_sidebar_right"; - - - $tests = array( - 0 => 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'), - 3 => array('url' => SITEURL."index.php?utm_source=asdd&utm_medium=asdsd", 'expected' => 'jumbotron_home'), - 4 => array('url' => SITEURL."news", 'expected' => 'jumbotron_sidebar_right'), - 5 => array('url' => SITEURL."forum", 'script' => "/forum/index.php", 'expected' => 'jumbotron_full'), - 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'), - 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'), - 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'), - 12 => array('url' => SITEURL."somepage/", 'script' => "/script.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'), - 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'), - 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'), - 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'), - 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'), - 23 => array('url' => SITEURL."news/?bla", 'script' => '/news.php', 'expected' => 'other_layout'), - - // Using e_ROUTE; - 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'), - 26 => array('url' => 'whatever.php', 'script'=>'whatever.php', 'route'=> 'myplugin/index', 'expected'=> 'jumbotron_full'), - - ); - - $themeObj = $this->tm; - - foreach($tests as $item=>$var) + public function testGetThemeInfo() { - $var['script'] = isset($var['script']) ? $var['script'] : null; - $result = $themeObj::getThemeLayout($pref, $defaultLayout, $var); - $diz = isset($var['route']) ? $var['route'] : $var['url']; - $this->assertEquals($var['expected'],$result, "Wrong theme layout returned for item [".$item."] ".$diz); + }*/ + + public function testGetThemeLayout() + { + + $pref = array( + 'jumbotron_home' => + array( + 0 => 'FRONTPAGE', + 1 => 'page.php?3!', + 2 => '/my-sef-url!', + 3 => '/news/?page=', + ), + 'jumbotron_full' => + array( + 0 => 'forum', + 1 => 'user.php!', // <-- exact match of URL + 2 => ':forum/index', + 3 => ':myplugin/', + + // 2 => '/user', // <-- Expecting URL to match both user and usersetting since it contains no "!" + ), + 'jumbotron_sidebar_right' => + array( + 0 => '/news', + 1 => '/user/', + 2 => 'user.php?id', + // 1 => '/usersettings.php' + ), + 'other_layout' => + array( + 0 => 'myplugin.php$', // <-- $ = script name match + 1 => 'forum/index.php', + 2 => 'page.php$', // <-- $ = script name match + 3 => '/user/settings?', + 4 => 'script.php$', + 5 => '/news/?bla', + 6 => ':news/view/index', + ), + 'script_match' => + array( + 0 => 'myplugin/index.php$', // <-- $ = script name match + + ), + ); + + $defaultLayout = "jumbotron_sidebar_right"; + + + $tests = array( + 0 => 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'), + 3 => array('url' => SITEURL . "index.php?utm_source=asdd&utm_medium=asdsd", 'expected' => 'jumbotron_home'), + 4 => array('url' => SITEURL . "news", 'expected' => 'jumbotron_sidebar_right'), + 5 => array('url' => SITEURL . "forum", 'script' => "/forum/index.php", 'expected' => 'jumbotron_full'), + 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'), + 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'), + 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'), + 12 => array('url' => SITEURL . "somepage/", 'script' => "/script.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'), + 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'), + 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'), + 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'), + 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'), + 23 => array('url' => SITEURL . "news/?bla", 'script' => '/news.php', 'expected' => 'other_layout'), + + // Using e_ROUTE; + 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'), + 26 => array('url' => 'whatever.php', 'script' => 'whatever.php', 'route' => 'myplugin/index', 'expected' => 'jumbotron_full'), + + ); + + $themeObj = $this->tm; + + foreach($tests as $item => $var) + { + $var['script'] = isset($var['script']) ? $var['script'] : null; + + $result = $themeObj::getThemeLayout($pref, $defaultLayout, $var); + $diz = isset($var['route']) ? $var['route'] : $var['url']; + $this->assertEquals($var['expected'], $result, "Wrong theme layout returned for item [" . $item . "] " . $diz); // echo $var['url']."\t\t\t".$result."\n\n"; + } + + + // print_r($_SERVER); + + } + + /* + public function testClearCache() + { + + } + + public function testGet() + { + + } + + public function testGetList() + { + + } + */ + + 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); } - - // print_r($_SERVER); - } -/* - public function testClearCache() - { - } - public function testGet() - { - } + } - public function testGetList() - { + 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', + ), + ); - public function testParse_theme_xml() - { - - } - */ + $this->assertSame($expected, $result); + } // public function testLoadLayout() // { - // $res = e_theme::loadLayout('full', 'bootstrap4'); + // $res = e_theme::loadLayout('full', 'bootstrap4'); - // var_dump($res); + // var_dump($res); // } -/* - public function testGetThemesMigrations() - { - $thm = e107::getSingleton('themeHandler'); - - $tests = array(null, 'id', 'xml'); - - foreach($tests as $mode) + /* + public function testGetThemesMigrations() { - $old = $thm->getThemes($mode); + $thm = e107::getSingleton('themeHandler'); + + $tests = array(null, 'id', 'xml'); + + foreach($tests as $mode) + { + $old = $thm->getThemes($mode); + + $this->tm->__construct(['force'=>true]); + $new = $this->tm->getThemes($mode); + + $this->assertSame($old,$new); + } - $this->tm->__construct(['force'=>true]); - $new = $this->tm->getThemes($mode); - $this->assertSame($old,$new); } + */ + /* + public function testThemeInfoMigration() + { + $thm = e107::getSingleton('themeHandler'); - } -*/ + $name = 'bootstrap3'; -/* - public function testThemeInfoMigration() - { - $thm = e107::getSingleton('themeHandler'); + $this->tm->__construct(['themedir'=>$name, 'force'=>true]); + $old = $thm->getThemeInfo($name); - $name = 'bootstrap3'; + $new = $this->tm->get(); - $this->tm->__construct(['themedir'=>$name, 'force'=>true]); - $old = $thm->getThemeInfo($name); + $this->assertNotEmpty($new, "New parsing of ".$name." returned null"); + $this->assertNotEmpty($old, "Old parsing of ".$name." returned null"); - $new = $this->tm->get(); + // unset($new['id']); // introduced. - $this->assertNotEmpty($new, "New parsing of ".$name." returned null"); - $this->assertNotEmpty($old, "Old parsing of ".$name." returned null"); + $this->assertSame($old, $new); - // unset($new['id']); // introduced. + } + */ - $this->assertSame($old, $new); - - } -*/ - - } +} diff --git a/e107_tests/tests/unit/plugins/tinymce4/wysiwygTest.php b/e107_tests/tests/unit/plugins/tinymce4/wysiwygTest.php index 3069f4988..3788553c9 100644 --- a/e107_tests/tests/unit/plugins/tinymce4/wysiwygTest.php +++ b/e107_tests/tests/unit/plugins/tinymce4/wysiwygTest.php @@ -1,83 +1,107 @@ tm = $this->make('wysiwyg'); + } + + catch(Exception $e) + { + $this->assertTrue(false, $e->getMessage()); + } + + } + + /* + public function testGetExternalPlugins() { - $this->tm = $this->make('wysiwyg'); + } - catch(Exception $e) + public function testConvertBoolean() { - $this->assertTrue(false, $e->getMessage()); + } - } -/* - public function testGetExternalPlugins() + public function test__construct() + { + + }*/ + + public function testGetEditorCSS() + { + + $tests = array( + 'bootstrap3' => array( + 0 => '/e107_web/lib/bootstrap/3/css/bootstrap.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', + 3 => '/e107_web/lib/animate.css/animate.min.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', + ) + + + ); + + + foreach($tests as $themedir => $expected) { + $result = $this->tm->getEditorCSS($themedir); - } + if(empty($expected)) + { + var_export($result); + continue; + } - public function testConvertBoolean() - { - - } - - public function test__construct() - { - - }*/ - - public function testGetEditorCSS() - { - $expected = array ( - 0 => '/e107_web/lib/bootstrap/3/css/bootstrap.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', - 3 => '/e107_web/lib/animate.css/animate.min.css', - 4 => '/e107_plugins/tinymce4/editor.css', - ); - - $result = $this->tm->getEditorCSS(); $this->assertSame($expected, $result); - } -/* - public function testGetTemplates() - { - - } - - public function testFilter_plugins() - { - - } - - public function testRenderConfig() - { - - } - - public function testTinymce_lang() - { - - } - - public function testGetConfig() - { - - } -*/ - } + /* + public function testGetTemplates() + { + + } + + public function testFilter_plugins() + { + + } + + public function testRenderConfig() + { + + } + + public function testTinymce_lang() + { + + } + + public function testGetConfig() + { + + } + */ + + +}