1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File contains Test class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\Core\Persistence\Cache\Tests; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\SPI\Persistence\Content\UrlAlias; |
12
|
|
|
use eZ\Publish\SPI\Persistence\Content\UrlAlias\Handler as SPIUrlAliasHandler; |
13
|
|
|
use Stash\Interfaces\ItemInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Test case for Persistence\Cache\UrlAliasHandler. |
17
|
|
|
*/ |
18
|
|
|
class UrlAliasHandlerTest extends HandlerTest |
19
|
|
|
{ |
20
|
|
|
protected function getCacheItemMock() |
21
|
|
|
{ |
22
|
|
|
return $this->createMock(ItemInterface::class); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
protected function getSPIUrlAliasHandlerMock() |
26
|
|
|
{ |
27
|
|
|
return $this->createMock(SPIUrlAliasHandler::class); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
|
|
public function providerForUnCachedMethods() |
34
|
|
|
{ |
35
|
|
|
return array( |
36
|
|
|
//array( 'publishUrlAliasForLocation', array( 44, 2, 'name', 'eng-GB', true ) ), |
37
|
|
|
//array( 'createCustomUrlAlias', array( 44, '/path', true, 'eng-GB', true ) ), |
38
|
|
|
//array( 'createGlobalUrlAlias', array( '/old', '/path', true, 'eng-GB', true ) ), |
39
|
|
|
array('listGlobalURLAliases', array('eng-GB', 10, 5)), |
40
|
|
|
//array( 'listURLAliasesForLocation', array( 44, true ) ), |
41
|
|
|
//array( 'removeURLAliases', array( array( 1, 2 ) ) ), |
42
|
|
|
//array( 'lookup', array( '/url' ) ), |
43
|
|
|
//array( 'loadUrlAlias', array( 88 ) ), |
44
|
|
|
//array( 'locationMoved', array( 44, 2, 45 ) ), |
45
|
|
|
//array( 'locationCopied', array( 44, 2, 45 ) ), |
46
|
|
|
//array( 'locationDeleted', array( 44 ) ), |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @dataProvider providerForUnCachedMethods |
52
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler |
53
|
|
|
*/ |
54
|
|
|
public function testUnCachedMethods($method, array $arguments) |
55
|
|
|
{ |
56
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
57
|
|
|
$this->cacheMock |
58
|
|
|
->expects($this->never()) |
59
|
|
|
->method($this->anything()); |
60
|
|
|
|
61
|
|
|
$innerHandler = $this->getSPIUrlAliasHandlerMock(); |
62
|
|
|
$this->persistenceHandlerMock |
63
|
|
|
->expects($this->once()) |
64
|
|
|
->method('urlAliasHandler') |
65
|
|
|
->will($this->returnValue($innerHandler)); |
66
|
|
|
|
67
|
|
|
$expects = $innerHandler |
68
|
|
|
->expects($this->once()) |
69
|
|
|
->method($method); |
70
|
|
|
|
71
|
|
|
if (isset($arguments[4])) { |
72
|
|
|
$expects->with($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4]); |
73
|
|
|
} elseif (isset($arguments[3])) { |
74
|
|
|
$expects->with($arguments[0], $arguments[1], $arguments[2], $arguments[3]); |
75
|
|
|
} elseif (isset($arguments[2])) { |
76
|
|
|
$expects->with($arguments[0], $arguments[1], $arguments[2]); |
77
|
|
|
} elseif (isset($arguments[1])) { |
78
|
|
|
$expects->with($arguments[0], $arguments[1]); |
79
|
|
|
} elseif (isset($arguments[0])) { |
80
|
|
|
$expects->with($arguments[0]); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$expects->will($this->returnValue(null)); |
84
|
|
|
|
85
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
86
|
|
|
call_user_func_array(array($handler, $method), $arguments); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::publishUrlAliasForLocation |
91
|
|
|
*/ |
92
|
|
|
public function testPublishUrlAliasForLocationWithoutCachedLocation() |
93
|
|
|
{ |
94
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
95
|
|
|
|
96
|
|
|
$innerHandler = $this->getSPIUrlAliasHandlerMock(); |
97
|
|
|
$cacheItem = $this->getCacheItemMock(); |
|
|
|
|
98
|
|
|
|
99
|
|
|
$this->persistenceHandlerMock |
100
|
|
|
->expects($this->once()) |
101
|
|
|
->method('urlAliasHandler') |
102
|
|
|
->will($this->returnValue($innerHandler)); |
103
|
|
|
|
104
|
|
|
$innerHandler |
105
|
|
|
->expects($this->once()) |
106
|
|
|
->method('publishUrlAliasForLocation') |
107
|
|
|
->with(44, 2, 'name', 'eng-GB', true) |
108
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 55)))); |
109
|
|
|
|
110
|
|
|
$this->cacheMock |
111
|
|
|
->expects($this->once()) |
112
|
|
|
->method('clear') |
113
|
|
|
->with('urlAlias') |
114
|
|
|
->will($this->returnValue(null)); |
115
|
|
|
|
116
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
117
|
|
|
$handler->publishUrlAliasForLocation(44, 2, 'name', 'eng-GB', true); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::publishUrlAliasForLocation |
122
|
|
|
*/ |
123
|
|
|
public function testPublishUrlAliasForLocationWithCachedLocation() |
124
|
|
|
{ |
125
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
126
|
|
|
|
127
|
|
|
$innerHandler = $this->getSPIUrlAliasHandlerMock(); |
128
|
|
|
$cacheItem = $this->getCacheItemMock(); |
|
|
|
|
129
|
|
|
|
130
|
|
|
$this->persistenceHandlerMock |
131
|
|
|
->expects($this->once()) |
132
|
|
|
->method('urlAliasHandler') |
133
|
|
|
->will($this->returnValue($innerHandler)); |
134
|
|
|
|
135
|
|
|
$innerHandler |
136
|
|
|
->expects($this->once()) |
137
|
|
|
->method('publishUrlAliasForLocation') |
138
|
|
|
->with(44, 2, 'name', 'eng-GB', true) |
139
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 55)))); |
140
|
|
|
|
141
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
142
|
|
|
$handler->publishUrlAliasForLocation(44, 2, 'name', 'eng-GB', true); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::createCustomUrlAlias |
147
|
|
|
*/ |
148
|
|
|
public function testCreateCustomUrlAliasHasCache() |
149
|
|
|
{ |
150
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
151
|
|
|
|
152
|
|
|
$urlAlias = new UrlAlias(array('id' => 55, 'destination' => 44)); |
153
|
|
|
$innerHandler = $this->getSPIUrlAliasHandlerMock(); |
154
|
|
|
$this->persistenceHandlerMock |
155
|
|
|
->expects($this->once()) |
156
|
|
|
->method('urlAliasHandler') |
157
|
|
|
->will($this->returnValue($innerHandler)); |
158
|
|
|
|
159
|
|
|
$innerHandler |
160
|
|
|
->expects($this->once()) |
161
|
|
|
->method('createCustomUrlAlias') |
162
|
|
|
->with(44, '/path', true, 'eng-GB', true) |
163
|
|
|
->will($this->returnValue($urlAlias)); |
164
|
|
|
|
165
|
|
|
$cacheItemMock = $this->getCacheItemMock(); |
166
|
|
|
$this->cacheMock |
167
|
|
|
->expects($this->at(0)) |
168
|
|
|
->method('getItem') |
169
|
|
|
->with('urlAlias', 55) |
170
|
|
|
->will($this->returnValue($cacheItemMock)); |
171
|
|
|
|
172
|
|
|
$cacheItemMock |
173
|
|
|
->expects($this->never()) |
174
|
|
|
->method('get'); |
175
|
|
|
$cacheItemMock |
176
|
|
|
->expects($this->once()) |
177
|
|
|
->method('set') |
178
|
|
|
->with($urlAlias) |
179
|
|
|
->will($this->returnValue($cacheItemMock)); |
180
|
|
|
|
181
|
|
|
$cacheItemMock |
182
|
|
|
->expects($this->once()) |
183
|
|
|
->method('save') |
184
|
|
|
->with(); |
185
|
|
|
|
186
|
|
|
$cacheItemMock2 = $this->getCacheItemMock(); |
187
|
|
|
$this->cacheMock |
188
|
|
|
->expects($this->at(1)) |
189
|
|
|
->method('getItem') |
190
|
|
|
->with('urlAlias', 'location', 44, 'custom') |
191
|
|
|
->will($this->returnValue($cacheItemMock2)); |
192
|
|
|
|
193
|
|
|
$cacheItemMock2 |
194
|
|
|
->expects($this->once()) |
195
|
|
|
->method('get') |
196
|
|
|
->will($this->returnValue(array(42))); |
197
|
|
|
|
198
|
|
|
$cacheItemMock2 |
199
|
|
|
->expects($this->once()) |
200
|
|
|
->method('isMiss') |
201
|
|
|
->will($this->returnValue(false)); |
202
|
|
|
|
203
|
|
|
$cacheItemMock2 |
204
|
|
|
->expects($this->once()) |
205
|
|
|
->method('set') |
206
|
|
|
->with(array(42, 55)) |
207
|
|
|
->will($this->returnValue($cacheItemMock2)); |
208
|
|
|
|
209
|
|
|
$cacheItemMock2 |
210
|
|
|
->expects($this->once()) |
211
|
|
|
->method('save') |
212
|
|
|
->with(); |
213
|
|
|
|
214
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
215
|
|
|
$handler->createCustomUrlAlias(44, '/path', true, 'eng-GB', true); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::createCustomUrlAlias |
220
|
|
|
*/ |
221
|
|
|
public function testCreateCustomUrlAliasIsMiss() |
222
|
|
|
{ |
223
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
224
|
|
|
|
225
|
|
|
$urlAlias = new UrlAlias(array('id' => 55, 'destination' => 44)); |
226
|
|
|
$innerHandler = $this->getSPIUrlAliasHandlerMock(); |
227
|
|
|
$this->persistenceHandlerMock |
228
|
|
|
->expects($this->once()) |
229
|
|
|
->method('urlAliasHandler') |
230
|
|
|
->will($this->returnValue($innerHandler)); |
231
|
|
|
|
232
|
|
|
$innerHandler |
233
|
|
|
->expects($this->once()) |
234
|
|
|
->method('createCustomUrlAlias') |
235
|
|
|
->with(44, '/path', true, 'eng-GB', true) |
236
|
|
|
->will($this->returnValue($urlAlias)); |
237
|
|
|
|
238
|
|
|
$cacheItemMock = $this->getCacheItemMock(); |
239
|
|
|
$this->cacheMock |
240
|
|
|
->expects($this->at(0)) |
241
|
|
|
->method('getItem') |
242
|
|
|
->with('urlAlias', 55) |
243
|
|
|
->will($this->returnValue($cacheItemMock)); |
244
|
|
|
|
245
|
|
|
$cacheItemMock |
246
|
|
|
->expects($this->never()) |
247
|
|
|
->method('get'); |
248
|
|
|
$cacheItemMock |
249
|
|
|
->expects($this->once()) |
250
|
|
|
->method('set') |
251
|
|
|
->with($urlAlias) |
252
|
|
|
->will($this->returnValue($cacheItemMock)); |
253
|
|
|
|
254
|
|
|
$cacheItemMock |
255
|
|
|
->expects($this->once()) |
256
|
|
|
->method('save') |
257
|
|
|
->with(); |
258
|
|
|
|
259
|
|
|
$cacheItemMock2 = $this->getCacheItemMock(); |
260
|
|
|
$this->cacheMock |
261
|
|
|
->expects($this->at(1)) |
262
|
|
|
->method('getItem') |
263
|
|
|
->with('urlAlias', 'location', 44, 'custom') |
264
|
|
|
->will($this->returnValue($cacheItemMock2)); |
265
|
|
|
|
266
|
|
|
$cacheItemMock2 |
267
|
|
|
->expects($this->once()) |
268
|
|
|
->method('get') |
269
|
|
|
->will($this->returnValue(null)); |
270
|
|
|
|
271
|
|
|
$cacheItemMock2 |
272
|
|
|
->expects($this->once()) |
273
|
|
|
->method('isMiss') |
274
|
|
|
->will($this->returnValue(true)); |
275
|
|
|
|
276
|
|
|
$cacheItemMock2 |
277
|
|
|
->expects($this->once()) |
278
|
|
|
->method('set') |
279
|
|
|
->with(array(55)) |
280
|
|
|
->will($this->returnValue($cacheItemMock2)); |
281
|
|
|
|
282
|
|
|
$cacheItemMock2 |
283
|
|
|
->expects($this->once()) |
284
|
|
|
->method('save') |
285
|
|
|
->with(); |
286
|
|
|
|
287
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
288
|
|
|
$handler->createCustomUrlAlias(44, '/path', true, 'eng-GB', true); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::createGlobalUrlAlias |
293
|
|
|
*/ |
294
|
|
|
public function testCreateGlobalUrlAlias() |
295
|
|
|
{ |
296
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
297
|
|
|
|
298
|
|
|
$innerHandler = $this->getSPIUrlAliasHandlerMock(); |
299
|
|
|
$this->persistenceHandlerMock |
300
|
|
|
->expects($this->once()) |
301
|
|
|
->method('urlAliasHandler') |
302
|
|
|
->will($this->returnValue($innerHandler)); |
303
|
|
|
|
304
|
|
|
$innerHandler |
305
|
|
|
->expects($this->once()) |
306
|
|
|
->method('createGlobalUrlAlias') |
307
|
|
|
->with('/old', '/path', true, 'eng-GB', true) |
308
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 55)))); |
309
|
|
|
|
310
|
|
|
$cacheItemMock = $this->getCacheItemMock(); |
311
|
|
|
$this->cacheMock |
312
|
|
|
->expects($this->once()) |
313
|
|
|
->method('getItem') |
314
|
|
|
->with('urlAlias', 55) |
315
|
|
|
->will($this->returnValue($cacheItemMock)); |
316
|
|
|
|
317
|
|
|
$cacheItemMock |
318
|
|
|
->expects($this->once()) |
319
|
|
|
->method('set') |
320
|
|
|
->with($this->isInstanceOf(UrlAlias::class)) |
321
|
|
|
->will($this->returnValue($cacheItemMock)); |
322
|
|
|
|
323
|
|
|
$cacheItemMock |
324
|
|
|
->expects($this->once()) |
325
|
|
|
->method('save') |
326
|
|
|
->with(); |
327
|
|
|
|
328
|
|
|
$cacheItemMock |
329
|
|
|
->expects($this->never()) |
330
|
|
|
->method('get'); |
331
|
|
|
|
332
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
333
|
|
|
$handler->createGlobalUrlAlias('/old', '/path', true, 'eng-GB', true); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::listURLAliasesForLocation |
338
|
|
|
*/ |
339
|
|
View Code Duplication |
public function testListURLAliasesForLocationIsMiss() |
340
|
|
|
{ |
341
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
342
|
|
|
|
343
|
|
|
$cacheItemMock = $this->getCacheItemMock(); |
344
|
|
|
$this->cacheMock |
345
|
|
|
->expects($this->once()) |
346
|
|
|
->method('getItem') |
347
|
|
|
->with('urlAlias', 'location', 44) |
348
|
|
|
->will($this->returnValue($cacheItemMock)); |
349
|
|
|
|
350
|
|
|
$cacheItemMock |
351
|
|
|
->expects($this->once()) |
352
|
|
|
->method('get') |
353
|
|
|
->will($this->returnValue(null)); |
354
|
|
|
|
355
|
|
|
$cacheItemMock |
356
|
|
|
->expects($this->once()) |
357
|
|
|
->method('isMiss') |
358
|
|
|
->will($this->returnValue(true)); |
359
|
|
|
|
360
|
|
|
$innerHandler = $this->getSPIUrlAliasHandlerMock(); |
361
|
|
|
$this->persistenceHandlerMock |
362
|
|
|
->expects($this->once()) |
363
|
|
|
->method('urlAliasHandler') |
364
|
|
|
->will($this->returnValue($innerHandler)); |
365
|
|
|
|
366
|
|
|
$innerHandler |
367
|
|
|
->expects($this->once()) |
368
|
|
|
->method('listURLAliasesForLocation') |
369
|
|
|
->with(44, false) |
370
|
|
|
->will( |
371
|
|
|
$this->returnValue( |
372
|
|
|
array( |
373
|
|
|
new UrlAlias(array('id' => 55)), |
374
|
|
|
new UrlAlias(array('id' => 58)), |
375
|
|
|
new UrlAlias(array('id' => 91)), |
376
|
|
|
) |
377
|
|
|
) |
378
|
|
|
); |
379
|
|
|
|
380
|
|
|
$cacheItemMock |
381
|
|
|
->expects($this->once()) |
382
|
|
|
->method('set') |
383
|
|
|
->with(array(55, 58, 91)) |
384
|
|
|
->will($this->returnValue($cacheItemMock)); |
385
|
|
|
|
386
|
|
|
$cacheItemMock |
387
|
|
|
->expects($this->once()) |
388
|
|
|
->method('save') |
389
|
|
|
->with(); |
390
|
|
|
|
391
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
392
|
|
|
$handler->listURLAliasesForLocation(44, false); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::listURLAliasesForLocation |
397
|
|
|
*/ |
398
|
|
View Code Duplication |
public function testListURLAliasesForLocationCustomIsMiss() |
399
|
|
|
{ |
400
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
401
|
|
|
|
402
|
|
|
$cacheItemMock = $this->getCacheItemMock(); |
403
|
|
|
$this->cacheMock |
404
|
|
|
->expects($this->once()) |
405
|
|
|
->method('getItem') |
406
|
|
|
->with('urlAlias', 'location', '44', 'custom') |
407
|
|
|
->will($this->returnValue($cacheItemMock)); |
408
|
|
|
|
409
|
|
|
$cacheItemMock |
410
|
|
|
->expects($this->once()) |
411
|
|
|
->method('get') |
412
|
|
|
->will($this->returnValue(null)); |
413
|
|
|
|
414
|
|
|
$cacheItemMock |
415
|
|
|
->expects($this->once()) |
416
|
|
|
->method('isMiss') |
417
|
|
|
->will($this->returnValue(true)); |
418
|
|
|
|
419
|
|
|
$innerHandler = $this->getSPIUrlAliasHandlerMock(); |
420
|
|
|
$this->persistenceHandlerMock |
421
|
|
|
->expects($this->once()) |
422
|
|
|
->method('urlAliasHandler') |
423
|
|
|
->will($this->returnValue($innerHandler)); |
424
|
|
|
|
425
|
|
|
$innerHandler |
426
|
|
|
->expects($this->once()) |
427
|
|
|
->method('listURLAliasesForLocation') |
428
|
|
|
->with(44, true) |
429
|
|
|
->will( |
430
|
|
|
$this->returnValue( |
431
|
|
|
array( |
432
|
|
|
new UrlAlias(array('id' => 55)), |
433
|
|
|
new UrlAlias(array('id' => 58)), |
434
|
|
|
new UrlAlias(array('id' => 91)), |
435
|
|
|
) |
436
|
|
|
) |
437
|
|
|
); |
438
|
|
|
|
439
|
|
|
$cacheItemMock |
440
|
|
|
->expects($this->once()) |
441
|
|
|
->method('set') |
442
|
|
|
->with(array(55, 58, 91)) |
443
|
|
|
->will($this->returnValue($cacheItemMock)); |
444
|
|
|
|
445
|
|
|
$cacheItemMock |
446
|
|
|
->expects($this->once()) |
447
|
|
|
->method('save') |
448
|
|
|
->with(); |
449
|
|
|
|
450
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
451
|
|
|
$handler->listURLAliasesForLocation(44, true); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
/** |
455
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::listURLAliasesForLocation |
456
|
|
|
*/ |
457
|
|
View Code Duplication |
public function testListURLAliasesForLocationHasCache() |
458
|
|
|
{ |
459
|
|
|
$this->loggerMock->expects($this->never())->method('logCall'); |
460
|
|
|
|
461
|
|
|
$cacheItemMock = $this->getCacheItemMock(); |
462
|
|
|
$this->cacheMock |
463
|
|
|
->expects($this->at(0)) |
464
|
|
|
->method('getItem') |
465
|
|
|
->with('urlAlias', 'location', 44) |
466
|
|
|
->will($this->returnValue($cacheItemMock)); |
467
|
|
|
|
468
|
|
|
$cacheItemMock |
469
|
|
|
->expects($this->once()) |
470
|
|
|
->method('get') |
471
|
|
|
->will($this->returnValue(array(55, 58, 91))); |
472
|
|
|
|
473
|
|
|
$cacheItemMock |
474
|
|
|
->expects($this->once()) |
475
|
|
|
->method('isMiss') |
476
|
|
|
->will($this->returnValue(false)); |
477
|
|
|
|
478
|
|
|
$this->persistenceHandlerMock |
479
|
|
|
->expects($this->never()) |
480
|
|
|
->method($this->anything()); |
481
|
|
|
|
482
|
|
|
$cacheItemMock |
483
|
|
|
->expects($this->never()) |
484
|
|
|
->method('set'); |
485
|
|
|
|
486
|
|
|
// inline calls to loadUrlAlias() using the cache |
487
|
|
|
$cacheItemMock2 = $this->getCacheItemMock(); |
488
|
|
|
$this->cacheMock |
489
|
|
|
->expects($this->at(1)) |
490
|
|
|
->method('getItem') |
491
|
|
|
->with('urlAlias', 55) |
492
|
|
|
->will($this->returnValue($cacheItemMock2)); |
493
|
|
|
|
494
|
|
|
$cacheItemMock2 |
495
|
|
|
->expects($this->at(0)) |
496
|
|
|
->method('get') |
497
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 55)))); |
498
|
|
|
|
499
|
|
|
$this->cacheMock |
500
|
|
|
->expects($this->at(2)) |
501
|
|
|
->method('getItem') |
502
|
|
|
->with('urlAlias', 58) |
503
|
|
|
->will($this->returnValue($cacheItemMock2)); |
504
|
|
|
|
505
|
|
|
$cacheItemMock2 |
506
|
|
|
->expects($this->at(1)) |
507
|
|
|
->method('get') |
508
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 58)))); |
509
|
|
|
|
510
|
|
|
$this->cacheMock |
511
|
|
|
->expects($this->at(3)) |
512
|
|
|
->method('getItem') |
513
|
|
|
->with('urlAlias', 91) |
514
|
|
|
->will($this->returnValue($cacheItemMock2)); |
515
|
|
|
|
516
|
|
|
$cacheItemMock2 |
517
|
|
|
->expects($this->at(2)) |
518
|
|
|
->method('get') |
519
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 91)))); |
520
|
|
|
|
521
|
|
|
$cacheItemMock2 |
522
|
|
|
->expects($this->exactly(3)) |
523
|
|
|
->method('isMiss') |
524
|
|
|
->will($this->returnValue(false)); |
525
|
|
|
|
526
|
|
|
$cacheItemMock2 |
527
|
|
|
->expects($this->never()) |
528
|
|
|
->method('set'); |
529
|
|
|
|
530
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
531
|
|
|
$handler->listURLAliasesForLocation(44, false); |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::listURLAliasesForLocation |
536
|
|
|
*/ |
537
|
|
View Code Duplication |
public function testListURLAliasesForLocationCustomHasCache() |
538
|
|
|
{ |
539
|
|
|
$this->loggerMock->expects($this->never())->method('logCall'); |
540
|
|
|
|
541
|
|
|
$cacheItemMock = $this->getCacheItemMock(); |
542
|
|
|
$this->cacheMock |
543
|
|
|
->expects($this->at(0)) |
544
|
|
|
->method('getItem') |
545
|
|
|
->with('urlAlias', 'location', '44', 'custom') |
546
|
|
|
->will($this->returnValue($cacheItemMock)); |
547
|
|
|
|
548
|
|
|
$cacheItemMock |
549
|
|
|
->expects($this->once()) |
550
|
|
|
->method('get') |
551
|
|
|
->will($this->returnValue(array(55, 58, 91))); |
552
|
|
|
|
553
|
|
|
$cacheItemMock |
554
|
|
|
->expects($this->once()) |
555
|
|
|
->method('isMiss') |
556
|
|
|
->will($this->returnValue(false)); |
557
|
|
|
|
558
|
|
|
$this->persistenceHandlerMock |
559
|
|
|
->expects($this->never()) |
560
|
|
|
->method($this->anything()); |
561
|
|
|
|
562
|
|
|
$cacheItemMock |
563
|
|
|
->expects($this->never()) |
564
|
|
|
->method('set'); |
565
|
|
|
|
566
|
|
|
$cacheItemMock2 = $this->getCacheItemMock(); |
567
|
|
|
$this->cacheMock |
568
|
|
|
->expects($this->at(1)) |
569
|
|
|
->method('getItem') |
570
|
|
|
->with('urlAlias', 55) |
571
|
|
|
->will($this->returnValue($cacheItemMock2)); |
572
|
|
|
|
573
|
|
|
$cacheItemMock2 |
574
|
|
|
->expects($this->at(0)) |
575
|
|
|
->method('get') |
576
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 55)))); |
577
|
|
|
|
578
|
|
|
$this->cacheMock |
579
|
|
|
->expects($this->at(2)) |
580
|
|
|
->method('getItem') |
581
|
|
|
->with('urlAlias', 58) |
582
|
|
|
->will($this->returnValue($cacheItemMock2)); |
583
|
|
|
|
584
|
|
|
$cacheItemMock2 |
585
|
|
|
->expects($this->at(1)) |
586
|
|
|
->method('get') |
587
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 58)))); |
588
|
|
|
|
589
|
|
|
$this->cacheMock |
590
|
|
|
->expects($this->at(3)) |
591
|
|
|
->method('getItem') |
592
|
|
|
->with('urlAlias', 91) |
593
|
|
|
->will($this->returnValue($cacheItemMock2)); |
594
|
|
|
|
595
|
|
|
$cacheItemMock2 |
596
|
|
|
->expects($this->at(2)) |
597
|
|
|
->method('get') |
598
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 91)))); |
599
|
|
|
|
600
|
|
|
$cacheItemMock2 |
601
|
|
|
->expects($this->exactly(3)) |
602
|
|
|
->method('isMiss') |
603
|
|
|
->will($this->returnValue(false)); |
604
|
|
|
|
605
|
|
|
$cacheItemMock2 |
606
|
|
|
->expects($this->never()) |
607
|
|
|
->method('set'); |
608
|
|
|
|
609
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
610
|
|
|
$handler->listURLAliasesForLocation(44, true); |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
/** |
614
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::removeURLAliases |
615
|
|
|
*/ |
616
|
|
|
public function testRemoveURLAliases() |
617
|
|
|
{ |
618
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
619
|
|
|
|
620
|
|
|
$innerHandler = $this->getSPIUrlAliasHandlerMock(); |
621
|
|
|
$this->persistenceHandlerMock |
622
|
|
|
->expects($this->once()) |
623
|
|
|
->method('urlAliasHandler') |
624
|
|
|
->will($this->returnValue($innerHandler)); |
625
|
|
|
|
626
|
|
|
$innerHandler |
627
|
|
|
->expects($this->once()) |
628
|
|
|
->method('removeURLAliases'); |
629
|
|
|
|
630
|
|
|
$this->cacheMock |
631
|
|
|
->expects($this->at(0)) |
632
|
|
|
->method('clear') |
633
|
|
|
->with('urlAlias', 'url'); |
634
|
|
|
|
635
|
|
|
$this->cacheMock |
636
|
|
|
->expects($this->at(1)) |
637
|
|
|
->method('clear') |
638
|
|
|
->with('urlAlias', 21); |
639
|
|
|
|
640
|
|
|
$this->cacheMock |
641
|
|
|
->expects($this->at(2)) |
642
|
|
|
->method('clear') |
643
|
|
|
->with('urlAlias', 32); |
644
|
|
|
|
645
|
|
|
$this->cacheMock |
646
|
|
|
->expects($this->at(3)) |
647
|
|
|
->method('clear') |
648
|
|
|
->with('urlAlias', 'location', 44); |
649
|
|
|
|
650
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
651
|
|
|
$handler->removeURLAliases( |
652
|
|
|
array( |
653
|
|
|
new UrlAlias(array('id' => 21)), |
654
|
|
|
new UrlAlias(array('id' => 32, 'type' => UrlAlias::LOCATION, 'destination' => 44)), |
655
|
|
|
) |
656
|
|
|
); |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
/** |
660
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::lookup |
661
|
|
|
*/ |
662
|
|
|
public function testLookupIsMissActive() |
663
|
|
|
{ |
664
|
|
|
$urlAlias = new UrlAlias( |
665
|
|
|
[ |
666
|
|
|
'id' => 55, |
667
|
|
|
'isHistory' => false, |
668
|
|
|
] |
669
|
|
|
); |
670
|
|
|
|
671
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
672
|
|
|
|
673
|
|
|
$missedUrlAliasIdCacheItem = $this->getCacheItemMock(); |
674
|
|
|
$missedUrlAliasIdCacheItem |
675
|
|
|
->expects($this->once()) |
676
|
|
|
->method('get') |
677
|
|
|
->will($this->returnValue(null)); |
678
|
|
|
|
679
|
|
|
$missedUrlAliasIdCacheItem |
680
|
|
|
->expects($this->once()) |
681
|
|
|
->method('isMiss') |
682
|
|
|
->will($this->returnValue(true)); |
683
|
|
|
|
684
|
|
|
$missedUrlAliasIdCacheItem |
685
|
|
|
->expects($this->once()) |
686
|
|
|
->method('set') |
687
|
|
|
->with(55) |
688
|
|
|
->will($this->returnValue($missedUrlAliasIdCacheItem)); |
689
|
|
|
|
690
|
|
|
$missedUrlAliasIdCacheItem |
691
|
|
|
->expects($this->once()) |
692
|
|
|
->method('save') |
693
|
|
|
->with(); |
694
|
|
|
|
695
|
|
|
$newUrlAliasCacheItem = $this->getCacheItemMock(); |
696
|
|
|
$newUrlAliasCacheItem |
697
|
|
|
->expects($this->once()) |
698
|
|
|
->method('set') |
699
|
|
|
->with($urlAlias) |
700
|
|
|
->will($this->returnValue($newUrlAliasCacheItem)); |
701
|
|
|
|
702
|
|
|
$newUrlAliasCacheItem |
703
|
|
|
->expects($this->once()) |
704
|
|
|
->method('save') |
705
|
|
|
->with(); |
706
|
|
|
|
707
|
|
|
$historyUrlAliasCacheItem = $this->getCacheItemMock(); |
708
|
|
|
$historyUrlAliasCacheItem |
709
|
|
|
->expects($this->once()) |
710
|
|
|
->method('get') |
711
|
|
|
->will($this->returnValue(null)); |
712
|
|
|
|
713
|
|
|
$historyUrlAliasCacheItem |
714
|
|
|
->expects($this->once()) |
715
|
|
|
->method('isMiss') |
716
|
|
|
->will($this->returnValue(true)); |
717
|
|
|
|
718
|
|
|
$this->cacheMock |
719
|
|
|
->expects($this->at(0)) |
720
|
|
|
->method('getItem') |
721
|
|
|
->with('urlAlias', 'url', '/url') |
722
|
|
|
->will($this->returnValue($missedUrlAliasIdCacheItem)); |
723
|
|
|
$this->cacheMock |
724
|
|
|
->expects($this->at(1)) |
725
|
|
|
->method('getItem') |
726
|
|
|
->with('urlAlias', 'url', 'history', '/url') |
727
|
|
|
->will($this->returnValue($historyUrlAliasCacheItem)); |
728
|
|
|
$this->cacheMock |
729
|
|
|
->expects($this->at(2)) |
730
|
|
|
->method('getItem') |
731
|
|
|
->with('urlAlias', 55) |
732
|
|
|
->will($this->returnValue($newUrlAliasCacheItem)); |
733
|
|
|
|
734
|
|
|
$innerHandler = $this->getSPIUrlAliasHandlerMock(); |
735
|
|
|
$this->persistenceHandlerMock |
736
|
|
|
->expects($this->once()) |
737
|
|
|
->method('urlAliasHandler') |
738
|
|
|
->will($this->returnValue($innerHandler)); |
739
|
|
|
|
740
|
|
|
$innerHandler |
741
|
|
|
->expects($this->once()) |
742
|
|
|
->method('lookup') |
743
|
|
|
->with('/url') |
744
|
|
|
->will($this->returnValue($urlAlias)); |
745
|
|
|
|
746
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
747
|
|
|
$handler->lookup('/url'); |
748
|
|
|
} |
749
|
|
|
|
750
|
|
|
/** |
751
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::lookup |
752
|
|
|
*/ |
753
|
|
|
public function testLookupIsMissHistory() |
754
|
|
|
{ |
755
|
|
|
$urlAlias = new UrlAlias( |
756
|
|
|
[ |
757
|
|
|
'id' => 55, |
758
|
|
|
'isHistory' => true, |
759
|
|
|
] |
760
|
|
|
); |
761
|
|
|
|
762
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
763
|
|
|
|
764
|
|
|
$missedUrlAliasIdCacheItem = $this->getCacheItemMock(); |
765
|
|
|
$missedUrlAliasIdCacheItem |
766
|
|
|
->expects($this->once()) |
767
|
|
|
->method('get') |
768
|
|
|
->will($this->returnValue(null)); |
769
|
|
|
|
770
|
|
|
$missedUrlAliasIdCacheItem |
771
|
|
|
->expects($this->once()) |
772
|
|
|
->method('isMiss') |
773
|
|
|
->will($this->returnValue(true)); |
774
|
|
|
|
775
|
|
|
$historyUrlAliasCacheItem = $this->getCacheItemMock(); |
776
|
|
|
$historyUrlAliasCacheItem |
777
|
|
|
->expects($this->once()) |
778
|
|
|
->method('get') |
779
|
|
|
->will($this->returnValue(null)); |
780
|
|
|
|
781
|
|
|
$historyUrlAliasCacheItem |
782
|
|
|
->expects($this->once()) |
783
|
|
|
->method('isMiss') |
784
|
|
|
->will($this->returnValue(true)); |
785
|
|
|
|
786
|
|
|
$historyUrlAliasCacheItem |
787
|
|
|
->expects($this->once()) |
788
|
|
|
->method('set') |
789
|
|
|
->with($urlAlias) |
790
|
|
|
->will($this->returnValue($historyUrlAliasCacheItem)); |
791
|
|
|
$historyUrlAliasCacheItem |
792
|
|
|
->expects($this->once()) |
793
|
|
|
->method('save') |
794
|
|
|
->with(); |
795
|
|
|
|
796
|
|
|
$this->cacheMock |
797
|
|
|
->expects($this->at(0)) |
798
|
|
|
->method('getItem') |
799
|
|
|
->with('urlAlias', 'url', '/url') |
800
|
|
|
->will($this->returnValue($missedUrlAliasIdCacheItem)); |
801
|
|
|
$this->cacheMock |
802
|
|
|
->expects($this->at(1)) |
803
|
|
|
->method('getItem') |
804
|
|
|
->with('urlAlias', 'url', 'history', '/url') |
805
|
|
|
->will($this->returnValue($historyUrlAliasCacheItem)); |
806
|
|
|
|
807
|
|
|
$innerHandler = $this->getSPIUrlAliasHandlerMock(); |
808
|
|
|
$this->persistenceHandlerMock |
809
|
|
|
->expects($this->once()) |
810
|
|
|
->method('urlAliasHandler') |
811
|
|
|
->will($this->returnValue($innerHandler)); |
812
|
|
|
|
813
|
|
|
$innerHandler |
814
|
|
|
->expects($this->once()) |
815
|
|
|
->method('lookup') |
816
|
|
|
->with('/url') |
817
|
|
|
->will($this->returnValue($urlAlias)); |
818
|
|
|
|
819
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
820
|
|
|
$handler->lookup('/url'); |
821
|
|
|
} |
822
|
|
|
|
823
|
|
|
/** |
824
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::lookup |
825
|
|
|
*/ |
826
|
|
View Code Duplication |
public function testLookupHasCache() |
827
|
|
|
{ |
828
|
|
|
$this->loggerMock->expects($this->never())->method('logCall'); |
829
|
|
|
|
830
|
|
|
$this->persistenceHandlerMock |
831
|
|
|
->expects($this->never()) |
832
|
|
|
->method($this->anything()); |
833
|
|
|
|
834
|
|
|
$cacheItemMock = $this->getCacheItemMock(); |
835
|
|
|
$this->cacheMock |
836
|
|
|
->expects($this->at(0)) |
837
|
|
|
->method('getItem') |
838
|
|
|
->with('urlAlias', 'url', '/url') |
839
|
|
|
->will($this->returnValue($cacheItemMock)); |
840
|
|
|
|
841
|
|
|
$cacheItemMock |
842
|
|
|
->expects($this->once()) |
843
|
|
|
->method('get') |
844
|
|
|
->will($this->returnValue(55)); |
845
|
|
|
|
846
|
|
|
$cacheItemMock |
847
|
|
|
->expects($this->once()) |
848
|
|
|
->method('isMiss') |
849
|
|
|
->will($this->returnValue(false)); |
850
|
|
|
|
851
|
|
|
$cacheItemMock |
852
|
|
|
->expects($this->never()) |
853
|
|
|
->method('set'); |
854
|
|
|
|
855
|
|
|
$cacheItemMock2 = $this->getCacheItemMock(); |
856
|
|
|
$this->cacheMock |
857
|
|
|
->expects($this->at(1)) |
858
|
|
|
->method('getItem') |
859
|
|
|
->with('urlAlias', 55) |
860
|
|
|
->will($this->returnValue($cacheItemMock2)); |
861
|
|
|
|
862
|
|
|
$cacheItemMock2 |
863
|
|
|
->expects($this->once()) |
864
|
|
|
->method('get') |
865
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 55)))); |
866
|
|
|
|
867
|
|
|
$cacheItemMock2 |
868
|
|
|
->expects($this->once()) |
869
|
|
|
->method('isMiss') |
870
|
|
|
->will($this->returnValue(false)); |
871
|
|
|
|
872
|
|
|
$cacheItemMock2 |
873
|
|
|
->expects($this->never()) |
874
|
|
|
->method('set'); |
875
|
|
|
|
876
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
877
|
|
|
$handler->lookup('/url'); |
878
|
|
|
} |
879
|
|
|
|
880
|
|
|
/** |
881
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::lookup |
882
|
|
|
*/ |
883
|
|
|
public function testLookupHasHistoryCache() |
884
|
|
|
{ |
885
|
|
|
$urlAlias = new UrlAlias(array('id' => 55)); |
886
|
|
|
|
887
|
|
|
$this->loggerMock |
888
|
|
|
->expects($this->never()) |
889
|
|
|
->method('logCall'); |
890
|
|
|
|
891
|
|
|
$missedUrlAliasIdCacheItem = $this->getCacheItemMock(); |
892
|
|
|
$missedUrlAliasIdCacheItem |
893
|
|
|
->expects($this->once()) |
894
|
|
|
->method('get') |
895
|
|
|
->will($this->returnValue(null)); |
896
|
|
|
|
897
|
|
|
$missedUrlAliasIdCacheItem |
898
|
|
|
->expects($this->once()) |
899
|
|
|
->method('isMiss') |
900
|
|
|
->will($this->returnValue(true)); |
901
|
|
|
|
902
|
|
|
$historyUrlAliasCacheItem = $this->getCacheItemMock(); |
903
|
|
|
$historyUrlAliasCacheItem |
904
|
|
|
->expects($this->once()) |
905
|
|
|
->method('get') |
906
|
|
|
->will($this->returnValue($urlAlias)); |
907
|
|
|
|
908
|
|
|
$historyUrlAliasCacheItem |
909
|
|
|
->expects($this->once()) |
910
|
|
|
->method('isMiss') |
911
|
|
|
->will($this->returnValue(false)); |
912
|
|
|
|
913
|
|
|
$this->cacheMock |
914
|
|
|
->expects($this->at(0)) |
915
|
|
|
->method('getItem') |
916
|
|
|
->with('urlAlias', 'url', '/url') |
917
|
|
|
->will($this->returnValue($missedUrlAliasIdCacheItem)); |
918
|
|
|
$this->cacheMock |
919
|
|
|
->expects($this->at(1)) |
920
|
|
|
->method('getItem') |
921
|
|
|
->with('urlAlias', 'url', 'history', '/url') |
922
|
|
|
->will($this->returnValue($historyUrlAliasCacheItem)); |
923
|
|
|
|
924
|
|
|
$this->persistenceHandlerMock |
925
|
|
|
->expects($this->never()) |
926
|
|
|
->method('urlAliasHandler'); |
927
|
|
|
|
928
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
929
|
|
|
$handler->lookup('/url'); |
930
|
|
|
} |
931
|
|
|
|
932
|
|
|
/** |
933
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::loadUrlAlias |
934
|
|
|
*/ |
935
|
|
View Code Duplication |
public function testLoadUrlAliasIsMiss() |
936
|
|
|
{ |
937
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
938
|
|
|
|
939
|
|
|
$cacheItemMock = $this->getCacheItemMock(); |
940
|
|
|
$this->cacheMock |
941
|
|
|
->expects($this->once()) |
942
|
|
|
->method('getItem') |
943
|
|
|
->with('urlAlias', 55) |
944
|
|
|
->will($this->returnValue($cacheItemMock)); |
945
|
|
|
|
946
|
|
|
$cacheItemMock |
947
|
|
|
->expects($this->once()) |
948
|
|
|
->method('get') |
949
|
|
|
->will($this->returnValue(null)); |
950
|
|
|
|
951
|
|
|
$cacheItemMock |
952
|
|
|
->expects($this->once()) |
953
|
|
|
->method('isMiss') |
954
|
|
|
->will($this->returnValue(true)); |
955
|
|
|
|
956
|
|
|
$innerHandler = $this->getSPIUrlAliasHandlerMock(); |
957
|
|
|
$this->persistenceHandlerMock |
958
|
|
|
->expects($this->once()) |
959
|
|
|
->method('urlAliasHandler') |
960
|
|
|
->will($this->returnValue($innerHandler)); |
961
|
|
|
|
962
|
|
|
$innerHandler |
963
|
|
|
->expects($this->once()) |
964
|
|
|
->method('loadUrlAlias') |
965
|
|
|
->with(55) |
966
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 55)))); |
967
|
|
|
|
968
|
|
|
$cacheItemMock |
969
|
|
|
->expects($this->once()) |
970
|
|
|
->method('set') |
971
|
|
|
->with($this->isInstanceOf(UrlAlias::class)) |
972
|
|
|
->will($this->returnValue($cacheItemMock)); |
973
|
|
|
|
974
|
|
|
$cacheItemMock |
975
|
|
|
->expects($this->once()) |
976
|
|
|
->method('save') |
977
|
|
|
->with(); |
978
|
|
|
|
979
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
980
|
|
|
$handler->loadUrlAlias(55); |
981
|
|
|
} |
982
|
|
|
|
983
|
|
|
/** |
984
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::loadUrlAlias |
985
|
|
|
*/ |
986
|
|
View Code Duplication |
public function testLoadUrlAliasHasCache() |
987
|
|
|
{ |
988
|
|
|
$this->loggerMock->expects($this->never())->method('logCall'); |
989
|
|
|
|
990
|
|
|
$this->persistenceHandlerMock |
991
|
|
|
->expects($this->never()) |
992
|
|
|
->method($this->anything()); |
993
|
|
|
|
994
|
|
|
$cacheItemMock = $this->getCacheItemMock(); |
995
|
|
|
$this->cacheMock |
996
|
|
|
->expects($this->once()) |
997
|
|
|
->method('getItem') |
998
|
|
|
->with('urlAlias', 55) |
999
|
|
|
->will($this->returnValue($cacheItemMock)); |
1000
|
|
|
|
1001
|
|
|
$cacheItemMock |
1002
|
|
|
->expects($this->once()) |
1003
|
|
|
->method('get') |
1004
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 55)))); |
1005
|
|
|
|
1006
|
|
|
$cacheItemMock |
1007
|
|
|
->expects($this->once()) |
1008
|
|
|
->method('isMiss') |
1009
|
|
|
->will($this->returnValue(false)); |
1010
|
|
|
|
1011
|
|
|
$cacheItemMock |
1012
|
|
|
->expects($this->never()) |
1013
|
|
|
->method('set'); |
1014
|
|
|
|
1015
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
1016
|
|
|
$handler->loadUrlAlias(55); |
1017
|
|
|
} |
1018
|
|
|
|
1019
|
|
|
/** |
1020
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::locationMoved |
1021
|
|
|
*/ |
1022
|
|
|
public function testLocationMoved() |
1023
|
|
|
{ |
1024
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
1025
|
|
|
|
1026
|
|
|
$innerHandler = $this->getSPIUrlAliasHandlerMock(); |
1027
|
|
|
$this->persistenceHandlerMock |
1028
|
|
|
->expects($this->once()) |
1029
|
|
|
->method('urlAliasHandler') |
1030
|
|
|
->will($this->returnValue($innerHandler)); |
1031
|
|
|
|
1032
|
|
|
$innerHandler |
1033
|
|
|
->expects($this->once()) |
1034
|
|
|
->method('locationMoved') |
1035
|
|
|
->with(44, 2, 45); |
1036
|
|
|
|
1037
|
|
|
$this->cacheMock |
1038
|
|
|
->expects($this->once()) |
1039
|
|
|
->method('clear') |
1040
|
|
|
->with('urlAlias') |
1041
|
|
|
->will($this->returnValue(null)); |
1042
|
|
|
|
1043
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
1044
|
|
|
$handler->locationMoved(44, 2, 45); |
1045
|
|
|
} |
1046
|
|
|
|
1047
|
|
|
/** |
1048
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::locationDeleted |
1049
|
|
|
*/ |
1050
|
|
|
public function testLocationDeletedWithoutCachedLocation() |
1051
|
|
|
{ |
1052
|
|
|
$locationNotCached = $this->getCacheItemMock(); |
1053
|
|
|
$locationNotCached |
1054
|
|
|
->expects($this->once()) |
1055
|
|
|
->method('isMiss') |
1056
|
|
|
->willReturn(true); |
1057
|
|
|
$locationNotCached |
1058
|
|
|
->expects($this->never()) |
1059
|
|
|
->method('clear'); |
1060
|
|
|
|
1061
|
|
|
$this->prepareDeleteMocks($locationNotCached); |
1062
|
|
|
|
1063
|
|
|
$this->cacheMock |
1064
|
|
|
->expects($this->once()) |
1065
|
|
|
->method('clear') |
1066
|
|
|
->with('urlAlias'); |
1067
|
|
|
|
1068
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
1069
|
|
|
$handler->locationDeleted(44); |
1070
|
|
|
} |
1071
|
|
|
|
1072
|
|
|
/** |
1073
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::locationDeleted |
1074
|
|
|
*/ |
1075
|
|
|
public function testLocationDeletedWithCachedLocation() |
1076
|
|
|
{ |
1077
|
|
|
$locationCacheItem = $this->getCacheItemMock(); |
1078
|
|
|
$locationCacheItem |
1079
|
|
|
->expects($this->once()) |
1080
|
|
|
->method('isMiss') |
1081
|
|
|
->willReturn(false); |
1082
|
|
|
$locationCacheItem |
1083
|
|
|
->expects($this->once()) |
1084
|
|
|
->method('get') |
1085
|
|
|
->willReturn(['44']) |
1086
|
|
|
; |
1087
|
|
|
$locationCacheItem |
1088
|
|
|
->expects($this->once()) |
1089
|
|
|
->method('clear') |
1090
|
|
|
->will($this->returnValue(null)); |
1091
|
|
|
|
1092
|
|
|
$this->prepareDeleteMocks($locationCacheItem); |
1093
|
|
|
|
1094
|
|
|
$this->cacheMock |
1095
|
|
|
->expects($this->at(1)) |
1096
|
|
|
->method('clear') |
1097
|
|
|
->with('urlAlias', 44); |
1098
|
|
|
$this->cacheMock |
1099
|
|
|
->expects($this->at(2)) |
1100
|
|
|
->method('clear') |
1101
|
|
|
->with('urlAlias', 'url'); |
1102
|
|
|
|
1103
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
1104
|
|
|
$handler->locationDeleted(44); |
1105
|
|
|
} |
1106
|
|
|
|
1107
|
|
|
/** |
1108
|
|
|
* @param $locationCacheMissed |
1109
|
|
|
*/ |
1110
|
|
View Code Duplication |
protected function prepareDeleteMocks($locationCacheMissed) |
1111
|
|
|
{ |
1112
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
1113
|
|
|
|
1114
|
|
|
$innerHandler = $this->getSPIUrlAliasHandlerMock(); |
1115
|
|
|
$this->persistenceHandlerMock |
1116
|
|
|
->expects($this->once()) |
1117
|
|
|
->method('urlAliasHandler') |
1118
|
|
|
->will($this->returnValue($innerHandler)); |
1119
|
|
|
|
1120
|
|
|
$innerHandler->expects($this->once())->method('locationDeleted')->with(44); |
1121
|
|
|
|
1122
|
|
|
$this->cacheMock |
1123
|
|
|
->expects($this->once()) |
1124
|
|
|
->method('getItem') |
1125
|
|
|
->willReturn($locationCacheMissed); |
1126
|
|
|
} |
1127
|
|
|
} |
1128
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.