Completed
Push — feature-EZP-25696 ( c75b51...ce24f7 )
by André
24:57 queued 26s
created

testLoadLocationsByContentHasCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 54
Code Lines 41

Duplication

Lines 54
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 41
nc 1
nop 0
dl 54
loc 54
rs 9.6716
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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