Completed
Push — test-EZP-26707-issearchable-fu... ( 965a07...6812c2 )
by
unknown
33:45 queued 07:39
created

UrlAliasHandlerTest::testLoadUrlAliasIsMiss()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 32

Duplication

Lines 41
Ratio 100 %

Importance

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