|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\ControllerPolicy\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Page; |
|
|
|
|
|
|
6
|
|
|
use SilverStripe\CMS\Controllers\ModelAsController; |
|
|
|
|
|
|
7
|
|
|
use SilverStripe\Control\HTTPRequest; |
|
8
|
|
|
use SilverStripe\Control\HTTPResponse; |
|
9
|
|
|
use SilverStripe\ControllerPolicy\PageControlledPolicy; |
|
10
|
|
|
use SilverStripe\ControllerPolicy\Policies\CachingPolicy; |
|
11
|
|
|
use SilverStripe\Core\Config\Config; |
|
12
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
13
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
14
|
|
|
use SilverStripe\Forms\LiteralField; |
|
15
|
|
|
|
|
16
|
|
|
class PageControlledPolicyTest extends SapphireTest |
|
17
|
|
|
{ |
|
18
|
|
|
protected static $fixture_file = 'PageControlledPolicyTest.yml'; |
|
19
|
|
|
|
|
20
|
|
|
protected static $required_extensions = [ |
|
21
|
|
|
Page::class => [ |
|
22
|
|
|
PageControlledPolicy::class, |
|
23
|
|
|
], |
|
24
|
|
|
]; |
|
25
|
|
|
|
|
26
|
|
|
protected function setUp() |
|
27
|
|
|
{ |
|
28
|
|
|
parent::setUp(); |
|
29
|
|
|
|
|
30
|
|
|
// Load some default caching policy configuration |
|
31
|
|
|
Injector::inst()->load([ |
|
32
|
|
|
'GeneralCachingPolicy' => [ |
|
33
|
|
|
'class' => CachingPolicy::class, |
|
34
|
|
|
'properties' => [ |
|
35
|
|
|
'CacheAge' => 900, // 15 mins |
|
36
|
|
|
] |
|
37
|
|
|
] |
|
38
|
|
|
]); |
|
39
|
|
|
|
|
40
|
|
|
Config::modify()->set(CachingPolicy::class, 'disable_cache_age_in_dev', false); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testInfoMessageIsShownToAdminUsersOnly() |
|
44
|
|
|
{ |
|
45
|
|
|
/** @var Page $page */ |
|
46
|
|
|
$page = $this->objFromFixture(Page::class, 'some_page'); |
|
47
|
|
|
|
|
48
|
|
|
$this->logInWithPermission('ADMIN'); |
|
49
|
|
|
$fields = $page->getCMSFields(); |
|
50
|
|
|
$this->assertInstanceOf(LiteralField::class, $fields->fieldByName('Root.Caching.Instruction')); |
|
51
|
|
|
|
|
52
|
|
|
$this->logOut(); |
|
53
|
|
|
$fields = $page->getCMSFields(); |
|
54
|
|
|
$this->assertNull($fields->fieldByName('Root.Caching.Instruction')); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testCustomMaxAgeIsHonoured() |
|
58
|
|
|
{ |
|
59
|
|
|
/** @var Page $page */ |
|
60
|
|
|
$page = $this->objFromFixture(Page::class, 'some_page'); |
|
61
|
|
|
$controller = ModelAsController::controller_for($page); |
|
62
|
|
|
|
|
63
|
|
|
$cachingPolicy = new CachingPolicy(); |
|
64
|
|
|
$request = new HTTPRequest('GET', '/'); |
|
65
|
|
|
$response = new HTTPResponse('Hello world'); |
|
66
|
|
|
$cachingPolicy->applyToResponse($controller, $request, $response); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertContains( |
|
69
|
|
|
'max-age=1620', |
|
70
|
|
|
(string) $response->getHeader('Cache-Control'), |
|
71
|
|
|
'CMS defined max age value (27 minutes) is used instead of the default (15 mins)' |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths