Completed
Push — signal_search_issues ( 5556b2...f328ba )
by André
63:06 queued 07:22
created

LocationHandlerTest::testCreate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 70
Code Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 57
nc 1
nop 0
dl 0
loc 70
rs 9.1724
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
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('user', 'role', 'assignments', 'byGroup')
608
            ->will($this->returnValue(true));
609
610
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
611
        $this->persistenceHandlerMock
612
            ->expects($this->once())
613
            ->method('locationHandler')
614
            ->will($this->returnValue($innerHandlerMock));
615
616
        $innerHandlerMock
617
            ->expects($this->once())
618
            ->method('swap')
619
            ->with(33, 66)
620
            ->will($this->returnValue(true));
621
622
        $handler = $this->persistenceCacheHandler->locationHandler();
623
        $handler->swap(33, 66);
624
    }
625
626
    /**
627
     * @covers eZ\Publish\Core\Persistence\Cache\LocationHandler::update
628
     */
629
    public function testUpdate()
630
    {
631
        $this->loggerMock->expects($this->once())->method('logCall');
632
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
633
        $this->cacheMock
634
            ->expects($this->at(0))
635
            ->method('clear')
636
            ->with('location', 33);
637
638
        $this->cacheMock
639
            ->expects($this->at(1))
640
            ->method('clear')
641
            ->with('location', 'subtree');
642
643
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
644
        $this->persistenceHandlerMock
645
            ->expects($this->once())
646
            ->method('locationHandler')
647
            ->will($this->returnValue($innerHandler));
648
649
        $innerHandler
650
            ->expects($this->once())
651
            ->method('update')
652
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\UpdateStruct'), 33)
653
            ->will($this->returnValue(new Location(array('id' => 33))));
654
655
        $cacheItemMock
656
            ->expects($this->never())
657
            ->method('get');
658
659
        $handler = $this->persistenceCacheHandler->locationHandler();
660
        $handler->update(new UpdateStruct(), 33);
661
    }
662
663
    /**
664
     * @covers eZ\Publish\Core\Persistence\Cache\LocationHandler::create
665
     */
666
    public function testCreate()
667
    {
668
        $this->loggerMock->expects($this->once())->method('logCall');
669
        $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface');
670
        $this->cacheMock
671
            ->expects($this->once())
672
            ->method('getItem')
673
            ->with('location', 33)
674
            ->will($this->returnValue($cacheItemMock));
675
676
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
677
        $this->persistenceHandlerMock
678
            ->expects($this->once())
679
            ->method('locationHandler')
680
            ->will($this->returnValue($innerHandlerMock));
681
682
        $innerHandlerMock
683
            ->expects($this->once())
684
            ->method('create')
685
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\CreateStruct'))
686
            ->will($this->returnValue(new Location(array('id' => 33, 'contentId' => 2))));
687
688
        $cacheItemMock
689
            ->expects($this->once())
690
            ->method('set')
691
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Location'));
692
693
        $cacheItemMock
694
            ->expects($this->never())
695
            ->method('get');
696
697
        $this->cacheMock
698
            ->expects($this->at(1))
699
            ->method('clear')
700
            ->with('location', 'subtree')
701
            ->will($this->returnValue(true));
702
703
        $this->cacheMock
704
            ->expects($this->at(2))
705
            ->method('clear')
706
            ->with('content', 'locations', 2)
707
            ->will($this->returnValue(true));
708
709
        $this->cacheMock
710
            ->expects($this->at(3))
711
            ->method('clear')
712
            ->with('content', 2)
713
            ->will($this->returnValue(true));
714
715
        $this->cacheMock
716
            ->expects($this->at(4))
717
            ->method('clear')
718
            ->with('content', 'info', 2)
719
            ->will($this->returnValue(true));
720
721
        $this->cacheMock
722
            ->expects($this->at(5))
723
            ->method('clear')
724
            ->with('user', 'role', 'assignments', 'byGroup', 2)
725
            ->will($this->returnValue(true));
726
727
        $this->cacheMock
728
            ->expects($this->at(6))
729
            ->method('clear')
730
            ->with('user', 'role', 'assignments', 'byGroup', 'inherited', 2)
731
            ->will($this->returnValue(true));
732
733
        $handler = $this->persistenceCacheHandler->locationHandler();
734
        $handler->create(new CreateStruct());
735
    }
