2009-12-16 06:30:46 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2009-12-16 06:30:46 +01:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class HtmlEditorConfigTest extends SapphireTest {
|
|
|
|
|
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-02-12 04:00:15 +01:00
|
|
|
Config::inst()->update('Director', 'alternate_base_url', 'http://mysite.com/subdir');
|
|
|
|
$c = new TinyMCEConfig();
|
|
|
|
$c->enablePlugins(array(
|
|
|
|
'plugin1' => 'mypath/plugin1.js',
|
|
|
|
'plugin2' => '/anotherbase/mypath/plugin2.js',
|
|
|
|
'plugin3' => 'https://www.google.com/plugin.js',
|
|
|
|
'plugin4' => null,
|
|
|
|
));
|
|
|
|
$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(
|
|
|
|
'http://mysite.com/subdir/framework/thirdparty/tinymce/plugins/plugin4/plugin.min.js',
|
|
|
|
$plugins['plugin4']
|
|
|
|
);
|
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-02-12 04:00:15 +01:00
|
|
|
$a = HtmlEditorConfig::get('configA');
|
2015-06-09 02:01:21 +02:00
|
|
|
$c = HtmlEditorConfig::get('configB');
|
|
|
|
|
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
|
|
|
}
|