Completed
Push — sf_multi_get ( c68a81 )
by André
25:43 queued 12:06
created

ContentHandlerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Importance

Changes 0
Metric Value
dl 0
loc 107
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getHandlerMethodName() 0 4 1
A getHandlerClassName() 0 4 1
A providerForUnCachedMethods() 0 22 1
A providerForCachedLoadMethods() 0 16 1
B testDeleteContent() 0 45 1
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
23
/**
24
 * Test case for Persistence\Cache\ContentHandler.
25
 */
26
class ContentHandlerTest extends AbstractCacheHandlerTest
27
{
28
    public function getHandlerMethodName() : string
29
    {
30
        return 'contentHandler';
31
    }
32
33
    public function getHandlerClassName() : string
34
    {
35
        return Handler::class;
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    public function providerForUnCachedMethods() : array
42
    {
43
        // string $method, array $arguments, array? $tags, string? $key
44
        return [
45
            ['create', [new CreateStruct]],
46
            ['createDraftFromVersion', [2, 1, 14]],
47
            ['copy', [2, 1]],
48
            ['loadDraftsForUser', [14]],
49
            ['setStatus', [2, 0, 1], null, 'ez-content-version-info-2-1'],
50
            ['setStatus', [2, 1, 1], ['content-2'], 'ez-content-version-info-2-1'],
51
            ['updateMetadata', [2, new MetadataUpdateStruct], ['content-2']],
52
            ['updateContent', [2, 1, new UpdateStruct], ['content-2']],
53
            //['deleteContent', [2]], own tests for relations complexity
54
            ['deleteVersion', [2, 1], ['content-2']],
55
            ['listVersions', [2]],
56
            ['addRelation', [new RelationCreateStruct]],
57
            ['removeRelation', [66, APIRelation::COMMON]],
58
            ['loadRelations', [2, 1, 3]],
59
            ['loadReverseRelations', [2, 3]],
60
            ['publish', [2, 3, new MetadataUpdateStruct], ['content-2']],
61
        ];
62
    }
63
64
    /**
65
     * @return array
66
     */
67
    public function providerForCachedLoadMethods() : array
68
    {
69
        $info = new ContentInfo(['id' => 2]);
70
        $version = new VersionInfo(['versionNo' => 1, 'contentInfo' => $info]);
71
        $content = new Content(['fields' => [], 'versionInfo' => $version]);
72
73
        // string $method, array $arguments, string $key, mixed? $data
74
        return [
75
            ['load', [2, 1], 'ez-content-2-1-'.ContentHandler::ALL_TRANSLATIONS_KEY, $content],
76
            ['load', [2, 1, ['eng-GB', 'eng-US']], 'ez-content-2-1-eng-GB|eng-US', $content],
77
            ['loadContentInfo', [2], 'ez-content-info-2', $info],
78
            ['loadContentInfoList', [[2]], 'ez-content-info-2', [2 => $info], true],
79
            ['loadContentInfoByRemoteId', ['3d8jrj'], 'ez-content-info-byRemoteId-3d8jrj', $info],
80
            ['loadVersionInfo', [2, 1], 'ez-content-version-info-2-1', $version],
81
        ];
82
    }
83
84
    /**
85
     * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::deleteContent
86
     */
87
    public function testDeleteContent()
88
    {
89
        $this->loggerMock->expects($this->once())->method('logCall');
90
91
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler');
92
        $this->persistenceHandlerMock
93
            ->expects($this->exactly(2))
94
            ->method('contentHandler')
95
            ->will($this->returnValue($innerHandlerMock));
96
97
        $innerHandlerMock
98
            ->expects($this->once())
99
            ->method('loadReverseRelations')
100
            ->with(2, APIRelation::FIELD)
101
            ->will(
102
                $this->returnValue(
103
                    array(
104
                        new SPIRelation(array('sourceContentId' => 42)),
105
                    )
106
                )
107
            );
108
109
        $innerHandlerMock
110
            ->expects($this->once())
111
            ->method('deleteContent')
112
            ->with(2)
113
            ->will($this->returnValue(true));
114
115
        $this->cacheMock
116
            ->expects($this->never())
117
            ->method('deleteItem');
118
119
        $this->cacheMock
120
            ->expects($this->at(0))
121
            ->method('invalidateTags')
122
            ->with(['content-2']);
123
124
        $this->cacheMock
125
            ->expects($this->at(1))
126
            ->method('invalidateTags')
127
            ->with(['content-fields-42']);
128
129
        $handler = $this->persistenceCacheHandler->contentHandler();
130
        $handler->deleteContent(2);
131
    }
132
}
133