Completed
Push — master ( 0b2951...459fb4 )
by Daniel
12:39
created

HTMLEditorSanitiserTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 52
rs 10
wmc 2
lcom 0
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A testSanitisation() 0 48 2
1
<?php
2
/**
3
 * @package framework
4
 * @subpackage tests
5
 */
6
class HTMLEditorSanitiserTest extends FunctionalTest {
7
8
	public function testSanitisation() {
9
		$tests = array(
10
			array(
11
				'p,strong',
12
				'<p>Leave Alone</p><div>Strip parent<strong>But keep children</strong> in order</div>',
13
				'<p>Leave Alone</p>Strip parent<strong>But keep children</strong> in order',
14
				'Non-whitelisted elements are stripped, but children are kept'
15
			),
16
			array(
17
				'p,strong',
18
				'<div>A <strong>B <div>Nested elements are still filtered</div> C</strong> D</div>',
19
				'A <strong>B Nested elements are still filtered C</strong> D',
20
				'Non-whitelisted elements are stripped even when children of non-whitelisted elements'
21
			),
22
			array(
23
				'p',
24
				'<p>Keep</p><script>Strip <strong>including children</strong></script>',
25
				'<p>Keep</p>',
26
				'Non-whitelisted script elements are totally stripped, including any children'
27
			),
28
			array(
29
				'p[id]',
30
				'<p id="keep" bad="strip">Test</p>',
31
				'<p id="keep">Test</p>',
32
				'Non-whitelisted attributes are stripped'
33
			),
34
			array(
35
				'p[default1=default1|default2=default2|force1:force1|force2:force2]',
36
				'<p default1="specific1" force1="specific1">Test</p>',
37
				'<p default1="specific1" force1="force1" default2="default2" force2="force2">Test</p>',
38
				'Default attributes are set when not present in input, forced attributes are always set'
39
			)
40
		);
41
42
		$config = HTMLEditorConfig::get('htmleditorsanitisertest');
43
44
		foreach($tests as $test) {
45
			list($validElements, $input, $output, $desc) = $test;
46
47
			$config->setOptions(array('valid_elements' => $validElements));
48
			$sanitiser = new HtmlEditorSanitiser($config);
49
50
			$htmlValue = Injector::inst()->create('HTMLValue', $input);
51
			$sanitiser->sanitise($htmlValue);
52
53
			$this->assertEquals($output, $htmlValue->getContent(), $desc);
54
		}
55
	}
56
57
}
58