Completed
Push — create-endpoint-fetcher ( 23bf41 )
by Sam
07:40
created

HtmlEditorConfigTest::testEnablePluginsByArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
/**
3
 * @package framework
4
 * @subpackage tests
5
 */
6
class HtmlEditorConfigTest extends SapphireTest {
7
8
	public function testEnablePluginsByString() {
9
		$c = new TinyMCEConfig();
10
		$c->enablePlugins('plugin1');
11
		$this->assertContains('plugin1', array_keys($c->getPlugins()));
12
	}
13
14
	public function testEnablePluginsByArray() {
15
		$c = new TinyMCEConfig();
16
		$c->enablePlugins(array('plugin1', 'plugin2'));
17
		$this->assertContains('plugin1', array_keys($c->getPlugins()));
18
		$this->assertContains('plugin2', array_keys($c->getPlugins()));
19
	}
20
21 View Code Duplication
	public function testEnablePluginsByMultipleStringParameters() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
		$c = new TinyMCEConfig();
23
		$c->enablePlugins('plugin1', 'plugin2');
24
		$this->assertContains('plugin1', array_keys($c->getPlugins()));
25
		$this->assertContains('plugin2', array_keys($c->getPlugins()));
26
	}
27
28
	public function testEnablePluginsByArrayWithPaths() {
29
		Config::inst()->update('Director', 'alternate_base_url', 'http://mysite.com/subdir');
30
		$c = new TinyMCEConfig();
31
		$c->setTheme('modern');
32
		$c->setOption('language', 'es');
33
		$c->disablePlugins('table', 'emoticons', 'paste', 'code', 'link', 'importcss');
34
		$c->enablePlugins(array(
35
			'plugin1' => 'mypath/plugin1.js',
36
			'plugin2' => '/anotherbase/mypath/plugin2.js',
37
			'plugin3' => 'https://www.google.com/plugin.js',
38
			'plugin4' => null,
39
			'plugin5' => null,
40
		));
41
		$attributes = $c->getAttributes();
42
		$config = Convert::json2array($attributes['data-config']);
43
		$plugins = $config['external_plugins'];
44
		$this->assertNotEmpty($plugins);
45
46
		// Plugin specified via relative url
47
		$this->assertContains('plugin1', array_keys($plugins));
48
		$this->assertEquals(
49
			'http://mysite.com/subdir/mypath/plugin1.js',
50
			$plugins['plugin1']
51
		);
52
53
		// Plugin specified via root-relative url
54
		$this->assertContains('plugin2', array_keys($plugins));
55
		$this->assertEquals(
56
			'http://mysite.com/anotherbase/mypath/plugin2.js',
57
			$plugins['plugin2']
58
		);
59
60
		// Plugin specified with absolute url
61
		$this->assertContains('plugin3', array_keys($plugins));
62
		$this->assertEquals(
63
			'https://www.google.com/plugin.js',
64
			$plugins['plugin3']
65
		);
66
67
		// Plugin specified with standard location
68
		$this->assertContains('plugin4', array_keys($plugins));
69
		$this->assertEquals(
70
			'http://mysite.com/subdir/framework/thirdparty/tinymce/plugins/plugin4/plugin.min.js',
71
			$plugins['plugin4']
72
		);
73
74
		// Check that internal plugins are extractable separately
75
		$this->assertEquals(['plugin4', 'plugin5'], $c->getInternalPlugins());
76
77
		// Test plugins included via gzip compresser
78
		Config::inst()->update('HtmlEditorField', 'use_gzip', true);
79
		$this->assertEquals(
80
			'framework/thirdparty/tinymce/tiny_mce_gzip.php?js=1&plugins=plugin4,plugin5&themes=modern&languages=es&diskcache=true&src=true',
81
			$c->getScriptURL()
82
		);
83
84
		// If gzip is disabled only the core plugin is loaded
85
		Config::inst()->remove('HtmlEditorField', 'use_gzip');
86
		$this->assertEquals(
87
			'framework/thirdparty/tinymce/tinymce.min.js',
88
			$c->getScriptURL()
89
		);
90
	}
91
92
	public function testDisablePluginsByString() {
93
		$c = new TinyMCEConfig();
94
		$c->enablePlugins('plugin1');
95
		$c->disablePlugins('plugin1');
96
		$this->assertNotContains('plugin1', array_keys($c->getPlugins()));
97
	}
98
99
	public function testDisablePluginsByArray() {
100
		$c = new TinyMCEConfig();
101
		$c->enablePlugins(array('plugin1', 'plugin2'));
102
		$c->disablePlugins(array('plugin1', 'plugin2'));
103
		$this->assertNotContains('plugin1', array_keys($c->getPlugins()));
104
		$this->assertNotContains('plugin2', array_keys($c->getPlugins()));
105
	}
106
107 View Code Duplication
	public function testDisablePluginsByMultipleStringParameters() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
108
		$c = new TinyMCEConfig();
109
		$c->enablePlugins('plugin1', 'plugin2');
110
		$c->disablePlugins('plugin1', 'plugin2');
111
		$this->assertNotContains('plugin1', array_keys($c->getPlugins()));
112
		$this->assertNotContains('plugin2', array_keys($c->getPlugins()));
113
	}
114
115
	public function testDisablePluginsByArrayWithPaths() {
116
		$c = new TinyMCEConfig();
117
		$c->enablePlugins(array('plugin1' => '/mypath/plugin1', 'plugin2' => '/mypath/plugin2'));
118
		$c->disablePlugins(array('plugin1', 'plugin2'));
119
		$plugins = $c->getPlugins();
120
		$this->assertNotContains('plugin1', array_keys($plugins));
121
		$this->assertNotContains('plugin2', array_keys($plugins));
122
	}
123
124
	public function testRequireJSIncludesAllConfigs() {
125
		$a = HtmlEditorConfig::get('configA');
126
		$c = HtmlEditorConfig::get('configB');
127
128
		$aAttributes = $a->getAttributes();
129
		$cAttributes = $c->getAttributes();
130
131
		$this->assertNotEmpty($aAttributes['data-config']);
132
		$this->assertNotEmpty($cAttributes['data-config']);
133
	}
134
}
135