Completed
Push — 6.13 ( 2d2b5c...9be36a )
by André
74:22 queued 54:25
created

testLoadVersionInfoCacheIsMiss()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 50
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 39
nc 1
nop 0
dl 0
loc 50
rs 9.3333
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\Handler;
16
use eZ\Publish\SPI\Persistence\Content\ContentInfo;
17
use eZ\Publish\SPI\Persistence\Content\VersionInfo;
18
use eZ\Publish\SPI\Persistence\Content\CreateStruct;
19
use eZ\Publish\SPI\Persistence\Content\UpdateStruct;
20
use eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct;
21
use eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct as RelationCreateStruct;
22
use eZ\Publish\SPI\Persistence\Content\Handler as SPIContentHandler;
23
use eZ\Publish\SPI\Persistence\Content\Location\Handler as SPILocationHandler;
24
use Stash\Interfaces\ItemInterface;
25
26
/**
27
 * Test case for Persistence\Cache\ContentHandler.
28
 */
29
class ContentHandlerTest extends HandlerTest
30
{
31
    /**
32
     * @return array
33
     */
34
    public function providerForUnCachedMethods()
35
    {
36
        return array(
37
            array('create', array(new CreateStruct())),
38
            array('createDraftFromVersion', array(2, 1, 14)),
39
            array('copy', array(2, 1)),
40
            //array( 'load', array( 2, 1, array( 'eng-GB' ) ) ),
41
            //array( 'load', array( 2, 1 ) ),
42
            //array( 'loadContentInfo', array( 2 ) ),
43
            //array('loadVersionInfo', array(2, 1)),
44
            array('loadDraftsForUser', array(14)),
45
            //array( 'setStatus', array( 2, 0, 1 ) ),
46
            //array( 'updateMetadata', array( 2, new MetadataUpdateStruct ) ),
47
            //array( 'updateContent', array( 2, 1, new UpdateStruct ) ),
48
            //array( 'deleteContent', array( 2 ) ),
49
            //array( 'deleteVersion', array( 2, 1 ) ),
50
            array('listVersions', array(2)),
51
            array('addRelation', array(new RelationCreateStruct())),
52
            array('removeRelation', array(66, APIRelation::COMMON)),
53
            array('loadRelations', array(2, 1, 3)),
54
            array('loadReverseRelations', array(2, 3)),
55
            //array( 'publish', array( 2, 3, new MetadataUpdateStruct ) ),
56
        );
57
    }
58
59
    /**
60
     * @dataProvider providerForUnCachedMethods
61
     * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler
62
     */
63 View Code Duplication
    public function testUnCachedMethods($method, array $arguments)
64
    {
65
        $this->loggerMock->expects($this->once())->method('logCall');
66
        $this->cacheMock
67
            ->expects($this->never())
68
            ->method($this->anything());
69
70
        $innerHandler = $this->createMock(SPIContentHandler::class);
71
        $this->persistenceHandlerMock
72
            ->expects($this->once())
73
            ->method('contentHandler')
74
            ->will($this->returnValue($innerHandler));
75
76
        $expects = $innerHandler
77
            ->expects($this->once())
78
            ->method($method);
79
80
        if (isset($arguments[2])) {
81
            $expects->with($arguments[0], $arguments[1], $arguments[2]);
82
        } elseif (isset($arguments[1])) {
83
            $expects->with($arguments[0], $arguments[1]);
84
        } elseif (isset($arguments[0])) {
85
            $expects->with($arguments[0]);
86
        }
87
88
        $expects->will($this->returnValue(null));
89
90
        $handler = $this->persistenceCacheHandler->contentHandler();
91
        call_user_func_array(array($handler, $method), $arguments);
92
    }
93
94
    /**
95
     * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::load
96
     */
97
    public function testLoadCacheIsMiss()
98
    {
99
        $this->loggerMock->expects($this->once())->method('logCall');
100
        $cacheItemMock = $this->createMock(ItemInterface::class);
101
        $this->cacheMock
102
            ->expects($this->once())
103
            ->method('getItem')
104
            ->with('content', 2, 1, 'eng-GB|eng-US')
105
            ->will($this->returnValue($cacheItemMock));
106
107
        $cacheItemMock
108
            ->expects($this->once())
109
            ->method('get')
110
            ->will($this->returnValue(null));
111
112
        $cacheItemMock
113
            ->expects($this->once())
114
            ->method('isMiss')
115
            ->will($this->returnValue(true));
116
117
        $innerHandlerMock = $this->createMock(SPIContentHandler::class);
118
        $this->persistenceHandlerMock
119
            ->expects($this->once())
120
            ->method('contentHandler')
121
            ->will($this->returnValue($innerHandlerMock));
122
123
        $innerHandlerMock
124
            ->expects($this->once())
125
            ->method('load')
126
            ->with(2, 1, array('eng-GB', 'eng-US'))
127
            ->will(
128
                $this->returnValue(
129
                    new Content(
130
                        array(
131
                            'fields' => array(),
132
                            'versionInfo' => new VersionInfo(
133
                                array(
134
                                    'versionNo' => 1,
135
                                    'contentInfo' => new ContentInfo(array('id' => 2)),
136
                                )
137
                            ),
138
                        )
139
                    )
140
                )
141
            );
142
143
        $cacheItemMock
144
            ->expects($this->once())
145
            ->method('set')
146
            ->with($this->isInstanceOf(Content::class))
147
            ->will($this->returnValue($cacheItemMock));
148
149
        $cacheItemMock
150
            ->expects($this->once())
151
            ->method('save')
152
            ->with();
153
154
        $handler = $this->persistenceCacheHandler->contentHandler();
155
        $handler->load(2, 1, array('eng-GB', 'eng-US'));
156
    }
157
158
    /**
159
     * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::load
160
     */
161
    public function testLoadHasCache()
162
    {
163
        $this->loggerMock->expects($this->never())->method($this->anything());
164
        $cacheItemMock = $this->createMock(ItemInterface::class);
165
        $this->cacheMock
166
            ->expects($this->once())
167
            ->method('getItem')
168
            ->with('content', 2, 1, ContentHandler::ALL_TRANSLATIONS_KEY)
169
            ->will($this->returnValue($cacheItemMock));
170
171
        $cacheItemMock
172
            ->expects($this->once())
173
            ->method('isMiss')
174
            ->will($this->returnValue(false));
175
176
        $this->persistenceHandlerMock
177
            ->expects($this->never())
178
            ->method('contentHandler');
179
180
        $cacheItemMock
181
            ->expects($this->once())
182
            ->method('get')
183
            ->will(
184
                $this->returnValue(
185
                    new Content(
186
                        array(
187
                            'fields' => array(),
188
                            'versionInfo' => new VersionInfo(
189
                                array(
190
                                    'versionNo' => 1,
191
                                    'contentInfo' => new ContentInfo(array('id' => 2)),
192
                                )
193
                            ),
194
                        )
195
                    )
196
                )
197
            );
198
199
        $cacheItemMock
200
            ->expects($this->never())
201
            ->method('set');
202
203
        $handler = $this->persistenceCacheHandler->contentHandler();
204
        $handler->load(2, 1);
205
    }
206
207
    /**
208
     * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::loadContentInfo
209
     */
210
    public function testLoadContentInfoCacheIsMiss()
211
    {
212
        $this->loggerMock->expects($this->once())->method('logCall');
213
        $cacheItemMock = $this->createMock(ItemInterface::class);
214
        $this->cacheMock
215
            ->expects($this->once())
216
            ->method('getItem')
217
            ->with('content', 'info', 2)
218
            ->will($this->returnValue($cacheItemMock));
219
220
        $cacheItemMock
221
            ->expects($this->once())
222
            ->method('get')
223
            ->will($this->returnValue(null));
224
225
        $cacheItemMock
226
            ->expects($this->once())
227
            ->method('isMiss')
228
            ->will($this->returnValue(true));
229
230
        $innerHandlerMock = $this->createMock(SPIContentHandler::class);
231
        $this->persistenceHandlerMock
232
            ->expects($this->once())
233
            ->method('contentHandler')
234
            ->will($this->returnValue($innerHandlerMock));
235
236
        $innerHandlerMock
237
            ->expects($this->once())
238
            ->method('loadContentInfo')
239
            ->with(2)
240
            ->will(
241
                $this->returnValue(
242
                    new ContentInfo(array('id' => 2))
243
                )
244
            );
245
246
        $cacheItemMock
247
            ->expects($this->once())
248
            ->method('set')
249
            ->with($this->isInstanceOf(ContentInfo::class))
250
            ->will($this->returnValue($cacheItemMock));
251
252
        $cacheItemMock
253
            ->expects($this->once())
254
            ->method('save')
255
            ->with();
256
257
        $handler = $this->persistenceCacheHandler->contentHandler();
258
        $handler->loadContentInfo(2, 1);
259
    }
260
261
    /**
262
     * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::loadContentInfo
263
     */
264
    public function testLoadContentInfoHasCache()
265
    {
266
        $this->loggerMock->expects($this->never())->method($this->anything());
267
        $cacheItemMock = $this->createMock(ItemInterface::class);
268
        $this->cacheMock
269
            ->expects($this->once())
270
            ->method('getItem')
271
            ->with('content', 'info', 2)
272
            ->will($this->returnValue($cacheItemMock));
273
274
        $cacheItemMock
275
            ->expects($this->once())
276
            ->method('isMiss')
277
            ->will($this->returnValue(false));
278
279
        $this->persistenceHandlerMock
280
            ->expects($this->never())
281
            ->method('contentHandler');
282
283
        $cacheItemMock
284
            ->expects($this->once())
285
            ->method('get')
286
            ->will(
287
                $this->returnValue(
288
                    new ContentInfo(array('id' => 2))
289
                )
290
            );
291
292
        $cacheItemMock
293
            ->expects($this->never())
294
            ->method('set');
295
296
        $handler = $this->persistenceCacheHandler->contentHandler();
297
        $handler->loadContentInfo(2);
298
    }
299
300
    /**
301
     * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::loadVersionInfo
302
     */
303
    public function testLoadVersionInfoCacheIsMiss()
304
    {
305
        $this->loggerMock->expects($this->once())->method('logCall');
306
        $cacheItemMock = $this->getMock(ItemInterface::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0; use createMock() or getMockBuilder() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
307
        $this->cacheMock
308
            ->expects($this->once())
309
            ->method('getItem')
310
            ->with('content', 'info', 2, 'versioninfo', 1)
311
            ->will($this->returnValue($cacheItemMock));
312
313
        $cacheItemMock
314
            ->expects($this->once())
315
            ->method('get')
316
            ->will($this->returnValue(null));
317
318
        $cacheItemMock
319
            ->expects($this->once())
320
            ->method('isMiss')
321
            ->will($this->returnValue(true));
322
323
        $innerHandlerMock = $this->getMock(Handler::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0; use createMock() or getMockBuilder() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
324
        $this->persistenceHandlerMock
325
            ->expects($this->once())
326
            ->method('contentHandler')
327
            ->will($this->returnValue($innerHandlerMock));
328
329
        $innerHandlerMock
330
            ->expects($this->once())
331
            ->method('loadVersionInfo')
332
            ->with(2, 1)
333
            ->will(
334
                $this->returnValue(
335
                    new VersionInfo(['contentInfo' => new ContentInfo(['id' => 2]), 'versionNo' => 1])
336
                )
337
            );
338
339
        $cacheItemMock
340
            ->expects($this->once())
341
            ->method('set')
342
            ->with($this->isInstanceOf(VersionInfo::class))
343
            ->will($this->returnValue($cacheItemMock));
344
345
        $cacheItemMock
346
            ->expects($this->once())
347
            ->method('save')
348
            ->with();
349
350
        $handler = $this->persistenceCacheHandler->contentHandler();
351
        $handler->loadVersionInfo(2, 1);
352
    }
353
354
    /**
355
     * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::loadVersionInfo
356
     */
357
    public function testLoadVersionInfoHasCache()
358
    {
359
        $this->loggerMock->expects($this->never())->method($this->anything());
360
        $cacheItemMock = $this->getMock(ItemInterface::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0; use createMock() or getMockBuilder() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
361
        $this->cacheMock
362
            ->expects($this->once())
363
            ->method('getItem')
364
            ->with('content', 'info', 2, 'versioninfo', 1)
365
            ->will($this->returnValue($cacheItemMock));
366
367
        $cacheItemMock
368
            ->expects($this->once())
369
            ->method('isMiss')
370
            ->will($this->returnValue(false));
371
372
        $this->persistenceHandlerMock
373
            ->expects($this->never())
374
            ->method('contentHandler');
375
376
        $cacheItemMock
377
            ->expects($this->once())
378
            ->method('get')
379
            ->will(
380
                $this->returnValue(
381
                    new VersionInfo(['contentInfo' => new ContentInfo(['id' => 2]), 'versionNo' => 1])
382
                )
383
            );
384
385
        $cacheItemMock
386
            ->expects($this->never())
387
            ->method('set');
388
389
        $handler = $this->persistenceCacheHandler->contentHandler();
390
        $handler->loadVersionInfo(2, 1);
391
    }
392
393
    /**
394
     * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::setStatus
395
     */
396 View Code Duplication
    public function testSetStatus()
397
    {
398
        $this->loggerMock->expects($this->once())->method('logCall');
399
400
        $innerHandlerMock = $this->createMock(SPIContentHandler::class);
401
        $this->persistenceHandlerMock
402
            ->expects($this->once())
403
            ->method('contentHandler')
404
            ->will($this->returnValue($innerHandlerMock));
405
406
        $innerHandlerMock
407
            ->expects($this->once())
408
            ->method('setStatus')
409
            ->with(2, VersionInfo::STATUS_ARCHIVED, 1)
410
            ->will($this->returnValue(true));
411
412
        $this->cacheMock
413
            ->expects($this->at(0))
414
            ->method('clear')
415
            ->with('content', 2, 1)
416
            ->will($this->returnValue(null));
417
418
        $this->cacheMock
419
            ->expects($this->at(1))
420
            ->method('clear')
421
            ->with('content', 'info', 2, 'versioninfo', 1)
422
            ->will($this->returnValue(null));
423
424
        $handler = $this->persistenceCacheHandler->contentHandler();
425
        $handler->setStatus(2, VersionInfo::STATUS_ARCHIVED, 1);
426
    }
427
428
    /**
429
     * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::setStatus
430
     */
431 View Code Duplication
    public function testSetStatusPublished()
432
    {
433
        $this->loggerMock->expects($this->once())->method('logCall');
434
435
        $innerHandlerMock = $this->createMock(SPIContentHandler::class);
436
        $this->persistenceHandlerMock
437
            ->expects($this->once())
438
            ->method('contentHandler')
439
            ->will($this->returnValue($innerHandlerMock));
440
441
        $innerHandlerMock
442
            ->expects($this->once())
443
            ->method('setStatus')
444
            ->with(2, VersionInfo::STATUS_PUBLISHED, 1)
445
            ->will($this->returnValue(true));
446
447
        $this->cacheMock
448
            ->expects($this->at(0))
449
            ->method('clear')
450
            ->with('content', 2, 1)
451
            ->will($this->returnValue(null));
452
453
        $this->cacheMock
454
            ->expects($this->at(1))
455
            ->method('clear')
456
            ->with('content', 'info', 2)
457
            ->will($this->returnValue(null));
458
459
        $handler = $this->persistenceCacheHandler->contentHandler();
460
        $handler->setStatus(2, VersionInfo::STATUS_PUBLISHED, 1);
461
    }
462
463
    /**
464
     * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::updateMetadata
465
     */
466
    public function testUpdateMetadata()
467
    {
468
        $this->loggerMock->expects($this->once())->method('logCall');
469
470
        $innerHandlerMock = $this->createMock(SPIContentHandler::class);
471
        $this->persistenceHandlerMock
472
            ->expects($this->once())
473
            ->method('contentHandler')
474
            ->will($this->returnValue($innerHandlerMock));
475
476
        $innerHandlerMock
477
            ->expects($this->once())
478
            ->method('updateMetadata')
479
            ->with(2, $this->isInstanceOf(MetadataUpdateStruct::class))
480
            ->willReturn(new ContentInfo(array('id' => 2, 'currentVersionNo' => 3, 'remoteId' => 'o34')));
481
482
        $this->cacheMock
483
            ->expects($this->at(0))
484
            ->method('clear')
485
            ->with('content', 2, 3)
486
            ->willReturn(null);
487
488
        $this->cacheMock
489
            ->expects($this->at(1))
490
            ->method('clear')
491
            ->with('content', 'info', 2)
492
            ->willReturn(null);
493
494
        $this->cacheMock
495
            ->expects($this->at(2))
496
            ->method('clear')
497
            ->with('content', 'info', 'remoteId', 'o34')
498
            ->willReturn(null);
499
500
        $handler = $this->persistenceCacheHandler->contentHandler();
501
        $handler->updateMetadata(2, new MetadataUpdateStruct());
502
    }
503
504
    /**
505
     * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::updateContent
506
     */
507
    public function testUpdateContent()
508
    {
509
        $this->loggerMock->expects($this->once())->method('logCall');
510
511
        $innerHandlerMock = $this->createMock(SPIContentHandler::class);
512
        $this->persistenceHandlerMock
513
            ->expects($this->once())
514
            ->method('contentHandler')
515
            ->will($this->returnValue($innerHandlerMock));
516
517
        $innerHandlerMock
518
            ->expects($this->once())
519
            ->method('updateContent')
520
            ->with(2, 1, $this->isInstanceOf(UpdateStruct::class))
521
            ->will(
522
                $this->returnValue(
523
                    new Content(
524
                        array(
525
                            'fields' => array(),
526
                            'versionInfo' => new VersionInfo(
527
                                array(
528
                                    'versionNo' => 1,
529
                                    'contentInfo' => new ContentInfo(array('id' => 2)),
530
                                )
531
                            ),
532
                        )
533
                    )
534
                )
535
            );
536
537
        $this->cacheMock
538
            ->expects($this->at(0))
539
            ->method('clear')
540
            ->with('content', 2, 1)
541
            ->will($this->returnValue(null));
542
543
        $this->cacheMock
544
            ->expects($this->at(1))
545
            ->method('clear')
546
            ->with('content', 'info', 2, 'versioninfo', 1)
547
            ->will($this->returnValue(null));
548
549
        $handler = $this->persistenceCacheHandler->contentHandler();
550
        $handler->updateContent(2, 1, new UpdateStruct());
551
    }
552
553
    /**
554
     * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::deleteContent
555
     */
556
    public function testDeleteContent()
557
    {
558
        $this->loggerMock->expects($this->once())->method('logCall');
559
560
        $innerLocationHandlerMock = $this->createMock(SPILocationHandler::class);
561
        $this->persistenceHandlerMock
562
            ->expects($this->exactly(1))
563
            ->method('locationHandler')
564
            ->will($this->returnValue($innerLocationHandlerMock));
565
566
        $innerLocationHandlerMock
567
            ->expects($this->once())
568
            ->method('loadLocationsByContent')
569
            ->with(2)
570
            ->willReturn([new Content\Location(array('id' => 58))]);
571
572
        $innerHandlerMock = $this->createMock(SPIContentHandler::class);
573
        $this->persistenceHandlerMock
574
            ->expects($this->exactly(2))
575
            ->method('contentHandler')
576
            ->will($this->returnValue($innerHandlerMock));
577
578
        $innerHandlerMock
579
            ->expects($this->once())
580
            ->method('loadReverseRelations')
581
            ->with(2, APIRelation::FIELD)
582
            ->will(
583
                $this->returnValue(
584
                    array(
585
                        new SPIRelation(array('sourceContentId' => 42)),
586
                    )
587
                )
588
            );
589
590
        $innerHandlerMock
591
            ->expects($this->once())
592
            ->method('deleteContent')
593
            ->with(2)
594
            ->will($this->returnValue(true));
595
596
        $this->cacheMock
597
            ->expects($this->at(0))
598
            ->method('clear')
599
            ->with('content', 42)
600
            ->will($this->returnValue(null));
601
602
        $this->cacheMock
603
            ->expects($this->at(1))
604
            ->method('clear')
605
            ->with('content', 2)
606
            ->will($this->returnValue(null));
607
608
        $this->cacheMock
609
            ->expects($this->at(2))
610
            ->method('clear')
611
            ->with('content', 'info', 2)
612
            ->will($this->returnValue(null));
613
614
        $this->cacheMock
615
            ->expects($this->at(3))
616
            ->method('clear')
617
            ->with('content', 'info', 'remoteId')
618
            ->will($this->returnValue(null));
619
620
        $this->cacheMock
621
            ->expects($this->at(4))
622
            ->method('clear')
623
            ->with('location', 'subtree')
624
            ->will($this->returnValue(null));
625
626
        $this->cacheMock
627
            ->expects($this->at(5))
628
            ->method('clear')
629
            ->with('location', 58)
630
            ->will($this->returnValue(null));
631
632
        $handler = $this->persistenceCacheHandler->contentHandler();
633
        $handler->deleteContent(2);
634
    }
635
636
    /**
637
     * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::deleteVersion
638
     */
639
    public function testDeleteVersion()
640
    {
641
        $this->loggerMock->expects($this->once())->method('logCall');
642
643
        $innerHandlerMock = $this->createMock(SPIContentHandler::class);
644
        $this->persistenceHandlerMock
645
            ->expects($this->once())
646
            ->method('contentHandler')
647
            ->will($this->returnValue($innerHandlerMock));
648
649
        $innerHandlerMock
650
            ->expects($this->once())
651
            ->method('deleteVersion')
652
            ->with(2, 1)
653
            ->will($this->returnValue(true));
654
655
        $this->cacheMock
656
            ->expects($this->at(0))
657
            ->method('clear')
658
            ->with('content', 2, 1)
659
            ->will($this->returnValue(null));
660
661
        $this->cacheMock
662
            ->expects($this->at(1))
663
            ->method('clear')
664
            ->with('content', 'info', 2)
665
            ->will($this->returnValue(null));
666
667
        $this->cacheMock
668
            ->expects($this->at(2))
669
            ->method('clear')
670
            ->with('content', 'info', 'remoteId')
671
            ->will($this->returnValue(null));
672
673
        $this->cacheMock
674
            ->expects($this->at(3))
675
            ->method('clear')
676
            ->with('location', 'subtree')
677
            ->will($this->returnValue(null));
678
679
        $handler = $this->persistenceCacheHandler->contentHandler();
680
        $handler->deleteVersion(2, 1);
681
    }
682
683
    /**
684
     * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::publish
685
     */
686
    public function testPublish()
687
    {
688
        $this->loggerMock->expects($this->once())->method('logCall');
689
690
        $innerHandlerMock = $this->createMock(SPIContentHandler::class);
691
        $this->persistenceHandlerMock
692
            ->expects($this->once())
693
            ->method('contentHandler')
694
            ->will($this->returnValue($innerHandlerMock));
695
696
        $innerHandlerMock
697
            ->expects($this->once())
698
            ->method('publish')
699
            ->with(2, 1, $this->isInstanceOf(MetadataUpdateStruct::class))
700
            ->will(
701
                $this->returnValue(
702
                    new Content(
703
                        array(
704
                            'fields' => array(),
705
                            'versionInfo' => new VersionInfo(
706
                                array(
707
                                    'versionNo' => 1,
708
                                    'contentInfo' => new ContentInfo(array('id' => 2)),
709
                                )
710
                            ),
711
                        )
712
                    )
713
                )
714
            );
715
716
        $this->cacheMock
717
            ->expects($this->at(0))
718
            ->method('clear')
719
            ->with('content', 2)
720
            ->will($this->returnValue(true));
721
722
        $this->cacheMock
723
            ->expects($this->at(1))
724
            ->method('clear')
725
            ->with('content', 'info', 2)
726
            ->will($this->returnValue(true));
727
728
        $this->cacheMock
729
            ->expects($this->at(2))
730
            ->method('clear')
731
            ->with('content', 'info', 'remoteId')
732
            ->will($this->returnValue(true));
733
734
        $this->cacheMock
735
            ->expects($this->at(3))
736
            ->method('clear')
737
            ->with('location', 'subtree')
738
            ->will($this->returnValue(true));
739
740
        $cacheItemMock = $this->createMock(ItemInterface::class);
741
        $this->cacheMock
742
            ->expects($this->at(4))
743
            ->method('getItem')
744
            ->with('content', 2, 1, ContentHandler::ALL_TRANSLATIONS_KEY)
745
            ->will($this->returnValue($cacheItemMock));
746
747
        $cacheItemMock
748
            ->expects($this->once())
749
            ->method('set')
750
            ->with($this->isInstanceOf(Content::class))
751
            ->will($this->returnValue($cacheItemMock));
752
753
        $cacheItemMock
754
            ->expects($this->once())
755
            ->method('save')
756
            ->with();
757
758
        $cacheItemMock
759
            ->expects($this->never())
760
            ->method('get');
761
762
        $cacheItemMock2 = $this->createMock(ItemInterface::class);
763
        $this->cacheMock
764
            ->expects($this->at(5))
765
            ->method('getItem')
766
            ->with('content', 'info', 2)
767
            ->will($this->returnValue($cacheItemMock2));
768
769
        $cacheItemMock2
770
            ->expects($this->once())
771
            ->method('set')
772
            ->with($this->isInstanceOf(ContentInfo::class))
773
            ->will($this->returnValue($cacheItemMock2));
774
775
        $cacheItemMock2
776
            ->expects($this->once())
777
            ->method('save')
778
            ->with();
779
780
        $cacheItemMock2
781
            ->expects($this->never())
782
            ->method('get');
783
784
        $handler = $this->persistenceCacheHandler->contentHandler();
785
        $handler->publish(2, 1, new MetadataUpdateStruct());
786
    }
787
}
788