|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File contains: eZ\Publish\Core\Repository\Tests\Service\Mock\DomainMapperTest 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\Repository\Tests\Service\Mock; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Exceptions\InvalidArgumentException; |
|
12
|
|
|
use eZ\Publish\API\Repository\Values\Content\Search\SearchHit; |
|
13
|
|
|
use eZ\Publish\API\Repository\Values\Content\Search\SearchResult; |
|
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\VersionInfo as APIVersionInfo; |
|
15
|
|
|
use eZ\Publish\Core\Repository\Tests\Service\Mock\Base as BaseServiceMockTest; |
|
16
|
|
|
use eZ\Publish\Core\Repository\Helper\DomainMapper; |
|
17
|
|
|
use eZ\Publish\Core\Repository\Values\Content\Content; |
|
18
|
|
|
use eZ\Publish\SPI\Persistence\Content\ContentInfo; |
|
19
|
|
|
use eZ\Publish\SPI\Persistence\Content\Location; |
|
20
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location as APILocation; |
|
21
|
|
|
use eZ\Publish\SPI\Persistence\Content\VersionInfo as SPIVersionInfo; |
|
22
|
|
|
use eZ\Publish\SPI\Persistence\Content\ContentInfo as SPIContentInfo; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Mock test case for internal DomainMapper. |
|
26
|
|
|
*/ |
|
27
|
|
|
class DomainMapperTest extends BaseServiceMockTest |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @covers \eZ\Publish\Core\Repository\Helper\DomainMapper::buildVersionInfoDomainObject |
|
31
|
|
|
* @dataProvider providerForBuildVersionInfo |
|
32
|
|
|
*/ |
|
33
|
|
|
public function testBuildVersionInfo(SPIVersionInfo $spiVersionInfo) |
|
34
|
|
|
{ |
|
35
|
|
|
$languageHandlerMock = $this->getLanguageHandlerMock(); |
|
36
|
|
|
$languageHandlerMock->expects($this->never())->method('load'); |
|
37
|
|
|
|
|
38
|
|
|
$versionInfo = $this->getDomainMapper()->buildVersionInfoDomainObject($spiVersionInfo); |
|
39
|
|
|
|
|
40
|
|
|
$this->assertInstanceOf(APIVersionInfo::class, $versionInfo); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @covers \eZ\Publish\Core\Repository\Helper\DomainMapper::buildLocationWithContent |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testBuildLocationWithContentForRootLocation() |
|
47
|
|
|
{ |
|
48
|
|
|
$spiRootLocation = new Location(['id' => 1, 'parentId' => 1]); |
|
49
|
|
|
$apiRootLocation = $this->getDomainMapper()->buildLocationWithContent($spiRootLocation, null); |
|
50
|
|
|
|
|
51
|
|
|
$expectedContentInfo = new ContentInfo([ |
|
52
|
|
|
'id' => 0, |
|
53
|
|
|
]); |
|
54
|
|
|
$expectedContent = new Content(); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertInstanceOf(APILocation::class, $apiRootLocation); |
|
57
|
|
|
$this->assertEquals($spiRootLocation->id, $apiRootLocation->id); |
|
58
|
|
|
$this->assertEquals($expectedContentInfo->id, $apiRootLocation->getContentInfo()->id); |
|
59
|
|
|
$this->assertEquals($expectedContent, $apiRootLocation->getContent()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @covers \eZ\Publish\Core\Repository\Helper\DomainMapper::buildLocationWithContent |
|
64
|
|
|
*/ |
|
65
|
|
|
public function testBuildLocationWithContentThrowsInvalidArgumentException() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
68
|
|
|
$this->expectExceptionMessage('Argument \'$content\' is invalid: Location 2 has missing Content'); |
|
69
|
|
|
|
|
70
|
|
|
$nonRootLocation = new Location(['id' => 2, 'parentId' => 1]); |
|
71
|
|
|
|
|
72
|
|
|
$this->getDomainMapper()->buildLocationWithContent($nonRootLocation, null); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function testBuildLocationWithContentIsAlignedWithBuildLocation() |
|
76
|
|
|
{ |
|
77
|
|
|
$spiRootLocation = new Location(['id' => 1, 'parentId' => 1]); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertEquals( |
|
80
|
|
|
$this->getDomainMapper()->buildLocationWithContent($spiRootLocation, null), |
|
81
|
|
|
$this->getDomainMapper()->buildLocation($spiRootLocation) |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function providerForBuildVersionInfo() |
|
86
|
|
|
{ |
|
87
|
|
|
return array( |
|
88
|
|
|
array( |
|
89
|
|
|
new SPIVersionInfo( |
|
90
|
|
|
array( |
|
91
|
|
|
'status' => 44, |
|
92
|
|
|
'contentInfo' => new SPIContentInfo(), |
|
93
|
|
|
) |
|
94
|
|
|
), |
|
95
|
|
|
), |
|
96
|
|
|
array( |
|
97
|
|
|
new SPIVersionInfo( |
|
98
|
|
|
array( |
|
99
|
|
|
'status' => SPIVersionInfo::STATUS_DRAFT, |
|
100
|
|
|
'contentInfo' => new SPIContentInfo(), |
|
101
|
|
|
) |
|
102
|
|
|
), |
|
103
|
|
|
), |
|
104
|
|
|
array( |
|
105
|
|
|
new SPIVersionInfo( |
|
106
|
|
|
array( |
|
107
|
|
|
'status' => SPIVersionInfo::STATUS_PENDING, |
|
108
|
|
|
'contentInfo' => new SPIContentInfo(), |
|
109
|
|
|
) |
|
110
|
|
|
), |
|
111
|
|
|
), |
|
112
|
|
|
array( |
|
113
|
|
|
new SPIVersionInfo( |
|
114
|
|
|
array( |
|
115
|
|
|
'status' => SPIVersionInfo::STATUS_ARCHIVED, |
|
116
|
|
|
'contentInfo' => new SPIContentInfo(), |
|
117
|
|
|
'languageCodes' => array('eng-GB', 'nor-NB', 'fre-FR'), |
|
118
|
|
|
) |
|
119
|
|
|
), |
|
120
|
|
|
), |
|
121
|
|
|
array( |
|
122
|
|
|
new SPIVersionInfo( |
|
123
|
|
|
array( |
|
124
|
|
|
'status' => SPIVersionInfo::STATUS_PUBLISHED, |
|
125
|
|
|
'contentInfo' => new SPIContentInfo(), |
|
126
|
|
|
) |
|
127
|
|
|
), |
|
128
|
|
|
), |
|
129
|
|
|
); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function providerForBuildLocationDomainObjectsOnSearchResult() |
|
133
|
|
|
{ |
|
134
|
|
|
$locationHits = [ |
|
135
|
|
|
new Location(['id' => 21, 'contentId' => 32]), |
|
136
|
|
|
new Location(['id' => 22, 'contentId' => 33]), |
|
137
|
|
|
]; |
|
138
|
|
|
|
|
139
|
|
|
return [ |
|
140
|
|
|
[$locationHits, [32, 33], [], [32 => new ContentInfo(['id' => 32]), 33 => new ContentInfo(['id' => 33])], 0], |
|
141
|
|
|
[$locationHits, [32, 33], ['languages' => ['eng-GB']], [32 => new ContentInfo(['id' => 32])], 1], |
|
142
|
|
|
[$locationHits, [32, 33], ['languages' => ['eng-GB']], [], 2], |
|
143
|
|
|
]; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @covers \eZ\Publish\Core\Repository\Helper\DomainMapper::buildLocationDomainObjectsOnSearchResult |
|
148
|
|
|
* @dataProvider providerForBuildLocationDomainObjectsOnSearchResult |
|
149
|
|
|
* |
|
150
|
|
|
* @param array $locationHits |
|
151
|
|
|
* @param array $contentIds |
|
152
|
|
|
* @param array $languageFilter |
|
153
|
|
|
* @param array $contentInfoList |
|
154
|
|
|
* @param int $missing |
|
155
|
|
|
*/ |
|
156
|
|
|
public function testBuildLocationDomainObjectsOnSearchResult( |
|
157
|
|
|
array $locationHits, |
|
158
|
|
|
array $contentIds, |
|
159
|
|
|
array $languageFilter, |
|
160
|
|
|
array $contentInfoList, |
|
161
|
|
|
int $missing |
|
162
|
|
|
) { |
|
163
|
|
|
$contentHandlerMock = $this->getContentHandlerMock(); |
|
164
|
|
|
$contentHandlerMock |
|
165
|
|
|
->expects($this->once()) |
|
166
|
|
|
->method('loadContentInfoList') |
|
167
|
|
|
->with($contentIds) |
|
168
|
|
|
->willReturn($contentInfoList); |
|
169
|
|
|
|
|
170
|
|
|
$result = new SearchResult(['totalCount' => 10]); |
|
171
|
|
|
foreach ($locationHits as $locationHit) { |
|
172
|
|
|
$result->searchHits[] = new SearchHit(['valueObject' => $locationHit]); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
$spiResult = clone $result; |
|
176
|
|
|
$missingLocations = $this->getDomainMapper()->buildLocationDomainObjectsOnSearchResult($result, $languageFilter); |
|
177
|
|
|
$this->assertIsArray($missingLocations); |
|
178
|
|
|
|
|
179
|
|
|
if (!$missing) { |
|
180
|
|
|
$this->assertEmpty($missingLocations); |
|
181
|
|
|
} else { |
|
182
|
|
|
$this->assertNotEmpty($missingLocations); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
$this->assertCount($missing, $missingLocations); |
|
186
|
|
|
$this->assertEquals($spiResult->totalCount - $missing, $result->totalCount); |
|
187
|
|
|
$this->assertCount(count($spiResult->searchHits) - $missing, $result->searchHits); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* Returns DomainMapper. |
|
192
|
|
|
* |
|
193
|
|
|
* @return \eZ\Publish\Core\Repository\Helper\DomainMapper |
|
194
|
|
|
*/ |
|
195
|
|
|
protected function getDomainMapper() |
|
196
|
|
|
{ |
|
197
|
|
|
return new DomainMapper( |
|
198
|
|
|
$this->getContentHandlerMock(), |
|
|
|
|
|
|
199
|
|
|
$this->getPersistenceMockHandler('Content\\Location\\Handler'), |
|
200
|
|
|
$this->getTypeHandlerMock(), |
|
|
|
|
|
|
201
|
|
|
$this->getContentTypeDomainMapperMock(), |
|
|
|
|
|
|
202
|
|
|
$this->getLanguageHandlerMock(), |
|
|
|
|
|
|
203
|
|
|
$this->getFieldTypeRegistryMock() |
|
|
|
|
|
|
204
|
|
|
); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* @return \eZ\Publish\SPI\Persistence\Content\Handler|\PHPUnit\Framework\MockObject\MockObject |
|
209
|
|
|
*/ |
|
210
|
|
|
protected function getContentHandlerMock() |
|
211
|
|
|
{ |
|
212
|
|
|
return $this->getPersistenceMockHandler('Content\\Handler'); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* @return \eZ\Publish\SPI\Persistence\Content\Language\Handler|\PHPUnit\Framework\MockObject\MockObject |
|
217
|
|
|
*/ |
|
218
|
|
|
protected function getLanguageHandlerMock() |
|
219
|
|
|
{ |
|
220
|
|
|
return $this->getPersistenceMockHandler('Content\\Language\\Handler'); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* @return \eZ\Publish\SPI\Persistence\Content\Type\Handler|\PHPUnit\Framework\MockObject\MockObject |
|
225
|
|
|
*/ |
|
226
|
|
|
protected function getTypeHandlerMock() |
|
227
|
|
|
{ |
|
228
|
|
|
return $this->getPersistenceMockHandler('Content\\Type\\Handler'); |
|
229
|
|
|
} |
|
230
|
|
|
} |
|
231
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.