Completed
Push — master ( 28c8cd...7e44c6 )
by André
18:53
created

LocationHandlerTest::getSPILocationHandlerMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
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
namespace eZ\Publish\Core\Persistence\Cache\Tests;
10
11
use eZ\Publish\API\Repository\Values\Content\Location as APILocation;
12
use eZ\Publish\Core\Persistence\Cache\LocationHandler;
13
use eZ\Publish\SPI\Persistence\Content\Location;
14
use eZ\Publish\SPI\Persistence\Content\Location\CreateStruct;
15
use eZ\Publish\SPI\Persistence\Content\Location\UpdateStruct;
16
use eZ\Publish\SPI\Persistence\Content\Location\Handler as SPILocationHandler;
17
use Stash\Interfaces\ItemInterface;
18
19
/**
20
 * Test case for Persistence\Cache\LocationHandler.
21
 */
22
class LocationHandlerTest extends HandlerTest
23
{
24
    protected function getCacheItemMock()
25
    {
26
        return $this->createMock(ItemInterface::class);
27
    }
28
29
    protected function getSPILocationHandlerMock()
30
    {
31
        return $this->createMock(SPILocationHandler::class);
32
    }
33
34
    /**
35
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::load
36
     */
37 View Code Duplication
    public function testLoadCacheIsMiss()
38
    {
39
        $this->loggerMock->expects($this->once())->method('logCall');
40
        $cacheItemMock = $this->getCacheItemMock();
41
        $this->cacheMock
42
            ->expects($this->once())
43
            ->method('getItem')
44
            ->with('location', 33)
45
            ->will($this->returnValue($cacheItemMock));
46
47
        $cacheItemMock
48
            ->expects($this->once())
49
            ->method('get')
50
            ->will($this->returnValue(null));
51
52
        $cacheItemMock
53
            ->expects($this->once())
54
            ->method('isMiss')
55
            ->will($this->returnValue(true));
56
57
        $innerHandlerMock = $this->getSPILocationHandlerMock();
58
        $this->persistenceHandlerMock
59
            ->expects($this->once())
60
            ->method('locationHandler')
61
            ->will($this->returnValue($innerHandlerMock));
62
63
        $innerHandlerMock
64
            ->expects($this->once())
65
            ->method('load')
66
            ->with(33)
67
            ->will($this->returnValue(new Location(array('id' => 33))));
68
69
        $cacheItemMock
70
            ->expects($this->once())
71
            ->method('set')
72
            ->with($this->isInstanceOf(Location::class))
73
            ->will($this->returnValue($cacheItemMock));
74
75
        $cacheItemMock
76
            ->expects($this->once())
77
            ->method('save')
78
            ->with();
79
80
        $handler = $this->persistenceCacheHandler->locationHandler();
81
        $handler->load(33);
82
    }
83
84
    /**
85
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::load
86
     */
87 View Code Duplication
    public function testLoadHasCache()
88
    {
89
        $this->loggerMock->expects($this->never())->method($this->anything());
90
        $cacheItemMock = $this->getCacheItemMock();
91
        $this->cacheMock
92
            ->expects($this->once())
93
            ->method('getItem')
94
            ->with('location', 33)
95
            ->will($this->returnValue($cacheItemMock));
96
97
        $cacheItemMock
98
            ->expects($this->once())
99
            ->method('get')
100
            ->will($this->returnValue(new Location(array('id' => 33))));
101
102
        $cacheItemMock
103
            ->expects($this->once())
104
            ->method('isMiss')
105
            ->will($this->returnValue(false));
106
107
        $this->persistenceHandlerMock
108
            ->expects($this->never())
109
            ->method('locationHandler');
110
111
        $cacheItemMock
112
            ->expects($this->never())
113
            ->method('set');
114
115
        $handler = $this->persistenceCacheHandler->locationHandler();
116
        $handler->load(33);
117
    }
118
119
    /**
120
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::loadLocationsByContent
121
     */
122
    public function testLoadLocationsByContentIsMiss()
123
    {
124
        $this->loggerMock->expects($this->once())->method('logCall');
125
        $cacheItemMock = $this->getCacheItemMock();
126
        $this->cacheMock
127
            ->expects($this->once())
128
            ->method('getItem')
129
            ->with('content', 'locations', 44)
130
            ->will($this->returnValue($cacheItemMock));
131
132
        $cacheItemMock
133
            ->expects($this->once())
134
            ->method('get')
135
            ->will($this->returnValue(null));
136
137
        $cacheItemMock
138
            ->expects($this->once())
139
            ->method('isMiss')
140
            ->will($this->returnValue(true));
141
142
        $innerHandlerMock = $this->getSPILocationHandlerMock();
143
        $this->persistenceHandlerMock
144
            ->expects($this->once())
145
            ->method('locationHandler')
146
            ->will($this->returnValue($innerHandlerMock));
147
148
        $innerHandlerMock
149
            ->expects($this->once())
150
            ->method('loadLocationsByContent')
151
            ->with(44)
152
            ->will($this->returnValue(array(new Location(array('id' => 33)))));
153
154
        $cacheItemMock
155
            ->expects($this->once())
156
            ->method('set')
157
            ->with(array(33))
158
            ->will($this->returnValue($cacheItemMock));
159
160
        $cacheItemMock
161
            ->expects($this->once())
162
            ->method('save')
163
            ->with();
164
165
        $handler = $this->persistenceCacheHandler->locationHandler();
166
        $handler->loadLocationsByContent(44);
167
    }
168
169
    /**
170
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::loadLocationsByContent
171
     */
172 View Code Duplication
    public function testLoadLocationsByContentHasCache()
173
    {
174
        $this->loggerMock->expects($this->never())->method($this->anything());
175
176
        $this->persistenceHandlerMock
177
            ->expects($this->never())
178
            ->method($this->anything());
179
180
        $cacheItemMock = $this->getCacheItemMock();
181
        $this->cacheMock
182
            ->expects($this->at(0))
183
            ->method('getItem')
184
            ->with('content', 'locations', 44)
185
            ->will($this->returnValue($cacheItemMock));
186
187
        $cacheItemMock
188
            ->expects($this->once())
189
            ->method('get')
190
            ->will($this->returnValue(array(33)));
191
192
        $cacheItemMock
193
            ->expects($this->once())
194
            ->method('isMiss')
195
            ->will($this->returnValue(false));
196
197
        $cacheItemMock
198
            ->expects($this->never())
199
            ->method('set');
200
201
        // inline call to load()
202
        $cacheItemMock2 = $this->getCacheItemMock();
203
        $this->cacheMock
204
            ->expects($this->at(1))
205
            ->method('getItem')
206
            ->with('location', 33)
207
            ->will($this->returnValue($cacheItemMock2));
208
209
        $cacheItemMock2
210
            ->expects($this->once())
211
            ->method('get')
212
            ->will($this->returnValue(new Location(array('id' => 33))));
213
214
        $cacheItemMock2
215
            ->expects($this->once())
216
            ->method('isMiss')
217
            ->will($this->returnValue(false));
218
219
        $cacheItemMock2
220
            ->expects($this->never())
221
            ->method('set');
222
223
        $handler = $this->persistenceCacheHandler->locationHandler();
224
        $handler->loadLocationsByContent(44);
225
    }
226
227
    /**
228
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::loadParentLocationsForDraftContent
229
     */
230 View Code Duplication
    public function testLoadParentLocationsForDraftContentIsMiss()
231
    {
232
        $this->loggerMock->expects($this->once())->method('logCall');
233
        $cacheItemMock = $this->getCacheItemMock();
234
        $this->cacheMock
235
            ->expects($this->once())
236
            ->method('getItem')
237
            ->with('content', 'locations', '44', 'parentLocationsForDraftContent')
238
            ->will($this->returnValue($cacheItemMock));
239
240
        $cacheItemMock
241
            ->expects($this->once())
242
            ->method('get')
243
            ->will($this->returnValue(null));
244
245
        $cacheItemMock
246
            ->expects($this->once())
247
            ->method('isMiss')
248
            ->will($this->returnValue(true));
249
250
        $innerHandlerMock = $this->getSPILocationHandlerMock();
251
        $this->persistenceHandlerMock
252
            ->expects($this->once())
253
            ->method('locationHandler')
254
            ->will($this->returnValue($innerHandlerMock));
255
256
        $innerHandlerMock
257
            ->expects($this->once())
258
            ->method('loadParentLocationsForDraftContent')
259
            ->with(44)
260
            ->will($this->returnValue(array(new Location(array('id' => 33)))));
261
262
        $cacheItemMock
263
            ->expects($this->once())
264
            ->method('set')
265
            ->with(array(33))
266
            ->will($this->returnValue($cacheItemMock));
267
268
        $cacheItemMock
269
            ->expects($this->once())
270
            ->method('save')
271
            ->with();
272
273
        $handler = $this->persistenceCacheHandler->locationHandler();
274
        $handler->loadParentLocationsForDraftContent(44);
275
    }
276
277
    /**
278
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::loadParentLocationsForDraftContent
279
     */
280 View Code Duplication
    public function testLoadParentLocationsForDraftContentHasCache()
281
    {
282
        $this->loggerMock->expects($this->never())->method($this->anything());
283
284
        $this->persistenceHandlerMock
285
            ->expects($this->never())
286
            ->method($this->anything());
287
288
        $cacheItemMock = $this->getCacheItemMock();
289
        $this->cacheMock
290
            ->expects($this->at(0))
291
            ->method('getItem')
292
            ->with('content', 'locations', '44', 'parentLocationsForDraftContent')
293
            ->will($this->returnValue($cacheItemMock));
294
295
        $cacheItemMock
296
            ->expects($this->once())
297
            ->method('get')
298
            ->will($this->returnValue(array(33)));
299
300
        $cacheItemMock
301
            ->expects($this->once())
302
            ->method('isMiss')
303
            ->will($this->returnValue(false));
304
305
        $cacheItemMock
306
            ->expects($this->never())
307
            ->method('set');
308
309
        // inline call to load()
310
        $cacheItemMock2 = $this->getCacheItemMock();
311
        $this->cacheMock
312
            ->expects($this->at(1))
313
            ->method('getItem')
314
            ->with('location', 33)
315
            ->will($this->returnValue($cacheItemMock2));
316
317
        $cacheItemMock2
318
            ->expects($this->once())
319
            ->method('get')
320
            ->will($this->returnValue(new Location(array('id' => 33))));
321
322
        $cacheItemMock2
323
            ->expects($this->once())
324
            ->method('isMiss')
325
            ->will($this->returnValue(false));
326
327
        $cacheItemMock2
328
            ->expects($this->never())
329
            ->method('set');
330
331
        $handler = $this->persistenceCacheHandler->locationHandler();
332
        $handler->loadParentLocationsForDraftContent(44);
333
    }
334
335
    /**
336
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::loadLocationsByContent
337
     */
338 View Code Duplication
    public function testLoadLocationsByContentWithRootIsMiss()
339
    {
340
        $this->loggerMock->expects($this->once())->method('logCall');
341
        $cacheItemMock = $this->getCacheItemMock();
342
        $this->cacheMock
343
            ->expects($this->once())
344
            ->method('getItem')
345
            ->with('content', 'locations', '44', 'root', '2')
346
            ->will($this->returnValue($cacheItemMock));
347
348
        $cacheItemMock
349
            ->expects($this->once())
350
            ->method('get')
351
            ->will($this->returnValue(null));
352
353
        $cacheItemMock
354
            ->expects($this->once())
355
            ->method('isMiss')
356
            ->will($this->returnValue(true));
357
358
        $innerHandlerMock = $this->getSPILocationHandlerMock();
359
        $this->persistenceHandlerMock
360
            ->expects($this->once())
361
            ->method('locationHandler')
362
            ->will($this->returnValue($innerHandlerMock));
363
364
        $innerHandlerMock
365
            ->expects($this->once())
366
            ->method('loadLocationsByContent')
367
            ->with(44, 2)
368
            ->will($this->returnValue(array(new Location(array('id' => 33)))));
369
370
        $cacheItemMock
371
            ->expects($this->once())
372
            ->method('set')
373
            ->with(array(33))
374
            ->will($this->returnValue($cacheItemMock));
375
376
        $cacheItemMock
377
            ->expects($this->once())
378
            ->method('save')
379
            ->with();
380
381
        $handler = $this->persistenceCacheHandler->locationHandler();
382
        $handler->loadLocationsByContent(44, 2);
383
    }
384
385
    /**
386
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::loadLocationsByContent
387
     */
388 View Code Duplication
    public function testLoadLocationsByContentWithRootHasCache()
389
    {
390
        $this->loggerMock->expects($this->never())->method($this->anything());
391
392
        $this->persistenceHandlerMock
393
            ->expects($this->never())
394
            ->method($this->anything());
395
396
        $cacheItemMock = $this->getCacheItemMock();
397
        $this->cacheMock
398
            ->expects($this->at(0))
399
            ->method('getItem')
400
            ->with('content', 'locations', '44', 'root', '2')
401
            ->will($this->returnValue($cacheItemMock));
402
403
        $cacheItemMock
404
            ->expects($this->once())
405
            ->method('get')
406
            ->will($this->returnValue(array(33)));
407
408
        $cacheItemMock
409
            ->expects($this->once())
410
            ->method('isMiss')
411
            ->will($this->returnValue(false));
412
413
        $cacheItemMock
414
            ->expects($this->never())
415
            ->method('set');
416
417
        // inline call to load()
418
        $cacheItemMock2 = $this->getCacheItemMock();
419
        $this->cacheMock
420
            ->expects($this->at(1))
421
            ->method('getItem')
422
            ->with('location', 33)
423
            ->will($this->returnValue($cacheItemMock2));
424
425
        $cacheItemMock2
426
            ->expects($this->once())
427
            ->method('get')
428
            ->will($this->returnValue(new Location(array('id' => 33))));
429
430
        $cacheItemMock2
431
            ->expects($this->once())
432
            ->method('isMiss')
433
            ->will($this->returnValue(false));
434
435
        $cacheItemMock2
436
            ->expects($this->never())
437
            ->method('set');
438
439
        $handler = $this->persistenceCacheHandler->locationHandler();
440
        $handler->loadLocationsByContent(44, 2);
441
    }
442
443
    /**
444
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::loadByRemoteId
445
     */
446 View Code Duplication
    public function testLoadByRemoteId()
447
    {
448
        $this->loggerMock->expects($this->once())->method('logCall');
449
        $this->cacheMock
450
            ->expects($this->never())
451
            ->method($this->anything());
452
453
        $innerHandler = $this->getSPILocationHandlerMock();
454
        $this->persistenceHandlerMock
455
            ->expects($this->once())
456
            ->method('locationHandler')
457
            ->will($this->returnValue($innerHandler));
458
459
        $innerHandler
460
            ->expects($this->once())
461
            ->method('loadByRemoteId')
462
            ->with('sve45gdy4e')
463
            ->will($this->returnValue(new Location(array('id' => 33))));
464
465
        $handler = $this->persistenceCacheHandler->locationHandler();
466
        $handler->loadByRemoteId('sve45gdy4e');
467
    }
468
469
    /**
470
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::copySubtree
471
     */
472 View Code Duplication
    public function testCopySubtree()
473
    {
474
        $this->loggerMock->expects($this->once())->method('logCall');
475
        $this->cacheMock
476
            ->expects($this->never())
477
            ->method($this->anything());
478
479
        $innerHandler = $this->getSPILocationHandlerMock();
480
        $this->persistenceHandlerMock
481
            ->expects($this->once())
482
            ->method('locationHandler')
483
            ->will($this->returnValue($innerHandler));
484
485
        $innerHandler
486
            ->expects($this->once())
487
            ->method('copySubtree')
488
            ->with(55, 66)
489
            ->will($this->returnValue(null));
490
491
        $handler = $this->persistenceCacheHandler->locationHandler();
492
        $handler->copySubtree(55, 66);
493
    }
494
495
    /**
496
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::move
497
     */
498 View Code Duplication
    public function testMove()
499
    {
500
        $this->loggerMock->expects($this->once())->method('logCall');
501
        $this->cacheMock
502
            ->expects($this->at(0))
503
            ->method('clear')
504
            ->with('location')
505
            ->will($this->returnValue(true));
506
507
        $this->cacheMock
508
            ->expects($this->at(1))
509
            ->method('clear')
510
            ->with('user', 'role', 'assignments', 'byGroup')
511
            ->will($this->returnValue(true));
512
513
        $this->cacheMock
514
            ->expects($this->at(2))
515
            ->method('clear')
516
            ->with('content')
517
            ->will($this->returnValue(true));
518
519
        $innerHandlerMock = $this->getSPILocationHandlerMock();
520
        $this->persistenceHandlerMock
521
            ->expects($this->once())
522
            ->method('locationHandler')
523
            ->will($this->returnValue($innerHandlerMock));
524
525
        $innerHandlerMock
526
            ->expects($this->once())
527
            ->method('move')
528
            ->with(33, 66)
529
            ->will($this->returnValue(true));
530
531
        $handler = $this->persistenceCacheHandler->locationHandler();
532
        $handler->move(33, 66);
533
    }
534
535
    /**
536
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::markSubtreeModified
537
     */
538 View Code Duplication
    public function testMarkSubtreeModified()
539
    {
540
        $this->loggerMock->expects($this->once())->method('logCall');
541
        $this->cacheMock
542
            ->expects($this->never())
543
            ->method($this->anything());
544
545
        $innerHandler = $this->getSPILocationHandlerMock();
546
        $this->persistenceHandlerMock
547
            ->expects($this->once())
548
            ->method('locationHandler')
549
            ->will($this->returnValue($innerHandler));
550
551
        $innerHandler
552
            ->expects($this->once())
553
            ->method('markSubtreeModified')
554
            ->with(55)
555
            ->will($this->returnValue(null));
556
557
        $handler = $this->persistenceCacheHandler->locationHandler();
558
        $handler->markSubtreeModified(55);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\SPI\Persisten...::markSubtreeModified() has been deprecated with message: As of 6.8, not been used by repository since 5.x.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
559
    }
560
561
    /**
562
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::hide
563
     */
564 View Code Duplication
    public function testHide()
565
    {
566
        $this->loggerMock->expects($this->once())->method('logCall');
567
        $this->cacheMock
568
            ->expects($this->once())
569
            ->method('clear')
570
            ->with('location')
571
            ->will($this->returnValue(true));
572
573
        $innerHandlerMock = $this->getSPILocationHandlerMock();
574
        $this->persistenceHandlerMock
575
            ->expects($this->once())
576
            ->method('locationHandler')
577
            ->will($this->returnValue($innerHandlerMock));
578
579
        $innerHandlerMock
580
            ->expects($this->once())
581
            ->method('hide')
582
            ->with(33)
583
            ->will($this->returnValue(true));
584
585
        $handler = $this->persistenceCacheHandler->locationHandler();
586
        $handler->hide(33);
587
    }
588
589
    /**
590
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::unhide
591
     */
592 View Code Duplication
    public function testUnhide()
593
    {
594
        $this->loggerMock->expects($this->once())->method('logCall');
595
        $this->cacheMock
596
            ->expects($this->once())
597
            ->method('clear')
598
            ->with('location')
599
            ->will($this->returnValue(true));
600
601
        $innerHandlerMock = $this->getSPILocationHandlerMock();
602
        $this->persistenceHandlerMock
603
            ->expects($this->once())
604
            ->method('locationHandler')
605
            ->will($this->returnValue($innerHandlerMock));
606
607
        $innerHandlerMock
608
            ->expects($this->once())
609
            ->method('unhide')
610
            ->with(33)
611
            ->will($this->returnValue(true));
612
613
        $handler = $this->persistenceCacheHandler->locationHandler();
614
        $handler->unhide(33);
615
    }
616
617
    /**
618
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::swap
619
     */
620
    public function testSwap()
621
    {
622
        $this->loggerMock->expects($this->once())->method('logCall');
623
        $this->cacheMock
624
            ->expects($this->at(0))
625
            ->method('clear')
626
            ->with('location', 33)
627
            ->will($this->returnValue(true));
628
629
        $this->cacheMock
630
            ->expects($this->at(1))
631
            ->method('clear')
632
            ->with('location', 66)
633
            ->will($this->returnValue(true));
634
635
        $this->cacheMock
636
            ->expects($this->at(2))
637
            ->method('clear')
638
            ->with('location', 'subtree')
639
            ->will($this->returnValue(true));
640
641
        $this->cacheMock
642
            ->expects($this->at(3))
643
            ->method('clear')
644
            ->with('content', 'locations')
645
            ->will($this->returnValue(true));
646
647
        $this->cacheMock
648
            ->expects($this->at(4))
649
            ->method('clear')
650
            ->with('user', 'role', 'assignments', 'byGroup')
651
            ->will($this->returnValue(true));
652
653
        $this->cacheMock
654
            ->expects($this->at(5))
655
            ->method('clear')
656
            ->with('content', $this->isType('integer'))
657
            ->will($this->returnValue(true));
658
659
        $this->cacheMock
660
            ->expects($this->at(6))
661
            ->method('clear')
662
            ->with('content', $this->isType('integer'))
663
            ->will($this->returnValue(true));
664
665
        $this->cacheMock
666
            ->expects($this->at(7))
667
            ->method('clear')
668
            ->with('content', 'info', $this->isType('integer'))
669
            ->will($this->returnValue(true));
670
671
        $this->cacheMock
672
            ->expects($this->at(8))
673
            ->method('clear')
674
            ->with('content', 'info', $this->isType('integer'))
675
            ->will($this->returnValue(true));
676
677
        $innerHandlerMock = $this->getSPILocationHandlerMock();
678
        $this->persistenceHandlerMock
679
            ->expects($this->once())
680
            ->method('locationHandler')
681
            ->will($this->returnValue($innerHandlerMock));
682
683
        $innerHandlerMock
684
            ->expects($this->once())
685
            ->method('swap')
686
            ->with(33, 66)
687
            ->will($this->returnValue(true));
688
689
        $locationMock = $this->createMock(APILocation::class);
690
        $locationMock
691
            ->expects($this->any())
692
            ->method('__get')
693
            ->with('contentId')
694
            ->will($this->returnValue(42));
695
696
        /** @var \eZ\Publish\SPI\Persistence\Content\Location\Handler|\PHPUnit_Framework_MockObject_MockObject $handler */
697
        $handler = $this
698
            ->getMockBuilder(LocationHandler::class)
699
            ->setMethods(['load'])
700
            ->setConstructorArgs(
701
                [
702
                    $this->cacheMock,
703
                    $this->persistenceHandlerMock,
704
                    $this->loggerMock,
705
                ]
706
            )
707
            ->getMock();
708
709
        $handler
710
            ->expects($this->any())
711
            ->method('load')
712
            ->will($this->returnValue($locationMock));
713
714
        $handler->swap(33, 66);
715
    }
716
717
    /**
718
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::update
719
     */
720
    public function testUpdate()
721
    {
722
        $this->loggerMock->expects($this->once())->method('logCall');
723
        $cacheItemMock = $this->getCacheItemMock();
724
        $this->cacheMock
725
            ->expects($this->at(0))
726
            ->method('clear')
727
            ->with('location', 33);
728
729
        $this->cacheMock
730
            ->expects($this->at(1))
731
            ->method('clear')
732
            ->with('location', 'subtree');
733
734
        $innerHandler = $this->getSPILocationHandlerMock();
735
        $this->persistenceHandlerMock
736
            ->expects($this->once())
737
            ->method('locationHandler')
738
            ->will($this->returnValue($innerHandler));
739
740
        $innerHandler
741
            ->expects($this->once())
742
            ->method('update')
743
            ->with($this->isInstanceOf(UpdateStruct::class), 33)
744
            ->will($this->returnValue(new Location(array('id' => 33))));
745
746
        $cacheItemMock
747
            ->expects($this->never())
748
            ->method('get');
749
750
        $handler = $this->persistenceCacheHandler->locationHandler();
751
        $handler->update(new UpdateStruct(), 33);
752
    }
753
754
    /**
755
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::create
756
     */
757
    public function testCreate()
758
    {
759
        $this->loggerMock->expects($this->once())->method('logCall');
760
        $cacheItemMock = $this->getCacheItemMock();
761
        $this->cacheMock
762
            ->expects($this->once())
763
            ->method('getItem')
764
            ->with('location', 33)
765
            ->will($this->returnValue($cacheItemMock));
766
767
        $innerHandlerMock = $this->getSPILocationHandlerMock();
768
        $this->persistenceHandlerMock
769
            ->expects($this->once())
770
            ->method('locationHandler')
771
            ->will($this->returnValue($innerHandlerMock));
772
773
        $innerHandlerMock
774
            ->expects($this->once())
775
            ->method('create')
776
            ->with($this->isInstanceOf(CreateStruct::class))
777
            ->will($this->returnValue(new Location(array('id' => 33, 'contentId' => 2))));
778
779
        $cacheItemMock
780
            ->expects($this->once())
781
            ->method('set')
782
            ->with($this->isInstanceOf(Location::class))
783
            ->will($this->returnValue($cacheItemMock));
784
785
        $cacheItemMock
786
            ->expects($this->once())
787
            ->method('save')
788
            ->with();
789
790
        $cacheItemMock
791
            ->expects($this->never())
792
            ->method('get');
793
794
        $this->cacheMock
795
            ->expects($this->at(1))
796
            ->method('clear')
797
            ->with('location', 'subtree')
798
            ->will($this->returnValue(true));
799
800
        $this->cacheMock
801
            ->expects($this->at(2))
802
            ->method('clear')
803
            ->with('content', 'locations', 2)
804
            ->will($this->returnValue(true));
805
806
        $this->cacheMock
807
            ->expects($this->at(3))
808
            ->method('clear')
809
            ->with('content', 2)
810
            ->will($this->returnValue(true));
811
812
        $this->cacheMock
813
            ->expects($this->at(4))
814
            ->method('clear')
815
            ->with('content', 'info', 2)
816
            ->will($this->returnValue(true));
817
818
        $this->cacheMock
819
            ->expects($this->at(5))
820
            ->method('clear')
821
            ->with('user', 'role', 'assignments', 'byGroup', 2)
822
            ->will($this->returnValue(true));
823
824
        $this->cacheMock
825
            ->expects($this->at(6))
826
            ->method('clear')
827
            ->with('user', 'role', 'assignments', 'byGroup', 'inherited', 2)
828
            ->will($this->returnValue(true));
829
830
        $handler = $this->persistenceCacheHandler->locationHandler();
831
        $handler->create(new CreateStruct());
832
    }
833
834
    /**
835
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::removeSubtree
836
     */
837 View Code Duplication
    public function testRemoveSubtree()
838
    {
839
        $this->loggerMock->expects($this->once())->method('logCall');
840
        $this->cacheMock
841
            ->expects($this->at(0))
842
            ->method('clear')
843
            ->with('location')
844
            ->will($this->returnValue(true));
845
846
        $this->cacheMock
847
            ->expects($this->at(1))
848
            ->method('clear')
849
            ->with('content')
850
            ->will($this->returnValue(true));
851
852
        $this->cacheMock
853
            ->expects($this->at(2))
854
            ->method('clear')
855
            ->with('user', 'role', 'assignments', 'byGroup')
856
            ->will($this->returnValue(true));
857
858
        $innerHandlerMock = $this->getSPILocationHandlerMock();
859
        $this->persistenceHandlerMock
860
            ->expects($this->once())
861
            ->method('locationHandler')
862
            ->will($this->returnValue($innerHandlerMock));
863
864
        $innerHandlerMock
865
            ->expects($this->once())
866
            ->method('removeSubtree')
867
            ->with(33)
868
            ->will($this->returnValue(true));
869
870
        $handler = $this->persistenceCacheHandler->locationHandler();
871
        $handler->removeSubtree(33);
872
    }
873
874
    /**
875
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::setSectionForSubtree
876
     */
877 View Code Duplication
    public function testSetSectionForSubtree()
878
    {
879
        $this->loggerMock->expects($this->once())->method('logCall');
880
        $this->cacheMock
881
            ->expects($this->once())
882
            ->method('clear')
883
            ->with('content');
884
885
        $innerHandler = $this->getSPILocationHandlerMock();
886
        $this->persistenceHandlerMock
887
            ->expects($this->once())
888
            ->method('locationHandler')
889
            ->will($this->returnValue($innerHandler));
890
891
        $innerHandler
892
            ->expects($this->once())
893
            ->method('setSectionForSubtree')
894
            ->with(33, 2)
895
            ->will($this->returnValue(null));
896
897
        $handler = $this->persistenceCacheHandler->locationHandler();
898
        $handler->setSectionForSubtree(33, 2);
899
    }
900
901
    /**
902
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::changeMainLocation
903
     */
904 View Code Duplication
    public function testChangeMainLocation()
905
    {
906
        $this->loggerMock->expects($this->once())->method('logCall');
907
908
        $this->cacheMock
909
            ->expects($this->at(0))
910
            ->method('clear')
911
            ->with('content', 30)
912
            ->will($this->returnValue(true));
913
914
        $this->cacheMock
915
            ->expects($this->at(1))
916
            ->method('clear')
917
            ->with('content', 'info', 30)
918
            ->will($this->returnValue(true));
919
920
        $innerHandlerMock = $this->getSPILocationHandlerMock();
921
        $this->persistenceHandlerMock
922
            ->expects($this->once())
923
            ->method('locationHandler')
924
            ->will($this->returnValue($innerHandlerMock));
925
926
        $innerHandlerMock
927
            ->expects($this->once())
928
            ->method('changeMainLocation')
929
            ->with(30, 33)
930
            ->will($this->returnValue(true));
931
932
        $handler = $this->persistenceCacheHandler->locationHandler();
933
        $handler->changeMainLocation(30, 33);
934
    }
935
}
936