Completed
Push — ezp-26146_location_swap_incons... ( 585e0a...60d346 )
by
unknown
36:22
created

LocationHandlerTest::testSwap()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 84
Code Lines 69

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 69
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 84
rs 8.7169

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