1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @mixin PHPUnit_Framework_Assert |
5
|
|
|
*/ |
6
|
|
|
class URLArrayObjectTest extends SapphireTest { |
|
|
|
|
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() { |
|
|
|
|
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() { |
|
|
|
|
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 |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
private static $db = array( |
|
|
|
|
69
|
|
|
'excludeFromCache' => 'Boolean' |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.