|
1
|
|
|
<?php |
|
2
|
|
|
namespace Qbus\SkipPageIsBeingGenerated\Tests\Unit; |
|
3
|
|
|
|
|
4
|
|
|
use Qbus\SkipPageIsBeingGenerated\Hooks\SetPageCacheHook; |
|
5
|
|
|
use TYPO3\CMS\Core\Cache\Backend\RedisBackend; |
|
6
|
|
|
use TYPO3\CMS\Core\Cache\Backend\BackendInterface; |
|
7
|
|
|
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; |
|
8
|
|
|
//use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
9
|
|
|
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* SetPageCacheHookTest |
|
13
|
|
|
* |
|
14
|
|
|
* @author Benjamin Franzke <[email protected]> |
|
15
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later |
|
16
|
|
|
*/ |
|
17
|
|
|
class SetPageCacheHookTest extends UnitTestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var ObjectProphecy |
|
|
|
|
|
|
21
|
|
|
*/ |
|
22
|
|
|
protected $cacheFrontendProphecy; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var ObjectProphecy |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $cacheBackendProphecy; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var params |
|
31
|
|
|
*/ |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var SetPageCacheHook |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $hook; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $entryIdentifier; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var array|bool |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $variable; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var int |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $lifetime; |
|
52
|
|
|
|
|
53
|
|
|
public function setUp() |
|
54
|
|
|
{ |
|
55
|
|
|
$cacheBackendProphecy = $this->prophesize(); |
|
56
|
|
|
$cacheBackendProphecy->willImplement(BackendInterface::class); |
|
57
|
|
|
|
|
58
|
|
|
$cacheFrontendProphecy = $this->prophesize(); |
|
59
|
|
|
$cacheFrontendProphecy->willImplement(FrontendInterface::class); |
|
60
|
|
|
$cacheFrontendProphecy->getIdentifier()->willReturn('cache_pages'); |
|
61
|
|
|
$cacheFrontendProphecy->getBackend()->will(function () use ($cacheBackendProphecy) { |
|
62
|
|
|
return $cacheBackendProphecy->reveal(); |
|
63
|
|
|
}); |
|
64
|
|
|
|
|
65
|
|
|
$this->cacheBackendProphecy = $cacheBackendProphecy; |
|
|
|
|
|
|
66
|
|
|
$this->cacheFrontendProphecy = $cacheFrontendProphecy; |
|
|
|
|
|
|
67
|
|
|
$this->hook = new SetpageCacheHook; |
|
68
|
|
|
|
|
69
|
|
|
$this->entryIdentifier = md5('foo'); |
|
70
|
|
|
$this->lifetime = 30; |
|
71
|
|
|
$this->variable = [ |
|
72
|
|
|
'foo' => 'bar', |
|
73
|
|
|
'temp_content' => true, |
|
74
|
|
|
]; |
|
75
|
|
|
$tags = []; |
|
76
|
|
|
|
|
77
|
|
|
$this->params = [ |
|
|
|
|
|
|
78
|
|
|
'entryIdentifier' => &$this->entryIdentifier, |
|
79
|
|
|
'variable' => &$this->variable, |
|
80
|
|
|
'lifetime' => &$this->lifetime, |
|
81
|
|
|
'tags' => &$tags, |
|
82
|
|
|
]; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function testSetInvalidatesLifetime() |
|
86
|
|
|
{ |
|
87
|
|
|
$this->hook->set($this->params, $this->cacheFrontendProphecy->reveal()); |
|
88
|
|
|
|
|
89
|
|
|
$this->assertEquals(-1, $this->lifetime); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function testSetInvalidatesLifetimeForRedis() |
|
93
|
|
|
{ |
|
94
|
|
|
$this->cacheBackendProphecy->willExtend(RedisBackend::class); |
|
95
|
|
|
|
|
96
|
|
|
$this->hook->set($this->params, $this->cacheFrontendProphecy->reveal()); |
|
97
|
|
|
|
|
98
|
|
|
$this->assertEquals(1, $this->lifetime); |
|
99
|
|
|
$this->assertFalse($this->variable); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function testSetDoesNothingForNonTemporaryPageCache() |
|
103
|
|
|
{ |
|
104
|
|
|
unset($this->variable['temp_content']); |
|
105
|
|
|
|
|
106
|
|
|
$this->hook->set($this->params, $this->cacheFrontendProphecy->reveal()); |
|
107
|
|
|
|
|
108
|
|
|
$this->assertEquals(30, $this->lifetime); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function testSetDoesNothingForNonPageCache() |
|
112
|
|
|
{ |
|
113
|
|
|
$this->cacheFrontendProphecy->getIdentifier()->willReturn('cache_pagesection'); |
|
114
|
|
|
|
|
115
|
|
|
$this->hook->set($this->params, $this->cacheFrontendProphecy->reveal()); |
|
116
|
|
|
|
|
117
|
|
|
$this->assertEquals(30, $this->lifetime); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function testSetDoesNothingForRedirectsPageCache() |
|
121
|
|
|
{ |
|
122
|
|
|
$this->entryIdentifier = 'redirects'; |
|
123
|
|
|
|
|
124
|
|
|
$this->hook->set($this->params, $this->cacheFrontendProphecy->reveal()); |
|
125
|
|
|
|
|
126
|
|
|
$this->assertEquals(30, $this->lifetime); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function testSetDoesNothingForTitleTagPageCache() |
|
130
|
|
|
{ |
|
131
|
|
|
$this->entryIdentifier .= '-titleTag-record'; |
|
132
|
|
|
|
|
133
|
|
|
$this->hook->set($this->params, $this->cacheFrontendProphecy->reveal()); |
|
134
|
|
|
|
|
135
|
|
|
$this->assertEquals(30, $this->lifetime); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function testSetDoesNothingForMetatagPageCache() |
|
139
|
|
|
{ |
|
140
|
|
|
$this->entryIdentifier .= '-metatag-html5'; |
|
141
|
|
|
|
|
142
|
|
|
$this->hook->set($this->params, $this->cacheFrontendProphecy->reveal()); |
|
143
|
|
|
|
|
144
|
|
|
$this->assertEquals(30, $this->lifetime); |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|
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