1 | <?php |
||
9 | class HtmlEditorFieldTest extends FunctionalTest { |
||
10 | |||
11 | protected static $fixture_file = 'HtmlEditorFieldTest.yml'; |
||
12 | |||
13 | protected static $use_draft_site = true; |
||
14 | |||
15 | protected $requiredExtensions = array( |
||
16 | 'HtmlEditorField_Toolbar' => array('HtmlEditorFieldTest_DummyMediaFormFieldExtension') |
||
17 | ); |
||
18 | |||
19 | protected $extraDataObjects = array('HtmlEditorFieldTest_Object'); |
||
20 | |||
21 | public function setUp() { |
||
22 | parent::setUp(); |
||
23 | |||
24 | // Set backend root to /HtmlEditorFieldTest |
||
25 | AssetStoreTest_SpyStore::activate('HtmlEditorFieldTest'); |
||
26 | |||
27 | // Create a test files for each of the fixture references |
||
28 | $files = File::get()->exclude('ClassName', 'Folder'); |
||
29 | foreach($files as $file) { |
||
30 | $fromPath = BASE_PATH . '/framework/tests/forms/images/' . $file->Name; |
||
31 | $destPath = AssetStoreTest_SpyStore::getLocalPath($file); // Only correct for test asset store |
||
32 | SS_Filesystem::makeFolder(dirname($destPath)); |
||
33 | copy($fromPath, $destPath); |
||
34 | } |
||
35 | } |
||
36 | |||
37 | public function tearDown() { |
||
41 | |||
42 | public function testBasicSaving() { |
||
54 | |||
55 | public function testNullSaving() { |
||
63 | |||
64 | public function testResizedImageInsertion() { |
||
65 | $obj = new HtmlEditorFieldTest_Object(); |
||
66 | $editor = new HtmlEditorField('Content'); |
||
67 | |||
68 | $fileID = $this->idFromFixture('Image', 'example_image'); |
||
69 | $editor->setValue(sprintf( |
||
70 | '[image src="assets/HTMLEditorFieldTest_example.jpg" width="10" height="20" id="%d"]', |
||
71 | $fileID |
||
72 | )); |
||
73 | $editor->saveInto($obj); |
||
74 | |||
75 | $parser = new CSSContentParser($obj->dbObject('Content')->forTemplate()); |
||
76 | $xml = $parser->getByXpath('//img'); |
||
77 | $this->assertEquals( |
||
78 | 'HTMLEditorFieldTest example', |
||
79 | (string)$xml[0]['alt'], |
||
80 | 'Alt tags are added by default based on filename' |
||
81 | ); |
||
82 | $this->assertEquals('', (string)$xml[0]['title'], 'Title tags are added by default.'); |
||
83 | $this->assertEquals(10, (int)$xml[0]['width'], 'Width tag of resized image is set.'); |
||
84 | $this->assertEquals(20, (int)$xml[0]['height'], 'Height tag of resized image is set.'); |
||
85 | |||
86 | $neededFilename |
||
87 | = '/assets/HtmlEditorFieldTest/f5c7c2f814/HTMLEditorFieldTest-example__ResizedImageWyIxMCIsIjIwIl0.jpg'; |
||
88 | |||
89 | $this->assertEquals($neededFilename, (string)$xml[0]['src'], 'Correct URL of resized image is set.'); |
||
90 | $this->assertTrue(file_exists(BASE_PATH.DIRECTORY_SEPARATOR.$neededFilename), 'File for resized image exists'); |
||
91 | $this->assertEquals(false, $obj->HasBrokenFile, 'Referenced image file exists.'); |
||
92 | } |
||
93 | |||
94 | public function testMultiLineSaving() { |
||
95 | $obj = $this->objFromFixture('HtmlEditorFieldTest_Object', 'home'); |
||
96 | $editor = new HtmlEditorField('Content'); |
||
97 | $editor->setValue('<p>First Paragraph</p><p>Second Paragraph</p>'); |
||
98 | $editor->saveInto($obj); |
||
|
|||
99 | $this->assertEquals('<p>First Paragraph</p><p>Second Paragraph</p>', $obj->Content); |
||
100 | } |
||
101 | |||
102 | public function testSavingLinksWithoutHref() { |
||
103 | $obj = $this->objFromFixture('HtmlEditorFieldTest_Object', 'home'); |
||
104 | $editor = new HtmlEditorField('Content'); |
||
105 | |||
106 | $editor->setValue('<p><a name="example-anchor"></a></p>'); |
||
107 | $editor->saveInto($obj); |
||
108 | |||
109 | $this->assertEquals ( |
||
110 | '<p><a name="example-anchor"></a></p>', $obj->Content, 'Saving a link without a href attribute works' |
||
111 | ); |
||
112 | } |
||
113 | |||
114 | public function testGetAnchors() { |
||
149 | |||
150 | public function testHtmlEditorFieldFileLocal() { |
||
157 | |||
158 | public function testHtmlEditorFieldFileRemote() { |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * @package framework |
||
188 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: