Completed
Push — EZP-29539 ( 39231f...0cae71 )
by
unknown
24:29
created

testLoadLocationsByContentIsMiss()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 46
rs 9.1781
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\SPI\Persistence\Content\Location;
12
use eZ\Publish\SPI\Persistence\Content\Location\CreateStruct;
13
use eZ\Publish\SPI\Persistence\Content\Location\UpdateStruct;
14
15
/**
16
 * Test case for Persistence\Cache\LocationHandler.
17
 */
18
class LocationHandlerTest extends HandlerTest
19
{
20
    /**
21
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::load
22
     */
23 View Code Duplication
    public function testLoadCacheIsMiss()
24
    {
25
        $this->loggerMock->expects($this->once())->method('logCall');
26
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
27
        $this->cacheMock
28
            ->expects($this->once())
29
            ->method('getItem')
30
            ->with('location', 33)
31
            ->will($this->returnValue($cacheItemMock));
32
33
        $cacheItemMock
34
            ->expects($this->once())
35
            ->method('get')
36
            ->will($this->returnValue(null));
37
38
        $cacheItemMock
39
            ->expects($this->once())
40
            ->method('isMiss')
41
            ->will($this->returnValue(true));
42
43
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
44
        $this->persistenceHandlerMock
45
            ->expects($this->once())
46
            ->method('locationHandler')
47
            ->will($this->returnValue($innerHandlerMock));
48
49
        $innerHandlerMock
50
            ->expects($this->once())
51
            ->method('load')
52
            ->with(33)
53
            ->will($this->returnValue(new Location(array('id' => 33))));
54
55
        $cacheItemMock
56
            ->expects($this->once())
57
            ->method('set')
58
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Location'))
59
            ->will($this->returnValue($cacheItemMock));
60
61
        $cacheItemMock
62
            ->expects($this->once())
63
            ->method('save')
64
            ->with();
65
66
        $handler = $this->persistenceCacheHandler->locationHandler();
67
        $handler->load(33);
68
    }
69
70
    /**
71
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::load
72
     */
73 View Code Duplication
    public function testLoadHasCache()
74
    {
75
        $this->loggerMock->expects($this->never())->method($this->anything());
76
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
77
        $this->cacheMock
78
            ->expects($this->once())
79
            ->method('getItem')
80
            ->with('location', 33)
81
            ->will($this->returnValue($cacheItemMock));
82
83
        $cacheItemMock
84
            ->expects($this->once())
85
            ->method('get')
86
            ->will($this->returnValue(new Location(array('id' => 33))));
87
88
        $cacheItemMock
89
            ->expects($this->once())
90
            ->method('isMiss')
91
            ->will($this->returnValue(false));
92
93
        $this->persistenceHandlerMock
94
            ->expects($this->never())
95
            ->method('locationHandler');
96
97
        $cacheItemMock
98
            ->expects($this->never())
99
            ->method('set');
100
101
        $handler = $this->persistenceCacheHandler->locationHandler();
102
        $handler->load(33);
103
    }
104
105
    /**
106
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::loadLocationsByContent
107
     */
108
    public function testLoadLocationsByContentIsMiss()
109
    {
110
        $this->loggerMock->expects($this->once())->method('logCall');
111
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
112
        $this->cacheMock
113
            ->expects($this->once())
114
            ->method('getItem')
115
            ->with('content', 'locations', 44)
116
            ->will($this->returnValue($cacheItemMock));
117
118
        $cacheItemMock
119
            ->expects($this->once())
120
            ->method('get')
121
            ->will($this->returnValue(null));
122
123
        $cacheItemMock
124
            ->expects($this->once())
125
            ->method('isMiss')
126
            ->will($this->returnValue(true));
127
128
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
129
        $this->persistenceHandlerMock
130
            ->expects($this->once())
131
            ->method('locationHandler')
132
            ->will($this->returnValue($innerHandlerMock));
133
134
        $innerHandlerMock
135
            ->expects($this->once())
136
            ->method('loadLocationsByContent')
137
            ->with(44)
138
            ->will($this->returnValue(array(new Location(array('id' => 33)))));
139
140
        $cacheItemMock
141
            ->expects($this->once())
142
            ->method('set')
143
            ->with(array(33))
144
            ->will($this->returnValue($cacheItemMock));
145
146
        $cacheItemMock
147
            ->expects($this->once())
148
            ->method('save')
149
            ->with();
150
151
        $handler = $this->persistenceCacheHandler->locationHandler();
152
        $handler->loadLocationsByContent(44);
153
    }
154
155
    /**
156
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::loadLocationsByContent
157
     */
158 View Code Duplication
    public function testLoadLocationsByContentHasCache()
159
    {
160
        $this->loggerMock->expects($this->never())->method($this->anything());
161
162
        $this->persistenceHandlerMock
163
            ->expects($this->never())
164
            ->method($this->anything());
165
166
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
167
        $this->cacheMock
168
            ->expects($this->at(0))
169
            ->method('getItem')
170
            ->with('content', 'locations', 44)
171
            ->will($this->returnValue($cacheItemMock));
172
173
        $cacheItemMock
174
            ->expects($this->once())
175
            ->method('get')
176
            ->will($this->returnValue(array(33)));
177
178
        $cacheItemMock
179
            ->expects($this->once())
180
            ->method('isMiss')
181
            ->will($this->returnValue(false));
182
183
        $cacheItemMock
184
            ->expects($this->never())
185
            ->method('set');
186
187
        // inline call to load()
188
        $cacheItemMock2 = $this->getMock('Stash\Interfaces\ItemInterface');
189
        $this->cacheMock
190
            ->expects($this->at(1))
191
            ->method('getItem')
192
            ->with('location', 33)
193
            ->will($this->returnValue($cacheItemMock2));
194
195
        $cacheItemMock2
196
            ->expects($this->once())
197
            ->method('get')
198
            ->will($this->returnValue(new Location(array('id' => 33))));
199
200
        $cacheItemMock2
201
            ->expects($this->once())
202
            ->method('isMiss')
203
            ->will($this->returnValue(false));
204
205
        $cacheItemMock2
206
            ->expects($this->never())
207
            ->method('set');
208
209
        $handler = $this->persistenceCacheHandler->locationHandler();
210
        $handler->loadLocationsByContent(44);
211
    }
212
213
    /**
214
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::loadParentLocationsForDraftContent
215
     */
216 View Code Duplication
    public function testLoadParentLocationsForDraftContentIsMiss()
217
    {
218
        $this->loggerMock->expects($this->once())->method('logCall');
219
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
220
        $this->cacheMock
221
            ->expects($this->once())
222
            ->method('getItem')
223
            ->with('content', 'locations', '44', 'parentLocationsForDraftContent')
224
            ->will($this->returnValue($cacheItemMock));
225
226
        $cacheItemMock
227
            ->expects($this->once())
228
            ->method('get')
229
            ->will($this->returnValue(null));
230
231
        $cacheItemMock
232
            ->expects($this->once())
233
            ->method('isMiss')
234
            ->will($this->returnValue(true));
235
236
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
237
        $this->persistenceHandlerMock
238
            ->expects($this->once())
239
            ->method('locationHandler')
240
            ->will($this->returnValue($innerHandlerMock));
241
242
        $innerHandlerMock
243
            ->expects($this->once())
244
            ->method('loadParentLocationsForDraftContent')
245
            ->with(44)
246
            ->will($this->returnValue(array(new Location(array('id' => 33)))));
247
248
        $cacheItemMock
249
            ->expects($this->once())
250
            ->method('set')
251
            ->with(array(33))
252
            ->will($this->returnValue($cacheItemMock));
253
254
        $cacheItemMock
255
            ->expects($this->once())
256
            ->method('save')
257
            ->with();
258
259
        $handler = $this->persistenceCacheHandler->locationHandler();
260
        $handler->loadParentLocationsForDraftContent(44);
261
    }
262
263
    /**
264
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::loadParentLocationsForDraftContent
265
     */
266 View Code Duplication
    public function testLoadParentLocationsForDraftContentHasCache()
267
    {
268
        $this->loggerMock->expects($this->never())->method($this->anything());
269
270
        $this->persistenceHandlerMock
271
            ->expects($this->never())
272
            ->method($this->anything());
273
274
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
275
        $this->cacheMock
276
            ->expects($this->at(0))
277
            ->method('getItem')
278
            ->with('content', 'locations', '44', 'parentLocationsForDraftContent')
279
            ->will($this->returnValue($cacheItemMock));
280
281
        $cacheItemMock
282
            ->expects($this->once())
283
            ->method('get')
284
            ->will($this->returnValue(array(33)));
285
286
        $cacheItemMock
287
            ->expects($this->once())
288
            ->method('isMiss')
289
            ->will($this->returnValue(false));
290
291
        $cacheItemMock
292
            ->expects($this->never())
293
            ->method('set');
294
295
        // inline call to load()
296
        $cacheItemMock2 = $this->getMock('Stash\Interfaces\ItemInterface');
297
        $this->cacheMock
298
            ->expects($this->at(1))
299
            ->method('getItem')
300
            ->with('location', 33)
301
            ->will($this->returnValue($cacheItemMock2));
302
303
        $cacheItemMock2
304
            ->expects($this->once())
305
            ->method('get')
306
            ->will($this->returnValue(new Location(array('id' => 33))));
307
308
        $cacheItemMock2
309
            ->expects($this->once())
310
            ->method('isMiss')
311
            ->will($this->returnValue(false));
312
313
        $cacheItemMock2
314
            ->expects($this->never())
315
            ->method('set');
316
317
        $handler = $this->persistenceCacheHandler->locationHandler();
318
        $handler->loadParentLocationsForDraftContent(44);
319
    }
320
321
    /**
322
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::loadLocationsByContent
323
     */
324 View Code Duplication
    public function testLoadLocationsByContentWithRootIsMiss()
325
    {
326
        $this->loggerMock->expects($this->once())->method('logCall');
327
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
328
        $this->cacheMock
329
            ->expects($this->once())
330
            ->method('getItem')
331
            ->with('content', 'locations', '44', 'root', '2')
332
            ->will($this->returnValue($cacheItemMock));
333
334
        $cacheItemMock
335
            ->expects($this->once())
336
            ->method('get')
337
            ->will($this->returnValue(null));
338
339
        $cacheItemMock
340
            ->expects($this->once())
341
            ->method('isMiss')
342
            ->will($this->returnValue(true));
343
344
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
345
        $this->persistenceHandlerMock
346
            ->expects($this->once())
347
            ->method('locationHandler')
348
            ->will($this->returnValue($innerHandlerMock));
349
350
        $innerHandlerMock
351
            ->expects($this->once())
352
            ->method('loadLocationsByContent')
353
            ->with(44, 2)
354
            ->will($this->returnValue(array(new Location(array('id' => 33)))));
355
356
        $cacheItemMock
357
            ->expects($this->once())
358
            ->method('set')
359
            ->with(array(33))
360
            ->will($this->returnValue($cacheItemMock));
361
362
        $cacheItemMock
363
            ->expects($this->once())
364
            ->method('save')
365
            ->with();
366
367
        $handler = $this->persistenceCacheHandler->locationHandler();
368
        $handler->loadLocationsByContent(44, 2);
369
    }
370
371
    /**
372
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::loadLocationsByContent
373
     */
374 View Code Duplication
    public function testLoadLocationsByContentWithRootHasCache()
375
    {
376
        $this->loggerMock->expects($this->never())->method($this->anything());
377
378
        $this->persistenceHandlerMock
379
            ->expects($this->never())
380
            ->method($this->anything());
381
382
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
383
        $this->cacheMock
384
            ->expects($this->at(0))
385
            ->method('getItem')
386
            ->with('content', 'locations', '44', 'root', '2')
387
            ->will($this->returnValue($cacheItemMock));
388
389
        $cacheItemMock
390
            ->expects($this->once())
391
            ->method('get')
392
            ->will($this->returnValue(array(33)));
393
394
        $cacheItemMock
395
            ->expects($this->once())
396
            ->method('isMiss')
397
            ->will($this->returnValue(false));
398
399
        $cacheItemMock
400
            ->expects($this->never())
401
            ->method('set');
402
403
        // inline call to load()
404
        $cacheItemMock2 = $this->getMock('Stash\Interfaces\ItemInterface');
405
        $this->cacheMock
406
            ->expects($this->at(1))
407
            ->method('getItem')
408
            ->with('location', 33)
409
            ->will($this->returnValue($cacheItemMock2));
410
411
        $cacheItemMock2
412
            ->expects($this->once())
413
            ->method('get')
414
            ->will($this->returnValue(new Location(array('id' => 33))));
415
416
        $cacheItemMock2
417
            ->expects($this->once())
418
            ->method('isMiss')
419
            ->will($this->returnValue(false));
420
421
        $cacheItemMock2
422
            ->expects($this->never())
423
            ->method('set');
424
425
        $handler = $this->persistenceCacheHandler->locationHandler();
426
        $handler->loadLocationsByContent(44, 2);
427
    }
428
429
    /**
430
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::loadByRemoteId
431
     */
432
    public function testLoadByRemoteId()
433
    {
434
        $this->loggerMock->expects($this->once())->method('logCall');
435
        $this->cacheMock
436
            ->expects($this->never())
437
            ->method($this->anything());
438
439
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
440
        $this->persistenceHandlerMock
441
            ->expects($this->once())
442
            ->method('locationHandler')
443
            ->will($this->returnValue($innerHandler));
444
445
        $innerHandler
446
            ->expects($this->once())
447
            ->method('loadByRemoteId')
448
            ->with('sve45gdy4e')
449
            ->will($this->returnValue(new Location(array('id' => 33))));
450
451
        $handler = $this->persistenceCacheHandler->locationHandler();
452
        $handler->loadByRemoteId('sve45gdy4e');
453
    }
454
455
    /**
456
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::copySubtree
457
     */
458
    public function testCopySubtree()
459
    {
460
        $this->loggerMock->expects($this->once())->method('logCall');
461
        $this->cacheMock
462
            ->expects($this->never())
463
            ->method($this->anything());
464
465
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
466
        $this->persistenceHandlerMock
467
            ->expects($this->once())
468
            ->method('locationHandler')
469
            ->will($this->returnValue($innerHandler));
470
471
        $innerHandler
472
            ->expects($this->once())
473
            ->method('copySubtree')
474
            ->with(55, 66)
475
            ->will($this->returnValue(null));
476
477
        $handler = $this->persistenceCacheHandler->locationHandler();
478
        $handler->copySubtree(55, 66);
479
    }
480
481
    /**
482
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::move
483
     */
484 View Code Duplication
    public function testMove()
485
    {
486
        $this->loggerMock->expects($this->once())->method('logCall');
487
        $this->cacheMock
488
            ->expects($this->at(0))
489
            ->method('clear')
490
            ->with('location')
491
            ->will($this->returnValue(true));
492
493
        $this->cacheMock
494
            ->expects($this->at(1))
495
            ->method('clear')
496
            ->with('user', 'role', 'assignments', 'byGroup')
497
            ->will($this->returnValue(true));
498
499
        $this->cacheMock
500
            ->expects($this->at(2))
501
            ->method('clear')
502
            ->with('content')
503
            ->will($this->returnValue(true));
504
505
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
506
        $this->persistenceHandlerMock
507
            ->expects($this->once())
508
            ->method('locationHandler')
509
            ->will($this->returnValue($innerHandlerMock));
510
511
        $innerHandlerMock
512
            ->expects($this->once())
513
            ->method('move')
514
            ->with(33, 66)
515
            ->will($this->returnValue(true));
516
517
        $handler = $this->persistenceCacheHandler->locationHandler();
518
        $handler->move(33, 66);
519
    }
520
521
    /**
522
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::markSubtreeModified
523
     */
524
    public function testMarkSubtreeModified()
525
    {
526
        $this->loggerMock->expects($this->once())->method('logCall');
527
        $this->cacheMock
528
            ->expects($this->never())
529
            ->method($this->anything());
530
531
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
532
        $this->persistenceHandlerMock
533
            ->expects($this->once())
534
            ->method('locationHandler')
535
            ->will($this->returnValue($innerHandler));
536
537
        $innerHandler
538
            ->expects($this->once())
539
            ->method('markSubtreeModified')
540
            ->with(55)
541
            ->will($this->returnValue(null));
542
543
        $handler = $this->persistenceCacheHandler->locationHandler();
544
        $handler->markSubtreeModified(55);
545
    }
546
547
    /**
548
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::hide
549
     */
550
    public function testHide()
551
    {
552
        $this->loggerMock->expects($this->once())->method('logCall');
553
        $this->cacheMock
554
            ->expects($this->once())
555
            ->method('clear')
556
            ->with('location')
557
            ->will($this->returnValue(true));
558
559
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
560
        $this->persistenceHandlerMock
561
            ->expects($this->once())
562
            ->method('locationHandler')
563
            ->will($this->returnValue($innerHandlerMock));
564
565
        $innerHandlerMock
566
            ->expects($this->once())
567
            ->method('hide')
568
            ->with(33)
569
            ->will($this->returnValue(true));
570
571
        $handler = $this->persistenceCacheHandler->locationHandler();
572
        $handler->hide(33);
573
    }
574
575
    /**
576
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::unhide
577
     */
578
    public function testUnhide()
579
    {
580
        $this->loggerMock->expects($this->once())->method('logCall');
581
        $this->cacheMock
582
            ->expects($this->once())
583
            ->method('clear')
584
            ->with('location')
585
            ->will($this->returnValue(true));
586
587
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
588
        $this->persistenceHandlerMock
589
            ->expects($this->once())
590
            ->method('locationHandler')
591
            ->will($this->returnValue($innerHandlerMock));
592
593
        $innerHandlerMock
594
            ->expects($this->once())
595
            ->method('unhide')
596
            ->with(33)
597
            ->will($this->returnValue(true));
598
599
        $handler = $this->persistenceCacheHandler->locationHandler();
600
        $handler->unhide(33);
601
    }
602
603
    /**
604
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::swap
605
     */
606
    public function testSwap()
607
    {
608
        $this->loggerMock->expects($this->once())->method('logCall');
609
        $this->cacheMock
610
            ->expects($this->at(0))
611
            ->method('clear')
612
            ->with('location', 33)
613
            ->will($this->returnValue(true));
614
615
        $this->cacheMock
616
            ->expects($this->at(1))
617
            ->method('clear')
618
            ->with('location', 66)
619
            ->will($this->returnValue(true));
620
621
        $this->cacheMock
622
            ->expects($this->at(2))
623
            ->method('clear')
624
            ->with('location', 'subtree')
625
            ->will($this->returnValue(true));
626
627
        $this->cacheMock
628
            ->expects($this->at(3))
629
            ->method('clear')
630
            ->with('content', 'locations')
631
            ->will($this->returnValue(true));
632
633
        $this->cacheMock
634
            ->expects($this->at(4))
635
            ->method('clear')
636
            ->with('user', 'role', 'assignments', 'byGroup')
637
            ->will($this->returnValue(true));
638
639
        $this->cacheMock
640
            ->expects($this->at(5))
641
            ->method('clear')
642
            ->with('content', $this->isType('integer'))
643
            ->will($this->returnValue(true));
644
645
        $this->cacheMock
646
            ->expects($this->at(6))
647
            ->method('clear')
648
            ->with('content', $this->isType('integer'))
649
            ->will($this->returnValue(true));
650
651
        $this->cacheMock
652
            ->expects($this->at(7))
653
            ->method('clear')
654
            ->with('content', 'info', $this->isType('integer'))
655
            ->will($this->returnValue(true));
656
657
        $this->cacheMock
658
            ->expects($this->at(8))
659
            ->method('clear')
660
            ->with('content', 'info', $this->isType('integer'))
661
            ->will($this->returnValue(true));
662
663
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
664
        $this->persistenceHandlerMock
665
            ->expects($this->once())
666
            ->method('locationHandler')
667
            ->will($this->returnValue($innerHandlerMock));
668
669
        $innerHandlerMock
670
            ->expects($this->once())
671
            ->method('swap')
672
            ->with(33, 66)
673
            ->will($this->returnValue(true));
674
675
        $locationMock = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\Content\\Location');
676
        $locationMock
677
            ->expects($this->any())
678
            ->method('__get')
679
            ->with('contentId')
680
            ->will($this->returnValue(42));
681
682
        /** @var \eZ\Publish\SPI\Persistence\Content\Location\Handler|\PHPUnit_Framework_MockObject_MockObject $handler */
683
        $handler = $this
684
            ->getMockBuilder('eZ\\Publish\\Core\\Persistence\\Cache\\LocationHandler')
685
            ->setMethods(['load'])
686
            ->setConstructorArgs(
687
                [
688
                    $this->cacheMock,
689
                    $this->persistenceHandlerMock,
690
                    $this->loggerMock,
691
                ]
692
            )
693
            ->getMock();
694
695
        $handler
696
            ->expects($this->any())
697
            ->method('load')
698
            ->will($this->returnValue($locationMock));
699
700
        $handler->swap(33, 66);
701
    }
702
703
    /**
704
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::update
705
     */
706
    public function testUpdate()
707
    {
708
        $this->loggerMock->expects($this->once())->method('logCall');
709
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
710
        $this->cacheMock
711
            ->expects($this->at(0))
712
            ->method('clear')
713
            ->with('location', 33);
714
715
        $this->cacheMock
716
            ->expects($this->at(1))
717
            ->method('clear')
718
            ->with('location', 'subtree');
719
720
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
721
        $this->persistenceHandlerMock
722
            ->expects($this->once())
723
            ->method('locationHandler')
724
            ->will($this->returnValue($innerHandler));
725
726
        $innerHandler
727
            ->expects($this->once())
728
            ->method('update')
729
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\UpdateStruct'), 33)
730
            ->will($this->returnValue(new Location(array('id' => 33))));
731
732
        $cacheItemMock
733
            ->expects($this->never())
734
            ->method('get');
735
736
        $handler = $this->persistenceCacheHandler->locationHandler();
737
        $handler->update(new UpdateStruct(), 33);
738
    }
739
740
    /**
741
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::create
742
     */
743
    public function testCreate()
744
    {
745
        $this->loggerMock->expects($this->once())->method('logCall');
746
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
747
        $this->cacheMock
748
            ->expects($this->once())
749
            ->method('getItem')
750
            ->with('location', 33)
751
            ->will($this->returnValue($cacheItemMock));
752
753
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
754
        $this->persistenceHandlerMock
755
            ->expects($this->once())
756
            ->method('locationHandler')
757
            ->will($this->returnValue($innerHandlerMock));
758
759
        $innerHandlerMock
760
            ->expects($this->once())
761
            ->method('create')
762
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\CreateStruct'))
763
            ->will($this->returnValue(new Location(array('id' => 33, 'contentId' => 2))));
764
765
        $cacheItemMock
766
            ->expects($this->once())
767
            ->method('set')
768
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Location'))
769
            ->will($this->returnValue($cacheItemMock));
770
771
        $cacheItemMock
772
            ->expects($this->once())
773
            ->method('save')
774
            ->with();
775
776
        $cacheItemMock
777
            ->expects($this->never())
778
            ->method('get');
779
780
        $this->cacheMock
781
            ->expects($this->at(1))
782
            ->method('clear')
783
            ->with('location', 'subtree')
784
            ->will($this->returnValue(true));
785
786
        $this->cacheMock
787
            ->expects($this->at(2))
788
            ->method('clear')
789
            ->with('content', 'locations', 2)
790
            ->will($this->returnValue(true));
791
792
        $this->cacheMock
793
            ->expects($this->at(3))
794
            ->method('clear')
795
            ->with('content', 2)
796
            ->will($this->returnValue(true));
797
798
        $this->cacheMock
799
            ->expects($this->at(4))
800
            ->method('clear')
801
            ->with('content', 'info', 2)
802
            ->will($this->returnValue(true));
803
804
        $this->cacheMock
805
            ->expects($this->at(5))
806
            ->method('clear')
807
            ->with('user', 'role', 'assignments', 'byGroup', 2)
808
            ->will($this->returnValue(true));
809
810
        $this->cacheMock
811
            ->expects($this->at(6))
812
            ->method('clear')
813
            ->with('user', 'role', 'assignments', 'byGroup', 'inherited', 2)
814
            ->will($this->returnValue(true));
815
816
        $handler = $this->persistenceCacheHandler->locationHandler();
817
        $handler->create(new CreateStruct());
818
    }
819
820
    /**
821
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::removeSubtree
822
     */
823 View Code Duplication
    public function testRemoveSubtree()
824
    {
825
        $this->loggerMock->expects($this->once())->method('logCall');
826
        $this->cacheMock
827
            ->expects($this->at(0))
828
            ->method('clear')
829
            ->with('location')
830
            ->will($this->returnValue(true));
831
832
        $this->cacheMock
833
            ->expects($this->at(1))
834
            ->method('clear')
835
            ->with('content')
836
            ->will($this->returnValue(true));
837
838
        $this->cacheMock
839
            ->expects($this->at(2))
840
            ->method('clear')
841
            ->with('user', 'role', 'assignments', 'byGroup')
842
            ->will($this->returnValue(true));
843
844
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
845
        $this->persistenceHandlerMock
846
            ->expects($this->once())
847
            ->method('locationHandler')
848
            ->will($this->returnValue($innerHandlerMock));
849
850
        $innerHandlerMock
851
            ->expects($this->once())
852
            ->method('removeSubtree')
853
            ->with(33)
854
            ->will($this->returnValue(true));
855
856
        $handler = $this->persistenceCacheHandler->locationHandler();
857
        $handler->removeSubtree(33);
858
    }
859
860
    /**
861
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::setSectionForSubtree
862
     */
863 View Code Duplication
    public function testSetSectionForSubtree()
864
    {
865
        $this->loggerMock->expects($this->once())->method('logCall');
866
        $this->cacheMock
867
            ->expects($this->once())
868
            ->method('clear')
869
            ->with('content');
870
871
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
872
        $this->persistenceHandlerMock
873
            ->expects($this->once())
874
            ->method('locationHandler')
875
            ->will($this->returnValue($innerHandler));
876
877
        $innerHandler
878
            ->expects($this->once())
879
            ->method('setSectionForSubtree')
880
            ->with(33, 2)
881
            ->will($this->returnValue(null));
882
883
        $handler = $this->persistenceCacheHandler->locationHandler();
884
        $handler->setSectionForSubtree(33, 2);
885
    }
886
887
    /**
888
     * @covers \eZ\Publish\Core\Persistence\Cache\LocationHandler::changeMainLocation
889
     */
890 View Code Duplication
    public function testChangeMainLocation()
891
    {
892
        $this->loggerMock->expects($this->once())->method('logCall');
893
894
        $this->cacheMock
895
            ->expects($this->at(0))
896
            ->method('clear')
897
            ->with('content', 30)
898
            ->will($this->returnValue(true));
899
900
        $this->cacheMock
901
            ->expects($this->at(1))
902
            ->method('clear')
903
            ->with('content', 'info', 30)
904
            ->will($this->returnValue(true));
905
906
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
907
        $this->persistenceHandlerMock
908
            ->expects($this->once())
909
            ->method('locationHandler')
910
            ->will($this->returnValue($innerHandlerMock));
911
912
        $innerHandlerMock
913
            ->expects($this->once())
914
            ->method('changeMainLocation')
915
            ->with(30, 33)
916
            ->will($this->returnValue(true));
917
918
        $handler = $this->persistenceCacheHandler->locationHandler();
919
        $handler->changeMainLocation(30, 33);
920
    }
921
}
922