736
737
    /**
738
     * @covers eZ\Publish\Core\Persistence\Cache\LocationHandler::removeSubtree
739
     */
740
    public function testRemoveSubtree()
741
    {
742
        $this->loggerMock->expects($this->once())->method('logCall');
743
        $this->cacheMock
744
            ->expects($this->at(0))
745
            ->method('clear')
746
            ->with('location')
747
            ->will($this->returnValue(true));
748
749
        $this->cacheMock
750
            ->expects($this->at(1))
751
            ->method('clear')
752
            ->with('content')
753
            ->will($this->returnValue(true));
754
755
        $this->cacheMock
756
            ->expects($this->at(2))
757
            ->method('clear')
758
            ->with('user', 'role', 'assignments', 'byGroup')
759
            ->will($this->returnValue(true));
760
761
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
762
        $this->persistenceHandlerMock
763
            ->expects($this->once())
764
            ->method('locationHandler')
765
            ->will($this->returnValue($innerHandlerMock));
766
767
        $innerHandlerMock
768
            ->expects($this->once())
769
            ->method('removeSubtree')
770
            ->with(33)
771
            ->will($this->returnValue(true));
772
773
        $handler = $this->persistenceCacheHandler->locationHandler();
774
        $handler->removeSubtree(33);
775
    }
776
777
    /**
778
     * @covers eZ\Publish\Core\Persistence\Cache\LocationHandler::setSectionForSubtree
779
     */
780 View Code Duplication
    public function testSetSectionForSubtree()
781
    {
782
        $this->loggerMock->expects($this->once())->method('logCall');
783
        $this->cacheMock
784
            ->expects($this->once())
785
            ->method('clear')
786
            ->with('content');
787
788
        $innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
789
        $this->persistenceHandlerMock
790
            ->expects($this->once())
791
            ->method('locationHandler')
792
            ->will($this->returnValue($innerHandler));
793
794
        $innerHandler
795
            ->expects($this->once())
796
            ->method('setSectionForSubtree')
797
            ->with(33, 2)
798
            ->will($this->returnValue(null));
799
800
        $handler = $this->persistenceCacheHandler->locationHandler();
801
        $handler->setSectionForSubtree(33, 2);
802
    }
803
804
    /**
805
     * @covers eZ\Publish\Core\Persistence\Cache\LocationHandler::changeMainLocation
806
     */
807 View Code Duplication
    public function testChangeMainLocation()
808
    {
809
        $this->loggerMock->expects($this->once())->method('logCall');
810
811
        $this->cacheMock
812
            ->expects($this->at(0))
813
            ->method('clear')
814
            ->with('content', 30)
815
            ->will($this->returnValue(true));
816
817
        $this->cacheMock
818
            ->expects($this->at(1))
819
            ->method('clear')
820
            ->with('content', 'info', 30)
821
            ->will($this->returnValue(true));
822
823
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Handler');
824
        $this->persistenceHandlerMock
825
            ->expects($this->once())
826
            ->method('locationHandler')
827
            ->will($this->returnValue($innerHandlerMock));
828
829
        $innerHandlerMock
830
            ->expects($this->once())
831
            ->method('changeMainLocation')
832
            ->with(30, 33)
833
            ->will($this->returnValue(true));
834
835
        $handler = $this->persistenceCacheHandler->locationHandler();
836
        $handler->changeMainLocation(30, 33);
837
    }
838
}
839