|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class HtmlEditorFieldToolbarTest_Toolbar extends HtmlEditorField_Toolbar { |
|
4
|
|
|
public function viewfile_getLocalFileByID($id) { |
|
5
|
|
|
return parent::viewfile_getLocalFileByID($id); |
|
6
|
|
|
} |
|
7
|
|
|
|
|
8
|
|
|
public function viewfile_getRemoteFileByURL($fileUrl) { |
|
9
|
|
|
return parent::viewfile_getRemoteFileByURL($fileUrl); |
|
10
|
|
|
} |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
class HtmlEditorFieldToolbarTest extends SapphireTest { |
|
14
|
|
|
|
|
15
|
|
|
protected static $fixture_file = 'HtmlEditorFieldToolbarTest.yml'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @return HtmlEditorFieldToolbarTest_Toolbar |
|
19
|
|
|
*/ |
|
20
|
|
|
protected function getToolbar() { |
|
21
|
|
|
return new HtmlEditorFieldToolbarTest_Toolbar(null, '/'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function setUp() { |
|
25
|
|
|
parent::setUp(); |
|
26
|
|
|
|
|
27
|
|
|
Config::inst()->update('HtmlEditorField_Toolbar', 'fileurl_scheme_whitelist', array('http')); |
|
28
|
|
|
Config::inst()->update('HtmlEditorField_Toolbar', 'fileurl_domain_whitelist', array('example.com')); |
|
29
|
|
|
|
|
30
|
|
|
// Filesystem mock |
|
31
|
|
|
AssetStoreTest_SpyStore::activate(__CLASS__); |
|
32
|
|
|
|
|
33
|
|
|
// Load up files |
|
34
|
|
|
/** @var File $file1 */ |
|
35
|
|
|
$file1 = $this->objFromFixture('File', 'example_file'); |
|
36
|
|
|
$file1->setFromString(str_repeat('x', 1000), $file1->Name); |
|
37
|
|
|
$file1->write(); |
|
38
|
|
|
|
|
39
|
|
|
/** @var Image $image1 */ |
|
40
|
|
|
$image1 = $this->objFromFixture('Image', 'example_image'); |
|
41
|
|
|
$image1->setFromLocalFile( |
|
42
|
|
|
__DIR__ . '/images/HTMLEditorFieldTest-example.jpg', |
|
43
|
|
|
'folder/subfolder/HTMLEditorFieldTest_example.jpg' |
|
44
|
|
|
); |
|
45
|
|
|
$image1->write(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testValidLocalReference() { |
|
49
|
|
|
/** @var File $exampleFile */ |
|
50
|
|
|
$exampleFile = $this->objFromFixture('File', 'example_file'); |
|
51
|
|
|
$expectedUrl = $exampleFile->AbsoluteLink(); |
|
52
|
|
|
Config::inst()->update('HtmlEditorField_Toolbar', 'fileurl_domain_whitelist', array( |
|
53
|
|
|
'example.com', |
|
54
|
|
|
strtolower(parse_url($expectedUrl, PHP_URL_HOST)) |
|
55
|
|
|
)); |
|
56
|
|
|
|
|
57
|
|
|
list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL($exampleFile->AbsoluteLink()); |
|
|
|
|
|
|
58
|
|
|
$this->assertEquals($expectedUrl, $url); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testValidScheme() { |
|
62
|
|
|
list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL('http://example.com/test.pdf'); |
|
|
|
|
|
|
63
|
|
|
$this->assertEquals($url, 'http://example.com/test.pdf'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** @expectedException SS_HTTPResponse_Exception */ |
|
67
|
|
|
public function testInvalidScheme() { |
|
68
|
|
|
list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL('nosuchscheme://example.com/test.pdf'); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testValidDomain() { |
|
72
|
|
|
list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL('http://example.com/test.pdf'); |
|
|
|
|
|
|
73
|
|
|
$this->assertEquals($url, 'http://example.com/test.pdf'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** @expectedException SS_HTTPResponse_Exception */ |
|
77
|
|
|
public function testInvalidDomain() { |
|
78
|
|
|
list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL('http://evil.com/test.pdf'); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
This checks looks for assignemnts to variables using the
list(...)function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$aand$care used. There was no need to assign$b.Instead, the list call could have been.