Completed
Pull Request — master (#70)
by Daniel
04:09
created

testExcludeFromCacheExcludesPageURLs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace SilverStripe\StaticPublishQueue\Test;
4
5
use PHPUnit_Framework_Assert;
6
use ReflectionMethod;
7
use SilverStripe\CMS\Model\SiteTree;
8
use SilverStripe\Dev\SapphireTest;
9
use SilverStripe\StaticPublishQueue\Extension\Engine\SiteTreePublishingEngine;
10
use SilverStripe\StaticPublishQueue\Model\URLArrayObject;
11
use SilverStripe\StaticPublishQueue\Test\URLArrayObjectTest\Model\URLArrayObjectTestPage;
12
13
/**
14
 * @mixin PHPUnit_Framework_Assert
15
 */
16
class URLArrayObjectTest extends SapphireTest {
17
18
	protected static $fixture_file = 'URLArrayObjectTestFixture.yml';
19
    protected static $extra_dataobjects = array(URLArrayObjectTestPage::class);
20
    protected static $required_extensions = array(
21
		SiteTree::class => array(SiteTreePublishingEngine::class),
22
	);
23
24 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...
25
		/** @var URLArrayObject $urlArrayObject */
26
		$urlArrayObject = singleton('SiteTree')->urlArrayObject;
27
		$method = $this->getProtectedOrPrivateMethod('excludeFromCache');
28
29
		/** @var SiteTree $excluded */
30
		$excluded = $this->objFromFixture(URLArrayObjectTestPage::class, 'excluded');
31
		/** @var SiteTree $included */
32
		$included = $this->objFromFixture(URLArrayObjectTestPage::class, 'included');
33
34
		$this->assertTrue($method->invoke($urlArrayObject, $excluded->Link()));
35
		$this->assertFalse($method->invoke($urlArrayObject, $included->Link()));
36
	}
37
38 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...
39
		/** @var URLArrayObject $urlArrayObject */
40
		$urlArrayObject = SiteTree::singleton()->urlArrayObject;
41
		$method = $this->getProtectedOrPrivateMethod('excludeFromCache');
42
43
		/** @var SiteTree $excluded */
44
		$excluded = $this->objFromFixture(URLArrayObjectTestPage::class, 'excluded');
45
		/** @var SiteTree $included */
46
		$included = $this->objFromFixture(URLArrayObjectTestPage::class, 'included');
47
48
		$this->assertTrue($method->invoke($urlArrayObject, $excluded->Link() . '?query=string'));
49
		$this->assertFalse($method->invoke($urlArrayObject, $included->Link() . '?query=string'));
50
	}
51
52
	public function testExcludeFromCachePrefersObjectAnnotationOverUrls() {
53
		/** @var URLArrayObject $urlArrayObject */
54
		$urlArrayObject = singleton('SiteTree')->urlArrayObject;
55
		$method = $this->getProtectedOrPrivateMethod('excludeFromCache');
56
57
		/** @var SiteTree $excluded */
58
		$excluded = $this->objFromFixture(URLArrayObjectTestPage::class, 'excluded');
59
		/** @var SiteTree $included */
60
		$included = $this->objFromFixture(URLArrayObjectTestPage::class, 'included');
61
62
		$actuallyExcludedUrl = $included->RelativeLink . "?_ID=$excluded->ID&_ClassName=$excluded->ClassName";
63
		$actuallyIncludedUrl = $excluded->RelativeLink . "?_ID=$included->ID&_ClassName=$included->ClassName";
64
		$this->assertTrue($method->invoke($urlArrayObject, $actuallyExcludedUrl));
65
		$this->assertFalse($method->invoke($urlArrayObject, $actuallyIncludedUrl));
66
	}
67
68
	private function getProtectedOrPrivateMethod($name) {
69
		$method = new ReflectionMethod(URLArrayObject::class, $name);
70
		$method->setAccessible(true);
71
72
		return $method;
73
	}
74
}
75
76