2009-12-16 06:30:46 +01:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
|
|
|
use SilverStripe\Core\Config\Config;
|
|
|
|
use SilverStripe\Core\Convert;
|
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
|
|
|
|
use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;
|
|
|
|
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
|
|
|
|
|
|
|
|
|
2009-12-16 06:30:46 +01:00
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2009-12-16 06:30:46 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2016-05-06 01:43:47 +02:00
|
|
|
class HTMLEditorConfigTest extends SapphireTest {
|
2009-12-16 06:30:46 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testEnablePluginsByString() {
|
2016-02-12 04:00:15 +01:00
|
|
|
$c = new TinyMCEConfig();
|
2009-12-16 06:30:46 +01:00
|
|
|
$c->enablePlugins('plugin1');
|
|
|
|
$this->assertContains('plugin1', array_keys($c->getPlugins()));
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testEnablePluginsByArray() {
|
2016-02-12 04:00:15 +01:00
|
|
|
$c = new TinyMCEConfig();
|
2009-12-16 06:30:46 +01:00
|
|
|
$c->enablePlugins(array('plugin1', 'plugin2'));
|
|
|
|
$this->assertContains('plugin1', array_keys($c->getPlugins()));
|
|
|
|
$this->assertContains('plugin2', array_keys($c->getPlugins()));
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testEnablePluginsByMultipleStringParameters() {
|
2016-02-12 04:00:15 +01:00
|
|
|
$c = new TinyMCEConfig();
|
2009-12-16 06:30:46 +01:00
|
|
|
$c->enablePlugins('plugin1', 'plugin2');
|
|
|
|
$this->assertContains('plugin1', array_keys($c->getPlugins()));
|
|
|
|
$this->assertContains('plugin2', array_keys($c->getPlugins()));
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testEnablePluginsByArrayWithPaths() {
|
2016-08-19 00:51:35 +02:00
|
|
|
Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_url', 'http://mysite.com/subdir');
|
2016-02-12 04:00:15 +01:00
|
|
|
$c = new TinyMCEConfig();
|
2016-04-03 23:59:31 +02:00
|
|
|
$c->setTheme('modern');
|
|
|
|
$c->setOption('language', 'es');
|
|
|
|
$c->disablePlugins('table', 'emoticons', 'paste', 'code', 'link', 'importcss');
|
2016-02-12 04:00:15 +01:00
|
|
|
$c->enablePlugins(array(
|
|
|
|
'plugin1' => 'mypath/plugin1.js',
|
|
|
|
'plugin2' => '/anotherbase/mypath/plugin2.js',
|
|
|
|
'plugin3' => 'https://www.google.com/plugin.js',
|
|
|
|
'plugin4' => null,
|
2016-04-03 23:59:31 +02:00
|
|
|
'plugin5' => null,
|
2016-02-12 04:00:15 +01:00
|
|
|
));
|
|
|
|
$attributes = $c->getAttributes();
|
|
|
|
$config = Convert::json2array($attributes['data-config']);
|
|
|
|
$plugins = $config['external_plugins'];
|
|
|
|
$this->assertNotEmpty($plugins);
|
|
|
|
|
|
|
|
// Plugin specified via relative url
|
2009-12-16 06:30:46 +01:00
|
|
|
$this->assertContains('plugin1', array_keys($plugins));
|
2016-02-12 04:00:15 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
'http://mysite.com/subdir/mypath/plugin1.js',
|
|
|
|
$plugins['plugin1']
|
|
|
|
);
|
|
|
|
|
|
|
|
// Plugin specified via root-relative url
|
2009-12-16 06:30:46 +01:00
|
|
|
$this->assertContains('plugin2', array_keys($plugins));
|
2016-02-12 04:00:15 +01:00
|
|
|
$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(
|
2016-11-01 21:11:35 +01:00
|
|
|
'http://mysite.com/subdir/'.ADMIN_THIRDPARTY_DIR.'/tinymce/plugins/plugin4/plugin.min.js',
|
2016-02-12 04:00:15 +01:00
|
|
|
$plugins['plugin4']
|
|
|
|
);
|
2016-04-03 23:59:31 +02:00
|
|
|
|
|
|
|
// Check that internal plugins are extractable separately
|
|
|
|
$this->assertEquals(['plugin4', 'plugin5'], $c->getInternalPlugins());
|
|
|
|
|
|
|
|
// Test plugins included via gzip compresser
|
2016-08-19 00:51:35 +02:00
|
|
|
HTMLEditorField::config()->update('use_gzip', true);
|
2016-04-03 23:59:31 +02:00
|
|
|
$this->assertEquals(
|
2016-09-12 08:16:39 +02:00
|
|
|
ADMIN_THIRDPARTY_DIR . '/tinymce/tiny_mce_gzip.php?js=1&plugins=plugin4,plugin5&themes=modern&languages=es&diskcache=true&src=true',
|
2016-04-03 23:59:31 +02:00
|
|
|
$c->getScriptURL()
|
|
|
|
);
|
|
|
|
|
|
|
|
// If gzip is disabled only the core plugin is loaded
|
2016-08-19 00:51:35 +02:00
|
|
|
HTMLEditorField::config()->remove('use_gzip');
|
2016-04-03 23:59:31 +02:00
|
|
|
$this->assertEquals(
|
2016-09-12 08:16:39 +02:00
|
|
|
ADMIN_THIRDPARTY_DIR . '/tinymce/tinymce.min.js',
|
2016-04-03 23:59:31 +02:00
|
|
|
$c->getScriptURL()
|
|
|
|
);
|
2009-12-16 06:30:46 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testDisablePluginsByString() {
|
2016-02-12 04:00:15 +01:00
|
|
|
$c = new TinyMCEConfig();
|
2009-12-16 06:30:46 +01:00
|
|
|
$c->enablePlugins('plugin1');
|
|
|
|
$c->disablePlugins('plugin1');
|
|
|
|
$this->assertNotContains('plugin1', array_keys($c->getPlugins()));
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testDisablePluginsByArray() {
|
2016-02-12 04:00:15 +01:00
|
|
|
$c = new TinyMCEConfig();
|
2009-12-16 06:30:46 +01:00
|
|
|
$c->enablePlugins(array('plugin1', 'plugin2'));
|
|
|
|
$c->disablePlugins(array('plugin1', 'plugin2'));
|
|
|
|
$this->assertNotContains('plugin1', array_keys($c->getPlugins()));
|
|
|
|
$this->assertNotContains('plugin2', array_keys($c->getPlugins()));
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testDisablePluginsByMultipleStringParameters() {
|
2016-02-12 04:00:15 +01:00
|
|
|
$c = new TinyMCEConfig();
|
2009-12-16 06:30:46 +01:00
|
|
|
$c->enablePlugins('plugin1', 'plugin2');
|
|
|
|
$c->disablePlugins('plugin1', 'plugin2');
|
|
|
|
$this->assertNotContains('plugin1', array_keys($c->getPlugins()));
|
|
|
|
$this->assertNotContains('plugin2', array_keys($c->getPlugins()));
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testDisablePluginsByArrayWithPaths() {
|
2016-02-12 04:00:15 +01:00
|
|
|
$c = new TinyMCEConfig();
|
2009-12-16 06:30:46 +01:00
|
|
|
$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));
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2015-06-09 02:01:21 +02:00
|
|
|
public function testRequireJSIncludesAllConfigs() {
|
2016-05-06 01:43:47 +02:00
|
|
|
$a = HTMLEditorConfig::get('configA');
|
|
|
|
$c = HTMLEditorConfig::get('configB');
|
2015-06-09 02:01:21 +02:00
|
|
|
|
2016-02-12 04:00:15 +01:00
|
|
|
$aAttributes = $a->getAttributes();
|
|
|
|
$cAttributes = $c->getAttributes();
|
2015-06-09 02:01:21 +02:00
|
|
|
|
2016-02-12 04:00:15 +01:00
|
|
|
$this->assertNotEmpty($aAttributes['data-config']);
|
|
|
|
$this->assertNotEmpty($cAttributes['data-config']);
|
2009-12-16 06:30:46 +01:00
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|