set('alternate_base_folder', __DIR__ . '/TinyMCECombinedGeneratorTest'); Director::config()->set('alternate_base_url', 'http://www.mysite.com/basedir/'); Director::config()->set('alternate_public_dir', ''); // Disable public dir SSViewer::config()->set('themes', [SSViewer::DEFAULT_THEME]); TinyMCEConfig::config() ->set('base_dir', 'tinymce') ->set('editor_css', [ 'mycode/editor.css' ]); } protected function tearDown(): void { parent::tearDown(); // Flush test configs HTMLEditorConfig::set_config('testconfig', null); } public function testConfig() { $module = new Module(Director::baseFolder() . '/mycode', Director::baseFolder()); // Disable nonces $c = new TinyMCEConfig(); $c->setTheme('testtheme'); $c->setOption('language', 'en'); $c->disablePlugins('table', 'emoticons', 'paste', 'code', 'link', 'importcss', 'lists'); $c->enablePlugins( [ 'plugin1' => 'mycode/plugin1.js', // 'plugin2' => '/anotherbase/mycode/plugin2.js', 'plugin3' => 'https://www.google.com/mycode/plugin3.js', 'plugin4' => null, 'plugin5' => null, 'plugin6' => '/basedir/mycode/plugin6.js', 'plugin7' => '/basedir/mycode/plugin7.js', 'plugin8' => $module->getResource('plugin8.js'), ] ); HTMLEditorConfig::set_config('testconfig', $c); // Get config for this /** @var TinyMCECombinedGenerator $generator */ $generator = Injector::inst()->create(TinyMCECombinedGenerator::class); $this->assertMatchesRegularExpression('#_tinymce/tinymce-testconfig-[0-9a-z]{10,10}#', $generator->generateFilename($c)); $content = $generator->generateContent($c); $this->assertStringContainsString( "var baseURL = baseTag.length ? baseTag[0].baseURI : 'http://www.mysite.com/basedir/';\n", $content ); // Main script file $this->assertStringContainsString("/* tinymce.js */\n", $content); // Locale file $this->assertStringContainsString("/* en.js */\n", $content); // Local plugins $this->assertStringContainsString("/* plugin1.js */\n", $content); $this->assertStringContainsString("/* plugin4.min.js */\n", $content); $this->assertStringContainsString("/* plugin4/langs/en.js */\n", $content); $this->assertStringContainsString("/* plugin5.js */\n", $content); $this->assertStringContainsString("/* plugin6.js */\n", $content); // module-resource plugin $this->assertStringContainsString("/* plugin8.js */\n", $content); // Exclude non-local plugins $this->assertStringNotContainsString('plugin2.js', $content); $this->assertStringNotContainsString('plugin3.js', $content); // Exclude missing file $this->assertStringNotContainsString('plugin7.js', $content); // Check themes $this->assertStringContainsString("/* theme.js */\n", $content); $this->assertStringContainsString("/* testtheme/langs/en.js */\n", $content); // Check plugin links included $this->assertStringContainsString( <<assertStringContainsString( <<setTheme('testtheme'); $c->setOption('language', 'en'); $c->disablePlugins('table', 'emoticons', 'paste', 'code', 'link', 'importcss', 'lists'); $c->enablePlugins(['plugin1' => 'mycode/plugin1.js']); HTMLEditorConfig::set_config('testconfig', $c); // Generate file for this /** @var TinyMCECombinedGenerator $generator */ $generator = Injector::inst()->create(TinyMCECombinedGenerator::class); $generator->getScriptURL($c); $filename = $generator->generateFilename($c); // Ensure content exists $this->assertNotEmpty($generator->getAssetHandler()->getContent($filename)); // Flush should destroy this TinyMCECombinedGenerator::flush(); $this->assertEmpty($generator->getAssetHandler()->getContent($filename)); } }