Completed
Push — EZP-31644 ( 2e0a1e...93bb44 )
by
unknown
19:12
created

ContentHandlerTest::testSetStatusPublished()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 37

Duplication

Lines 37
Ratio 100 %

Importance

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