From 45372f285ce6338c5432f51809759e8b6b6b0f33 Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 5 Apr 2022 09:56:25 -0700 Subject: [PATCH] Fixes #4747 - wysiwyg editor value retention. --- e107_handlers/e107_class.php | 8 +++++--- e107_handlers/js_manager.php | 15 +++------------ e107_tests/tests/unit/e107Test.php | 24 +++++++++++++++++++----- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 33e8ec757..c87801068 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -4505,6 +4505,8 @@ class e107 static $availEditors; $fallbackEditor = 'bbcode'; + global $_E107; + if (self::getPref('wysiwyg',false) != true) { // wysiwyg disabled by global pref @@ -4512,12 +4514,11 @@ class e107 } else { - if(!isset($availEditors)) + if(!isset($availEditors) || !empty($_E107['phpunit'])) { // init list of installed wysiwyg editors $default = self::isInstalled('tinymce4') ? array('tinymce4'=>'TinyMce4') : array(); // if missing pref fallback. $availEditors = self::getPref('wysiwyg_list', $default); - // $availEditors = array_keys(e107::getPlug()->getInstalledWysiwygEditors()); // very slow. } @@ -4531,7 +4532,7 @@ class e107 // check if choosen editor is installed, // if not, but a different editor is available use that one (e.g. tinymce4 choosen, but only simplemde available available, use simplemde) // if no wysiwyg editor available, use fallback editor (bbcode) - if(is_bool($editor) || ($editor !== $fallbackEditor && !in_array($editor, $availEditors))) + if(is_bool($editor) || ($editor !== $fallbackEditor && empty($availEditors[$editor]))) { $names = array_keys($availEditors); // $editor = count($availEditors) > 0 ? $availEditors[0] : $fallbackEditor; @@ -4539,6 +4540,7 @@ class e107 } } + // $returnEditor => false: // false => fallback editor (bbcode) // true => default wysiwyg editor diff --git a/e107_handlers/js_manager.php b/e107_handlers/js_manager.php index fa7082492..cc991baeb 100644 --- a/e107_handlers/js_manager.php +++ b/e107_handlers/js_manager.php @@ -239,18 +239,9 @@ class e_jsmanager } else // Front-End. { - if(defset('e_DEBUG_JQUERY') === 2) - { - e107::library('load', 'jquery'); - // jQuery Once is used in e107.behaviors. - e107::library('load', 'jquery.once'); - } - else - { - e107::library('load', 'jquery3'); - } - - + $jqueryLib = (defset('e_DEBUG_JQUERY') === 2) ? 'jquery' : 'jquery3'; + e107::library('load',$jqueryLib); + e107::library('load', 'jquery.once'); // jQuery Once is used in e107.behaviors. } // TODO diff --git a/e107_tests/tests/unit/e107Test.php b/e107_tests/tests/unit/e107Test.php index 4776b95f3..1e9f3ddb2 100644 --- a/e107_tests/tests/unit/e107Test.php +++ b/e107_tests/tests/unit/e107Test.php @@ -1808,15 +1808,28 @@ class e107Test extends \Codeception\Test\Unit public function testWysiwyg() { + // Simulate editors being installed. + $editors = array ( + 'tinymce4' => 'TinyMce4', + 'simplemde' => 'SimpleMDE', + ); - e107::getConfig()->setPref('wysiwyg', true)->save(); - $tinyMceInstalled = e107::isInstalled('tinymce4'); + e107::getConfig() + ->setPref('wysiwyg', true) + ->setPref('wysiwyg_list', $editors) + ->save(); + + global $_E107; + $_E107['phpunit'] = true; // make sure pref is re-loaded. + // $tinyMceInstalled = e107::isInstalled('tinymce4'); $tests = array( //input => expected - 'default' => ($tinyMceInstalled) ? 'tinymce4' : 'bbcode', - 'bbcode' => 'bbcode', - 'tinymce4' => ($tinyMceInstalled) ? 'tinymce4' : 'bbcode', + 'default' => 'tinymce4', + 'bbcode' => 'bbcode', + 'tinymce4' => 'tinymce4', + 'simplemde' => 'simplemde', + 'nonexist' => 'tinymce4', ); foreach($tests as $input => $expected) @@ -1835,6 +1848,7 @@ class e107Test extends \Codeception\Test\Unit $this->assertSame($expected, $result); + e107::getConfig()->setPref('wysiwyg', false)->save(); // wysiwyg is disabled. } /*