2009-12-16 06:30:46 +01:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\Forms\Tests\HTMLEditor;
|
|
|
|
|
2017-06-22 12:50:45 +02:00
|
|
|
use Exception;
|
2017-05-10 03:18:44 +02:00
|
|
|
use SilverStripe\Control\Director;
|
2017-06-27 04:30:48 +02:00
|
|
|
use SilverStripe\Control\SimpleResourceURLGenerator;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Core\Config\Config;
|
|
|
|
use SilverStripe\Core\Convert;
|
2017-06-27 04:30:48 +02:00
|
|
|
use SilverStripe\Core\Injector\Injector;
|
2017-05-10 03:18:44 +02:00
|
|
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
|
|
|
use SilverStripe\Core\Manifest\ModuleManifest;
|
2017-06-27 04:30:48 +02:00
|
|
|
use SilverStripe\Core\Manifest\ResourceURLGenerator;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2017-06-22 12:50:45 +02:00
|
|
|
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;
|
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
class HTMLEditorConfigTest extends SapphireTest
|
|
|
|
{
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2017-05-10 03:18:44 +02:00
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
TinyMCEConfig::config()->set('base_dir', 'test/thirdparty/tinymce');
|
|
|
|
}
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testEnablePluginsByString()
|
|
|
|
{
|
|
|
|
$c = new TinyMCEConfig();
|
|
|
|
$c->enablePlugins('plugin1');
|
|
|
|
$this->assertContains('plugin1', array_keys($c->getPlugins()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEnablePluginsByArray()
|
|
|
|
{
|
|
|
|
$c = new TinyMCEConfig();
|
|
|
|
$c->enablePlugins(array('plugin1', 'plugin2'));
|
|
|
|
$this->assertContains('plugin1', array_keys($c->getPlugins()));
|
|
|
|
$this->assertContains('plugin2', array_keys($c->getPlugins()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEnablePluginsByMultipleStringParameters()
|
|
|
|
{
|
|
|
|
$c = new TinyMCEConfig();
|
|
|
|
$c->enablePlugins('plugin1', 'plugin2');
|
|
|
|
$this->assertContains('plugin1', array_keys($c->getPlugins()));
|
|
|
|
$this->assertContains('plugin2', array_keys($c->getPlugins()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEnablePluginsByArrayWithPaths()
|
|
|
|
{
|
2017-06-27 04:30:48 +02:00
|
|
|
// Disable nonces
|
|
|
|
$urlGenerator = new SimpleResourceURLGenerator();
|
|
|
|
Injector::inst()->registerService($urlGenerator, ResourceURLGenerator::class);
|
|
|
|
|
2017-06-22 12:50:45 +02:00
|
|
|
Config::modify()->set(Director::class, 'alternate_base_url', 'http://mysite.com/subdir');
|
2016-12-16 05:34:21 +01:00
|
|
|
$c = new TinyMCEConfig();
|
|
|
|
$c->setTheme('modern');
|
|
|
|
$c->setOption('language', 'es');
|
2017-09-01 02:20:10 +02:00
|
|
|
$c->disablePlugins('table', 'emoticons', 'paste', 'code', 'link', 'importcss', 'lists');
|
2016-12-16 05:34:21 +01:00
|
|
|
$c->enablePlugins(
|
|
|
|
array(
|
2017-05-10 03:18:44 +02:00
|
|
|
'plugin1' => 'mypath/plugin1.js',
|
|
|
|
'plugin2' => '/anotherbase/mypath/plugin2.js',
|
|
|
|
'plugin3' => 'https://www.google.com/plugin.js',
|
|
|
|
'plugin4' => null,
|
|
|
|
'plugin5' => null,
|
2016-12-16 05:34:21 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$attributes = $c->getAttributes();
|
|
|
|
$config = Convert::json2array($attributes['data-config']);
|
|
|
|
$plugins = $config['external_plugins'];
|
|
|
|
$this->assertNotEmpty($plugins);
|
|
|
|
|
|
|
|
// Plugin specified via relative url
|
|
|
|
$this->assertContains('plugin1', array_keys($plugins));
|
|
|
|
$this->assertEquals(
|
|
|
|
'http://mysite.com/subdir/mypath/plugin1.js',
|
|
|
|
$plugins['plugin1']
|
|
|
|
);
|
|
|
|
|
|
|
|
// Plugin specified via root-relative url
|
|
|
|
$this->assertContains('plugin2', array_keys($plugins));
|
|
|
|
$this->assertEquals(
|
|
|
|
'http://mysite.com/anotherbase/mypath/plugin2.js',
|
|
|
|
$plugins['plugin2']
|
|
|
|
);
|
|
|
|
|
|
|
|
// Plugin specified with absolute url
|
|
|
|
$this->assertContains('plugin3', array_keys($plugins));
|
|
|
|
$this->assertEquals(
|
|
|
|
'https://www.google.com/plugin.js',
|
|
|
|
$plugins['plugin3']
|
|
|
|
);
|
|
|
|
|
|
|
|
// Plugin specified with standard location
|
|
|
|
$this->assertContains('plugin4', array_keys($plugins));
|
|
|
|
$this->assertEquals(
|
2017-07-13 00:27:27 +02:00
|
|
|
'/subdir/test/thirdparty/tinymce/plugins/plugin4/plugin.min.js',
|
2016-12-16 05:34:21 +01:00
|
|
|
$plugins['plugin4']
|
|
|
|
);
|
|
|
|
|
|
|
|
// Check that internal plugins are extractable separately
|
|
|
|
$this->assertEquals(['plugin4', 'plugin5'], $c->getInternalPlugins());
|
2017-05-10 03:18:44 +02:00
|
|
|
}
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testDisablePluginsByString()
|
|
|
|
{
|
|
|
|
$c = new TinyMCEConfig();
|
|
|
|
$c->enablePlugins('plugin1');
|
|
|
|
$c->disablePlugins('plugin1');
|
|
|
|
$this->assertNotContains('plugin1', array_keys($c->getPlugins()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDisablePluginsByArray()
|
|
|
|
{
|
|
|
|
$c = new TinyMCEConfig();
|
|
|
|
$c->enablePlugins(array('plugin1', 'plugin2'));
|
|
|
|
$c->disablePlugins(array('plugin1', 'plugin2'));
|
|
|
|
$this->assertNotContains('plugin1', array_keys($c->getPlugins()));
|
|
|
|
$this->assertNotContains('plugin2', array_keys($c->getPlugins()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDisablePluginsByMultipleStringParameters()
|
|
|
|
{
|
|
|
|
$c = new TinyMCEConfig();
|
|
|
|
$c->enablePlugins('plugin1', 'plugin2');
|
|
|
|
$c->disablePlugins('plugin1', 'plugin2');
|
|
|
|
$this->assertNotContains('plugin1', array_keys($c->getPlugins()));
|
|
|
|
$this->assertNotContains('plugin2', array_keys($c->getPlugins()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDisablePluginsByArrayWithPaths()
|
|
|
|
{
|
|
|
|
$c = new TinyMCEConfig();
|
|
|
|
$c->enablePlugins(array('plugin1' => '/mypath/plugin1', 'plugin2' => '/mypath/plugin2'));
|
|
|
|
$c->disablePlugins(array('plugin1', 'plugin2'));
|
|
|
|
$plugins = $c->getPlugins();
|
|
|
|
$this->assertNotContains('plugin1', array_keys($plugins));
|
|
|
|
$this->assertNotContains('plugin2', array_keys($plugins));
|
|
|
|
}
|
2018-11-02 00:26:53 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testRequireJSIncludesAllConfigs()
|
|
|
|
{
|
|
|
|
$a = HTMLEditorConfig::get('configA');
|
|
|
|
$c = HTMLEditorConfig::get('configB');
|
|
|
|
|
|
|
|
$aAttributes = $a->getAttributes();
|
|
|
|
$cAttributes = $c->getAttributes();
|
|
|
|
|
|
|
|
$this->assertNotEmpty($aAttributes['data-config']);
|
|
|
|
$this->assertNotEmpty($cAttributes['data-config']);
|
|
|
|
}
|
2017-05-10 03:18:44 +02:00
|
|
|
|
2017-07-31 08:04:20 +02:00
|
|
|
public function testExceptionThrownWhenBaseDirAbsent()
|
2017-05-10 03:18:44 +02:00
|
|
|
{
|
|
|
|
TinyMCEConfig::config()->remove('base_dir');
|
2017-06-22 12:50:45 +02:00
|
|
|
ModuleLoader::inst()->pushManifest(new ModuleManifest(__DIR__));
|
|
|
|
|
|
|
|
try {
|
|
|
|
$config = new TinyMCEConfig();
|
|
|
|
$this->expectException(Exception::class);
|
|
|
|
$this->expectExceptionMessageRegExp('/module is not installed/');
|
|
|
|
$config->getScriptURL();
|
|
|
|
} finally {
|
|
|
|
ModuleLoader::inst()->popManifest();
|
|
|
|
}
|
2017-05-10 03:18:44 +02:00
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|