From c1f5a6f8dc8fd7b6125c2687334fd7a2fc436cf2 Mon Sep 17 00:00:00 2001 From: Cameron Date: Sat, 12 Dec 2020 12:40:26 -0800 Subject: [PATCH] Increase speed of TinyMce footer. --- e107_handlers/e107_class.php | 6 ++++-- e107_handlers/plugin_class.php | 5 ++++- e107_tests/tests/unit/e107Test.php | 11 +++++++---- e107_tests/tests/unit/e_pluginTest.php | 16 ++++++++++++++-- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 8c44a7062..4516e13cd 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -3858,7 +3858,8 @@ class e107 if(!isset($availEditors)) { // init list of installed wysiwyg editors - $availEditors = array_keys(e107::getPlug()->getInstalledWysiwygEditors()); + $availEditors = self::getPref('wysiwyg_list', array()); + // $availEditors = array_keys(e107::getPlug()->getInstalledWysiwygEditors()); // very slow. } if(!is_null($val)) @@ -3873,7 +3874,8 @@ class e107 // if no wysiwyg editor available, use fallback editor (bbcode) if(is_bool($editor) || ($editor !== $fallbackEditor && !in_array($editor, $availEditors))) { - $editor = count($availEditors) > 0 ? $availEditors[0] : $fallbackEditor; + $names = array_keys($availEditors); + $editor = count($availEditors) > 0 ? reset($names) : $fallbackEditor; } } // $returnEditor => false: diff --git a/e107_handlers/plugin_class.php b/e107_handlers/plugin_class.php index dd2035dfe..cea5c4652 100644 --- a/e107_handlers/plugin_class.php +++ b/e107_handlers/plugin_class.php @@ -1111,7 +1111,8 @@ class e_plugin $core->set('bbcode_list', array()) ->set('shortcode_legacy_list', array()) ->set('shortcode_list', array()) - ->set('lan_global_list', array()); + ->set('lan_global_list', array()) + ->set('wysiwyg_list', array()); $paths = $this->getDetected(); @@ -1240,6 +1241,8 @@ class e_plugin } } + $editors = $this->getInstalledWysiwygEditors(); + $core->setPref('wysiwyg_list',$editors); $core->save(false, true, false); diff --git a/e107_tests/tests/unit/e107Test.php b/e107_tests/tests/unit/e107Test.php index d0aeb6dcc..5d5b93ae5 100644 --- a/e107_tests/tests/unit/e107Test.php +++ b/e107_tests/tests/unit/e107Test.php @@ -878,13 +878,16 @@ class e107Test extends \Codeception\Test\Unit $this->assertEquals($expected,$result); } -/* + public function testWysiwyg() { - $res = null; - $this->assertTrue($res); - } + $result = e107::wysiwyg(null, true); + $expected = 'bbcode'; + $this->assertSame($expected, $result); + + } +/* public function testLoadLanFiles() { $res = null; diff --git a/e107_tests/tests/unit/e_pluginTest.php b/e107_tests/tests/unit/e_pluginTest.php index 5d86dac16..c1545dee2 100644 --- a/e107_tests/tests/unit/e_pluginTest.php +++ b/e107_tests/tests/unit/e_pluginTest.php @@ -30,7 +30,15 @@ } } + public function testGetInstalledWysiwygEditors() + { + $expected = array('tinymce4'=>'TinyMce4'); + $result = $this->ep->getInstalledWysiwygEditors(); + $this->assertSame($expected,$result); + + + } /** * Creates a dummy plugin entry to make sure such plugins are ignored */ @@ -99,21 +107,25 @@ $newUrls = array('gallery'=>0, 'news'=>'news', 'rss_menu'=>0); e107::getConfig()->setData('e_url_list', $newUrls)->save(false,false,false); + e107::getConfig()->setData('wysiwyg_list', array())->save(false,false,false); $urlsBefore = e107::pref('core', 'e_url_list'); $userBefore = e107::pref('core', 'e_user_list'); + $wysiwygBefore = e107::pref('core', 'wysiwyg_list',array()); - // print_r($userBefore); + // print_r($wysiwygBefore); $this->ep->clearCache()->buildAddonPrefLists(); $urlsAfter = e107::pref('core', 'e_url_list'); $userAfter = e107::pref('core', 'e_user_list'); + $wysiwygAfter = e107::pref('core', 'wysiwyg_list'); - // print_r($userAfter); + // print_r($wysiwygAfter); $this->assertEquals($urlsBefore['gallery'],$urlsAfter['gallery']); $this->assertEquals($userBefore['user'],$userAfter['user']); + $this->assertNotSame($wysiwygBefore,$wysiwygAfter); }