Completed
Push — master ( 622a07...7c2344 )
by Daniel
108:51 queued 72:30
created

testReadonlyDisplaySpecialHTML()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\Forms\Tests;
4
5
use SilverStripe\Dev\SapphireTest;
6
use SilverStripe\Forms\TextareaField;
7
8
class TextareaFieldTest extends SapphireTest {
9
10
	/**
11
	 * Quick smoke test to ensure that text with unicodes is being displayed properly in readonly fields.
12
	 */
13
	public function testReadonlyDisplayUnicodes() {
14
		$inputText = "These are some unicodes: äöü";
15
		$field = new TextareaField("Test", "Test");
16
		$field->setValue($inputText);
17
		$field = $field->performReadonlyTransformation();
18
		$this->assertContains('These are some unicodes: äöü', $field->Field());
19
	}
20
21
	/**
22
	 * Quick smoke test to ensure that text with special html chars is being displayed properly in readonly fields.
23
	 */
24
	public function testReadonlyDisplaySpecialHTML() {
25
		$inputText = "These are some special <html> chars including 'single' & \"double\" quotations";
26
		$field = new TextareaField("Test", "Test");
27
		$field = $field->performReadonlyTransformation();
28
		$field->setValue($inputText);
29
		$this->assertContains('These are some special &lt;html&gt; chars including &#039;single&#039; &amp;'
30
			. ' &quot;double&quot; quotations', $field->Field());
31
	}
32
33
	public function testValueEntities() {
34
		$inputText = "These <b>are</b> some unicodes: äöü";
35
		$field = new TextareaField("Test", "Test");
36
		$field->setValue($inputText);
37
38
		// Value should be safe-encoding only, but ValueEntities should be more aggressive
39
		$this->assertEquals(
40
			"These &lt;b&gt;are&lt;/b&gt; some unicodes: &auml;&ouml;&uuml;",
41
			$field->obj('ValueEntities')->forTemplate()
42
		);
43
44
		// Shortcodes are disabled
45
		$this->assertEquals(
46
			false,
47
			$field->obj('ValueEntities')->getProcessShortcodes()
48
		);
49
	}
50
51
}
52