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
|
|
|
|
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 SPIContentHandler::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], ['content-2-version-list']], |
47
|
|
|
['copy', [2, 1]], |
48
|
|
|
['loadDraftsForUser', [14]], |
49
|
|
|
['setStatus', [2, 0, 1], ['content-2-version-list'], '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
|
|
|
['addRelation', [new RelationCreateStruct()]], |
56
|
|
|
['removeRelation', [66, APIRelation::COMMON]], |
57
|
|
|
['loadRelations', [2, 1, 3]], |
58
|
|
|
['loadReverseRelations', [2, 3]], |
59
|
|
|
['publish', [2, 3, new MetadataUpdateStruct()], ['content-2']], |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
|
|
public function providerForCachedLoadMethods(): array |
67
|
|
|
{ |
68
|
|
|
$info = new ContentInfo(['id' => 2]); |
69
|
|
|
$version = new VersionInfo(['versionNo' => 1, 'contentInfo' => $info]); |
70
|
|
|
$content = new Content(['fields' => [], 'versionInfo' => $version]); |
71
|
|
|
|
72
|
|
|
// string $method, array $arguments, string $key, mixed? $data |
73
|
|
|
return [ |
74
|
|
|
['load', [2, 1], 'ez-content-2-1-' . ContentHandler::ALL_TRANSLATIONS_KEY, $content], |
75
|
|
|
['load', [2, 1, ['eng-GB', 'eng-US']], 'ez-content-2-1-eng-GB|eng-US', $content], |
76
|
|
|
['loadContentInfo', [2], 'ez-content-info-2', $info], |
77
|
|
|
['loadContentInfoList', [[2]], 'ez-content-info-2', [2 => $info], true], |
78
|
|
|
['loadContentInfoByRemoteId', ['3d8jrj'], 'ez-content-info-byRemoteId-3d8jrj', $info], |
79
|
|
|
['loadVersionInfo', [2, 1], 'ez-content-version-info-2-1', $version], |
80
|
|
|
['listVersions', [2], 'ez-content-2-version-list', [$version]], |
81
|
|
|
['listVersions', [2, 1], 'ez-content-2-version-list-byStatus-1', [$version]], |
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @covers \eZ\Publish\Core\Persistence\Cache\ContentHandler::deleteContent |
87
|
|
|
*/ |
88
|
|
|
public function testDeleteContent() |
89
|
|
|
{ |
90
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
91
|
|
|
|
92
|
|
|
$innerHandlerMock = $this->createMock(SPIContentHandler::class); |
93
|
|
|
$this->persistenceHandlerMock |
94
|
|
|
->expects($this->exactly(2)) |
95
|
|
|
->method('contentHandler') |
96
|
|
|
->will($this->returnValue($innerHandlerMock)); |
97
|
|
|
|
98
|
|
|
$innerHandlerMock |
99
|
|
|
->expects($this->once()) |
100
|
|
|
->method('loadReverseRelations') |
101
|
|
|
->with(2, APIRelation::FIELD) |
102
|
|
|
->will( |
103
|
|
|
$this->returnValue( |
104
|
|
|
array( |
105
|
|
|
new SPIRelation(array('sourceContentId' => 42)), |
106
|
|
|
) |
107
|
|
|
) |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$innerHandlerMock |
111
|
|
|
->expects($this->once()) |
112
|
|
|
->method('deleteContent') |
113
|
|
|
->with(2) |
114
|
|
|
->will($this->returnValue(true)); |
115
|
|
|
|
116
|
|
|
$this->cacheMock |
117
|
|
|
->expects($this->never()) |
118
|
|
|
->method('deleteItem'); |
119
|
|
|
|
120
|
|
|
$this->cacheMock |
121
|
|
|
->expects($this->at(0)) |
122
|
|
|
->method('invalidateTags') |
123
|
|
|
->with(['content-2']); |
124
|
|
|
|
125
|
|
|
$this->cacheMock |
126
|
|
|
->expects($this->at(1)) |
127
|
|
|
->method('invalidateTags') |
128
|
|
|
->with(['content-fields-42']); |
129
|
|
|
|
130
|
|
|
$handler = $this->persistenceCacheHandler->contentHandler(); |
131
|
|
|
$handler->deleteContent(2); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|