Completed
Pull Request — master (#70)
by Daniel
06:38
created

testExcludeFromCachePrefersObjectAnnotationOverUrls()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
/**
4
 * @mixin PHPUnit_Framework_Assert
5
 */
6
class URLArrayObjectTest extends SapphireTest {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
8
	protected static $fixture_file = 'URLArrayObjectTestFixture.yml';
9
	protected $extraDataObjects = array('URLArrayObjectTestPage');
10
	protected $requiredExtensions = array(
11
		'SiteTree' => array('SiteTreePublishingEngine')
12
	);
13
14 View Code Duplication
	public function testExcludeFromCacheExcludesPageURLs() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
		/** @var URLArrayObject $urlArrayObject */
16
		$urlArrayObject = singleton('SiteTree')->urlArrayObject;
17
		$method = $this->getProtectedOrPrivateMethod('excludeFromCache');
18
19
		/** @var SiteTree $excluded */
20
		$excluded = $this->objFromFixture('URLArrayObjectTestPage', 'excluded');
21
		/** @var SiteTree $included */
22
		$included = $this->objFromFixture('URLArrayObjectTestPage', 'included');
23
24
		$this->assertEquals(true, $method->invoke($urlArrayObject, $excluded->Link()));
25
		$this->assertEquals(false, $method->invoke($urlArrayObject, $included->Link()));
26
	}
27
28 View Code Duplication
	public function testExcludeFromCacheExcludesPageURLsWithQueryStrings() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
		/** @var URLArrayObject $urlArrayObject */
30
		$urlArrayObject = singleton('SiteTree')->urlArrayObject;
31
		$method = $this->getProtectedOrPrivateMethod('excludeFromCache');
32
33
		/** @var SiteTree $excluded */
34
		$excluded = $this->objFromFixture('URLArrayObjectTestPage', 'excluded');
35
		/** @var SiteTree $included */
36
		$included = $this->objFromFixture('URLArrayObjectTestPage', 'included');
37
38
		$this->assertEquals(true, $method->invoke($urlArrayObject, $excluded->Link() . '?query=string'));
39
		$this->assertEquals(false, $method->invoke($urlArrayObject, $included->Link() . '?query=string'));
40
	}
41
42
	public function testExcludeFromCachePrefersObjectAnnotationOverUrls() {
43
		/** @var URLArrayObject $urlArrayObject */
44
		$urlArrayObject = singleton('SiteTree')->urlArrayObject;
45
		$method = $this->getProtectedOrPrivateMethod('excludeFromCache');
46
47
		/** @var SiteTree $excluded */
48
		$excluded = $this->objFromFixture('URLArrayObjectTestPage', 'excluded');
49
		/** @var SiteTree $included */
50
		$included = $this->objFromFixture('URLArrayObjectTestPage', 'included');
51
52
		$actuallyExcludedUrl = $included->RelativeLink . "?_ID=$excluded->ID&_ClassName=$excluded->ClassName";
53
		$actuallyIncludedUrl = $excluded->RelativeLink . "?_ID=$included->ID&_ClassName=$included->ClassName";
54
		$this->assertEquals(true, $method->invoke($urlArrayObject, $actuallyExcludedUrl));
55
		$this->assertEquals(false, $method->invoke($urlArrayObject, $actuallyIncludedUrl));
56
	}
57
58
	private function getProtectedOrPrivateMethod($name) {
59
		$method = new ReflectionMethod('URLArrayObject', $name);
60
		$method->setAccessible(true);
61
62
		return $method;
63
	}
64
}
65
66
class URLArrayObjectTestPage extends SiteTree implements TestOnly
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
67
{
68
	private static $db = array(
0 ignored issues
show
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
69
		'excludeFromCache' => 'Boolean'
70
	);
71
}
72