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_getLocalFileByURL($fileUrl) { |
9
|
|
|
return parent::viewfile_getLocalFileByURL($fileUrl); |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
public function viewfile_getRemoteFileByURL($fileUrl) { |
13
|
|
|
return parent::viewfile_getRemoteFileByURL($fileUrl); |
14
|
|
|
} |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
class HtmlEditorFieldToolbarTest extends SapphireTest { |
18
|
|
|
|
19
|
|
|
protected static $fixture_file = 'HtmlEditorFieldToolbarTest.yml'; |
20
|
|
|
|
21
|
|
|
protected function getToolbar() { |
22
|
|
|
return new HtmlEditorFieldToolbarTest_Toolbar(null, '/'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function setUp() { |
26
|
|
|
parent::setUp(); |
27
|
|
|
|
28
|
|
|
Config::inst()->update('HtmlEditorField_Toolbar', 'fileurl_scheme_whitelist', array('http')); |
29
|
|
|
Config::inst()->update('HtmlEditorField_Toolbar', 'fileurl_domain_whitelist', array('example.com')); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testValidLocalReference() { |
33
|
|
|
list($file, $url) = $this->getToolbar()->viewfile_getLocalFileByURL('folder/subfolder/example.pdf'); |
|
|
|
|
34
|
|
|
$this->assertEquals($this->objFromFixture('File', 'example_file'), $file); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testInvalidLocalReference() { |
38
|
|
|
list($file, $url) = $this->getToolbar()->viewfile_getLocalFileByURL('folder/subfolder/missing.pdf'); |
|
|
|
|
39
|
|
|
$this->assertNull($file); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testValidScheme() { |
43
|
|
|
list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL('http://example.com/test.pdf'); |
|
|
|
|
44
|
|
|
$this->assertInstanceOf('File', $file); |
45
|
|
|
$this->assertEquals($file->Filename, 'http://example.com/test.pdf'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** @expectedException SS_HTTPResponse_Exception */ |
49
|
|
|
public function testInvalidScheme() { |
50
|
|
|
list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL('nosuchscheme://example.com/test.pdf'); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testValidDomain() { |
54
|
|
|
list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL('http://example.com/test.pdf'); |
|
|
|
|
55
|
|
|
$this->assertInstanceOf('File', $file); |
56
|
|
|
$this->assertEquals($file->Filename, 'http://example.com/test.pdf'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** @expectedException SS_HTTPResponse_Exception */ |
60
|
|
|
public function testInvalidDomain() { |
61
|
|
|
list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL('http://evil.com/test.pdf'); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
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
$a
and$c
are used. There was no need to assign$b
.Instead, the list call could have been.