Completed
Push — 6.3 ( 3b806d...581b00 )
by
unknown
28:01 queued 08:03
created

UrlAliasHandlerTest::testRemoveURLAliases()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 42
Code Lines 31

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 42
rs 8.8571
cc 1
eloc 31
nc 1
nop 0
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
     */
591
    public function testLookupIsMiss()
592
    {
593
        $this->loggerMock->expects($this->once())->method('logCall');
594
595
        $urlAliasIdCacheItem = $this->getMock('Stash\Interfaces\ItemInterface');
596
        $urlAliasIdCacheItem
597
            ->expects($this->once())
598
            ->method('get')
599
            ->will($this->returnValue(null));
600
601
        $urlAliasIdCacheItem
602
            ->expects($this->once())
603
            ->method('isMiss')
604
            ->will($this->returnValue(true));
605
606
        $urlAliasIdCacheItem
607
            ->expects($this->once())
608
            ->method('set')
609
            ->with(55);
610
611
        $this->cacheMock
612
            ->expects($this->once())
613
            ->method('getItem')
614
            ->with('urlAlias', 'url', '/url')
615
            ->will($this->returnValue($urlAliasIdCacheItem));
616
617
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias\\Handler');
618
        $this->persistenceHandlerMock
619
            ->expects($this->once())
620
            ->method('urlAliasHandler')
621
            ->will($this->returnValue($innerHandler));
622
623
        $innerHandler
624
            ->expects($this->once())
625
            ->method('lookup')
626
            ->with('/url')
627
            ->will($this->returnValue(new UrlAlias(array('id' => 55))));
628
629
        $handler = $this->persistenceCacheHandler->urlAliasHandler();
630
        $handler->lookup('/url');
631
    }
632
633
    /**
634
     * @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::lookup
635
     */
636 View Code Duplication
    public function testLookupHasCache()
637
    {
638
        $this->loggerMock->expects($this->never())->method('logCall');
639
640
        $this->persistenceHandlerMock
641
            ->expects($this->never())
642
            ->method($this->anything());
643
644
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
645
        $this->cacheMock
646
            ->expects($this->at(0))
647
            ->method('getItem')
648
            ->with('urlAlias', 'url', '/url')
649
            ->will($this->returnValue($cacheItemMock));
650
651
        $cacheItemMock
652
            ->expects($this->once())
653
            ->method('get')
654
            ->will($this->returnValue(55));
655
656
        $cacheItemMock
657
            ->expects($this->once())
658
            ->method('isMiss')
659
            ->will($this->returnValue(false));
660
661
        $cacheItemMock
662
            ->expects($this->never())
663
            ->method('set');
664
665
        $cacheItemMock2 = $this->getMock('Stash\Interfaces\ItemInterface');
666
        $this->cacheMock
667
            ->expects($this->at(1))
668
            ->method('getItem')
669
            ->with('urlAlias', 55)
670
            ->will($this->returnValue($cacheItemMock2));
671
672
        $cacheItemMock2
673
            ->expects($this->once())
674
            ->method('get')
675
            ->will($this->returnValue(new UrlAlias(array('id' => 55))));
676
677
        $cacheItemMock2
678
            ->expects($this->once())
679
            ->method('isMiss')
680
            ->will($this->returnValue(false));
681
682
        $cacheItemMock2
683
            ->expects($this->never())
684
            ->method('set');
685
686
        $handler = $this->persistenceCacheHandler->urlAliasHandler();
687
        $handler->lookup('/url');
688
    }
689
690
    /**
691
     * @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::loadUrlAlias
692
     */
693 View Code Duplication
    public function testLoadUrlAliasIsMiss()
694
    {
695
        $this->loggerMock->expects($this->once())->method('logCall');
696
697
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
698
        $this->cacheMock
699
            ->expects($this->once())
700
            ->method('getItem')
701
            ->with('urlAlias', 55)
702
            ->will($this->returnValue($cacheItemMock));
703
704
        $cacheItemMock
705
            ->expects($this->once())
706
            ->method('get')
707
            ->will($this->returnValue(null));
708
709
        $cacheItemMock
710
            ->expects($this->once())
711
            ->method('isMiss')
712
            ->will($this->returnValue(true));
713
714
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias\\Handler');
715
        $this->persistenceHandlerMock
716
            ->expects($this->once())
717
            ->method('urlAliasHandler')
718
            ->will($this->returnValue($innerHandler));
719
720
        $innerHandler
721
            ->expects($this->once())
722
            ->method('loadUrlAlias')
723
            ->with(55)
724
            ->will($this->returnValue(new UrlAlias(array('id' => 55))));
725
726
        $cacheItemMock
727
            ->expects($this->once())
728
            ->method('set')
729
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias'));
730
731
        $handler = $this->persistenceCacheHandler->urlAliasHandler();
732
        $handler->loadUrlAlias(55);
733
    }
