Completed
Push — fix_xsl_dupe_ids ( fff5a5 )
by
unknown
21:16
created

ContentHandlerTest   C

Complexity

Total Complexity 18

Size/Duplication

Total Lines 759
Duplicated Lines 8.04 %

Coupling/Cohesion

Components 1
Dependencies 12

Importance

Changes 0
Metric Value
dl 61
loc 759
rs 5.2093
c 0
b 0
f 0
wmc 18
lcom 1
cbo 12

15 Methods

Rating   Name   Duplication   Size   Complexity  
B testUnCachedMethods() 30 30 4
B testLoadHasCache() 0 45 1
B testLoadContentInfoHasCache() 0 35 1
A testLoadCacheIsMiss() 0 60 1
A testLoadContentInfoCacheIsMiss() 0 50 1
B providerForUnCachedMethods() 0 24 1
A testLoadVersionInfoCacheIsMiss() 0 50 1
B testSetStatusPublished() 31 31 1
B testUpdateMetadata() 0 37 1
B testUpdateContent() 0 45 1
B testDeleteContent() 0 79 1
B testDeleteVersion() 0 43 1
B testPublish() 0 101 1
B testLoadVersionInfoHasCache() 0 35 1
B testSetStatus() 0 31 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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