Completed
Pull Request — 3.4 (#6961)
by Daniel
09:45
created

HtmlEditorFieldToolbarTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
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');
0 ignored issues
show
Unused Code introduced by
The assignment to $url is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
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');
0 ignored issues
show
Unused Code introduced by
The assignment to $url is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
39
		$this->assertNull($file);
40
	}
41
42
	public function testValidScheme() {
43
		list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL('http://example.com/test.pdf');
0 ignored issues
show
Unused Code introduced by
The assignment to $url is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
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');
0 ignored issues
show
Unused Code introduced by
The assignment to $file is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $url is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
51
	}
52
53
	public function testValidDomain() {
54
		list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL('http://example.com/test.pdf');
0 ignored issues
show
Unused Code introduced by
The assignment to $url is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
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');
0 ignored issues
show
Unused Code introduced by
The assignment to $file is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $url is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
62
	}
63
64
}
65