1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Testing of HTTPCacheControl class |
5
|
|
|
*/ |
6
|
|
|
class HTTPCacheControlTest extends SapphireTest |
7
|
|
|
{ |
8
|
|
|
public function testCachingPriorities() |
9
|
|
|
{ |
10
|
|
|
$hcc = new HTTPCacheControl(); |
11
|
|
|
$this->assertTrue($this->isDisabled($hcc), 'caching starts as disabled'); |
12
|
|
|
|
13
|
|
|
$hcc->enableCache(); |
14
|
|
|
$this->assertFalse($this->isDisabled($hcc)); |
15
|
|
|
|
16
|
|
|
$hcc->publicCache(); |
17
|
|
|
$this->assertTrue($this->isPublic($hcc), 'public can be set at start'); |
18
|
|
|
|
19
|
|
|
$hcc->privateCache(); |
20
|
|
|
$this->assertTrue($this->isPrivate($hcc), 'private overrides public'); |
21
|
|
|
|
22
|
|
|
$hcc->publicCache(); |
23
|
|
|
$this->assertFalse($this->isPublic($hcc), 'public does not overrides private'); |
24
|
|
|
|
25
|
|
|
$hcc->disableCache(); |
26
|
|
|
$this->assertTrue($this->isDisabled($hcc), 'disabled overrides private'); |
27
|
|
|
|
28
|
|
|
$hcc->privateCache(); |
29
|
|
|
$this->assertFalse($this->isPrivate($hcc), 'private does not override disabled'); |
30
|
|
|
|
31
|
|
|
$hcc->enableCache(true); |
32
|
|
|
$this->assertFalse($this->isDisabled($hcc)); |
33
|
|
|
|
34
|
|
|
$hcc->publicCache(true); |
35
|
|
|
$this->assertTrue($this->isPublic($hcc), 'force-public overrides disabled'); |
36
|
|
|
|
37
|
|
|
$hcc->privateCache(); |
38
|
|
|
$this->assertFalse($this->isPrivate($hcc), 'private does not overrdie force-public'); |
39
|
|
|
|
40
|
|
|
$hcc->privateCache(true); |
41
|
|
|
$this->assertTrue($this->isPrivate($hcc), 'force-private overrides force-public'); |
42
|
|
|
|
43
|
|
|
$hcc->publicCache(true); |
44
|
|
|
$this->assertFalse($this->isPublic($hcc), 'force-public does not override force-private'); |
45
|
|
|
|
46
|
|
|
$hcc->disableCache(true); |
47
|
|
|
$this->assertTrue($this->isDisabled($hcc), 'force-disabled overrides force-private'); |
48
|
|
|
|
49
|
|
|
$hcc->publicCache(true); |
50
|
|
|
$this->assertFalse($this->isPublic($hcc), 'force-public does not overrides force-disabled'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function isPrivate(HTTPCacheControl $hcc) |
54
|
|
|
{ |
55
|
|
|
return $hcc->hasDirective('private') && !$hcc->hasDirective('public') && !$hcc->hasDirective('no-cache'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function isPublic(HTTPCacheControl $hcc) |
59
|
|
|
{ |
60
|
|
|
return $hcc->hasDirective('public') && !$hcc->hasDirective('private') && !$hcc->hasDirective('no-cache'); |
61
|
|
|
} |
62
|
|
|
protected function isDisabled(HTTPCacheControl $hcc) |
63
|
|
|
{ |
64
|
|
|
return $hcc->hasDirective('no-cache') && !$hcc->hasDirective('private') && !$hcc->hasDirective('public'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|