Completed
Push — master ( a7f5ef...db6af3 )
by Hamish
22:46 queued 12:25
created

HtmlEditorFieldToolbarTest_Toolbar   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 9
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 9
rs 10
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A viewfile_getLocalFileByID() 0 3 1
A viewfile_getRemoteFileByURL() 0 3 1
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());
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...
58
		$this->assertEquals($expectedUrl, $url);
59
	}
60
61
	public function testValidScheme() {
62
		list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL('http://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...
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');
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...
69
	}
70
71
	public function testValidDomain() {
72
		list($file, $url) = $this->getToolbar()->viewfile_getRemoteFileByURL('http://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...
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');
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...
79
	}
80
81
}
82