Completed
Push — sf_cache ( b9ead9...8c890f )
by André
18:16
created

ContentHandlerTest::getHandlerClassName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
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
23
/**
24
 * Test case for Persistence\Cache\ContentHandler.
25
 */
26
class ContentHandlerTest extends HandlerTest
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
            ['loadContentInfoByRemoteId', ['3d8jrj'], 'ez-content-info-byRemoteId-3d8jrj', $info],
79
            ['loadVersionInfo', [2, 1], 'ez-content-version-info-2-1', $version],
80
        ];
81
    }
82
83
    /**
84
     * @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::deleteContent
85
     */
86
    public function testDeleteContent()
87
    {
88
        $this->loggerMock->expects($this->once())->method('logCall');
89
90
        $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Handler');
91
        $this->persistenceHandlerMock
92
            ->expects($this->exactly(2))
93
            ->method('contentHandler')
94
            ->will($this->returnValue($innerHandlerMock));
95
96
        $innerHandlerMock
97
            ->expects($this->once())
98
            ->method('loadReverseRelations')
99
            ->with(2, APIRelation::FIELD)
100
            ->will(
101
                $this->returnValue(
102
                    array(
103
                        new SPIRelation(array('sourceContentId' => 42)),
104
                    )
105
                )
106
            );
107
108
        $innerHandlerMock
109
            ->expects($this->once())
110
            ->method('deleteContent')
111
            ->with(2)
112
            ->will($this->returnValue(true));
113
114
        $this->cacheMock
115
            ->expects($this->never())
116
            ->method('deleteItem');
117
118
        $this->cacheMock
119
            ->expects($this->at(0))
120
            ->method('invalidateTags')
121
            ->with(['content-2']);
122
123
        $this->cacheMock
124
            ->expects($this->at(1))
125
            ->method('invalidateTags')
126
            ->with(['content-fields-42']);
127
128
        $handler = $this->persistenceCacheHandler->contentHandler();
129
        $handler->deleteContent(2);
130
    }
131
}
132