734
735
    /**
736
     * @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::loadUrlAlias
737
     */
738 View Code Duplication
    public function testLoadUrlAliasHasCache()
739
    {
740
        $this->loggerMock->expects($this->never())->method('logCall');
741
742
        $this->persistenceHandlerMock
743
            ->expects($this->never())
744
            ->method($this->anything());
745
746
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
747
        $this->cacheMock
748
            ->expects($this->once())
749
            ->method('getItem')
750
            ->with('urlAlias', 55)
751
            ->will($this->returnValue($cacheItemMock));
752
753
        $cacheItemMock
754
            ->expects($this->once())
755
            ->method('get')
756
            ->will($this->returnValue(new UrlAlias(array('id' => 55))));
757
758
        $cacheItemMock
759
            ->expects($this->once())
760
            ->method('isMiss')
761
            ->will($this->returnValue(false));
762
763
        $cacheItemMock
764
            ->expects($this->never())
765
            ->method('set');
766
767
        $handler = $this->persistenceCacheHandler->urlAliasHandler();
768
        $handler->loadUrlAlias(55);
769
    }
770
771
    /**
772
     * @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::locationMoved
773
     */
774 View Code Duplication
    public function testLocationMoved()
775
    {
776
        $this->loggerMock->expects($this->once())->method('logCall');
777
778
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias\\Handler');
779
        $this->persistenceHandlerMock
780
            ->expects($this->once())
781
            ->method('urlAliasHandler')
782
            ->will($this->returnValue($innerHandler));
783
784
        $innerHandler
785
            ->expects($this->once())
786
            ->method('locationMoved')
787
            ->with(44, 2, 45);
788
789
        $this->cacheMock
790
            ->expects($this->once())
791
            ->method('clear')
792
            ->with('urlAlias')
793
            ->will($this->returnValue(null));
794
795
        $handler = $this->persistenceCacheHandler->urlAliasHandler();
796
        $handler->locationMoved(44, 2, 45);
797
    }
798
799
    /**
800
     * @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::locationDeleted
801
     */
802
    public function testLocationDeletedWithoutCachedLocation()
803
    {
804
        $locationNotCached = $this->getMock('Stash\Interfaces\ItemInterface');
805
        $locationNotCached
806
            ->expects($this->once())
807
            ->method('isMiss')
808
            ->willReturn(true);
809
810
        $this->prepareDeleteMocks($locationNotCached);
811
812
        $this->cacheMock
813
            ->expects($this->once())
814
            ->method('clear')
815
            ->with('urlAlias');
816
817
        $handler = $this->persistenceCacheHandler->urlAliasHandler();
818
        $handler->locationDeleted(44);
819
    }
820
821
    /**
822
     * @covers eZ\Publish\Core\Persistence\Cache\UrlAliasHandler::locationDeleted
823
     */
824
    public function testLocationDeletedWithCachedLocation()
825
    {
826
        $locationCacheItem = $this->getMock('Stash\Interfaces\ItemInterface');
827
        $locationCacheItem
828
            ->expects($this->once())
829
            ->method('isMiss')
830
            ->willReturn(false);
831
        $locationCacheItem
832
            ->expects($this->once())
833
            ->method('get')
834
            ->willReturn(['44'])
835
        ;
836
837
        $this->prepareDeleteMocks($locationCacheItem);
838
839
        $this->cacheMock
840
            ->expects($this->at(1))
841
            ->method('clear')
842
            ->with('urlAlias', 44);
843
        $this->cacheMock
844
            ->expects($this->at(2))
845
            ->method('clear')
846
            ->with('urlAlias', 'url');
847
848
        $handler = $this->persistenceCacheHandler->urlAliasHandler();
849
        $handler->locationDeleted(44);
850
    }
851
852
    /**
853
     * @param $locationCacheMissed
854
     */
855 View Code Duplication
    protected function prepareDeleteMocks($locationCacheMissed)
856
    {
857
        $this->loggerMock->expects($this->once())->method('logCall');
858
859
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\UrlAlias\\Handler');
860
        $this->persistenceHandlerMock
861
            ->expects($this->once())
862
            ->method('urlAliasHandler')
863
            ->will($this->returnValue($innerHandler));
864
865
        $innerHandler->expects($this->once())->method('locationDeleted')->with(44);
866
867
        $this->cacheMock
868
            ->expects($this->once())
869
            ->method('getItem')
870
            ->willReturn($locationCacheMissed);
871
    }
872
}
873