|
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, array $languages, array $expected) |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
$languageHandlerMock = $this->getLanguageHandlerMock(); |
|
36
|
|
|
$languageHandlerMock->expects($this->never())->method('load'); |
|
37
|
|
|
|
|
38
|
|
|
$versionInfo = $this->getDomainMapper()->buildVersionInfoDomainObject($spiVersionInfo); |
|
39
|
|
|
$this->assertInstanceOf(APIVersionInfo::class, $versionInfo); |
|
40
|
|
|
|
|
41
|
|
|
foreach ($expected as $expectedProperty => $expectedValue) { |
|
42
|
|
|
$this->assertAttributeSame( |
|
|
|
|
|
|
43
|
|
|
$expectedValue, |
|
44
|
|
|
$expectedProperty, |
|
45
|
|
|
$versionInfo |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @covers \eZ\Publish\Core\Repository\Helper\DomainMapper::buildLocationWithContent |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testBuildLocationWithContentForRootLocation() |
|
54
|
|
|
{ |
|
55
|
|
|
$spiRootLocation = new Location(['id' => 1, 'parentId' => 1]); |
|
56
|
|
|
$apiRootLocation = $this->getDomainMapper()->buildLocationWithContent($spiRootLocation, null); |
|
57
|
|
|
|
|
58
|
|
|
$expectedContentInfo = new ContentInfo([ |
|
59
|
|
|
'id' => 0, |
|
60
|
|
|
]); |
|
61
|
|
|
$expectedContent = new Content(); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertInstanceOf(APILocation::class, $apiRootLocation); |
|
64
|
|
|
$this->assertEquals($spiRootLocation->id, $apiRootLocation->id); |
|
65
|
|
|
$this->assertEquals($expectedContentInfo->id, $apiRootLocation->getContentInfo()->id); |
|
66
|
|
|
$this->assertEquals($expectedContent, $apiRootLocation->getContent()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @covers \eZ\Publish\Core\Repository\Helper\DomainMapper::buildLocationWithContent |
|
71
|
|
|
*/ |
|
72
|
|
|
public function testBuildLocationWithContentThrowsInvalidArgumentException() |
|
73
|
|
|
{ |
|
74
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
75
|
|
|
$this->expectExceptionMessage('Argument \'$content\' is invalid: Location 2 has missing Content'); |
|
76
|
|
|
|
|
77
|
|
|
$nonRootLocation = new Location(['id' => 2, 'parentId' => 1]); |
|
78
|
|
|
|
|
79
|
|
|
$this->getDomainMapper()->buildLocationWithContent($nonRootLocation, null); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testBuildLocationWithContentIsAlignedWithBuildLocation() |
|
83
|
|
|
{ |
|
84
|
|
|
$spiRootLocation = new Location(['id' => 1, 'parentId' => 1]); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertEquals( |
|
87
|
|
|
$this->getDomainMapper()->buildLocationWithContent($spiRootLocation, null), |
|
88
|
|
|
$this->getDomainMapper()->buildLocation($spiRootLocation) |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function providerForBuildVersionInfo() |
|
93
|
|
|
{ |
|
94
|
|
|
return array( |
|
95
|
|
|
array( |
|
96
|
|
|
new SPIVersionInfo( |
|
97
|
|
|
array( |
|
98
|
|
|
'status' => 44, |
|
99
|
|
|
'contentInfo' => new SPIContentInfo(), |
|
100
|
|
|
) |
|
101
|
|
|
), |
|
102
|
|
|
array(), |
|
103
|
|
|
array('status' => APIVersionInfo::STATUS_DRAFT), |
|
104
|
|
|
), |
|
105
|
|
|
array( |
|
106
|
|
|
new SPIVersionInfo( |
|
107
|
|
|
array( |
|
108
|
|
|
'status' => SPIVersionInfo::STATUS_DRAFT, |
|
109
|
|
|
'contentInfo' => new SPIContentInfo(), |
|
110
|
|
|
) |
|
111
|
|
|
), |
|
112
|
|
|
array(), |
|
113
|
|
|
array('status' => APIVersionInfo::STATUS_DRAFT), |
|
114
|
|
|
), |
|
115
|
|
|
array( |
|
116
|
|
|
new SPIVersionInfo( |
|
117
|
|
|
array( |
|
118
|
|
|
'status' => SPIVersionInfo::STATUS_PENDING, |
|
119
|
|
|
'contentInfo' => new SPIContentInfo(), |
|
120
|
|
|
) |
|
121
|
|
|
), |
|
122
|
|
|
array(), |
|
123
|
|
|
array('status' => APIVersionInfo::STATUS_DRAFT), |
|
124
|
|
|
), |
|
125
|
|
|
array( |
|
126
|
|
|
new SPIVersionInfo( |
|
127
|
|
|
array( |
|
128
|
|
|
'status' => SPIVersionInfo::STATUS_ARCHIVED, |
|
129
|
|
|
'contentInfo' => new SPIContentInfo(), |
|
130
|
|
|
'languageCodes' => array('eng-GB', 'nor-NB', 'fre-FR'), |
|
131
|
|
|
) |
|
132
|
|
|
), |
|
133
|
|
|
array(1 => 'eng-GB', 3 => 'nor-NB', 5 => 'fre-FR'), |
|
134
|
|
|
array( |
|
135
|
|
|
'status' => APIVersionInfo::STATUS_ARCHIVED, |
|
136
|
|
|
'languageCodes' => array('eng-GB', 'nor-NB', 'fre-FR'), |
|
137
|
|
|
), |
|
138
|
|
|
), |
|
139
|
|
|
array( |
|
140
|
|
|
new SPIVersionInfo( |
|
141
|
|
|
array( |
|
142
|
|
|
'status' => SPIVersionInfo::STATUS_PUBLISHED, |
|
143
|
|
|
'contentInfo' => new SPIContentInfo(), |
|
144
|
|
|
) |
|
145
|
|
|
), |
|
146
|
|
|
array(), |
|
147
|
|
|
array('status' => APIVersionInfo::STATUS_PUBLISHED), |
|
148
|
|
|
), |
|
149
|
|
|
); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function providerForBuildLocationDomainObjectsOnSearchResult() |
|
153
|
|
|
{ |
|
154
|
|
|
$locationHits = [ |
|
155
|
|
|
new Location(['id' => 21, 'contentId' => 32]), |
|
156
|
|
|
new Location(['id' => 22, 'contentId' => 33]), |
|
157
|
|
|
]; |
|
158
|
|
|
|
|
159
|
|
|
return [ |
|
160
|
|
|
[$locationHits, [32, 33], [], [32 => new ContentInfo(['id' => 32]), 33 => new ContentInfo(['id' => 33])], 0], |
|
161
|
|
|
[$locationHits, [32, 33], ['languages' => ['eng-GB']], [32 => new ContentInfo(['id' => 32])], 1], |
|
162
|
|
|
[$locationHits, [32, 33], ['languages' => ['eng-GB']], [], 2], |
|
163
|
|
|
]; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @covers \eZ\Publish\Core\Repository\Helper\DomainMapper::buildLocationDomainObjectsOnSearchResult |
|
168
|
|
|
* @dataProvider providerForBuildLocationDomainObjectsOnSearchResult |
|
169
|
|
|
* |
|
170
|
|
|
* @param array $locationHits |
|
171
|
|
|
* @param array $contentIds |
|
172
|
|
|
* @param array $languageFilter |
|
173
|
|
|
* @param array $contentInfoList |
|
174
|
|
|
* @param int $missing |
|
175
|
|
|
*/ |
|
176
|
|
|
public function testBuildLocationDomainObjectsOnSearchResult( |
|
177
|
|
|
array $locationHits, |
|
178
|
|
|
array $contentIds, |
|
179
|
|
|
array $languageFilter, |
|
180
|
|
|
array $contentInfoList, |
|
181
|
|
|
int $missing |
|
182
|
|
|
) { |
|
183
|
|
|
$contentHandlerMock = $this->getContentHandlerMock(); |
|
184
|
|
|
$contentHandlerMock |
|
185
|
|
|
->expects($this->once()) |
|
186
|
|
|
->method('loadContentInfoList') |
|
187
|
|
|
->with($contentIds) |
|
188
|
|
|
->willReturn($contentInfoList); |
|
189
|
|
|
|
|
190
|
|
|
$result = new SearchResult(['totalCount' => 10]); |
|
191
|
|
|
foreach ($locationHits as $locationHit) { |
|
192
|
|
|
$result->searchHits[] = new SearchHit(['valueObject' => $locationHit]); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
$spiResult = clone $result; |
|
196
|
|
|
$missingLocations = $this->getDomainMapper()->buildLocationDomainObjectsOnSearchResult($result, $languageFilter); |
|
197
|
|
|
$this->assertInternalType('array', $missingLocations); |
|
|
|
|
|
|
198
|
|
|
|
|
199
|
|
|
if (!$missing) { |
|
200
|
|
|
$this->assertEmpty($missingLocations); |
|
201
|
|
|
} else { |
|
202
|
|
|
$this->assertNotEmpty($missingLocations); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
$this->assertCount($missing, $missingLocations); |
|
206
|
|
|
$this->assertEquals($spiResult->totalCount - $missing, $result->totalCount); |
|
207
|
|
|
$this->assertCount(count($spiResult->searchHits) - $missing, $result->searchHits); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* Returns DomainMapper. |
|
212
|
|
|
* |
|
213
|
|
|
* @return \eZ\Publish\Core\Repository\Helper\DomainMapper |
|
214
|
|
|
*/ |
|
215
|
|
|
protected function getDomainMapper() |
|
216
|
|
|
{ |
|
217
|
|
|
return new DomainMapper( |
|
218
|
|
|
$this->getContentHandlerMock(), |
|
|
|
|
|
|
219
|
|
|
$this->getPersistenceMockHandler('Content\\Location\\Handler'), |
|
220
|
|
|
$this->getTypeHandlerMock(), |
|
|
|
|
|
|
221
|
|
|
$this->getContentTypeDomainMapperMock(), |
|
|
|
|
|
|
222
|
|
|
$this->getLanguageHandlerMock(), |
|
|
|
|
|
|
223
|
|
|
$this->getFieldTypeRegistryMock() |
|
|
|
|
|
|
224
|
|
|
); |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* @return \eZ\Publish\SPI\Persistence\Content\Handler|\PHPUnit\Framework\MockObject\MockObject |
|
229
|
|
|
*/ |
|
230
|
|
|
protected function getContentHandlerMock() |
|
231
|
|
|
{ |
|
232
|
|
|
return $this->getPersistenceMockHandler('Content\\Handler'); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* @return \eZ\Publish\SPI\Persistence\Content\Language\Handler|\PHPUnit\Framework\MockObject\MockObject |
|
237
|
|
|
*/ |
|
238
|
|
|
protected function getLanguageHandlerMock() |
|
239
|
|
|
{ |
|
240
|
|
|
return $this->getPersistenceMockHandler('Content\\Language\\Handler'); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* @return \eZ\Publish\SPI\Persistence\Content\Type\Handler|\PHPUnit\Framework\MockObject\MockObject |
|
245
|
|
|
*/ |
|
246
|
|
|
protected function getTypeHandlerMock() |
|
247
|
|
|
{ |
|
248
|
|
|
return $this->getPersistenceMockHandler('Content\\Type\\Handler'); |
|
249
|
|
|
} |
|
250
|
|
|
} |
|
251
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.