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 testPublishUrlAliasForLocation() |
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
|
|
|
$this->cacheMock |
101
|
|
|
->expects($this->once()) |
102
|
|
|
->method('clear') |
103
|
|
|
->with('urlAlias') |
104
|
|
|
->will($this->returnValue(null)); |
105
|
|
|
|
106
|
|
|
$this->cacheMock |
107
|
|
|
->expects($this->once()) |
108
|
|
|
->method('getItem') |
109
|
|
|
->willReturn($cacheItem); |
110
|
|
|
|
111
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
112
|
|
|
$handler->publishUrlAliasForLocation(44, 2, 'name', 'eng-GB', true); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::createCustomUrlAlias |
117
|
|
|
*/ |
118
|
|
|
public function testCreateCustomUrlAliasHasCache() |
119
|
|
|
{ |
120
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
121
|
|
|
|
122
|
|
|
$urlAlias = new UrlAlias(array('id' => 55, 'destination' => 44)); |
123
|
|
|
$innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias\\Handler'); |
124
|
|
|
$this->persistenceHandlerMock |
125
|
|
|
->expects($this->once()) |
126
|
|
|
->method('urlAliasHandler') |
127
|
|
|
->will($this->returnValue($innerHandler)); |
128
|
|
|
|
129
|
|
|
$innerHandler |
130
|
|
|
->expects($this->once()) |
131
|
|
|
->method('createCustomUrlAlias') |
132
|
|
|
->with(44, '/path', true, 'eng-GB', true) |
133
|
|
|
->will($this->returnValue($urlAlias)); |
134
|
|
|
|
135
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
136
|
|
|
$this->cacheMock |
137
|
|
|
->expects($this->at(0)) |
138
|
|
|
->method('getItem') |
139
|
|
|
->with('urlAlias', 55) |
140
|
|
|
->will($this->returnValue($cacheItemMock)); |
141
|
|
|
|
142
|
|
|
$cacheItemMock |
143
|
|
|
->expects($this->never()) |
144
|
|
|
->method('get'); |
145
|
|
|
$cacheItemMock |
146
|
|
|
->expects($this->once()) |
147
|
|
|
->method('set') |
148
|
|
|
->with($urlAlias); |
149
|
|
|
|
150
|
|
|
$cacheItemMock2 = $this->getMock('Stash\Interfaces\ItemInterface'); |
151
|
|
|
$this->cacheMock |
152
|
|
|
->expects($this->at(1)) |
153
|
|
|
->method('getItem') |
154
|
|
|
->with('urlAlias', 'location', 44, 'custom') |
155
|
|
|
->will($this->returnValue($cacheItemMock2)); |
156
|
|
|
|
157
|
|
|
$cacheItemMock2 |
158
|
|
|
->expects($this->once()) |
159
|
|
|
->method('get') |
160
|
|
|
->will($this->returnValue(array(42))); |
161
|
|
|
|
162
|
|
|
$cacheItemMock2 |
163
|
|
|
->expects($this->once()) |
164
|
|
|
->method('isMiss') |
165
|
|
|
->will($this->returnValue(false)); |
166
|
|
|
|
167
|
|
|
$cacheItemMock2 |
168
|
|
|
->expects($this->once()) |
169
|
|
|
->method('set') |
170
|
|
|
->with(array(42, 55)); |
171
|
|
|
|
172
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
173
|
|
|
$handler->createCustomUrlAlias(44, '/path', true, 'eng-GB', true); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::createCustomUrlAlias |
178
|
|
|
*/ |
179
|
|
|
public function testCreateCustomUrlAliasIsMiss() |
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
|
|
|
|
211
|
|
|
$cacheItemMock2 = $this->getMock('Stash\Interfaces\ItemInterface'); |
212
|
|
|
$this->cacheMock |
213
|
|
|
->expects($this->at(1)) |
214
|
|
|
->method('getItem') |
215
|
|
|
->with('urlAlias', 'location', 44, 'custom') |
216
|
|
|
->will($this->returnValue($cacheItemMock2)); |
217
|
|
|
|
218
|
|
|
$cacheItemMock2 |
219
|
|
|
->expects($this->once()) |
220
|
|
|
->method('get') |
221
|
|
|
->will($this->returnValue(null)); |
222
|
|
|
|
223
|
|
|
$cacheItemMock2 |
224
|
|
|
->expects($this->once()) |
225
|
|
|
->method('isMiss') |
226
|
|
|
->will($this->returnValue(true)); |
227
|
|
|
|
228
|
|
|
$cacheItemMock2 |
229
|
|
|
->expects($this->once()) |
230
|
|
|
->method('set') |
231
|
|
|
->with(array(55)); |
232
|
|
|
|
233
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
234
|
|
|
$handler->createCustomUrlAlias(44, '/path', true, 'eng-GB', true); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::createGlobalUrlAlias |
239
|
|
|
*/ |
240
|
|
|
public function testCreateGlobalUrlAlias() |
241
|
|
|
{ |
242
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
243
|
|
|
|
244
|
|
|
$innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias\\Handler'); |
245
|
|
|
$this->persistenceHandlerMock |
246
|
|
|
->expects($this->once()) |
247
|
|
|
->method('urlAliasHandler') |
248
|
|
|
->will($this->returnValue($innerHandler)); |
249
|
|
|
|
250
|
|
|
$innerHandler |
251
|
|
|
->expects($this->once()) |
252
|
|
|
->method('createGlobalUrlAlias') |
253
|
|
|
->with('/old', '/path', true, 'eng-GB', true) |
254
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 55)))); |
255
|
|
|
|
256
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
257
|
|
|
$this->cacheMock |
258
|
|
|
->expects($this->once()) |
259
|
|
|
->method('getItem') |
260
|
|
|
->with('urlAlias', 55) |
261
|
|
|
->will($this->returnValue($cacheItemMock)); |
262
|
|
|
|
263
|
|
|
$cacheItemMock |
264
|
|
|
->expects($this->once()) |
265
|
|
|
->method('set') |
266
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias')); |
267
|
|
|
|
268
|
|
|
$cacheItemMock |
269
|
|
|
->expects($this->never()) |
270
|
|
|
->method('get'); |
271
|
|
|
|
272
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
273
|
|
|
$handler->createGlobalUrlAlias('/old', '/path', true, 'eng-GB', true); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::listURLAliasesForLocation |
278
|
|
|
*/ |
279
|
|
View Code Duplication |
public function testListURLAliasesForLocationIsMiss() |
280
|
|
|
{ |
281
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
282
|
|
|
|
283
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
284
|
|
|
$this->cacheMock |
285
|
|
|
->expects($this->once()) |
286
|
|
|
->method('getItem') |
287
|
|
|
->with('urlAlias', 'location', 44) |
288
|
|
|
->will($this->returnValue($cacheItemMock)); |
289
|
|
|
|
290
|
|
|
$cacheItemMock |
291
|
|
|
->expects($this->once()) |
292
|
|
|
->method('get') |
293
|
|
|
->will($this->returnValue(null)); |
294
|
|
|
|
295
|
|
|
$cacheItemMock |
296
|
|
|
->expects($this->once()) |
297
|
|
|
->method('isMiss') |
298
|
|
|
->will($this->returnValue(true)); |
299
|
|
|
|
300
|
|
|
$innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias\\Handler'); |
301
|
|
|
$this->persistenceHandlerMock |
302
|
|
|
->expects($this->once()) |
303
|
|
|
->method('urlAliasHandler') |
304
|
|
|
->will($this->returnValue($innerHandler)); |
305
|
|
|
|
306
|
|
|
$innerHandler |
307
|
|
|
->expects($this->once()) |
308
|
|
|
->method('listURLAliasesForLocation') |
309
|
|
|
->with(44, false) |
310
|
|
|
->will( |
311
|
|
|
$this->returnValue( |
312
|
|
|
array( |
313
|
|
|
new UrlAlias(array('id' => 55)), |
314
|
|
|
new UrlAlias(array('id' => 58)), |
315
|
|
|
new UrlAlias(array('id' => 91)), |
316
|
|
|
) |
317
|
|
|
) |
318
|
|
|
); |
319
|
|
|
|
320
|
|
|
$cacheItemMock |
321
|
|
|
->expects($this->once()) |
322
|
|
|
->method('set') |
323
|
|
|
->with(array(55, 58, 91)); |
324
|
|
|
|
325
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
326
|
|
|
$handler->listURLAliasesForLocation(44, false); |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::listURLAliasesForLocation |
331
|
|
|
*/ |
332
|
|
View Code Duplication |
public function testListURLAliasesForLocationCustomIsMiss() |
333
|
|
|
{ |
334
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
335
|
|
|
|
336
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
337
|
|
|
$this->cacheMock |
338
|
|
|
->expects($this->once()) |
339
|
|
|
->method('getItem') |
340
|
|
|
->with('urlAlias', 'location', '44', 'custom') |
341
|
|
|
->will($this->returnValue($cacheItemMock)); |
342
|
|
|
|
343
|
|
|
$cacheItemMock |
344
|
|
|
->expects($this->once()) |
345
|
|
|
->method('get') |
346
|
|
|
->will($this->returnValue(null)); |
347
|
|
|
|
348
|
|
|
$cacheItemMock |
349
|
|
|
->expects($this->once()) |
350
|
|
|
->method('isMiss') |
351
|
|
|
->will($this->returnValue(true)); |
352
|
|
|
|
353
|
|
|
$innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias\\Handler'); |
354
|
|
|
$this->persistenceHandlerMock |
355
|
|
|
->expects($this->once()) |
356
|
|
|
->method('urlAliasHandler') |
357
|
|
|
->will($this->returnValue($innerHandler)); |
358
|
|
|
|
359
|
|
|
$innerHandler |
360
|
|
|
->expects($this->once()) |
361
|
|
|
->method('listURLAliasesForLocation') |
362
|
|
|
->with(44, true) |
363
|
|
|
->will( |
364
|
|
|
$this->returnValue( |
365
|
|
|
array( |
366
|
|
|
new UrlAlias(array('id' => 55)), |
367
|
|
|
new UrlAlias(array('id' => 58)), |
368
|
|
|
new UrlAlias(array('id' => 91)), |
369
|
|
|
) |
370
|
|
|
) |
371
|
|
|
); |
372
|
|
|
|
373
|
|
|
$cacheItemMock |
374
|
|
|
->expects($this->once()) |
375
|
|
|
->method('set') |
376
|
|
|
->with(array(55, 58, 91)); |
377
|
|
|
|
378
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
379
|
|
|
$handler->listURLAliasesForLocation(44, true); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::listURLAliasesForLocation |
384
|
|
|
*/ |
385
|
|
View Code Duplication |
public function testListURLAliasesForLocationHasCache() |
386
|
|
|
{ |
387
|
|
|
$this->loggerMock->expects($this->never())->method('logCall'); |
388
|
|
|
|
389
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
390
|
|
|
$this->cacheMock |
391
|
|
|
->expects($this->at(0)) |
392
|
|
|
->method('getItem') |
393
|
|
|
->with('urlAlias', 'location', 44) |
394
|
|
|
->will($this->returnValue($cacheItemMock)); |
395
|
|
|
|
396
|
|
|
$cacheItemMock |
397
|
|
|
->expects($this->once()) |
398
|
|
|
->method('get') |
399
|
|
|
->will($this->returnValue(array(55, 58, 91))); |
400
|
|
|
|
401
|
|
|
$cacheItemMock |
402
|
|
|
->expects($this->once()) |
403
|
|
|
->method('isMiss') |
404
|
|
|
->will($this->returnValue(false)); |
405
|
|
|
|
406
|
|
|
$this->persistenceHandlerMock |
407
|
|
|
->expects($this->never()) |
408
|
|
|
->method($this->anything()); |
409
|
|
|
|
410
|
|
|
$cacheItemMock |
411
|
|
|
->expects($this->never()) |
412
|
|
|
->method('set'); |
413
|
|
|
|
414
|
|
|
// inline calls to loadUrlAlias() using the cache |
415
|
|
|
$cacheItemMock2 = $this->getMock('Stash\Interfaces\ItemInterface'); |
416
|
|
|
$this->cacheMock |
417
|
|
|
->expects($this->at(1)) |
418
|
|
|
->method('getItem') |
419
|
|
|
->with('urlAlias', 55) |
420
|
|
|
->will($this->returnValue($cacheItemMock2)); |
421
|
|
|
|
422
|
|
|
$cacheItemMock2 |
423
|
|
|
->expects($this->at(0)) |
424
|
|
|
->method('get') |
425
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 55)))); |
426
|
|
|
|
427
|
|
|
$this->cacheMock |
428
|
|
|
->expects($this->at(2)) |
429
|
|
|
->method('getItem') |
430
|
|
|
->with('urlAlias', 58) |
431
|
|
|
->will($this->returnValue($cacheItemMock2)); |
432
|
|
|
|
433
|
|
|
$cacheItemMock2 |
434
|
|
|
->expects($this->at(1)) |
435
|
|
|
->method('get') |
436
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 58)))); |
437
|
|
|
|
438
|
|
|
$this->cacheMock |
439
|
|
|
->expects($this->at(3)) |
440
|
|
|
->method('getItem') |
441
|
|
|
->with('urlAlias', 91) |
442
|
|
|
->will($this->returnValue($cacheItemMock2)); |
443
|
|
|
|
444
|
|
|
$cacheItemMock2 |
445
|
|
|
->expects($this->at(2)) |
446
|
|
|
->method('get') |
447
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 91)))); |
448
|
|
|
|
449
|
|
|
$cacheItemMock2 |
450
|
|
|
->expects($this->exactly(3)) |
451
|
|
|
->method('isMiss') |
452
|
|
|
->will($this->returnValue(false)); |
453
|
|
|
|
454
|
|
|
$cacheItemMock2 |
455
|
|
|
->expects($this->never()) |
456
|
|
|
->method('set'); |
457
|
|
|
|
458
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
459
|
|
|
$handler->listURLAliasesForLocation(44, false); |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
/** |
463
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::listURLAliasesForLocation |
464
|
|
|
*/ |
465
|
|
View Code Duplication |
public function testListURLAliasesForLocationCustomHasCache() |
466
|
|
|
{ |
467
|
|
|
$this->loggerMock->expects($this->never())->method('logCall'); |
468
|
|
|
|
469
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
470
|
|
|
$this->cacheMock |
471
|
|
|
->expects($this->at(0)) |
472
|
|
|
->method('getItem') |
473
|
|
|
->with('urlAlias', 'location', '44', 'custom') |
474
|
|
|
->will($this->returnValue($cacheItemMock)); |
475
|
|
|
|
476
|
|
|
$cacheItemMock |
477
|
|
|
->expects($this->once()) |
478
|
|
|
->method('get') |
479
|
|
|
->will($this->returnValue(array(55, 58, 91))); |
480
|
|
|
|
481
|
|
|
$cacheItemMock |
482
|
|
|
->expects($this->once()) |
483
|
|
|
->method('isMiss') |
484
|
|
|
->will($this->returnValue(false)); |
485
|
|
|
|
486
|
|
|
$this->persistenceHandlerMock |
487
|
|
|
->expects($this->never()) |
488
|
|
|
->method($this->anything()); |
489
|
|
|
|
490
|
|
|
$cacheItemMock |
491
|
|
|
->expects($this->never()) |
492
|
|
|
->method('set'); |
493
|
|
|
|
494
|
|
|
// inline calls to loadUrlAlias() using the cache |
495
|
|
|
$cacheItemMock2 = $this->getMock('Stash\Interfaces\ItemInterface'); |
496
|
|
|
$this->cacheMock |
497
|
|
|
->expects($this->at(1)) |
498
|
|
|
->method('getItem') |
499
|
|
|
->with('urlAlias', 55) |
500
|
|
|
->will($this->returnValue($cacheItemMock2)); |
501
|
|
|
|
502
|
|
|
$cacheItemMock2 |
503
|
|
|
->expects($this->at(0)) |
504
|
|
|
->method('get') |
505
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 55)))); |
506
|
|
|
|
507
|
|
|
$this->cacheMock |
508
|
|
|
->expects($this->at(2)) |
509
|
|
|
->method('getItem') |
510
|
|
|
->with('urlAlias', 58) |
511
|
|
|
->will($this->returnValue($cacheItemMock2)); |
512
|
|
|
|
513
|
|
|
$cacheItemMock2 |
514
|
|
|
->expects($this->at(1)) |
515
|
|
|
->method('get') |
516
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 58)))); |
517
|
|
|
|
518
|
|
|
$this->cacheMock |
519
|
|
|
->expects($this->at(3)) |
520
|
|
|
->method('getItem') |
521
|
|
|
->with('urlAlias', 91) |
522
|
|
|
->will($this->returnValue($cacheItemMock2)); |
523
|
|
|
|
524
|
|
|
$cacheItemMock2 |
525
|
|
|
->expects($this->at(2)) |
526
|
|
|
->method('get') |
527
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 91)))); |
528
|
|
|
|
529
|
|
|
$cacheItemMock2 |
530
|
|
|
->expects($this->exactly(3)) |
531
|
|
|
->method('isMiss') |
532
|
|
|
->will($this->returnValue(false)); |
533
|
|
|
|
534
|
|
|
$cacheItemMock2 |
535
|
|
|
->expects($this->never()) |
536
|
|
|
->method('set'); |
537
|
|
|
|
538
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
539
|
|
|
$handler->listURLAliasesForLocation(44, true); |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
/** |
543
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::removeURLAliases |
544
|
|
|
*/ |
545
|
|
|
public function testRemoveURLAliases() |
546
|
|
|
{ |
547
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
548
|
|
|
|
549
|
|
|
$innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias\\Handler'); |
550
|
|
|
$this->persistenceHandlerMock |
551
|
|
|
->expects($this->once()) |
552
|
|
|
->method('urlAliasHandler') |
553
|
|
|
->will($this->returnValue($innerHandler)); |
554
|
|
|
|
555
|
|
|
$innerHandler |
556
|
|
|
->expects($this->once()) |
557
|
|
|
->method('removeURLAliases'); |
558
|
|
|
|
559
|
|
|
$this->cacheMock |
560
|
|
|
->expects($this->at(0)) |
561
|
|
|
->method('clear') |
562
|
|
|
->with('urlAlias', 'url'); |
563
|
|
|
|
564
|
|
|
$this->cacheMock |
565
|
|
|
->expects($this->at(1)) |
566
|
|
|
->method('clear') |
567
|
|
|
->with('urlAlias', 21); |
568
|
|
|
|
569
|
|
|
$this->cacheMock |
570
|
|
|
->expects($this->at(2)) |
571
|
|
|
->method('clear') |
572
|
|
|
->with('urlAlias', 32); |
573
|
|
|
|
574
|
|
|
$this->cacheMock |
575
|
|
|
->expects($this->at(3)) |
576
|
|
|
->method('clear') |
577
|
|
|
->with('urlAlias', 'location', 44); |
578
|
|
|
|
579
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
580
|
|
|
$handler->removeURLAliases( |
581
|
|
|
array( |
582
|
|
|
new UrlAlias(array('id' => 21)), |
583
|
|
|
new UrlAlias(array('id' => 32, 'type' => UrlAlias::LOCATION, 'destination' => 44)), |
584
|
|
|
) |
585
|
|
|
); |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
/** |
589
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::lookup |
590
|
|
|
* @group justme |
591
|
|
|
*/ |
592
|
|
|
public function testLookupIsMiss() |
593
|
|
|
{ |
594
|
|
|
$urlAlias = new UrlAlias(array('id' => 55)); |
595
|
|
|
|
596
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
597
|
|
|
|
598
|
|
|
$missedUrlAliasIdCacheItem = $this->getMock('Stash\Interfaces\ItemInterface'); |
599
|
|
|
$missedUrlAliasIdCacheItem |
600
|
|
|
->expects($this->once()) |
601
|
|
|
->method('get') |
602
|
|
|
->will($this->returnValue(null)); |
603
|
|
|
|
604
|
|
|
$missedUrlAliasIdCacheItem |
605
|
|
|
->expects($this->once()) |
606
|
|
|
->method('isMiss') |
607
|
|
|
->will($this->returnValue(true)); |
608
|
|
|
|
609
|
|
|
$missedUrlAliasIdCacheItem |
610
|
|
|
->expects($this->once()) |
611
|
|
|
->method('set') |
612
|
|
|
->with(55); |
613
|
|
|
|
614
|
|
|
$newUrlAliasCacheItem = $this->getMock('Stash\Interfaces\ItemInterface'); |
615
|
|
|
$newUrlAliasCacheItem |
616
|
|
|
->expects($this->once()) |
617
|
|
|
->method('set') |
618
|
|
|
->with($urlAlias); |
619
|
|
|
|
620
|
|
|
$this->cacheMock |
621
|
|
|
->expects($this->at(0)) |
622
|
|
|
->method('getItem') |
623
|
|
|
->with('urlAlias', 'url', '/url') |
624
|
|
|
->will($this->returnValue($missedUrlAliasIdCacheItem)); |
625
|
|
|
$this->cacheMock |
626
|
|
|
->expects($this->at(1)) |
627
|
|
|
->method('getItem') |
628
|
|
|
->with('urlAlias', 55) |
629
|
|
|
->will($this->returnValue($newUrlAliasCacheItem)); |
630
|
|
|
|
631
|
|
|
$innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias\\Handler'); |
632
|
|
|
$this->persistenceHandlerMock |
633
|
|
|
->expects($this->once()) |
634
|
|
|
->method('urlAliasHandler') |
635
|
|
|
->will($this->returnValue($innerHandler)); |
636
|
|
|
|
637
|
|
|
$innerHandler |
638
|
|
|
->expects($this->once()) |
639
|
|
|
->method('lookup') |
640
|
|
|
->with('/url') |
641
|
|
|
->will($this->returnValue($urlAlias)); |
642
|
|
|
|
643
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
644
|
|
|
$handler->lookup('/url'); |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
/** |
648
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::lookup |
649
|
|
|
*/ |
650
|
|
View Code Duplication |
public function testLookupHasCache() |
651
|
|
|
{ |
652
|
|
|
$this->loggerMock->expects($this->never())->method('logCall'); |
653
|
|
|
|
654
|
|
|
$this->persistenceHandlerMock |
655
|
|
|
->expects($this->never()) |
656
|
|
|
->method($this->anything()); |
657
|
|
|
|
658
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
659
|
|
|
$this->cacheMock |
660
|
|
|
->expects($this->at(0)) |
661
|
|
|
->method('getItem') |
662
|
|
|
->with('urlAlias', 'url', '/url') |
663
|
|
|
->will($this->returnValue($cacheItemMock)); |
664
|
|
|
|
665
|
|
|
$cacheItemMock |
666
|
|
|
->expects($this->once()) |
667
|
|
|
->method('get') |
668
|
|
|
->will($this->returnValue(55)); |
669
|
|
|
|
670
|
|
|
$cacheItemMock |
671
|
|
|
->expects($this->once()) |
672
|
|
|
->method('isMiss') |
673
|
|
|
->will($this->returnValue(false)); |
674
|
|
|
|
675
|
|
|
$cacheItemMock |
676
|
|
|
->expects($this->never()) |
677
|
|
|
->method('set'); |
678
|
|
|
|
679
|
|
|
$cacheItemMock2 = $this->getMock('Stash\Interfaces\ItemInterface'); |
680
|
|
|
$this->cacheMock |
681
|
|
|
->expects($this->at(1)) |
682
|
|
|
->method('getItem') |
683
|
|
|
->with('urlAlias', 55) |
684
|
|
|
->will($this->returnValue($cacheItemMock2)); |
685
|
|
|
|
686
|
|
|
$cacheItemMock2 |
687
|
|
|
->expects($this->once()) |
688
|
|
|
->method('get') |
689
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 55)))); |
690
|
|
|
|
691
|
|
|
$cacheItemMock2 |
692
|
|
|
->expects($this->once()) |
693
|
|
|
->method('isMiss') |
694
|
|
|
->will($this->returnValue(false)); |
695
|
|
|
|
696
|
|
|
$cacheItemMock2 |
697
|
|
|
->expects($this->never()) |
698
|
|
|
->method('set'); |
699
|
|
|
|
700
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
701
|
|
|
$handler->lookup('/url'); |
702
|
|
|
} |
703
|
|
|
|
704
|
|
|
/** |
705
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::loadUrlAlias |
706
|
|
|
*/ |
707
|
|
View Code Duplication |
public function testLoadUrlAliasIsMiss() |
708
|
|
|
{ |
709
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
710
|
|
|
|
711
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
712
|
|
|
$this->cacheMock |
713
|
|
|
->expects($this->once()) |
714
|
|
|
->method('getItem') |
715
|
|
|
->with('urlAlias', 55) |
716
|
|
|
->will($this->returnValue($cacheItemMock)); |
717
|
|
|
|
718
|
|
|
$cacheItemMock |
719
|
|
|
->expects($this->once()) |
720
|
|
|
->method('get') |
721
|
|
|
->will($this->returnValue(null)); |
722
|
|
|
|
723
|
|
|
$cacheItemMock |
724
|
|
|
->expects($this->once()) |
725
|
|
|
->method('isMiss') |
726
|
|
|
->will($this->returnValue(true)); |
727
|
|
|
|
728
|
|
|
$innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias\\Handler'); |
729
|
|
|
$this->persistenceHandlerMock |
730
|
|
|
->expects($this->once()) |
731
|
|
|
->method('urlAliasHandler') |
732
|
|
|
->will($this->returnValue($innerHandler)); |
733
|
|
|
|
734
|
|
|
$innerHandler |
735
|
|
|
->expects($this->once()) |
736
|
|
|
->method('loadUrlAlias') |
737
|
|
|
->with(55) |
738
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 55)))); |
739
|
|
|
|
740
|
|
|
$cacheItemMock |
741
|
|
|
->expects($this->once()) |
742
|
|
|
->method('set') |
743
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias')); |
744
|
|
|
|
745
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
746
|
|
|
$handler->loadUrlAlias(55); |
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
/** |
750
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::loadUrlAlias |
751
|
|
|
*/ |
752
|
|
View Code Duplication |
public function testLoadUrlAliasHasCache() |
753
|
|
|
{ |
754
|
|
|
$this->loggerMock->expects($this->never())->method('logCall'); |
755
|
|
|
|
756
|
|
|
$this->persistenceHandlerMock |
757
|
|
|
->expects($this->never()) |
758
|
|
|
->method($this->anything()); |
759
|
|
|
|
760
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
761
|
|
|
$this->cacheMock |
762
|
|
|
->expects($this->once()) |
763
|
|
|
->method('getItem') |
764
|
|
|
->with('urlAlias', 55) |
765
|
|
|
->will($this->returnValue($cacheItemMock)); |
766
|
|
|
|
767
|
|
|
$cacheItemMock |
768
|
|
|
->expects($this->once()) |
769
|
|
|
->method('get') |
770
|
|
|
->will($this->returnValue(new UrlAlias(array('id' => 55)))); |
771
|
|
|
|
772
|
|
|
$cacheItemMock |
773
|
|
|
->expects($this->once()) |
774
|
|
|
->method('isMiss') |
775
|
|
|
->will($this->returnValue(false)); |
776
|
|
|
|
777
|
|
|
$cacheItemMock |
778
|
|
|
->expects($this->never()) |
779
|
|
|
->method('set'); |
780
|
|
|
|
781
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
782
|
|
|
$handler->loadUrlAlias(55); |
783
|
|
|
} |
784
|
|
|
|
785
|
|
|
/** |
786
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::locationMoved |
787
|
|
|
*/ |
788
|
|
View Code Duplication |
public function testLocationMoved() |
789
|
|
|
{ |
790
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
791
|
|
|
|
792
|
|
|
$innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias\\Handler'); |
793
|
|
|
$this->persistenceHandlerMock |
794
|
|
|
->expects($this->once()) |
795
|
|
|
->method('urlAliasHandler') |
796
|
|
|
->will($this->returnValue($innerHandler)); |
797
|
|
|
|
798
|
|
|
$innerHandler |
799
|
|
|
->expects($this->once()) |
800
|
|
|
->method('locationMoved') |
801
|
|
|
->with(44, 2, 45); |
802
|
|
|
|
803
|
|
|
$this->cacheMock |
804
|
|
|
->expects($this->once()) |
805
|
|
|
->method('clear') |
806
|
|
|
->with('urlAlias') |
807
|
|
|
->will($this->returnValue(null)); |
808
|
|
|
|
809
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
810
|
|
|
$handler->locationMoved(44, 2, 45); |
811
|
|
|
} |
812
|
|
|
|
813
|
|
|
/** |
814
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::locationDeleted |
815
|
|
|
*/ |
816
|
|
|
public function testLocationDeletedWithoutCachedLocation() |
817
|
|
|
{ |
818
|
|
|
$locationNotCached = $this->getMock('Stash\Interfaces\ItemInterface'); |
819
|
|
|
$locationNotCached |
820
|
|
|
->expects($this->once()) |
821
|
|
|
->method('isMiss') |
822
|
|
|
->willReturn(true); |
823
|
|
|
|
824
|
|
|
$this->prepareDeleteMocks($locationNotCached); |
825
|
|
|
|
826
|
|
|
$this->cacheMock |
827
|
|
|
->expects($this->once()) |
828
|
|
|
->method('clear') |
829
|
|
|
->with('urlAlias'); |
830
|
|
|
|
831
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
832
|
|
|
$handler->locationDeleted(44); |
833
|
|
|
} |
834
|
|
|
|
835
|
|
|
/** |
836
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::locationDeleted |
837
|
|
|
*/ |
838
|
|
|
public function testLocationDeletedWithCachedLocation() |
839
|
|
|
{ |
840
|
|
|
$locationCacheItem = $this->getMock('Stash\Interfaces\ItemInterface'); |
841
|
|
|
$locationCacheItem |
842
|
|
|
->expects($this->once()) |
843
|
|
|
->method('isMiss') |
844
|
|
|
->willReturn(false); |
845
|
|
|
$locationCacheItem |
846
|
|
|
->expects($this->once()) |
847
|
|
|
->method('get') |
848
|
|
|
->willReturn(['44']) |
849
|
|
|
; |
850
|
|
|
|
851
|
|
|
$this->prepareDeleteMocks($locationCacheItem); |
852
|
|
|
|
853
|
|
|
$this->cacheMock |
854
|
|
|
->expects($this->at(1)) |
855
|
|
|
->method('clear') |
856
|
|
|
->with('urlAlias', 44); |
857
|
|
|
$this->cacheMock |
858
|
|
|
->expects($this->at(2)) |
859
|
|
|
->method('clear') |
860
|
|
|
->with('urlAlias', 'url'); |
861
|
|
|
|
862
|
|
|
$handler = $this->persistenceCacheHandler->urlAliasHandler(); |
863
|
|
|
$handler->locationDeleted(44); |
864
|
|
|
} |
865
|
|
|
|
866
|
|
|
/** |
867
|
|
|
* @param $locationCacheMissed |
868
|
|
|
*/ |
869
|
|
View Code Duplication |
protected function prepareDeleteMocks($locationCacheMissed) |
870
|
|
|
{ |
871
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
872
|
|
|
|
873
|
|
|
$innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias\\Handler'); |
874
|
|
|
$this->persistenceHandlerMock |
875
|
|
|
->expects($this->once()) |
876
|
|
|
->method('urlAliasHandler') |
877
|
|
|
->will($this->returnValue($innerHandler)); |
878
|
|
|
|
879
|
|
|
$innerHandler->expects($this->once())->method('locationDeleted')->with(44); |
880
|
|
|
|
881
|
|
|
$this->cacheMock |
882
|
|
|
->expects($this->once()) |
883
|
|
|
->method('getItem') |
884
|
|
|
->willReturn($locationCacheMissed); |
885
|
|
|
} |
886
|
|
|
} |
887
|
|
|
|