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