1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the ContentServiceTest 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\API\Repository\Tests; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Exceptions\BadStateException; |
12
|
|
|
use eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException; |
13
|
|
|
use eZ\Publish\API\Repository\Exceptions\InvalidArgumentException as APIInvalidArgumentException; |
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\Content; |
15
|
|
|
use eZ\Publish\API\Repository\Exceptions\UnauthorizedException; |
16
|
|
|
use eZ\Publish\API\Repository\Values\Content\ContentCreateStruct; |
17
|
|
|
use eZ\Publish\API\Repository\Values\Content\ContentInfo; |
18
|
|
|
use eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct; |
19
|
|
|
use eZ\Publish\API\Repository\Values\Content\Field; |
20
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
21
|
|
|
use eZ\Publish\API\Repository\Values\Content\DraftList\Item\UnauthorizedContentDraftListItem; |
22
|
|
|
use eZ\Publish\API\Repository\Values\Content\URLAlias; |
23
|
|
|
use eZ\Publish\API\Repository\Values\Content\Relation; |
24
|
|
|
use eZ\Publish\API\Repository\Values\Content\VersionInfo; |
25
|
|
|
use eZ\Publish\API\Repository\Values\User\Limitation\SectionLimitation; |
26
|
|
|
use eZ\Publish\API\Repository\Values\User\Limitation\LocationLimitation; |
27
|
|
|
use eZ\Publish\API\Repository\Values\User\Limitation\ContentTypeLimitation; |
28
|
|
|
use eZ\Publish\API\Repository\Exceptions\NotFoundException; |
29
|
|
|
use DOMDocument; |
30
|
|
|
use Exception; |
31
|
|
|
use eZ\Publish\API\Repository\Values\User\User; |
32
|
|
|
use eZ\Publish\Core\Base\Exceptions\UnauthorizedException as CoreUnauthorizedException; |
33
|
|
|
use eZ\Publish\Core\Repository\Values\Content\ContentUpdateStruct; |
34
|
|
|
use InvalidArgumentException; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Test case for operations in the ContentService using in memory storage. |
38
|
|
|
* |
39
|
|
|
* @see \eZ\Publish\API\Repository\ContentService |
40
|
|
|
* @group content |
41
|
|
|
*/ |
42
|
|
|
class ContentServiceTest extends BaseContentServiceTest |
43
|
|
|
{ |
44
|
|
|
private const ADMINISTRATORS_USER_GROUP_NAME = 'Administrators'; |
45
|
|
|
private const ADMINISTRATORS_USER_GROUP_ID = 12; |
46
|
|
|
private const ADMINISTRATORS_USER_GROUP_LOCATION_ID = 13; |
47
|
|
|
|
48
|
|
|
private const WRITERS_USER_GROUP_NAME = 'Writers'; |
49
|
|
|
|
50
|
|
|
private const MEMBERS_USER_GROUP_ID = 11; |
51
|
|
|
|
52
|
|
|
private const MEDIA_CONTENT_ID = 41; |
53
|
|
|
|
54
|
|
|
private const MEDIA_REMOTE_ID = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
55
|
|
|
private const DEMO_DESIGN_REMOTE_ID = '8b8b22fe3c6061ed500fbd2b377b885f'; |
56
|
|
|
|
57
|
|
|
private const FORUM_IDENTIFIER = 'forum'; |
58
|
|
|
|
59
|
|
|
private const ENG_US = 'eng-US'; |
60
|
|
|
private const GER_DE = 'ger-DE'; |
61
|
|
|
private const ENG_GB = 'eng-GB'; |
62
|
|
|
|
63
|
|
|
/** @var \eZ\Publish\API\Repository\PermissionResolver */ |
64
|
|
|
private $permissionResolver; |
65
|
|
|
|
66
|
|
|
/** @var \eZ\Publish\API\Repository\ContentService */ |
67
|
|
|
private $contentService; |
68
|
|
|
|
69
|
|
|
/** @var \eZ\Publish\API\Repository\LocationService */ |
70
|
|
|
private $locationService; |
71
|
|
|
|
72
|
|
|
public function setUp(): void |
73
|
|
|
{ |
74
|
|
|
parent::setUp(); |
75
|
|
|
|
76
|
|
|
$repository = $this->getRepository(); |
77
|
|
|
$this->permissionResolver = $repository->getPermissionResolver(); |
78
|
|
|
$this->contentService = $repository->getContentService(); |
79
|
|
|
$this->locationService = $repository->getLocationService(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Test for the newContentCreateStruct() method. |
84
|
|
|
* |
85
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::newContentCreateStruct() |
86
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeByIdentifier |
87
|
|
|
* @group user |
88
|
|
|
* @group field-type |
89
|
|
|
*/ |
90
|
|
|
public function testNewContentCreateStruct() |
91
|
|
|
{ |
92
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
93
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
94
|
|
|
|
95
|
|
|
$contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
96
|
|
|
|
97
|
|
|
$this->assertInstanceOf(ContentCreateStruct::class, $contentCreate); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Test for the createContent() method. |
102
|
|
|
* |
103
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
104
|
|
|
* |
105
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent() |
106
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentCreateStruct |
107
|
|
|
* @group user |
108
|
|
|
* @group field-type |
109
|
|
|
*/ |
110
|
|
|
public function testCreateContent() |
111
|
|
|
{ |
112
|
|
|
if ($this->isVersion4()) { |
113
|
|
|
$this->markTestSkipped('This test requires eZ Publish 5'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
117
|
|
|
|
118
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
119
|
|
|
|
120
|
|
|
$contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
121
|
|
|
$contentCreate->setField('name', 'My awesome forum'); |
122
|
|
|
|
123
|
|
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
124
|
|
|
$contentCreate->alwaysAvailable = true; |
125
|
|
|
|
126
|
|
|
$content = $this->contentService->createContent($contentCreate); |
127
|
|
|
|
128
|
|
|
$this->assertInstanceOf(Content::class, $content); |
129
|
|
|
|
130
|
|
|
return $content; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Test for the createContent() method. |
135
|
|
|
* |
136
|
|
|
* Tests made for issue #EZP-20955 where Anonymous user is granted access to create content |
137
|
|
|
* and should have access to do that. |
138
|
|
|
* |
139
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
140
|
|
|
* |
141
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent() |
142
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentCreateStruct |
143
|
|
|
* @group user |
144
|
|
|
* @group field-type |
145
|
|
|
*/ |
146
|
|
|
public function testCreateContentAndPublishWithPrivilegedAnonymousUser() |
147
|
|
|
{ |
148
|
|
|
if ($this->isVersion4()) { |
149
|
|
|
$this->markTestSkipped('This test requires eZ Publish 5'); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
153
|
|
|
|
154
|
|
|
$repository = $this->getRepository(); |
155
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
156
|
|
|
$roleService = $repository->getRoleService(); |
157
|
|
|
|
158
|
|
|
// Give Anonymous user role additional rights |
159
|
|
|
$role = $roleService->loadRoleByIdentifier('Anonymous'); |
160
|
|
|
$roleDraft = $roleService->createRoleDraft($role); |
161
|
|
|
$policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'create'); |
162
|
|
|
$policyCreateStruct->addLimitation(new SectionLimitation(['limitationValues' => [1]])); |
163
|
|
|
$policyCreateStruct->addLimitation(new LocationLimitation(['limitationValues' => [2]])); |
164
|
|
|
$policyCreateStruct->addLimitation(new ContentTypeLimitation(['limitationValues' => [1]])); |
165
|
|
|
$roleDraft = $roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct); |
166
|
|
|
|
167
|
|
|
$policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'publish'); |
168
|
|
|
$policyCreateStruct->addLimitation(new SectionLimitation(['limitationValues' => [1]])); |
169
|
|
|
$policyCreateStruct->addLimitation(new LocationLimitation(['limitationValues' => [2]])); |
170
|
|
|
$policyCreateStruct->addLimitation(new ContentTypeLimitation(['limitationValues' => [1]])); |
171
|
|
|
$roleDraft = $roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct); |
172
|
|
|
$roleService->publishRoleDraft($roleDraft); |
173
|
|
|
|
174
|
|
|
// Set Anonymous user as current |
175
|
|
|
$repository->getPermissionResolver()->setCurrentUserReference($repository->getUserService()->loadUser($anonymousUserId)); |
176
|
|
|
|
177
|
|
|
// Create a new content object: |
178
|
|
|
$contentCreate = $this->contentService->newContentCreateStruct( |
179
|
|
|
$contentTypeService->loadContentTypeByIdentifier('folder'), |
180
|
|
|
self::ENG_GB |
181
|
|
|
); |
182
|
|
|
|
183
|
|
|
$contentCreate->setField('name', 'Folder 1'); |
184
|
|
|
|
185
|
|
|
$content = $this->contentService->createContent( |
186
|
|
|
$contentCreate, |
187
|
|
|
[$this->locationService->newLocationCreateStruct(2)] |
188
|
|
|
); |
189
|
|
|
|
190
|
|
|
$this->contentService->publishVersion( |
191
|
|
|
$content->getVersionInfo() |
192
|
|
|
); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Test for the createContent() method. |
197
|
|
|
* |
198
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $content |
199
|
|
|
* |
200
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
201
|
|
|
* |
202
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent() |
203
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
204
|
|
|
*/ |
205
|
|
|
public function testCreateContentSetsContentInfo($content) |
206
|
|
|
{ |
207
|
|
|
$this->assertInstanceOf(ContentInfo::class, $content->contentInfo); |
208
|
|
|
|
209
|
|
|
return $content; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Test for the createContent() method. |
214
|
|
|
* |
215
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $content |
216
|
|
|
* |
217
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent() |
218
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentSetsContentInfo |
219
|
|
|
*/ |
220
|
|
|
public function testCreateContentSetsExpectedContentInfo($content) |
221
|
|
|
{ |
222
|
|
|
$this->assertEquals( |
223
|
|
|
[ |
224
|
|
|
$content->id, |
225
|
|
|
28, // id of content type "forum" |
226
|
|
|
true, |
227
|
|
|
1, |
228
|
|
|
'abcdef0123456789abcdef0123456789', |
229
|
|
|
self::ENG_US, |
230
|
|
|
$this->getRepository()->getCurrentUser()->id, |
|
|
|
|
231
|
|
|
false, |
232
|
|
|
null, |
233
|
|
|
// Main Location id for unpublished Content should be null |
234
|
|
|
null, |
235
|
|
|
], |
236
|
|
|
[ |
237
|
|
|
$content->contentInfo->id, |
238
|
|
|
$content->contentInfo->contentTypeId, |
239
|
|
|
$content->contentInfo->alwaysAvailable, |
240
|
|
|
$content->contentInfo->currentVersionNo, |
241
|
|
|
$content->contentInfo->remoteId, |
242
|
|
|
$content->contentInfo->mainLanguageCode, |
243
|
|
|
$content->contentInfo->ownerId, |
244
|
|
|
$content->contentInfo->published, |
245
|
|
|
$content->contentInfo->publishedDate, |
246
|
|
|
$content->contentInfo->mainLocationId, |
247
|
|
|
] |
248
|
|
|
); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Test for the createContent() method. |
253
|
|
|
* |
254
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $content |
255
|
|
|
* |
256
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
257
|
|
|
* |
258
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent() |
259
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
260
|
|
|
*/ |
261
|
|
|
public function testCreateContentSetsVersionInfo($content) |
262
|
|
|
{ |
263
|
|
|
$this->assertInstanceOf(VersionInfo::class, $content->getVersionInfo()); |
264
|
|
|
|
265
|
|
|
return $content; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Test for the createContent() method. |
270
|
|
|
* |
271
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $content |
272
|
|
|
* |
273
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent() |
274
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentSetsVersionInfo |
275
|
|
|
*/ |
276
|
|
|
public function testCreateContentSetsExpectedVersionInfo($content) |
277
|
|
|
{ |
278
|
|
|
$this->assertEquals( |
279
|
|
|
[ |
280
|
|
|
'status' => VersionInfo::STATUS_DRAFT, |
281
|
|
|
'versionNo' => 1, |
282
|
|
|
'creatorId' => $this->getRepository()->getCurrentUser()->id, |
|
|
|
|
283
|
|
|
'initialLanguageCode' => self::ENG_US, |
284
|
|
|
], |
285
|
|
|
[ |
286
|
|
|
'status' => $content->getVersionInfo()->status, |
287
|
|
|
'versionNo' => $content->getVersionInfo()->versionNo, |
288
|
|
|
'creatorId' => $content->getVersionInfo()->creatorId, |
289
|
|
|
'initialLanguageCode' => $content->getVersionInfo()->initialLanguageCode, |
290
|
|
|
] |
291
|
|
|
); |
292
|
|
|
$this->assertTrue($content->getVersionInfo()->isDraft()); |
293
|
|
|
$this->assertFalse($content->getVersionInfo()->isPublished()); |
294
|
|
|
$this->assertFalse($content->getVersionInfo()->isArchived()); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* Test for the createContent() method. |
299
|
|
|
* |
300
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $content |
301
|
|
|
* |
302
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent() |
303
|
|
|
* @depends testCreateContent |
304
|
|
|
*/ |
305
|
|
|
public function testCreateContentSetsExpectedContentType($content) |
306
|
|
|
{ |
307
|
|
|
$contentType = $content->getContentType(); |
308
|
|
|
|
309
|
|
|
$this->assertEquals( |
310
|
|
|
[ |
311
|
|
|
$contentType->id, |
312
|
|
|
// Won't match as it's set to true in createContentDraftVersion1() |
313
|
|
|
//$contentType->defaultAlwaysAvailable, |
314
|
|
|
//$contentType->defaultSortField, |
315
|
|
|
//$contentType->defaultSortOrder, |
316
|
|
|
], |
317
|
|
|
[ |
318
|
|
|
$content->contentInfo->contentTypeId, |
319
|
|
|
//$content->contentInfo->alwaysAvailable, |
320
|
|
|
//$location->sortField, |
321
|
|
|
//$location->sortOrder, |
322
|
|
|
] |
323
|
|
|
); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Test for the createContent() method. |
328
|
|
|
* |
329
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent() |
330
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
331
|
|
|
*/ |
332
|
|
|
public function testCreateContentThrowsInvalidArgumentException() |
333
|
|
|
{ |
334
|
|
|
if ($this->isVersion4()) { |
335
|
|
|
$this->markTestSkipped('This test requires eZ Publish 5'); |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
339
|
|
|
|
340
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
341
|
|
|
|
342
|
|
|
$contentCreate1 = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
343
|
|
|
$contentCreate1->setField('name', 'An awesome Sidelfingen forum'); |
344
|
|
|
|
345
|
|
|
$contentCreate1->remoteId = 'abcdef0123456789abcdef0123456789'; |
346
|
|
|
$contentCreate1->alwaysAvailable = true; |
347
|
|
|
|
348
|
|
|
$draft = $this->contentService->createContent($contentCreate1); |
349
|
|
|
$this->contentService->publishVersion($draft->versionInfo); |
350
|
|
|
|
351
|
|
|
$contentCreate2 = $this->contentService->newContentCreateStruct($contentType, self::ENG_GB); |
352
|
|
|
$contentCreate2->setField('name', 'An awesome Bielefeld forum'); |
353
|
|
|
|
354
|
|
|
$contentCreate2->remoteId = 'abcdef0123456789abcdef0123456789'; |
355
|
|
|
$contentCreate2->alwaysAvailable = false; |
356
|
|
|
|
357
|
|
|
$this->expectException(APIInvalidArgumentException::class); |
358
|
|
|
$this->contentService->createContent($contentCreate2); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* Test for the createContent() method. |
363
|
|
|
* |
364
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent() |
365
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
366
|
|
|
*/ |
367
|
|
|
public function testCreateContentThrowsInvalidArgumentExceptionOnFieldTypeNotAccept() |
368
|
|
|
{ |
369
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
370
|
|
|
|
371
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
372
|
|
|
|
373
|
|
|
$contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
374
|
|
|
// The name field does only accept strings and null as its values |
375
|
|
|
$contentCreate->setField('name', new \stdClass()); |
376
|
|
|
|
377
|
|
|
$this->expectException(APIInvalidArgumentException::class); |
378
|
|
|
$this->contentService->createContent($contentCreate); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* Test for the createContent() method. |
383
|
|
|
* |
384
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent() |
385
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
386
|
|
|
*/ |
387
|
|
|
public function testCreateContentThrowsContentFieldValidationException() |
388
|
|
|
{ |
389
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
390
|
|
|
|
391
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
392
|
|
|
|
393
|
|
|
$contentCreate1 = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
394
|
|
|
$contentCreate1->setField('name', 'An awesome Sidelfingen folder'); |
395
|
|
|
// Violates string length constraint |
396
|
|
|
$contentCreate1->setField('short_name', str_repeat('a', 200)); |
397
|
|
|
|
398
|
|
|
$this->expectException(ContentFieldValidationException::class); |
399
|
|
|
|
400
|
|
|
// Throws ContentFieldValidationException, since short_name does not pass validation of the string length validator |
401
|
|
|
$this->contentService->createContent($contentCreate1); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* Test for the createContent() method. |
406
|
|
|
* |
407
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent() |
408
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
409
|
|
|
*/ |
410
|
|
|
public function testCreateContentRequiredFieldMissing() |
411
|
|
|
{ |
412
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
413
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
414
|
|
|
|
415
|
|
|
$contentCreate1 = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
416
|
|
|
// Required field "name" is not set |
417
|
|
|
|
418
|
|
|
$this->expectException(ContentFieldValidationException::class); |
419
|
|
|
|
420
|
|
|
// Throws a ContentFieldValidationException, since a required field is missing |
421
|
|
|
$this->contentService->createContent($contentCreate1); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* Test for the createContent() method. |
426
|
|
|
* |
427
|
|
|
* NOTE: We have bidirectional dependencies between the ContentService and |
428
|
|
|
* the LocationService, so that we cannot use PHPUnit's test dependencies |
429
|
|
|
* here. |
430
|
|
|
* |
431
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs) |
432
|
|
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation |
433
|
|
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationByRemoteId |
434
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
435
|
|
|
* @group user |
436
|
|
|
*/ |
437
|
|
|
public function testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately() |
438
|
|
|
{ |
439
|
|
|
$this->createContentDraftVersion1(); |
440
|
|
|
|
441
|
|
|
$this->expectException(NotFoundException::class); |
442
|
|
|
|
443
|
|
|
// The location will not have been created, yet, so this throws an exception |
444
|
|
|
$this->locationService->loadLocationByRemoteId('0123456789abcdef0123456789abcdef'); |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
/** |
448
|
|
|
* Test for the createContent() method. |
449
|
|
|
* |
450
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs) |
451
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately |
452
|
|
|
*/ |
453
|
|
|
public function testCreateContentThrowsInvalidArgumentExceptionWithLocationCreateParameter() |
454
|
|
|
{ |
455
|
|
|
$parentLocationId = $this->generateId('location', 56); |
456
|
|
|
// $parentLocationId is a valid location ID |
457
|
|
|
|
458
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
459
|
|
|
|
460
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
461
|
|
|
|
462
|
|
|
// Configure new locations |
463
|
|
|
$locationCreate1 = $this->locationService->newLocationCreateStruct($parentLocationId); |
464
|
|
|
|
465
|
|
|
$locationCreate1->priority = 23; |
466
|
|
|
$locationCreate1->hidden = true; |
467
|
|
|
$locationCreate1->remoteId = '0123456789abcdef0123456789aaaaaa'; |
468
|
|
|
$locationCreate1->sortField = Location::SORT_FIELD_NODE_ID; |
469
|
|
|
$locationCreate1->sortOrder = Location::SORT_ORDER_DESC; |
470
|
|
|
|
471
|
|
|
$locationCreate2 = $this->locationService->newLocationCreateStruct($parentLocationId); |
472
|
|
|
|
473
|
|
|
$locationCreate2->priority = 42; |
474
|
|
|
$locationCreate2->hidden = true; |
475
|
|
|
$locationCreate2->remoteId = '0123456789abcdef0123456789bbbbbb'; |
476
|
|
|
$locationCreate2->sortField = Location::SORT_FIELD_NODE_ID; |
477
|
|
|
$locationCreate2->sortOrder = Location::SORT_ORDER_DESC; |
478
|
|
|
|
479
|
|
|
// Configure new content object |
480
|
|
|
$contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
481
|
|
|
|
482
|
|
|
$contentCreate->setField('name', 'A awesome Sindelfingen forum'); |
483
|
|
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
484
|
|
|
$contentCreate->alwaysAvailable = true; |
485
|
|
|
|
486
|
|
|
// Create new content object under the specified location |
487
|
|
|
$draft = $this->contentService->createContent( |
488
|
|
|
$contentCreate, |
489
|
|
|
[$locationCreate1] |
490
|
|
|
); |
491
|
|
|
$this->contentService->publishVersion($draft->versionInfo); |
492
|
|
|
|
493
|
|
|
$this->expectException(APIInvalidArgumentException::class); |
494
|
|
|
// Content remoteId already exists, |
495
|
|
|
$this->contentService->createContent( |
496
|
|
|
$contentCreate, |
497
|
|
|
[$locationCreate2] |
498
|
|
|
); |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
/** |
502
|
|
|
* Test for the loadContentInfo() method. |
503
|
|
|
* |
504
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentInfo() |
505
|
|
|
* @group user |
506
|
|
|
*/ |
507
|
|
|
public function testLoadContentInfo() |
508
|
|
|
{ |
509
|
|
|
$mediaFolderId = $this->generateId('object', self::MEDIA_CONTENT_ID); |
510
|
|
|
|
511
|
|
|
// Load the ContentInfo for "Media" folder |
512
|
|
|
$contentInfo = $this->contentService->loadContentInfo($mediaFolderId); |
513
|
|
|
|
514
|
|
|
$this->assertInstanceOf(ContentInfo::class, $contentInfo); |
515
|
|
|
|
516
|
|
|
return $contentInfo; |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
/** |
520
|
|
|
* Test for the returned value of the loadContentInfo() method. |
521
|
|
|
* |
522
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
523
|
|
|
* @covers \eZ\Publish\API\Repository\ContentService::loadContentInfo |
524
|
|
|
* |
525
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
526
|
|
|
*/ |
527
|
|
|
public function testLoadContentInfoSetsExpectedContentInfo(ContentInfo $contentInfo) |
528
|
|
|
{ |
529
|
|
|
$this->assertPropertiesCorrectUnsorted( |
530
|
|
|
$this->getExpectedMediaContentInfoProperties(), |
531
|
|
|
$contentInfo |
532
|
|
|
); |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
/** |
536
|
|
|
* Test for the loadContentInfo() method. |
537
|
|
|
* |
538
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentInfo() |
539
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
540
|
|
|
*/ |
541
|
|
|
public function testLoadContentInfoThrowsNotFoundException() |
542
|
|
|
{ |
543
|
|
|
$nonExistentContentId = $this->generateId('object', self::DB_INT_MAX); |
544
|
|
|
|
545
|
|
|
$this->expectException(NotFoundException::class); |
546
|
|
|
|
547
|
|
|
$this->contentService->loadContentInfo($nonExistentContentId); |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
/** |
551
|
|
|
* Test for the loadContentInfoList() method. |
552
|
|
|
* |
553
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentInfoList() |
554
|
|
|
*/ |
555
|
|
|
public function testLoadContentInfoList() |
556
|
|
|
{ |
557
|
|
|
$mediaFolderId = $this->generateId('object', self::MEDIA_CONTENT_ID); |
558
|
|
|
$list = $this->contentService->loadContentInfoList([$mediaFolderId]); |
559
|
|
|
|
560
|
|
|
$this->assertCount(1, $list); |
561
|
|
|
$this->assertEquals([$mediaFolderId], array_keys($list), 'Array key was not content id'); |
562
|
|
|
$this->assertInstanceOf( |
563
|
|
|
ContentInfo::class, |
564
|
|
|
$list[$mediaFolderId] |
565
|
|
|
); |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
/** |
569
|
|
|
* Test for the loadContentInfoList() method. |
570
|
|
|
* |
571
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentInfoList() |
572
|
|
|
* @depends testLoadContentInfoList |
573
|
|
|
*/ |
574
|
|
|
public function testLoadContentInfoListSkipsNotFoundItems() |
575
|
|
|
{ |
576
|
|
|
$nonExistentContentId = $this->generateId('object', self::DB_INT_MAX); |
577
|
|
|
$list = $this->contentService->loadContentInfoList([$nonExistentContentId]); |
578
|
|
|
|
579
|
|
|
$this->assertCount(0, $list); |
580
|
|
|
} |
581
|
|
|
|
582
|
|
|
/** |
583
|
|
|
* Test for the loadContentInfoByRemoteId() method. |
584
|
|
|
* |
585
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentInfoByRemoteId() |
586
|
|
|
*/ |
587
|
|
|
public function testLoadContentInfoByRemoteId() |
588
|
|
|
{ |
589
|
|
|
// Load the ContentInfo for "Media" folder |
590
|
|
|
$contentInfo = $this->contentService->loadContentInfoByRemoteId('faaeb9be3bd98ed09f606fc16d144eca'); |
591
|
|
|
|
592
|
|
|
$this->assertInstanceOf(ContentInfo::class, $contentInfo); |
593
|
|
|
|
594
|
|
|
return $contentInfo; |
595
|
|
|
} |
596
|
|
|
|
597
|
|
|
/** |
598
|
|
|
* Test for the returned value of the loadContentInfoByRemoteId() method. |
599
|
|
|
* |
600
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfoByRemoteId |
601
|
|
|
* @covers \eZ\Publish\API\Repository\ContentService::loadContentInfoByRemoteId |
602
|
|
|
* |
603
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
604
|
|
|
*/ |
605
|
|
|
public function testLoadContentInfoByRemoteIdSetsExpectedContentInfo(ContentInfo $contentInfo) |
606
|
|
|
{ |
607
|
|
|
$this->assertPropertiesCorrectUnsorted( |
608
|
|
|
[ |
609
|
|
|
'id' => 10, |
610
|
|
|
'contentTypeId' => 4, |
611
|
|
|
'name' => 'Anonymous User', |
612
|
|
|
'sectionId' => 2, |
613
|
|
|
'currentVersionNo' => 2, |
614
|
|
|
'published' => true, |
615
|
|
|
'ownerId' => 14, |
616
|
|
|
'modificationDate' => $this->createDateTime(1072180405), |
617
|
|
|
'publishedDate' => $this->createDateTime(1033920665), |
618
|
|
|
'alwaysAvailable' => 1, |
619
|
|
|
'remoteId' => 'faaeb9be3bd98ed09f606fc16d144eca', |
620
|
|
|
'mainLanguageCode' => self::ENG_US, |
621
|
|
|
'mainLocationId' => 45, |
622
|
|
|
], |
623
|
|
|
$contentInfo |
624
|
|
|
); |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
/** |
628
|
|
|
* Test for the loadContentInfoByRemoteId() method. |
629
|
|
|
* |
630
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentInfoByRemoteId() |
631
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfoByRemoteId |
632
|
|
|
*/ |
633
|
|
|
public function testLoadContentInfoByRemoteIdThrowsNotFoundException() |
634
|
|
|
{ |
635
|
|
|
$this->expectException(NotFoundException::class); |
636
|
|
|
|
637
|
|
|
$this->contentService->loadContentInfoByRemoteId('abcdefghijklmnopqrstuvwxyz0123456789'); |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
/** |
641
|
|
|
* Test for the loadVersionInfo() method. |
642
|
|
|
* |
643
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo() |
644
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
645
|
|
|
* @group user |
646
|
|
|
*/ |
647
|
|
|
public function testLoadVersionInfo() |
648
|
|
|
{ |
649
|
|
|
$mediaFolderId = $this->generateId('object', self::MEDIA_CONTENT_ID); |
650
|
|
|
// $mediaFolderId contains the ID of the "Media" folder |
651
|
|
|
|
652
|
|
|
// Load the ContentInfo for "Media" folder |
653
|
|
|
$contentInfo = $this->contentService->loadContentInfo($mediaFolderId); |
654
|
|
|
|
655
|
|
|
// Now load the current version info of the "Media" folder |
656
|
|
|
$versionInfo = $this->contentService->loadVersionInfo($contentInfo); |
657
|
|
|
|
658
|
|
|
$this->assertInstanceOf( |
659
|
|
|
VersionInfo::class, |
660
|
|
|
$versionInfo |
661
|
|
|
); |
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
/** |
665
|
|
|
* Test for the loadVersionInfoById() method. |
666
|
|
|
* |
667
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById() |
668
|
|
|
*/ |
669
|
|
|
public function testLoadVersionInfoById() |
670
|
|
|
{ |
671
|
|
|
$mediaFolderId = $this->generateId('object', self::MEDIA_CONTENT_ID); |
672
|
|
|
// $mediaFolderId contains the ID of the "Media" folder |
673
|
|
|
|
674
|
|
|
// Load the VersionInfo for "Media" folder |
675
|
|
|
$versionInfo = $this->contentService->loadVersionInfoById($mediaFolderId); |
676
|
|
|
|
677
|
|
|
$this->assertInstanceOf( |
678
|
|
|
VersionInfo::class, |
679
|
|
|
$versionInfo |
680
|
|
|
); |
681
|
|
|
|
682
|
|
|
return $versionInfo; |
683
|
|
|
} |
684
|
|
|
|
685
|
|
|
/** |
686
|
|
|
* Test for the returned value of the loadVersionInfoById() method. |
687
|
|
|
* |
688
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoById |
689
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById |
690
|
|
|
* |
691
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
692
|
|
|
*/ |
693
|
|
|
public function testLoadVersionInfoByIdSetsExpectedVersionInfo(VersionInfo $versionInfo) |
694
|
|
|
{ |
695
|
|
|
$this->assertPropertiesCorrect( |
696
|
|
|
[ |
697
|
|
|
'names' => [ |
698
|
|
|
self::ENG_US => 'Media', |
699
|
|
|
], |
700
|
|
|
'contentInfo' => new ContentInfo($this->getExpectedMediaContentInfoProperties()), |
701
|
|
|
'id' => 472, |
702
|
|
|
'versionNo' => 1, |
703
|
|
|
'modificationDate' => $this->createDateTime(1060695457), |
704
|
|
|
'creatorId' => 14, |
705
|
|
|
'creationDate' => $this->createDateTime(1060695450), |
706
|
|
|
'status' => VersionInfo::STATUS_PUBLISHED, |
707
|
|
|
'initialLanguageCode' => self::ENG_US, |
708
|
|
|
'languageCodes' => [ |
709
|
|
|
self::ENG_US, |
710
|
|
|
], |
711
|
|
|
], |
712
|
|
|
$versionInfo |
713
|
|
|
); |
714
|
|
|
$this->assertTrue($versionInfo->isPublished()); |
715
|
|
|
$this->assertFalse($versionInfo->isDraft()); |
716
|
|
|
$this->assertFalse($versionInfo->isArchived()); |
717
|
|
|
} |
718
|
|
|
|
719
|
|
|
/** |
720
|
|
|
* Test for the loadVersionInfoById() method. |
721
|
|
|
* |
722
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById() |
723
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoById |
724
|
|
|
*/ |
725
|
|
|
public function testLoadVersionInfoByIdThrowsNotFoundException() |
726
|
|
|
{ |
727
|
|
|
$nonExistentContentId = $this->generateId('object', self::DB_INT_MAX); |
728
|
|
|
|
729
|
|
|
$this->expectException(NotFoundException::class); |
730
|
|
|
|
731
|
|
|
$this->contentService->loadVersionInfoById($nonExistentContentId); |
732
|
|
|
} |
733
|
|
|
|
734
|
|
|
/** |
735
|
|
|
* Test for the loadContentByContentInfo() method. |
736
|
|
|
* |
737
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo() |
738
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
739
|
|
|
*/ |
740
|
|
|
public function testLoadContentByContentInfo() |
741
|
|
|
{ |
742
|
|
|
$mediaFolderId = $this->generateId('object', self::MEDIA_CONTENT_ID); |
743
|
|
|
// $mediaFolderId contains the ID of the "Media" folder |
744
|
|
|
|
745
|
|
|
// Load the ContentInfo for "Media" folder |
746
|
|
|
$contentInfo = $this->contentService->loadContentInfo($mediaFolderId); |
747
|
|
|
|
748
|
|
|
// Now load the current content version for the info instance |
749
|
|
|
$content = $this->contentService->loadContentByContentInfo($contentInfo); |
750
|
|
|
|
751
|
|
|
$this->assertInstanceOf( |
752
|
|
|
Content::class, |
753
|
|
|
$content |
754
|
|
|
); |
755
|
|
|
} |
756
|
|
|
|
757
|
|
|
/** |
758
|
|
|
* Test for the loadContentByVersionInfo() method. |
759
|
|
|
* |
760
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByVersionInfo() |
761
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
762
|
|
|
*/ |
763
|
|
|
public function testLoadContentByVersionInfo() |
764
|
|
|
{ |
765
|
|
|
$mediaFolderId = $this->generateId('object', self::MEDIA_CONTENT_ID); |
766
|
|
|
// $mediaFolderId contains the ID of the "Media" folder |
767
|
|
|
|
768
|
|
|
// Load the ContentInfo for "Media" folder |
769
|
|
|
$contentInfo = $this->contentService->loadContentInfo($mediaFolderId); |
770
|
|
|
|
771
|
|
|
// Load the current VersionInfo |
772
|
|
|
$versionInfo = $this->contentService->loadVersionInfo($contentInfo); |
773
|
|
|
|
774
|
|
|
// Now load the current content version for the info instance |
775
|
|
|
$content = $this->contentService->loadContentByVersionInfo($versionInfo); |
776
|
|
|
|
777
|
|
|
$this->assertInstanceOf( |
778
|
|
|
Content::class, |
779
|
|
|
$content |
780
|
|
|
); |
781
|
|
|
} |
782
|
|
|
|
783
|
|
|
/** |
784
|
|
|
* Test for the loadContent() method. |
785
|
|
|
* |
786
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContent() |
787
|
|
|
* @group user |
788
|
|
|
* @group field-type |
789
|
|
|
*/ |
790
|
|
|
public function testLoadContent() |
791
|
|
|
{ |
792
|
|
|
$mediaFolderId = $this->generateId('object', self::MEDIA_CONTENT_ID); |
793
|
|
|
// $mediaFolderId contains the ID of the "Media" folder |
794
|
|
|
|
795
|
|
|
// Load the Content for "Media" folder, any language and current version |
796
|
|
|
$content = $this->contentService->loadContent($mediaFolderId); |
797
|
|
|
|
798
|
|
|
$this->assertInstanceOf( |
799
|
|
|
Content::class, |
800
|
|
|
$content |
801
|
|
|
); |
802
|
|
|
} |
803
|
|
|
|
804
|
|
|
/** |
805
|
|
|
* Test for the loadContent() method. |
806
|
|
|
* |
807
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContent() |
808
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
809
|
|
|
*/ |
810
|
|
|
public function testLoadContentThrowsNotFoundException() |
811
|
|
|
{ |
812
|
|
|
$nonExistentContentId = $this->generateId('object', self::DB_INT_MAX); |
813
|
|
|
|
814
|
|
|
$this->expectException(NotFoundException::class); |
815
|
|
|
|
816
|
|
|
$this->contentService->loadContent($nonExistentContentId); |
817
|
|
|
} |
818
|
|
|
|
819
|
|
|
/** |
820
|
|
|
* Data provider for testLoadContentByRemoteId(). |
821
|
|
|
* |
822
|
|
|
* @return array |
823
|
|
|
*/ |
824
|
|
|
public function contentRemoteIdVersionLanguageProvider() |
825
|
|
|
{ |
826
|
|
|
return [ |
827
|
|
|
['f5c88a2209584891056f987fd965b0ba', null, null], |
828
|
|
|
['f5c88a2209584891056f987fd965b0ba', [self::ENG_US], null], |
829
|
|
|
['f5c88a2209584891056f987fd965b0ba', null, 1], |
830
|
|
|
['f5c88a2209584891056f987fd965b0ba', [self::ENG_US], 1], |
831
|
|
|
[self::MEDIA_REMOTE_ID, null, null], |
832
|
|
|
[self::MEDIA_REMOTE_ID, [self::ENG_US], null], |
833
|
|
|
[self::MEDIA_REMOTE_ID, null, 1], |
834
|
|
|
[self::MEDIA_REMOTE_ID, [self::ENG_US], 1], |
835
|
|
|
]; |
836
|
|
|
} |
837
|
|
|
|
838
|
|
|
/** |
839
|
|
|
* Test for the loadContentByRemoteId() method. |
840
|
|
|
* |
841
|
|
|
* @covers \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId |
842
|
|
|
* @dataProvider contentRemoteIdVersionLanguageProvider |
843
|
|
|
* |
844
|
|
|
* @param string $remoteId |
845
|
|
|
* @param array|null $languages |
846
|
|
|
* @param int $versionNo |
847
|
|
|
*/ |
848
|
|
|
public function testLoadContentByRemoteId($remoteId, $languages, $versionNo) |
849
|
|
|
{ |
850
|
|
|
$content = $this->contentService->loadContentByRemoteId($remoteId, $languages, $versionNo); |
851
|
|
|
|
852
|
|
|
$this->assertInstanceOf( |
853
|
|
|
Content::class, |
854
|
|
|
$content |
855
|
|
|
); |
856
|
|
|
|
857
|
|
|
$this->assertEquals($remoteId, $content->contentInfo->remoteId); |
858
|
|
|
if ($languages !== null) { |
859
|
|
|
$this->assertEquals($languages, $content->getVersionInfo()->languageCodes); |
860
|
|
|
} |
861
|
|
|
$this->assertEquals($versionNo ?: 1, $content->getVersionInfo()->versionNo); |
862
|
|
|
} |
863
|
|
|
|
864
|
|
|
/** |
865
|
|
|
* Test for the loadContentByRemoteId() method. |
866
|
|
|
* |
867
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId() |
868
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteId |
869
|
|
|
*/ |
870
|
|
|
public function testLoadContentByRemoteIdThrowsNotFoundException() |
871
|
|
|
{ |
872
|
|
|
$this->expectException(NotFoundException::class); |
873
|
|
|
|
874
|
|
|
// This call will fail with a "NotFoundException", because no content object exists for the given remoteId |
875
|
|
|
$this->contentService->loadContentByRemoteId('a1b1c1d1e1f1a2b2c2d2e2f2a3b3c3d3'); |
876
|
|
|
} |
877
|
|
|
|
878
|
|
|
/** |
879
|
|
|
* Test for the publishVersion() method. |
880
|
|
|
* |
881
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
882
|
|
|
* |
883
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
884
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
885
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
886
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
887
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately |
888
|
|
|
* @group user |
889
|
|
|
* @group field-type |
890
|
|
|
*/ |
891
|
|
|
public function testPublishVersion() |
892
|
|
|
{ |
893
|
|
|
$time = time(); |
894
|
|
|
$content = $this->createContentVersion1(); |
895
|
|
|
|
896
|
|
|
$this->assertInstanceOf(Content::class, $content); |
897
|
|
|
$this->assertTrue($content->contentInfo->published); |
898
|
|
|
$this->assertEquals(VersionInfo::STATUS_PUBLISHED, $content->versionInfo->status); |
899
|
|
|
$this->assertGreaterThanOrEqual($time, $content->contentInfo->publishedDate->getTimestamp()); |
900
|
|
|
$this->assertGreaterThanOrEqual($time, $content->contentInfo->modificationDate->getTimestamp()); |
901
|
|
|
$this->assertTrue($content->versionInfo->isPublished()); |
902
|
|
|
$this->assertFalse($content->versionInfo->isDraft()); |
903
|
|
|
$this->assertFalse($content->versionInfo->isArchived()); |
904
|
|
|
|
905
|
|
|
return $content; |
906
|
|
|
} |
907
|
|
|
|
908
|
|
|
/** |
909
|
|
|
* Test for the publishVersion() method. |
910
|
|
|
* |
911
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $content |
912
|
|
|
* |
913
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
914
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
915
|
|
|
*/ |
916
|
|
|
public function testPublishVersionSetsExpectedContentInfo($content) |
917
|
|
|
{ |
918
|
|
|
$this->assertEquals( |
919
|
|
|
[ |
920
|
|
|
$content->id, |
921
|
|
|
true, |
922
|
|
|
1, |
923
|
|
|
'abcdef0123456789abcdef0123456789', |
924
|
|
|
self::ENG_US, |
925
|
|
|
$this->getRepository()->getCurrentUser()->id, |
|
|
|
|
926
|
|
|
true, |
927
|
|
|
], |
928
|
|
|
[ |
929
|
|
|
$content->contentInfo->id, |
930
|
|
|
$content->contentInfo->alwaysAvailable, |
931
|
|
|
$content->contentInfo->currentVersionNo, |
932
|
|
|
$content->contentInfo->remoteId, |
933
|
|
|
$content->contentInfo->mainLanguageCode, |
934
|
|
|
$content->contentInfo->ownerId, |
935
|
|
|
$content->contentInfo->published, |
936
|
|
|
] |
937
|
|
|
); |
938
|
|
|
|
939
|
|
|
$this->assertNotNull($content->contentInfo->mainLocationId); |
940
|
|
|
$date = new \DateTime('1984/01/01'); |
941
|
|
|
$this->assertGreaterThan( |
942
|
|
|
$date->getTimestamp(), |
943
|
|
|
$content->contentInfo->publishedDate->getTimestamp() |
944
|
|
|
); |
945
|
|
|
} |
946
|
|
|
|
947
|
|
|
/** |
948
|
|
|
* Test for the publishVersion() method. |
949
|
|
|
* |
950
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $content |
951
|
|
|
* |
952
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
953
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
954
|
|
|
*/ |
955
|
|
|
public function testPublishVersionSetsExpectedVersionInfo($content) |
956
|
|
|
{ |
957
|
|
|
$this->assertEquals( |
958
|
|
|
[ |
959
|
|
|
$this->getRepository()->getCurrentUser()->id, |
|
|
|
|
960
|
|
|
self::ENG_US, |
961
|
|
|
VersionInfo::STATUS_PUBLISHED, |
962
|
|
|
1, |
963
|
|
|
], |
964
|
|
|
[ |
965
|
|
|
$content->getVersionInfo()->creatorId, |
966
|
|
|
$content->getVersionInfo()->initialLanguageCode, |
967
|
|
|
$content->getVersionInfo()->status, |
968
|
|
|
$content->getVersionInfo()->versionNo, |
969
|
|
|
] |
970
|
|
|
); |
971
|
|
|
|
972
|
|
|
$date = new \DateTime('1984/01/01'); |
973
|
|
|
$this->assertGreaterThan( |
974
|
|
|
$date->getTimestamp(), |
975
|
|
|
$content->getVersionInfo()->modificationDate->getTimestamp() |
976
|
|
|
); |
977
|
|
|
|
978
|
|
|
$this->assertNotNull($content->getVersionInfo()->modificationDate); |
979
|
|
|
$this->assertTrue($content->getVersionInfo()->isPublished()); |
980
|
|
|
$this->assertFalse($content->getVersionInfo()->isDraft()); |
981
|
|
|
$this->assertFalse($content->getVersionInfo()->isArchived()); |
982
|
|
|
} |
983
|
|
|
|
984
|
|
|
/** |
985
|
|
|
* Test for the publishVersion() method. |
986
|
|
|
* |
987
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $content |
988
|
|
|
* |
989
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
990
|
|
|
* @depends testPublishVersion |
991
|
|
|
*/ |
992
|
|
|
public function testPublishVersionSetsExpectedContentType($content) |
993
|
|
|
{ |
994
|
|
|
$contentType = $content->getContentType(); |
995
|
|
|
|
996
|
|
|
$this->assertEquals( |
997
|
|
|
[ |
998
|
|
|
$contentType->id, |
999
|
|
|
// won't be a match as it's set to true in createContentDraftVersion1() |
1000
|
|
|
//$contentType->defaultAlwaysAvailable, |
1001
|
|
|
//$contentType->defaultSortField, |
1002
|
|
|
//$contentType->defaultSortOrder, |
1003
|
|
|
], |
1004
|
|
|
[ |
1005
|
|
|
$content->contentInfo->contentTypeId, |
1006
|
|
|
//$content->contentInfo->alwaysAvailable, |
1007
|
|
|
//$location->sortField, |
1008
|
|
|
//$location->sortOrder, |
1009
|
|
|
] |
1010
|
|
|
); |
1011
|
|
|
} |
1012
|
|
|
|
1013
|
|
|
/** |
1014
|
|
|
* Test for the publishVersion() method. |
1015
|
|
|
* |
1016
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
1017
|
|
|
* |
1018
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
1019
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately |
1020
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
1021
|
|
|
*/ |
1022
|
|
|
public function testPublishVersionCreatesLocationsDefinedOnCreate() |
1023
|
|
|
{ |
1024
|
|
|
$content = $this->createContentVersion1(); |
1025
|
|
|
|
1026
|
|
|
$location = $this->locationService->loadLocationByRemoteId( |
1027
|
|
|
'0123456789abcdef0123456789abcdef' |
1028
|
|
|
); |
1029
|
|
|
|
1030
|
|
|
$this->assertEquals( |
1031
|
|
|
$location->getContentInfo(), |
1032
|
|
|
$content->getVersionInfo()->getContentInfo() |
1033
|
|
|
); |
1034
|
|
|
|
1035
|
|
|
return [$content, $location]; |
1036
|
|
|
} |
1037
|
|
|
|
1038
|
|
|
/** |
1039
|
|
|
* Test for the publishVersion() method. |
1040
|
|
|
* |
1041
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
1042
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionCreatesLocationsDefinedOnCreate |
1043
|
|
|
*/ |
1044
|
|
|
public function testCreateContentWithLocationCreateParameterCreatesExpectedLocation(array $testData) |
1045
|
|
|
{ |
1046
|
|
|
/** @var \eZ\Publish\API\Repository\Values\Content\Content $content */ |
1047
|
|
|
/** @var \eZ\Publish\API\Repository\Values\Content\Location $location */ |
1048
|
|
|
list($content, $location) = $testData; |
1049
|
|
|
|
1050
|
|
|
$parentLocationId = $this->generateId('location', 56); |
1051
|
|
|
$parentLocation = $this->getRepository()->getLocationService()->loadLocation($parentLocationId); |
1052
|
|
|
$mainLocationId = $content->getVersionInfo()->getContentInfo()->mainLocationId; |
1053
|
|
|
|
1054
|
|
|
$this->assertPropertiesCorrect( |
1055
|
|
|
[ |
1056
|
|
|
'id' => $mainLocationId, |
1057
|
|
|
'priority' => 23, |
1058
|
|
|
'hidden' => true, |
1059
|
|
|
'invisible' => true, |
1060
|
|
|
'remoteId' => '0123456789abcdef0123456789abcdef', |
1061
|
|
|
'parentLocationId' => $parentLocationId, |
1062
|
|
|
'pathString' => $parentLocation->pathString . $mainLocationId . '/', |
1063
|
|
|
'depth' => $parentLocation->depth + 1, |
1064
|
|
|
'sortField' => Location::SORT_FIELD_NODE_ID, |
1065
|
|
|
'sortOrder' => Location::SORT_ORDER_DESC, |
1066
|
|
|
], |
1067
|
|
|
$location |
1068
|
|
|
); |
1069
|
|
|
} |
1070
|
|
|
|
1071
|
|
|
/** |
1072
|
|
|
* Test for the publishVersion() method. |
1073
|
|
|
* |
1074
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
1075
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
1076
|
|
|
*/ |
1077
|
|
|
public function testPublishVersionThrowsBadStateException() |
1078
|
|
|
{ |
1079
|
|
|
$draft = $this->createContentDraftVersion1(); |
1080
|
|
|
|
1081
|
|
|
// Publish the content draft |
1082
|
|
|
$this->contentService->publishVersion($draft->getVersionInfo()); |
1083
|
|
|
|
1084
|
|
|
$this->expectException(BadStateException::class); |
1085
|
|
|
|
1086
|
|
|
// This call will fail with a "BadStateException", because the version is already published. |
1087
|
|
|
$this->contentService->publishVersion($draft->getVersionInfo()); |
1088
|
|
|
} |
1089
|
|
|
|
1090
|
|
|
/** |
1091
|
|
|
* Test that publishVersion() does not affect publishedDate (assuming previous version exists). |
1092
|
|
|
* |
1093
|
|
|
* @covers \eZ\Publish\API\Repository\ContentService::publishVersion |
1094
|
|
|
*/ |
1095
|
|
|
public function testPublishVersionDoesNotChangePublishedDate() |
1096
|
|
|
{ |
1097
|
|
|
$publishedContent = $this->createContentVersion1(); |
1098
|
|
|
|
1099
|
|
|
// force timestamps to differ |
1100
|
|
|
sleep(1); |
1101
|
|
|
|
1102
|
|
|
$contentDraft = $this->contentService->createContentDraft($publishedContent->contentInfo); |
1103
|
|
|
$contentUpdateStruct = $this->contentService->newContentUpdateStruct(); |
1104
|
|
|
$contentUpdateStruct->setField('name', 'New name'); |
1105
|
|
|
$contentDraft = $this->contentService->updateContent($contentDraft->versionInfo, $contentUpdateStruct); |
1106
|
|
|
$republishedContent = $this->contentService->publishVersion($contentDraft->versionInfo); |
1107
|
|
|
|
1108
|
|
|
$this->assertEquals( |
1109
|
|
|
$publishedContent->contentInfo->publishedDate->getTimestamp(), |
1110
|
|
|
$republishedContent->contentInfo->publishedDate->getTimestamp() |
1111
|
|
|
); |
1112
|
|
|
$this->assertGreaterThan( |
1113
|
|
|
$publishedContent->contentInfo->modificationDate->getTimestamp(), |
1114
|
|
|
$republishedContent->contentInfo->modificationDate->getTimestamp() |
1115
|
|
|
); |
1116
|
|
|
} |
1117
|
|
|
|
1118
|
|
|
/** |
1119
|
|
|
* Test for the createContentDraft() method. |
1120
|
|
|
* |
1121
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
1122
|
|
|
* |
1123
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
1124
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
1125
|
|
|
* @group user |
1126
|
|
|
*/ |
1127
|
|
|
public function testCreateContentDraft() |
1128
|
|
|
{ |
1129
|
|
|
$content = $this->createContentVersion1(); |
1130
|
|
|
|
1131
|
|
|
// Now we create a new draft from the published content |
1132
|
|
|
$draftedContent = $this->contentService->createContentDraft($content->contentInfo); |
1133
|
|
|
|
1134
|
|
|
$this->assertInstanceOf( |
1135
|
|
|
Content::class, |
1136
|
|
|
$draftedContent |
1137
|
|
|
); |
1138
|
|
|
|
1139
|
|
|
return $draftedContent; |
1140
|
|
|
} |
1141
|
|
|
|
1142
|
|
|
/** |
1143
|
|
|
* Test for the createContentDraft() method. |
1144
|
|
|
* |
1145
|
|
|
* Test that editor has access to edit own draft. |
1146
|
|
|
* Note: Editors have access to version_read, which is needed to load content drafts. |
1147
|
|
|
* |
1148
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
1149
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
1150
|
|
|
* @group user |
1151
|
|
|
*/ |
1152
|
|
|
public function testCreateContentDraftAndLoadAccess() |
1153
|
|
|
{ |
1154
|
|
|
$user = $this->createUserVersion1(); |
1155
|
|
|
|
1156
|
|
|
// Set new editor as user |
1157
|
|
|
$this->permissionResolver->setCurrentUserReference($user); |
1158
|
|
|
|
1159
|
|
|
// Create draft |
1160
|
|
|
$draft = $this->createContentDraftVersion1(2, 'folder'); |
1161
|
|
|
|
1162
|
|
|
// Try to load the draft |
1163
|
|
|
$loadedDraft = $this->contentService->loadContent($draft->id); |
1164
|
|
|
|
1165
|
|
|
$this->assertEquals($draft->id, $loadedDraft->id); |
1166
|
|
|
} |
1167
|
|
|
|
1168
|
|
|
/** |
1169
|
|
|
* Test for the createContentDraft() method. |
1170
|
|
|
* |
1171
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $draft |
1172
|
|
|
* |
1173
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
1174
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
1175
|
|
|
*/ |
1176
|
|
|
public function testCreateContentDraftSetsExpectedProperties($draft) |
1177
|
|
|
{ |
1178
|
|
|
$this->assertEquals( |
1179
|
|
|
[ |
1180
|
|
|
'fieldCount' => 2, |
1181
|
|
|
'relationCount' => 0, |
1182
|
|
|
], |
1183
|
|
|
[ |
1184
|
|
|
'fieldCount' => count($draft->getFields()), |
1185
|
|
|
'relationCount' => count($this->getRepository()->getContentService()->loadRelations($draft->getVersionInfo())), |
1186
|
|
|
] |
1187
|
|
|
); |
1188
|
|
|
} |
1189
|
|
|
|
1190
|
|
|
/** |
1191
|
|
|
* Test for the createContentDraft() method. |
1192
|
|
|
* |
1193
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $draft |
1194
|
|
|
* |
1195
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
1196
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
1197
|
|
|
*/ |
1198
|
|
|
public function testCreateContentDraftSetsContentInfo($draft) |
1199
|
|
|
{ |
1200
|
|
|
$contentInfo = $draft->contentInfo; |
1201
|
|
|
|
1202
|
|
|
$this->assertEquals( |
1203
|
|
|
[ |
1204
|
|
|
$draft->id, |
1205
|
|
|
true, |
1206
|
|
|
1, |
1207
|
|
|
self::ENG_US, |
1208
|
|
|
$this->getRepository()->getCurrentUser()->id, |
|
|
|
|
1209
|
|
|
'abcdef0123456789abcdef0123456789', |
1210
|
|
|
1, |
1211
|
|
|
], |
1212
|
|
|
[ |
1213
|
|
|
$contentInfo->id, |
1214
|
|
|
$contentInfo->alwaysAvailable, |
1215
|
|
|
$contentInfo->currentVersionNo, |
1216
|
|
|
$contentInfo->mainLanguageCode, |
1217
|
|
|
$contentInfo->ownerId, |
1218
|
|
|
$contentInfo->remoteId, |
1219
|
|
|
$contentInfo->sectionId, |
1220
|
|
|
] |
1221
|
|
|
); |
1222
|
|
|
} |
1223
|
|
|
|
1224
|
|
|
/** |
1225
|
|
|
* Test for the createContentDraft() method. |
1226
|
|
|
* |
1227
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $draft |
1228
|
|
|
* |
1229
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
1230
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
1231
|
|
|
*/ |
1232
|
|
|
public function testCreateContentDraftSetsVersionInfo($draft) |
1233
|
|
|
{ |
1234
|
|
|
$versionInfo = $draft->getVersionInfo(); |
1235
|
|
|
|
1236
|
|
|
$this->assertEquals( |
1237
|
|
|
[ |
1238
|
|
|
'creatorId' => $this->getRepository()->getCurrentUser()->id, |
|
|
|
|
1239
|
|
|
'initialLanguageCode' => self::ENG_US, |
1240
|
|
|
'languageCodes' => [0 => self::ENG_US], |
1241
|
|
|
'status' => VersionInfo::STATUS_DRAFT, |
1242
|
|
|
'versionNo' => 2, |
1243
|
|
|
], |
1244
|
|
|
[ |
1245
|
|
|
'creatorId' => $versionInfo->creatorId, |
1246
|
|
|
'initialLanguageCode' => $versionInfo->initialLanguageCode, |
1247
|
|
|
'languageCodes' => $versionInfo->languageCodes, |
1248
|
|
|
'status' => $versionInfo->status, |
1249
|
|
|
'versionNo' => $versionInfo->versionNo, |
1250
|
|
|
] |
1251
|
|
|
); |
1252
|
|
|
$this->assertTrue($versionInfo->isDraft()); |
1253
|
|
|
$this->assertFalse($versionInfo->isPublished()); |
1254
|
|
|
$this->assertFalse($versionInfo->isArchived()); |
1255
|
|
|
} |
1256
|
|
|
|
1257
|
|
|
/** |
1258
|
|
|
* Test for the createContentDraft() method. |
1259
|
|
|
* |
1260
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $draft |
1261
|
|
|
* |
1262
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
1263
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
1264
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
1265
|
|
|
*/ |
1266
|
|
|
public function testCreateContentDraftLoadVersionInfoStillLoadsPublishedVersion($draft) |
|
|
|
|
1267
|
|
|
{ |
1268
|
|
|
$content = $this->createContentVersion1(); |
1269
|
|
|
|
1270
|
|
|
// Now we create a new draft from the published content |
1271
|
|
|
$this->contentService->createContentDraft($content->contentInfo); |
1272
|
|
|
|
1273
|
|
|
// This call will still load the published version |
1274
|
|
|
$versionInfoPublished = $this->contentService->loadVersionInfo($content->contentInfo); |
1275
|
|
|
|
1276
|
|
|
$this->assertEquals(1, $versionInfoPublished->versionNo); |
1277
|
|
|
} |
1278
|
|
|
|
1279
|
|
|
/** |
1280
|
|
|
* Test for the createContentDraft() method. |
1281
|
|
|
* |
1282
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
1283
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
1284
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
1285
|
|
|
*/ |
1286
|
|
|
public function testCreateContentDraftLoadContentStillLoadsPublishedVersion() |
1287
|
|
|
{ |
1288
|
|
|
$content = $this->createContentVersion1(); |
1289
|
|
|
|
1290
|
|
|
// Now we create a new draft from the published content |
1291
|
|
|
$this->contentService->createContentDraft($content->contentInfo); |
1292
|
|
|
|
1293
|
|
|
// This call will still load the published content version |
1294
|
|
|
$contentPublished = $this->contentService->loadContent($content->id); |
1295
|
|
|
|
1296
|
|
|
$this->assertEquals(1, $contentPublished->getVersionInfo()->versionNo); |
1297
|
|
|
} |
1298
|
|
|
|
1299
|
|
|
/** |
1300
|
|
|
* Test for the createContentDraft() method. |
1301
|
|
|
* |
1302
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
1303
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteId |
1304
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
1305
|
|
|
*/ |
1306
|
|
|
public function testCreateContentDraftLoadContentByRemoteIdStillLoadsPublishedVersion() |
1307
|
|
|
{ |
1308
|
|
|
$content = $this->createContentVersion1(); |
1309
|
|
|
|
1310
|
|
|
// Now we create a new draft from the published content |
1311
|
|
|
$this->contentService->createContentDraft($content->contentInfo); |
1312
|
|
|
|
1313
|
|
|
// This call will still load the published content version |
1314
|
|
|
$contentPublished = $this->contentService->loadContentByRemoteId('abcdef0123456789abcdef0123456789'); |
1315
|
|
|
|
1316
|
|
|
$this->assertEquals(1, $contentPublished->getVersionInfo()->versionNo); |
1317
|
|
|
} |
1318
|
|
|
|
1319
|
|
|
/** |
1320
|
|
|
* Test for the createContentDraft() method. |
1321
|
|
|
* |
1322
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
1323
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfo |
1324
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
1325
|
|
|
*/ |
1326
|
|
|
public function testCreateContentDraftLoadContentByContentInfoStillLoadsPublishedVersion() |
1327
|
|
|
{ |
1328
|
|
|
$content = $this->createContentVersion1(); |
1329
|
|
|
|
1330
|
|
|
// Now we create a new draft from the published content |
1331
|
|
|
$this->contentService->createContentDraft($content->contentInfo); |
1332
|
|
|
|
1333
|
|
|
// This call will still load the published content version |
1334
|
|
|
$contentPublished = $this->contentService->loadContentByContentInfo($content->contentInfo); |
1335
|
|
|
|
1336
|
|
|
$this->assertEquals(1, $contentPublished->getVersionInfo()->versionNo); |
1337
|
|
|
} |
1338
|
|
|
|
1339
|
|
|
/** |
1340
|
|
|
* Test for the newContentUpdateStruct() method. |
1341
|
|
|
* |
1342
|
|
|
* @covers \eZ\Publish\API\Repository\ContentService::newContentUpdateStruct |
1343
|
|
|
* @group user |
1344
|
|
|
*/ |
1345
|
|
|
public function testNewContentUpdateStruct() |
1346
|
|
|
{ |
1347
|
|
|
$updateStruct = $this->contentService->newContentUpdateStruct(); |
1348
|
|
|
|
1349
|
|
|
$this->assertInstanceOf( |
1350
|
|
|
ContentUpdateStruct::class, |
1351
|
|
|
$updateStruct |
1352
|
|
|
); |
1353
|
|
|
|
1354
|
|
|
$this->assertPropertiesCorrect( |
1355
|
|
|
[ |
1356
|
|
|
'initialLanguageCode' => null, |
1357
|
|
|
'fields' => [], |
1358
|
|
|
], |
1359
|
|
|
$updateStruct |
1360
|
|
|
); |
1361
|
|
|
} |
1362
|
|
|
|
1363
|
|
|
/** |
1364
|
|
|
* Test for the updateContent() method. |
1365
|
|
|
* |
1366
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
1367
|
|
|
* |
1368
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContent() |
1369
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentUpdateStruct |
1370
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
1371
|
|
|
* @group user |
1372
|
|
|
* @group field-type |
1373
|
|
|
*/ |
1374
|
|
|
public function testUpdateContent() |
1375
|
|
|
{ |
1376
|
|
|
$draftVersion2 = $this->createUpdatedDraftVersion2(); |
1377
|
|
|
|
1378
|
|
|
$this->assertInstanceOf( |
1379
|
|
|
Content::class, |
1380
|
|
|
$draftVersion2 |
1381
|
|
|
); |
1382
|
|
|
|
1383
|
|
|
$this->assertEquals( |
1384
|
|
|
$this->generateId('user', 10), |
1385
|
|
|
$draftVersion2->versionInfo->creatorId, |
1386
|
|
|
'creatorId is not properly set on new Version' |
1387
|
|
|
); |
1388
|
|
|
|
1389
|
|
|
return $draftVersion2; |
1390
|
|
|
} |
1391
|
|
|
|
1392
|
|
|
/** |
1393
|
|
|
* Test for the updateContent_WithDifferentUser() method. |
1394
|
|
|
* |
1395
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
1396
|
|
|
* |
1397
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContent() |
1398
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentUpdateStruct |
1399
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
1400
|
|
|
* @group user |
1401
|
|
|
* @group field-type |
1402
|
|
|
*/ |
1403
|
|
|
public function testUpdateContentWithDifferentUser() |
1404
|
|
|
{ |
1405
|
|
|
$arrayWithDraftVersion2 = $this->createUpdatedDraftVersion2NotAdmin(); |
1406
|
|
|
|
1407
|
|
|
$this->assertInstanceOf( |
1408
|
|
|
Content::class, |
1409
|
|
|
$arrayWithDraftVersion2[0] |
1410
|
|
|
); |
1411
|
|
|
|
1412
|
|
|
$this->assertEquals( |
1413
|
|
|
$this->generateId('user', $arrayWithDraftVersion2[1]), |
1414
|
|
|
$arrayWithDraftVersion2[0]->versionInfo->creatorId, |
1415
|
|
|
'creatorId is not properly set on new Version' |
1416
|
|
|
); |
1417
|
|
|
|
1418
|
|
|
return $arrayWithDraftVersion2[0]; |
1419
|
|
|
} |
1420
|
|
|
|
1421
|
|
|
/** |
1422
|
|
|
* Test for the updateContent() method. |
1423
|
|
|
* |
1424
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $content |
1425
|
|
|
* |
1426
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContent() |
1427
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
1428
|
|
|
*/ |
1429
|
|
|
public function testUpdateContentSetsExpectedFields($content) |
1430
|
|
|
{ |
1431
|
|
|
$actual = $this->normalizeFields($content->getFields()); |
1432
|
|
|
|
1433
|
|
|
$expected = [ |
1434
|
|
|
new Field( |
1435
|
|
|
[ |
1436
|
|
|
'id' => 0, |
1437
|
|
|
'value' => true, |
1438
|
|
|
'languageCode' => self::ENG_GB, |
1439
|
|
|
'fieldDefIdentifier' => 'description', |
1440
|
|
|
'fieldTypeIdentifier' => 'ezrichtext', |
1441
|
|
|
] |
1442
|
|
|
), |
1443
|
|
|
new Field( |
1444
|
|
|
[ |
1445
|
|
|
'id' => 0, |
1446
|
|
|
'value' => true, |
1447
|
|
|
'languageCode' => self::ENG_US, |
1448
|
|
|
'fieldDefIdentifier' => 'description', |
1449
|
|
|
'fieldTypeIdentifier' => 'ezrichtext', |
1450
|
|
|
] |
1451
|
|
|
), |
1452
|
|
|
new Field( |
1453
|
|
|
[ |
1454
|
|
|
'id' => 0, |
1455
|
|
|
'value' => true, |
1456
|
|
|
'languageCode' => self::ENG_GB, |
1457
|
|
|
'fieldDefIdentifier' => 'name', |
1458
|
|
|
'fieldTypeIdentifier' => 'ezstring', |
1459
|
|
|
] |
1460
|
|
|
), |
1461
|
|
|
new Field( |
1462
|
|
|
[ |
1463
|
|
|
'id' => 0, |
1464
|
|
|
'value' => true, |
1465
|
|
|
'languageCode' => self::ENG_US, |
1466
|
|
|
'fieldDefIdentifier' => 'name', |
1467
|
|
|
'fieldTypeIdentifier' => 'ezstring', |
1468
|
|
|
] |
1469
|
|
|
), |
1470
|
|
|
]; |
1471
|
|
|
|
1472
|
|
|
$this->assertEquals($expected, $actual); |
1473
|
|
|
} |
1474
|
|
|
|
1475
|
|
|
/** |
1476
|
|
|
* Test for the updateContent() method. |
1477
|
|
|
* |
1478
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContent() |
1479
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
1480
|
|
|
*/ |
1481
|
|
|
public function testUpdateContentThrowsBadStateException() |
1482
|
|
|
{ |
1483
|
|
|
$content = $this->createContentVersion1(); |
1484
|
|
|
|
1485
|
|
|
// Now create an update struct and modify some fields |
1486
|
|
|
$contentUpdateStruct = $this->contentService->newContentUpdateStruct(); |
1487
|
|
|
$contentUpdateStruct->setField('title', 'An awesome² story about ezp.'); |
1488
|
|
|
$contentUpdateStruct->setField('title', 'An awesome²³ story about ezp.', self::ENG_GB); |
1489
|
|
|
|
1490
|
|
|
$contentUpdateStruct->initialLanguageCode = self::ENG_US; |
1491
|
|
|
|
1492
|
|
|
$this->expectException(BadStateException::class); |
1493
|
|
|
|
1494
|
|
|
// This call will fail with a "BadStateException", because $publishedContent is not a draft. |
1495
|
|
|
$this->contentService->updateContent( |
1496
|
|
|
$content->getVersionInfo(), |
1497
|
|
|
$contentUpdateStruct |
1498
|
|
|
); |
1499
|
|
|
} |
1500
|
|
|
|
1501
|
|
|
/** |
1502
|
|
|
* Test for the updateContent() method. |
1503
|
|
|
* |
1504
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContent() |
1505
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
1506
|
|
|
*/ |
1507
|
|
|
public function testUpdateContentThrowsInvalidArgumentExceptionWhenFieldTypeDoesNotAccept() |
1508
|
|
|
{ |
1509
|
|
|
$draft = $this->createContentDraftVersion1(); |
1510
|
|
|
|
1511
|
|
|
// Now create an update struct and modify some fields |
1512
|
|
|
$contentUpdateStruct = $this->contentService->newContentUpdateStruct(); |
1513
|
|
|
// The name field does not accept a stdClass object as its input |
1514
|
|
|
$contentUpdateStruct->setField('name', new \stdClass(), self::ENG_US); |
1515
|
|
|
|
1516
|
|
|
$this->expectException(APIInvalidArgumentException::class); |
1517
|
|
|
// is not accepted |
1518
|
|
|
$this->contentService->updateContent( |
1519
|
|
|
$draft->getVersionInfo(), |
1520
|
|
|
$contentUpdateStruct |
1521
|
|
|
); |
1522
|
|
|
} |
1523
|
|
|
|
1524
|
|
|
/** |
1525
|
|
|
* Test for the updateContent() method. |
1526
|
|
|
* |
1527
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContent() |
1528
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
1529
|
|
|
*/ |
1530
|
|
|
public function testUpdateContentWhenMandatoryFieldIsEmpty() |
1531
|
|
|
{ |
1532
|
|
|
$draft = $this->createContentDraftVersion1(); |
1533
|
|
|
|
1534
|
|
|
// Now create an update struct and set a mandatory field to null |
1535
|
|
|
$contentUpdateStruct = $this->contentService->newContentUpdateStruct(); |
1536
|
|
|
$contentUpdateStruct->setField('name', null); |
1537
|
|
|
|
1538
|
|
|
// Don't set this, then the above call without languageCode will fail |
1539
|
|
|
$contentUpdateStruct->initialLanguageCode = self::ENG_US; |
1540
|
|
|
|
1541
|
|
|
$this->expectException(ContentFieldValidationException::class); |
1542
|
|
|
|
1543
|
|
|
// This call will fail with a "ContentFieldValidationException", because the mandatory "name" field is empty. |
1544
|
|
|
$this->contentService->updateContent( |
1545
|
|
|
$draft->getVersionInfo(), |
1546
|
|
|
$contentUpdateStruct |
1547
|
|
|
); |
1548
|
|
|
} |
1549
|
|
|
|
1550
|
|
|
/** |
1551
|
|
|
* Test for the updateContent() method. |
1552
|
|
|
* |
1553
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContent() |
1554
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
1555
|
|
|
*/ |
1556
|
|
|
public function testUpdateContentThrowsContentFieldValidationException() |
1557
|
|
|
{ |
1558
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
1559
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
1560
|
|
|
|
1561
|
|
|
$contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
1562
|
|
|
$contentCreate->setField('name', 'An awesome Sidelfingen folder'); |
1563
|
|
|
|
1564
|
|
|
$draft = $this->contentService->createContent($contentCreate); |
1565
|
|
|
|
1566
|
|
|
$contentUpdate = $this->contentService->newContentUpdateStruct(); |
1567
|
|
|
// Violates string length constraint |
1568
|
|
|
$contentUpdate->setField('short_name', str_repeat('a', 200), self::ENG_US); |
1569
|
|
|
|
1570
|
|
|
$this->expectException(ContentFieldValidationException::class); |
1571
|
|
|
|
1572
|
|
|
// Throws ContentFieldValidationException because the string length validation of the field "short_name" fails |
1573
|
|
|
$this->contentService->updateContent($draft->getVersionInfo(), $contentUpdate); |
1574
|
|
|
} |
1575
|
|
|
|
1576
|
|
|
/** |
1577
|
|
|
* Test for the updateContent() method. |
1578
|
|
|
* |
1579
|
|
|
* @covers \eZ\Publish\API\Repository\ContentService::updateContent() |
1580
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
1581
|
|
|
*/ |
1582
|
|
|
public function testUpdateContentValidatorIgnoresRequiredFieldsOfNotUpdatedLanguages() |
1583
|
|
|
{ |
1584
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
1585
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
1586
|
|
|
|
1587
|
|
|
// Create multilangual content |
1588
|
|
|
$contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
1589
|
|
|
$contentCreate->setField('name', 'An awesome Sidelfingen folder', self::ENG_US); |
1590
|
|
|
$contentCreate->setField('name', 'An awesome Sidelfingen folder', self::ENG_GB); |
1591
|
|
|
|
1592
|
|
|
$contentDraft = $this->contentService->createContent($contentCreate); |
1593
|
|
|
|
1594
|
|
|
// 2. Update content type definition |
1595
|
|
|
$contentTypeDraft = $contentTypeService->createContentTypeDraft($contentType); |
1596
|
|
|
|
1597
|
|
|
$fieldDefinition = $contentType->getFieldDefinition('description'); |
1598
|
|
|
$fieldDefinitionUpdate = $contentTypeService->newFieldDefinitionUpdateStruct(); |
1599
|
|
|
$fieldDefinitionUpdate->identifier = 'description'; |
1600
|
|
|
$fieldDefinitionUpdate->isRequired = true; |
1601
|
|
|
|
1602
|
|
|
$contentTypeService->updateFieldDefinition( |
1603
|
|
|
$contentTypeDraft, |
1604
|
|
|
$fieldDefinition, |
1605
|
|
|
$fieldDefinitionUpdate |
1606
|
|
|
); |
1607
|
|
|
$contentTypeService->publishContentTypeDraft($contentTypeDraft); |
1608
|
|
|
|
1609
|
|
|
// 3. Update only eng-US translation |
1610
|
|
|
$description = new DOMDocument(); |
1611
|
|
|
$description->loadXML(<<<XML |
1612
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
1613
|
|
|
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml" xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" version="5.0-variant ezpublish-1.0"> |
1614
|
|
|
<para>Lorem ipsum dolor</para> |
1615
|
|
|
</section> |
1616
|
|
|
XML |
1617
|
|
|
); |
1618
|
|
|
|
1619
|
|
|
$contentUpdate = $this->contentService->newContentUpdateStruct(); |
1620
|
|
|
$contentUpdate->setField('name', 'An awesome Sidelfingen folder (updated)', self::ENG_US); |
1621
|
|
|
$contentUpdate->setField('description', $description); |
1622
|
|
|
|
1623
|
|
|
$this->contentService->updateContent($contentDraft->getVersionInfo(), $contentUpdate); |
1624
|
|
|
} |
1625
|
|
|
|
1626
|
|
|
/** |
1627
|
|
|
* Test for the updateContent() method. |
1628
|
|
|
* |
1629
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContent() |
1630
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
1631
|
|
|
*/ |
1632
|
|
|
public function testUpdateContentWithNotUpdatingMandatoryField() |
1633
|
|
|
{ |
1634
|
|
|
$draft = $this->createContentDraftVersion1(); |
1635
|
|
|
|
1636
|
|
|
// Now create an update struct which does not overwrite mandatory |
1637
|
|
|
// fields |
1638
|
|
|
$contentUpdateStruct = $this->contentService->newContentUpdateStruct(); |
1639
|
|
|
$contentUpdateStruct->setField( |
1640
|
|
|
'description', |
1641
|
|
|
'<?xml version="1.0" encoding="UTF-8"?><section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0-variant ezpublish-1.0"/>' |
1642
|
|
|
); |
1643
|
|
|
|
1644
|
|
|
// Don't set this, then the above call without languageCode will fail |
1645
|
|
|
$contentUpdateStruct->initialLanguageCode = self::ENG_US; |
1646
|
|
|
|
1647
|
|
|
// This will only update the "description" field in the "eng-US" language |
1648
|
|
|
$updatedDraft = $this->contentService->updateContent( |
1649
|
|
|
$draft->getVersionInfo(), |
1650
|
|
|
$contentUpdateStruct |
1651
|
|
|
); |
1652
|
|
|
|
1653
|
|
|
foreach ($updatedDraft->getFields() as $field) { |
1654
|
|
|
if ($field->languageCode === self::ENG_US && $field->fieldDefIdentifier === 'name' && $field->value !== null) { |
1655
|
|
|
// Found field |
1656
|
|
|
return; |
1657
|
|
|
} |
1658
|
|
|
} |
1659
|
|
|
$this->fail( |
1660
|
|
|
'Field with identifier "name" in language "eng-US" could not be found or has empty value.' |
1661
|
|
|
); |
1662
|
|
|
} |
1663
|
|
|
|
1664
|
|
|
/** |
1665
|
|
|
* Test for the createContentDraft() method. |
1666
|
|
|
* |
1667
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft($contentInfo, $versionInfo) |
1668
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
1669
|
|
|
*/ |
1670
|
|
|
public function testCreateContentDraftWithSecondParameter() |
1671
|
|
|
{ |
1672
|
|
|
$contentVersion2 = $this->createContentVersion2(); |
1673
|
|
|
|
1674
|
|
|
// Now we create a new draft from the initial version |
1675
|
|
|
$draftedContentReloaded = $this->contentService->createContentDraft( |
1676
|
|
|
$contentVersion2->contentInfo, |
1677
|
|
|
$contentVersion2->getVersionInfo() |
1678
|
|
|
); |
1679
|
|
|
|
1680
|
|
|
$this->assertEquals(3, $draftedContentReloaded->getVersionInfo()->versionNo); |
1681
|
|
|
} |
1682
|
|
|
|
1683
|
|
|
/** |
1684
|
|
|
* Test for the createContentDraft() method with third parameter. |
1685
|
|
|
* |
1686
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
1687
|
|
|
*/ |
1688
|
|
|
public function testCreateContentDraftWithThirdParameter() |
1689
|
|
|
{ |
1690
|
|
|
$content = $this->contentService->loadContent(4); |
1691
|
|
|
$user = $this->createUserVersion1(); |
1692
|
|
|
|
1693
|
|
|
$draftContent = $this->contentService->createContentDraft( |
1694
|
|
|
$content->contentInfo, |
1695
|
|
|
$content->getVersionInfo(), |
1696
|
|
|
$user |
1697
|
|
|
); |
1698
|
|
|
|
1699
|
|
|
$this->assertInstanceOf( |
1700
|
|
|
Content::class, |
1701
|
|
|
$draftContent |
1702
|
|
|
); |
1703
|
|
|
} |
1704
|
|
|
|
1705
|
|
|
/** |
1706
|
|
|
* Test for the publishVersion() method. |
1707
|
|
|
* |
1708
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
1709
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
1710
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
1711
|
|
|
*/ |
1712
|
|
|
public function testPublishVersionFromContentDraft() |
1713
|
|
|
{ |
1714
|
|
|
$contentVersion2 = $this->createContentVersion2(); |
1715
|
|
|
|
1716
|
|
|
$versionInfo = $this->contentService->loadVersionInfo($contentVersion2->contentInfo); |
1717
|
|
|
|
1718
|
|
|
$this->assertEquals( |
1719
|
|
|
[ |
1720
|
|
|
'status' => VersionInfo::STATUS_PUBLISHED, |
1721
|
|
|
'versionNo' => 2, |
1722
|
|
|
], |
1723
|
|
|
[ |
1724
|
|
|
'status' => $versionInfo->status, |
1725
|
|
|
'versionNo' => $versionInfo->versionNo, |
1726
|
|
|
] |
1727
|
|
|
); |
1728
|
|
|
$this->assertTrue($versionInfo->isPublished()); |
1729
|
|
|
$this->assertFalse($versionInfo->isDraft()); |
1730
|
|
|
$this->assertFalse($versionInfo->isArchived()); |
1731
|
|
|
} |
1732
|
|
|
|
1733
|
|
|
/** |
1734
|
|
|
* Test for the publishVersion() method. |
1735
|
|
|
* |
1736
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
1737
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
1738
|
|
|
*/ |
1739
|
|
|
public function testPublishVersionFromContentDraftArchivesOldVersion() |
1740
|
|
|
{ |
1741
|
|
|
$contentVersion2 = $this->createContentVersion2(); |
1742
|
|
|
|
1743
|
|
|
$versionInfo = $this->contentService->loadVersionInfo($contentVersion2->contentInfo, 1); |
1744
|
|
|
|
1745
|
|
|
$this->assertEquals( |
1746
|
|
|
[ |
1747
|
|
|
'status' => VersionInfo::STATUS_ARCHIVED, |
1748
|
|
|
'versionNo' => 1, |
1749
|
|
|
], |
1750
|
|
|
[ |
1751
|
|
|
'status' => $versionInfo->status, |
1752
|
|
|
'versionNo' => $versionInfo->versionNo, |
1753
|
|
|
] |
1754
|
|
|
); |
1755
|
|
|
$this->assertTrue($versionInfo->isArchived()); |
1756
|
|
|
$this->assertFalse($versionInfo->isDraft()); |
1757
|
|
|
$this->assertFalse($versionInfo->isPublished()); |
1758
|
|
|
} |
1759
|
|
|
|
1760
|
|
|
/** |
1761
|
|
|
* Test for the publishVersion() method. |
1762
|
|
|
* |
1763
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
1764
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
1765
|
|
|
*/ |
1766
|
|
|
public function testPublishVersionFromContentDraftUpdatesContentInfoCurrentVersion() |
1767
|
|
|
{ |
1768
|
|
|
$contentVersion2 = $this->createContentVersion2(); |
1769
|
|
|
|
1770
|
|
|
$this->assertEquals(2, $contentVersion2->contentInfo->currentVersionNo); |
1771
|
|
|
} |
1772
|
|
|
|
1773
|
|
|
/** |
1774
|
|
|
* Test for the publishVersion() method. |
1775
|
|
|
* |
1776
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
1777
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
1778
|
|
|
*/ |
1779
|
|
|
public function testPublishVersionFromOldContentDraftArchivesNewerVersionNo() |
1780
|
|
|
{ |
1781
|
|
|
$content = $this->createContentVersion1(); |
1782
|
|
|
|
1783
|
|
|
// Create a new draft with versionNo = 2 |
1784
|
|
|
$draftedContentVersion2 = $this->contentService->createContentDraft($content->contentInfo); |
1785
|
|
|
|
1786
|
|
|
// Create another new draft with versionNo = 3 |
1787
|
|
|
$draftedContentVersion3 = $this->contentService->createContentDraft($content->contentInfo); |
1788
|
|
|
|
1789
|
|
|
// Publish draft with versionNo = 3 |
1790
|
|
|
$this->contentService->publishVersion($draftedContentVersion3->getVersionInfo()); |
1791
|
|
|
|
1792
|
|
|
// Publish the first draft with versionNo = 2 |
1793
|
|
|
// currentVersionNo is now 2, versionNo 3 will be archived |
1794
|
|
|
$publishedDraft = $this->contentService->publishVersion($draftedContentVersion2->getVersionInfo()); |
1795
|
|
|
|
1796
|
|
|
$this->assertEquals(2, $publishedDraft->contentInfo->currentVersionNo); |
1797
|
|
|
} |
1798
|
|
|
|
1799
|
|
|
/** |
1800
|
|
|
* Test for the publishVersion() method, and that it creates limited archives. |
1801
|
|
|
* |
1802
|
|
|
* @todo Adapt this when per content type archive limited is added on repository Content Type model. |
1803
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
1804
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
1805
|
|
|
*/ |
1806
|
|
|
public function testPublishVersionNotCreatingUnlimitedArchives() |
1807
|
|
|
{ |
1808
|
|
|
$content = $this->createContentVersion1(); |
1809
|
|
|
|
1810
|
|
|
// load first to make sure list gets updated also (cache) |
1811
|
|
|
$versionInfoList = $this->contentService->loadVersions($content->contentInfo); |
1812
|
|
|
$this->assertEquals(1, count($versionInfoList)); |
1813
|
|
|
$this->assertEquals(1, $versionInfoList[0]->versionNo); |
1814
|
|
|
|
1815
|
|
|
// Create a new draft with versionNo = 2 |
1816
|
|
|
$draftedContentVersion = $this->contentService->createContentDraft($content->contentInfo); |
1817
|
|
|
$this->contentService->publishVersion($draftedContentVersion->getVersionInfo()); |
1818
|
|
|
|
1819
|
|
|
// Create a new draft with versionNo = 3 |
1820
|
|
|
$draftedContentVersion = $this->contentService->createContentDraft($content->contentInfo); |
1821
|
|
|
$this->contentService->publishVersion($draftedContentVersion->getVersionInfo()); |
1822
|
|
|
|
1823
|
|
|
// Create a new draft with versionNo = 4 |
1824
|
|
|
$draftedContentVersion = $this->contentService->createContentDraft($content->contentInfo); |
1825
|
|
|
$this->contentService->publishVersion($draftedContentVersion->getVersionInfo()); |
1826
|
|
|
|
1827
|
|
|
// Create a new draft with versionNo = 5 |
1828
|
|
|
$draftedContentVersion = $this->contentService->createContentDraft($content->contentInfo); |
1829
|
|
|
$this->contentService->publishVersion($draftedContentVersion->getVersionInfo()); |
1830
|
|
|
|
1831
|
|
|
// Create a new draft with versionNo = 6 |
1832
|
|
|
$draftedContentVersion = $this->contentService->createContentDraft($content->contentInfo); |
1833
|
|
|
$this->contentService->publishVersion($draftedContentVersion->getVersionInfo()); |
1834
|
|
|
|
1835
|
|
|
// Create a new draft with versionNo = 7 |
1836
|
|
|
$draftedContentVersion = $this->contentService->createContentDraft($content->contentInfo); |
1837
|
|
|
$this->contentService->publishVersion($draftedContentVersion->getVersionInfo()); |
1838
|
|
|
|
1839
|
|
|
$versionInfoList = $this->contentService->loadVersions($content->contentInfo); |
1840
|
|
|
|
1841
|
|
|
$this->assertEquals(6, count($versionInfoList)); |
1842
|
|
|
$this->assertEquals(2, $versionInfoList[0]->versionNo); |
1843
|
|
|
$this->assertEquals(7, $versionInfoList[5]->versionNo); |
1844
|
|
|
|
1845
|
|
|
$this->assertEquals( |
1846
|
|
|
[ |
1847
|
|
|
VersionInfo::STATUS_ARCHIVED, |
1848
|
|
|
VersionInfo::STATUS_ARCHIVED, |
1849
|
|
|
VersionInfo::STATUS_ARCHIVED, |
1850
|
|
|
VersionInfo::STATUS_ARCHIVED, |
1851
|
|
|
VersionInfo::STATUS_ARCHIVED, |
1852
|
|
|
VersionInfo::STATUS_PUBLISHED, |
1853
|
|
|
], |
1854
|
|
|
[ |
1855
|
|
|
$versionInfoList[0]->status, |
1856
|
|
|
$versionInfoList[1]->status, |
1857
|
|
|
$versionInfoList[2]->status, |
1858
|
|
|
$versionInfoList[3]->status, |
1859
|
|
|
$versionInfoList[4]->status, |
1860
|
|
|
$versionInfoList[5]->status, |
1861
|
|
|
] |
1862
|
|
|
); |
1863
|
|
|
} |
1864
|
|
|
|
1865
|
|
|
/** |
1866
|
|
|
* Test for the newContentMetadataUpdateStruct() method. |
1867
|
|
|
* |
1868
|
|
|
* @covers \eZ\Publish\API\Repository\ContentService::newContentMetadataUpdateStruct |
1869
|
|
|
* @group user |
1870
|
|
|
*/ |
1871
|
|
|
public function testNewContentMetadataUpdateStruct() |
1872
|
|
|
{ |
1873
|
|
|
// Creates a new metadata update struct |
1874
|
|
|
$metadataUpdate = $this->contentService->newContentMetadataUpdateStruct(); |
1875
|
|
|
|
1876
|
|
|
foreach ($metadataUpdate as $propertyName => $propertyValue) { |
|
|
|
|
1877
|
|
|
$this->assertNull($propertyValue, "Property '{$propertyName}' initial value should be null'"); |
1878
|
|
|
} |
1879
|
|
|
|
1880
|
|
|
$metadataUpdate->remoteId = 'aaaabbbbccccddddeeeeffff11112222'; |
1881
|
|
|
$metadataUpdate->mainLanguageCode = self::ENG_GB; |
1882
|
|
|
$metadataUpdate->alwaysAvailable = false; |
1883
|
|
|
|
1884
|
|
|
$this->assertInstanceOf( |
1885
|
|
|
ContentMetadataUpdateStruct::class, |
1886
|
|
|
$metadataUpdate |
1887
|
|
|
); |
1888
|
|
|
} |
1889
|
|
|
|
1890
|
|
|
/** |
1891
|
|
|
* Test for the updateContentMetadata() method. |
1892
|
|
|
* |
1893
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
1894
|
|
|
* |
1895
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
1896
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
1897
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentMetadataUpdateStruct |
1898
|
|
|
* @group user |
1899
|
|
|
*/ |
1900
|
|
|
public function testUpdateContentMetadata() |
1901
|
|
|
{ |
1902
|
|
|
$content = $this->createContentVersion1(); |
1903
|
|
|
|
1904
|
|
|
// Creates a metadata update struct |
1905
|
|
|
$metadataUpdate = $this->contentService->newContentMetadataUpdateStruct(); |
1906
|
|
|
|
1907
|
|
|
$metadataUpdate->remoteId = 'aaaabbbbccccddddeeeeffff11112222'; |
1908
|
|
|
$metadataUpdate->mainLanguageCode = self::ENG_GB; |
1909
|
|
|
$metadataUpdate->alwaysAvailable = false; |
1910
|
|
|
$metadataUpdate->publishedDate = $this->createDateTime(441759600); // 1984/01/01 |
1911
|
|
|
$metadataUpdate->modificationDate = $this->createDateTime(441759600); // 1984/01/01 |
1912
|
|
|
|
1913
|
|
|
// Update the metadata of the published content object |
1914
|
|
|
$content = $this->contentService->updateContentMetadata( |
1915
|
|
|
$content->contentInfo, |
1916
|
|
|
$metadataUpdate |
1917
|
|
|
); |
1918
|
|
|
|
1919
|
|
|
$this->assertInstanceOf( |
1920
|
|
|
Content::class, |
1921
|
|
|
$content |
1922
|
|
|
); |
1923
|
|
|
|
1924
|
|
|
return $content; |
1925
|
|
|
} |
1926
|
|
|
|
1927
|
|
|
/** |
1928
|
|
|
* Test for the updateContentMetadata() method. |
1929
|
|
|
* |
1930
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $content |
1931
|
|
|
* |
1932
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
1933
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
1934
|
|
|
*/ |
1935
|
|
|
public function testUpdateContentMetadataSetsExpectedProperties($content) |
1936
|
|
|
{ |
1937
|
|
|
$contentInfo = $content->contentInfo; |
1938
|
|
|
|
1939
|
|
|
$this->assertEquals( |
1940
|
|
|
[ |
1941
|
|
|
'remoteId' => 'aaaabbbbccccddddeeeeffff11112222', |
1942
|
|
|
'sectionId' => $this->generateId('section', 1), |
1943
|
|
|
'alwaysAvailable' => false, |
1944
|
|
|
'currentVersionNo' => 1, |
1945
|
|
|
'mainLanguageCode' => self::ENG_GB, |
1946
|
|
|
'modificationDate' => $this->createDateTime(441759600), |
1947
|
|
|
'ownerId' => $this->getRepository()->getCurrentUser()->id, |
|
|
|
|
1948
|
|
|
'published' => true, |
1949
|
|
|
'publishedDate' => $this->createDateTime(441759600), |
1950
|
|
|
], |
1951
|
|
|
[ |
1952
|
|
|
'remoteId' => $contentInfo->remoteId, |
1953
|
|
|
'sectionId' => $contentInfo->sectionId, |
1954
|
|
|
'alwaysAvailable' => $contentInfo->alwaysAvailable, |
1955
|
|
|
'currentVersionNo' => $contentInfo->currentVersionNo, |
1956
|
|
|
'mainLanguageCode' => $contentInfo->mainLanguageCode, |
1957
|
|
|
'modificationDate' => $contentInfo->modificationDate, |
1958
|
|
|
'ownerId' => $contentInfo->ownerId, |
1959
|
|
|
'published' => $contentInfo->published, |
1960
|
|
|
'publishedDate' => $contentInfo->publishedDate, |
1961
|
|
|
] |
1962
|
|
|
); |
1963
|
|
|
} |
1964
|
|
|
|
1965
|
|
|
/** |
1966
|
|
|
* Test for the updateContentMetadata() method. |
1967
|
|
|
* |
1968
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $content |
1969
|
|
|
* |
1970
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
1971
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
1972
|
|
|
*/ |
1973
|
|
|
public function testUpdateContentMetadataNotUpdatesContentVersion($content) |
1974
|
|
|
{ |
1975
|
|
|
$this->assertEquals(1, $content->getVersionInfo()->versionNo); |
1976
|
|
|
} |
1977
|
|
|
|
1978
|
|
|
/** |
1979
|
|
|
* Test for the updateContentMetadata() method. |
1980
|
|
|
* |
1981
|
|
|
* @covers \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
1982
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
1983
|
|
|
*/ |
1984
|
|
|
public function testUpdateContentMetadataThrowsInvalidArgumentExceptionOnDuplicateRemoteId() |
1985
|
|
|
{ |
1986
|
|
|
$content = $this->createContentVersion1(); |
1987
|
|
|
|
1988
|
|
|
// Creates a metadata update struct |
1989
|
|
|
$metadataUpdate = $this->contentService->newContentMetadataUpdateStruct(); |
1990
|
|
|
$metadataUpdate->remoteId = self::MEDIA_REMOTE_ID; |
1991
|
|
|
|
1992
|
|
|
$this->expectException(APIInvalidArgumentException::class); |
1993
|
|
|
// specified remoteId is already used by the "Media" page. |
1994
|
|
|
$this->contentService->updateContentMetadata( |
1995
|
|
|
$content->contentInfo, |
1996
|
|
|
$metadataUpdate |
1997
|
|
|
); |
1998
|
|
|
} |
1999
|
|
|
|
2000
|
|
|
/** |
2001
|
|
|
* Test for the updateContentMetadata() method. |
2002
|
|
|
* |
2003
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata |
2004
|
|
|
*/ |
2005
|
|
|
public function testUpdateContentMetadataThrowsInvalidArgumentExceptionOnNoMetadataPropertiesSet() |
2006
|
|
|
{ |
2007
|
|
|
$contentInfo = $this->contentService->loadContentInfo(4); |
2008
|
|
|
$contentMetadataUpdateStruct = $this->contentService->newContentMetadataUpdateStruct(); |
2009
|
|
|
|
2010
|
|
|
$this->expectException(APIInvalidArgumentException::class); |
2011
|
|
|
$this->contentService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct); |
2012
|
|
|
} |
2013
|
|
|
|
2014
|
|
|
/** |
2015
|
|
|
* Test for the deleteContent() method. |
2016
|
|
|
* |
2017
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteContent() |
2018
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
2019
|
|
|
*/ |
2020
|
|
|
public function testDeleteContent() |
2021
|
|
|
{ |
2022
|
|
|
$contentVersion2 = $this->createContentVersion2(); |
2023
|
|
|
|
2024
|
|
|
// Load the locations for this content object |
2025
|
|
|
$locations = $this->locationService->loadLocations($contentVersion2->contentInfo); |
2026
|
|
|
|
2027
|
|
|
// This will delete the content, all versions and the associated locations |
2028
|
|
|
$this->contentService->deleteContent($contentVersion2->contentInfo); |
2029
|
|
|
|
2030
|
|
|
$this->expectException(NotFoundException::class); |
2031
|
|
|
|
2032
|
|
|
foreach ($locations as $location) { |
2033
|
|
|
$this->locationService->loadLocation($location->id); |
2034
|
|
|
} |
2035
|
|
|
} |
2036
|
|
|
|
2037
|
|
|
/** |
2038
|
|
|
* Test for the deleteContent() method. |
2039
|
|
|
* |
2040
|
|
|
* Test for issue EZP-21057: |
2041
|
|
|
* "contentService: Unable to delete a content with an empty file attribute" |
2042
|
|
|
* |
2043
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteContent() |
2044
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
2045
|
|
|
*/ |
2046
|
|
|
public function testDeleteContentWithEmptyBinaryField() |
2047
|
|
|
{ |
2048
|
|
|
$contentVersion = $this->createContentVersion1EmptyBinaryField(); |
2049
|
|
|
|
2050
|
|
|
// Load the locations for this content object |
2051
|
|
|
$locations = $this->locationService->loadLocations($contentVersion->contentInfo); |
2052
|
|
|
|
2053
|
|
|
// This will delete the content, all versions and the associated locations |
2054
|
|
|
$this->contentService->deleteContent($contentVersion->contentInfo); |
2055
|
|
|
|
2056
|
|
|
$this->expectException(NotFoundException::class); |
2057
|
|
|
|
2058
|
|
|
foreach ($locations as $location) { |
2059
|
|
|
$this->locationService->loadLocation($location->id); |
2060
|
|
|
} |
2061
|
|
|
} |
2062
|
|
|
|
2063
|
|
|
public function testCountContentDraftsReturnsZeroByDefault(): void |
2064
|
|
|
{ |
2065
|
|
|
$this->assertSame(0, $this->contentService->countContentDrafts()); |
2066
|
|
|
} |
2067
|
|
|
|
2068
|
|
|
public function testCountContentDrafts(): void |
2069
|
|
|
{ |
2070
|
|
|
// Create 5 drafts |
2071
|
|
|
$this->createContentDrafts(5); |
2072
|
|
|
|
2073
|
|
|
$this->assertSame(5, $this->contentService->countContentDrafts()); |
2074
|
|
|
} |
2075
|
|
|
|
2076
|
|
|
public function testCountContentDraftsForUsers(): void |
2077
|
|
|
{ |
2078
|
|
|
$newUser = $this->createUserWithPolicies( |
2079
|
|
|
'new_user', |
2080
|
|
|
[ |
2081
|
|
|
['module' => 'content', 'function' => 'create'], |
2082
|
|
|
['module' => 'content', 'function' => 'read'], |
2083
|
|
|
['module' => 'content', 'function' => 'publish'], |
2084
|
|
|
['module' => 'content', 'function' => 'edit'], |
2085
|
|
|
] |
2086
|
|
|
); |
2087
|
|
|
|
2088
|
|
|
$previousUser = $this->permissionResolver->getCurrentUserReference(); |
2089
|
|
|
|
2090
|
|
|
// Set new editor as user |
2091
|
|
|
$this->permissionResolver->setCurrentUserReference($newUser); |
2092
|
|
|
|
2093
|
|
|
// Create a content draft as newUser |
2094
|
|
|
$publishedContent = $this->createContentVersion1(); |
2095
|
|
|
$this->contentService->createContentDraft($publishedContent->contentInfo); |
2096
|
|
|
|
2097
|
|
|
// Reset to previous current user |
2098
|
|
|
$this->permissionResolver->setCurrentUserReference($previousUser); |
2099
|
|
|
|
2100
|
|
|
// Now $contentDrafts for the previous current user and the new user |
2101
|
|
|
$newUserDrafts = $this->contentService->countContentDrafts($newUser); |
2102
|
|
|
$previousUserDrafts = $this->contentService->countContentDrafts(); |
2103
|
|
|
|
2104
|
|
|
$this->assertSame(1, $newUserDrafts); |
2105
|
|
|
$this->assertSame(0, $previousUserDrafts); |
2106
|
|
|
} |
2107
|
|
|
|
2108
|
|
|
/** |
2109
|
|
|
* Test for the loadContentDrafts() method. |
2110
|
|
|
* |
2111
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts() |
2112
|
|
|
*/ |
2113
|
|
|
public function testLoadContentDraftsReturnsEmptyArrayByDefault() |
2114
|
|
|
{ |
2115
|
|
|
$contentDrafts = $this->contentService->loadContentDrafts(); |
2116
|
|
|
|
2117
|
|
|
$this->assertSame([], $contentDrafts); |
2118
|
|
|
} |
2119
|
|
|
|
2120
|
|
|
/** |
2121
|
|
|
* Test for the loadContentDrafts() method. |
2122
|
|
|
* |
2123
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts() |
2124
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
2125
|
|
|
*/ |
2126
|
|
|
public function testLoadContentDrafts() |
2127
|
|
|
{ |
2128
|
|
|
// "Media" content object |
2129
|
|
|
$mediaContentInfo = $this->contentService->loadContentInfoByRemoteId(self::MEDIA_REMOTE_ID); |
2130
|
|
|
|
2131
|
|
|
// "eZ Publish Demo Design ..." content object |
2132
|
|
|
$demoDesignContentInfo = $this->contentService->loadContentInfoByRemoteId(self::DEMO_DESIGN_REMOTE_ID); |
2133
|
|
|
|
2134
|
|
|
// Create some drafts |
2135
|
|
|
$this->contentService->createContentDraft($mediaContentInfo); |
2136
|
|
|
$this->contentService->createContentDraft($demoDesignContentInfo); |
2137
|
|
|
|
2138
|
|
|
// Now $contentDrafts should contain two drafted versions |
2139
|
|
|
$draftedVersions = $this->contentService->loadContentDrafts(); |
2140
|
|
|
|
2141
|
|
|
$actual = [ |
2142
|
|
|
$draftedVersions[0]->status, |
2143
|
|
|
$draftedVersions[0]->getContentInfo()->remoteId, |
2144
|
|
|
$draftedVersions[1]->status, |
2145
|
|
|
$draftedVersions[1]->getContentInfo()->remoteId, |
2146
|
|
|
]; |
2147
|
|
|
sort($actual, SORT_STRING); |
2148
|
|
|
|
2149
|
|
|
$this->assertEquals( |
2150
|
|
|
[ |
2151
|
|
|
VersionInfo::STATUS_DRAFT, |
2152
|
|
|
VersionInfo::STATUS_DRAFT, |
2153
|
|
|
self::DEMO_DESIGN_REMOTE_ID, |
2154
|
|
|
self::MEDIA_REMOTE_ID, |
2155
|
|
|
], |
2156
|
|
|
$actual |
2157
|
|
|
); |
2158
|
|
|
} |
2159
|
|
|
|
2160
|
|
|
/** |
2161
|
|
|
* Test for the loadContentDrafts() method. |
2162
|
|
|
* |
2163
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts($user) |
2164
|
|
|
*/ |
2165
|
|
|
public function testLoadContentDraftsWithFirstParameter() |
2166
|
|
|
{ |
2167
|
|
|
$user = $this->createUserVersion1(); |
2168
|
|
|
|
2169
|
|
|
// Get current user |
2170
|
|
|
$oldCurrentUser = $this->permissionResolver->getCurrentUserReference(); |
2171
|
|
|
|
2172
|
|
|
// Set new editor as user |
2173
|
|
|
$this->permissionResolver->setCurrentUserReference($user); |
2174
|
|
|
|
2175
|
|
|
// "Media" content object |
2176
|
|
|
$mediaContentInfo = $this->contentService->loadContentInfoByRemoteId(self::MEDIA_REMOTE_ID); |
2177
|
|
|
|
2178
|
|
|
// Create a content draft |
2179
|
|
|
$this->contentService->createContentDraft($mediaContentInfo); |
2180
|
|
|
|
2181
|
|
|
// Reset to previous current user |
2182
|
|
|
$this->permissionResolver->setCurrentUserReference($oldCurrentUser); |
2183
|
|
|
|
2184
|
|
|
// Now $contentDrafts for the previous current user and the new user |
2185
|
|
|
$newCurrentUserDrafts = $this->contentService->loadContentDrafts($user); |
2186
|
|
|
$oldCurrentUserDrafts = $this->contentService->loadContentDrafts(); |
2187
|
|
|
|
2188
|
|
|
$this->assertSame([], $oldCurrentUserDrafts); |
2189
|
|
|
|
2190
|
|
|
$this->assertEquals( |
2191
|
|
|
[ |
2192
|
|
|
VersionInfo::STATUS_DRAFT, |
2193
|
|
|
self::MEDIA_REMOTE_ID, |
2194
|
|
|
], |
2195
|
|
|
[ |
2196
|
|
|
$newCurrentUserDrafts[0]->status, |
2197
|
|
|
$newCurrentUserDrafts[0]->getContentInfo()->remoteId, |
2198
|
|
|
] |
2199
|
|
|
); |
2200
|
|
|
$this->assertTrue($newCurrentUserDrafts[0]->isDraft()); |
2201
|
|
|
$this->assertFalse($newCurrentUserDrafts[0]->isArchived()); |
2202
|
|
|
$this->assertFalse($newCurrentUserDrafts[0]->isPublished()); |
2203
|
|
|
} |
2204
|
|
|
|
2205
|
|
|
/** |
2206
|
|
|
* Test for the loadContentDraftList() method. |
2207
|
|
|
* |
2208
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts() |
2209
|
|
|
*/ |
2210
|
|
|
public function testLoadContentDraftListWithPaginationParameters() |
2211
|
|
|
{ |
2212
|
|
|
// Create some drafts |
2213
|
|
|
$publishedContent = $this->createContentVersion1(); |
2214
|
|
|
$draftContentA = $this->contentService->createContentDraft($publishedContent->contentInfo); |
2215
|
|
|
$draftContentB = $this->contentService->createContentDraft($draftContentA->contentInfo); |
2216
|
|
|
$draftContentC = $this->contentService->createContentDraft($draftContentB->contentInfo); |
2217
|
|
|
$draftContentD = $this->contentService->createContentDraft($draftContentC->contentInfo); |
2218
|
|
|
$draftContentE = $this->contentService->createContentDraft($draftContentD->contentInfo); |
2219
|
|
|
|
2220
|
|
|
$draftsOnPage1 = $this->contentService->loadContentDraftList(null, 0, 2); |
2221
|
|
|
$draftsOnPage2 = $this->contentService->loadContentDraftList(null, 2, 2); |
2222
|
|
|
|
2223
|
|
|
$this->assertSame(5, $draftsOnPage1->totalCount); |
2224
|
|
|
$this->assertSame(5, $draftsOnPage2->totalCount); |
2225
|
|
|
$this->assertEquals($draftContentE->getVersionInfo(), $draftsOnPage1->items[0]->getVersionInfo()); |
2226
|
|
|
$this->assertEquals($draftContentD->getVersionInfo(), $draftsOnPage1->items[1]->getVersionInfo()); |
2227
|
|
|
$this->assertEquals($draftContentC->getVersionInfo(), $draftsOnPage2->items[0]->getVersionInfo()); |
2228
|
|
|
$this->assertEquals($draftContentB->getVersionInfo(), $draftsOnPage2->items[1]->getVersionInfo()); |
2229
|
|
|
} |
2230
|
|
|
|
2231
|
|
|
/** |
2232
|
|
|
* Test for the loadContentDraftList() method. |
2233
|
|
|
* |
2234
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts($user) |
2235
|
|
|
*/ |
2236
|
|
|
public function testLoadContentDraftListWithForUserWithLimitation() |
2237
|
|
|
{ |
2238
|
|
|
$oldUser = $this->permissionResolver->getCurrentUserReference(); |
2239
|
|
|
|
2240
|
|
|
$parentContent = $this->createFolder(['eng-US' => 'parentFolder'], 2); |
2241
|
|
|
$content = $this->createFolder(['eng-US' => 'parentFolder'], $parentContent->contentInfo->mainLocationId); |
2242
|
|
|
|
2243
|
|
|
// User has limitation to read versions only for `$content`, not for `$parentContent` |
2244
|
|
|
$newUser = $this->createUserWithVersionReadLimitations([$content->contentInfo->mainLocationId]); |
2245
|
|
|
|
2246
|
|
|
$this->permissionResolver->setCurrentUserReference($newUser); |
2247
|
|
|
|
2248
|
|
|
$contentDraftUnauthorized = $this->contentService->createContentDraft($parentContent->contentInfo); |
2249
|
|
|
$contentDraftA = $this->contentService->createContentDraft($content->contentInfo); |
2250
|
|
|
$contentDraftB = $this->contentService->createContentDraft($content->contentInfo); |
2251
|
|
|
|
2252
|
|
|
$newUserDraftList = $this->contentService->loadContentDraftList($newUser, 0); |
2253
|
|
|
$this->assertSame(3, $newUserDraftList->totalCount); |
2254
|
|
|
$this->assertEquals($contentDraftB->getVersionInfo(), $newUserDraftList->items[0]->getVersionInfo()); |
2255
|
|
|
$this->assertEquals($contentDraftA->getVersionInfo(), $newUserDraftList->items[1]->getVersionInfo()); |
2256
|
|
|
$this->assertEquals( |
2257
|
|
|
new UnauthorizedContentDraftListItem('content', 'versionread', ['contentId' => $contentDraftUnauthorized->id]), |
2258
|
|
|
$newUserDraftList->items[2] |
2259
|
|
|
); |
2260
|
|
|
|
2261
|
|
|
// Reset to previous user |
2262
|
|
|
$this->permissionResolver->setCurrentUserReference($oldUser); |
2263
|
|
|
|
2264
|
|
|
$oldUserDraftList = $this->contentService->loadContentDraftList(); |
2265
|
|
|
|
2266
|
|
|
$this->assertSame(0, $oldUserDraftList->totalCount); |
2267
|
|
|
$this->assertSame([], $oldUserDraftList->items); |
2268
|
|
|
} |
2269
|
|
|
|
2270
|
|
|
/** |
2271
|
|
|
* Test for the loadContentDraftList() method. |
2272
|
|
|
* |
2273
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts() |
2274
|
|
|
*/ |
2275
|
|
|
public function testLoadAllContentDrafts() |
2276
|
|
|
{ |
2277
|
|
|
// Create more drafts then default pagination limit |
2278
|
|
|
$this->createContentDrafts(12); |
2279
|
|
|
|
2280
|
|
|
$this->assertCount(12, $this->contentService->loadContentDraftList()); |
2281
|
|
|
} |
2282
|
|
|
|
2283
|
|
|
/** |
2284
|
|
|
* Test for the loadVersionInfo() method. |
2285
|
|
|
* |
2286
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo($contentInfo, $versionNo) |
2287
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
2288
|
|
|
*/ |
2289
|
|
|
public function testLoadVersionInfoWithSecondParameter() |
2290
|
|
|
{ |
2291
|
|
|
$publishedContent = $this->createContentVersion1(); |
2292
|
|
|
|
2293
|
|
|
$this->contentService->createContentDraft($publishedContent->contentInfo); |
2294
|
|
|
|
2295
|
|
|
// Will return the VersionInfo of the $draftContent |
2296
|
|
|
$versionInfo = $this->contentService->loadVersionInfoById($publishedContent->id, 2); |
2297
|
|
|
|
2298
|
|
|
$this->assertEquals(2, $versionInfo->versionNo); |
2299
|
|
|
|
2300
|
|
|
// Check that ContentInfo contained in VersionInfo has correct main Location id set |
2301
|
|
|
$this->assertEquals( |
2302
|
|
|
$publishedContent->getVersionInfo()->getContentInfo()->mainLocationId, |
2303
|
|
|
$versionInfo->getContentInfo()->mainLocationId |
2304
|
|
|
); |
2305
|
|
|
} |
2306
|
|
|
|
2307
|
|
|
/** |
2308
|
|
|
* Test for the loadVersionInfo() method. |
2309
|
|
|
* |
2310
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo($contentInfo, $versionNo) |
2311
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoWithSecondParameter |
2312
|
|
|
*/ |
2313
|
|
|
public function testLoadVersionInfoThrowsNotFoundExceptionWithSecondParameter() |
2314
|
|
|
{ |
2315
|
|
|
$draft = $this->createContentDraftVersion1(); |
2316
|
|
|
|
2317
|
|
|
$this->expectException(NotFoundException::class); |
2318
|
|
|
|
2319
|
|
|
// This call will fail with a "NotFoundException", because not versionNo 2 exists for this content object. |
2320
|
|
|
$this->contentService->loadVersionInfo($draft->contentInfo, 2); |
2321
|
|
|
} |
2322
|
|
|
|
2323
|
|
|
/** |
2324
|
|
|
* Test for the loadVersionInfoById() method. |
2325
|
|
|
* |
2326
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById($contentId, $versionNo) |
2327
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoWithSecondParameter |
2328
|
|
|
*/ |
2329
|
|
|
public function testLoadVersionInfoByIdWithSecondParameter() |
2330
|
|
|
{ |
2331
|
|
|
$publishedContent = $this->createContentVersion1(); |
2332
|
|
|
|
2333
|
|
|
$draftContent = $this->contentService->createContentDraft($publishedContent->contentInfo); |
2334
|
|
|
|
2335
|
|
|
// Will return the VersionInfo of the $draftContent |
2336
|
|
|
$versionInfo = $this->contentService->loadVersionInfoById($publishedContent->id, 2); |
2337
|
|
|
|
2338
|
|
|
$this->assertEquals(2, $versionInfo->versionNo); |
2339
|
|
|
|
2340
|
|
|
// Check that ContentInfo contained in VersionInfo has correct main Location id set |
2341
|
|
|
$this->assertEquals( |
2342
|
|
|
$publishedContent->getVersionInfo()->getContentInfo()->mainLocationId, |
2343
|
|
|
$versionInfo->getContentInfo()->mainLocationId |
2344
|
|
|
); |
2345
|
|
|
|
2346
|
|
|
return [ |
2347
|
|
|
'versionInfo' => $versionInfo, |
2348
|
|
|
'draftContent' => $draftContent, |
2349
|
|
|
]; |
2350
|
|
|
} |
2351
|
|
|
|
2352
|
|
|
/** |
2353
|
|
|
* Test for the returned value of the loadVersionInfoById() method. |
2354
|
|
|
* |
2355
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoByIdWithSecondParameter |
2356
|
|
|
* @covers \eZ\Publish\API\Repository\ContentService::loadVersionInfoById |
2357
|
|
|
* |
2358
|
|
|
* @param array $data |
2359
|
|
|
*/ |
2360
|
|
|
public function testLoadVersionInfoByIdWithSecondParameterSetsExpectedVersionInfo(array $data) |
2361
|
|
|
{ |
2362
|
|
|
/** @var VersionInfo $versionInfo */ |
2363
|
|
|
$versionInfo = $data['versionInfo']; |
2364
|
|
|
/** @var \eZ\Publish\API\Repository\Values\Content\Content $draftContent */ |
2365
|
|
|
$draftContent = $data['draftContent']; |
2366
|
|
|
|
2367
|
|
|
$this->assertPropertiesCorrect( |
2368
|
|
|
[ |
2369
|
|
|
'names' => [ |
2370
|
|
|
self::ENG_US => 'An awesome forum', |
2371
|
|
|
], |
2372
|
|
|
'contentInfo' => new ContentInfo([ |
2373
|
|
|
'id' => $draftContent->contentInfo->id, |
2374
|
|
|
'contentTypeId' => 28, |
2375
|
|
|
'name' => 'An awesome forum', |
2376
|
|
|
'sectionId' => 1, |
2377
|
|
|
'currentVersionNo' => 1, |
2378
|
|
|
'published' => true, |
2379
|
|
|
'ownerId' => 14, |
2380
|
|
|
// this Content Object is created at the test runtime |
2381
|
|
|
'modificationDate' => $versionInfo->contentInfo->modificationDate, |
2382
|
|
|
'publishedDate' => $versionInfo->contentInfo->publishedDate, |
2383
|
|
|
'alwaysAvailable' => 1, |
2384
|
|
|
'remoteId' => 'abcdef0123456789abcdef0123456789', |
2385
|
|
|
'mainLanguageCode' => self::ENG_US, |
2386
|
|
|
'mainLocationId' => $draftContent->contentInfo->mainLocationId, |
2387
|
|
|
'status' => ContentInfo::STATUS_PUBLISHED, |
2388
|
|
|
]), |
2389
|
|
|
'id' => $draftContent->versionInfo->id, |
2390
|
|
|
'versionNo' => 2, |
2391
|
|
|
'creatorId' => 14, |
2392
|
|
|
'status' => 0, |
2393
|
|
|
'initialLanguageCode' => self::ENG_US, |
2394
|
|
|
'languageCodes' => [ |
2395
|
|
|
self::ENG_US, |
2396
|
|
|
], |
2397
|
|
|
], |
2398
|
|
|
$versionInfo |
2399
|
|
|
); |
2400
|
|
|
} |
2401
|
|
|
|
2402
|
|
|
/** |
2403
|
|
|
* Test for the loadVersionInfoById() method. |
2404
|
|
|
* |
2405
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById($contentId, $versionNo) |
2406
|
|
|
*/ |
2407
|
|
|
public function testLoadVersionInfoByIdThrowsNotFoundExceptionWithSecondParameter() |
2408
|
|
|
{ |
2409
|
|
|
$content = $this->createContentVersion1(); |
2410
|
|
|
|
2411
|
|
|
$this->expectException(NotFoundException::class); |
2412
|
|
|
|
2413
|
|
|
// This call will fail with a "NotFoundException", because not versionNo 2 exists for this content object. |
2414
|
|
|
$this->contentService->loadVersionInfoById($content->id, 2); |
2415
|
|
|
} |
2416
|
|
|
|
2417
|
|
|
/** |
2418
|
|
|
* Test for the loadContentByVersionInfo() method. |
2419
|
|
|
* |
2420
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByVersionInfo($versionInfo, $languages) |
2421
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
2422
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByVersionInfo |
2423
|
|
|
*/ |
2424
|
|
|
public function testLoadContentByVersionInfoWithSecondParameter() |
2425
|
|
|
{ |
2426
|
|
|
$sectionId = $this->generateId('section', 1); |
2427
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
2428
|
|
|
|
2429
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
2430
|
|
|
|
2431
|
|
|
$contentCreateStruct = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
2432
|
|
|
|
2433
|
|
|
$contentCreateStruct->setField('name', 'Sindelfingen forum²'); |
2434
|
|
|
|
2435
|
|
|
$contentCreateStruct->setField('name', 'Sindelfingen forum²³', self::ENG_GB); |
2436
|
|
|
|
2437
|
|
|
$contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
2438
|
|
|
// $sectionId contains the ID of section 1 |
2439
|
|
|
$contentCreateStruct->sectionId = $sectionId; |
2440
|
|
|
$contentCreateStruct->alwaysAvailable = true; |
2441
|
|
|
|
2442
|
|
|
// Create a new content draft |
2443
|
|
|
$content = $this->contentService->createContent($contentCreateStruct); |
2444
|
|
|
|
2445
|
|
|
// Now publish this draft |
2446
|
|
|
$publishedContent = $this->contentService->publishVersion($content->getVersionInfo()); |
2447
|
|
|
|
2448
|
|
|
// Will return a content instance with fields in "eng-US" |
2449
|
|
|
$reloadedContent = $this->contentService->loadContentByVersionInfo( |
2450
|
|
|
$publishedContent->getVersionInfo(), |
2451
|
|
|
[ |
2452
|
|
|
self::ENG_GB, |
2453
|
|
|
], |
2454
|
|
|
false |
2455
|
|
|
); |
2456
|
|
|
|
2457
|
|
|
$actual = []; |
2458
|
|
|
foreach ($reloadedContent->getFields() as $field) { |
2459
|
|
|
$actual[] = new Field( |
2460
|
|
|
[ |
2461
|
|
|
'id' => 0, |
2462
|
|
|
'value' => $field->value !== null, // Actual value tested by FieldType integration tests |
2463
|
|
|
'languageCode' => $field->languageCode, |
2464
|
|
|
'fieldDefIdentifier' => $field->fieldDefIdentifier, |
2465
|
|
|
] |
2466
|
|
|
); |
2467
|
|
|
} |
2468
|
|
|
usort( |
2469
|
|
|
$actual, |
2470
|
|
|
function ($field1, $field2) { |
2471
|
|
|
if (0 === ($return = strcasecmp($field1->fieldDefIdentifier, $field2->fieldDefIdentifier))) { |
2472
|
|
|
return strcasecmp($field1->languageCode, $field2->languageCode); |
2473
|
|
|
} |
2474
|
|
|
|
2475
|
|
|
return $return; |
2476
|
|
|
} |
2477
|
|
|
); |
2478
|
|
|
|
2479
|
|
|
$expected = [ |
2480
|
|
|
new Field( |
2481
|
|
|
[ |
2482
|
|
|
'id' => 0, |
2483
|
|
|
'value' => true, |
2484
|
|
|
'languageCode' => self::ENG_GB, |
2485
|
|
|
'fieldDefIdentifier' => 'description', |
2486
|
|
|
] |
2487
|
|
|
), |
2488
|
|
|
new Field( |
2489
|
|
|
[ |
2490
|
|
|
'id' => 0, |
2491
|
|
|
'value' => true, |
2492
|
|
|
'languageCode' => self::ENG_GB, |
2493
|
|
|
'fieldDefIdentifier' => 'name', |
2494
|
|
|
] |
2495
|
|
|
), |
2496
|
|
|
]; |
2497
|
|
|
|
2498
|
|
|
$this->assertEquals($expected, $actual); |
2499
|
|
|
} |
2500
|
|
|
|
2501
|
|
|
/** |
2502
|
|
|
* Test for the loadContentByContentInfo() method. |
2503
|
|
|
* |
2504
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo($contentInfo, $languages) |
2505
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfo |
2506
|
|
|
*/ |
2507
|
|
|
public function testLoadContentByContentInfoWithLanguageParameters() |
2508
|
|
|
{ |
2509
|
|
|
$sectionId = $this->generateId('section', 1); |
2510
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
2511
|
|
|
|
2512
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
2513
|
|
|
|
2514
|
|
|
$contentCreateStruct = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
2515
|
|
|
|
2516
|
|
|
$contentCreateStruct->setField('name', 'Sindelfingen forum²'); |
2517
|
|
|
|
2518
|
|
|
$contentCreateStruct->setField('name', 'Sindelfingen forum²³', self::ENG_GB); |
2519
|
|
|
|
2520
|
|
|
$contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
2521
|
|
|
// $sectionId contains the ID of section 1 |
2522
|
|
|
$contentCreateStruct->sectionId = $sectionId; |
2523
|
|
|
$contentCreateStruct->alwaysAvailable = true; |
2524
|
|
|
|
2525
|
|
|
// Create a new content draft |
2526
|
|
|
$content = $this->contentService->createContent($contentCreateStruct); |
2527
|
|
|
|
2528
|
|
|
// Now publish this draft |
2529
|
|
|
$publishedContent = $this->contentService->publishVersion($content->getVersionInfo()); |
2530
|
|
|
|
2531
|
|
|
// Will return a content instance with fields in "eng-US" |
2532
|
|
|
$reloadedContent = $this->contentService->loadContentByContentInfo( |
2533
|
|
|
$publishedContent->contentInfo, |
2534
|
|
|
[ |
2535
|
|
|
self::ENG_US, |
2536
|
|
|
], |
2537
|
|
|
null, |
2538
|
|
|
false |
2539
|
|
|
); |
2540
|
|
|
|
2541
|
|
|
$actual = $this->normalizeFields($reloadedContent->getFields()); |
2542
|
|
|
|
2543
|
|
|
$expected = [ |
2544
|
|
|
new Field( |
2545
|
|
|
[ |
2546
|
|
|
'id' => 0, |
2547
|
|
|
'value' => true, |
2548
|
|
|
'languageCode' => self::ENG_US, |
2549
|
|
|
'fieldDefIdentifier' => 'description', |
2550
|
|
|
'fieldTypeIdentifier' => 'ezrichtext', |
2551
|
|
|
] |
2552
|
|
|
), |
2553
|
|
|
new Field( |
2554
|
|
|
[ |
2555
|
|
|
'id' => 0, |
2556
|
|
|
'value' => true, |
2557
|
|
|
'languageCode' => self::ENG_US, |
2558
|
|
|
'fieldDefIdentifier' => 'name', |
2559
|
|
|
'fieldTypeIdentifier' => 'ezstring', |
2560
|
|
|
] |
2561
|
|
|
), |
2562
|
|
|
]; |
2563
|
|
|
|
2564
|
|
|
$this->assertEquals($expected, $actual); |
2565
|
|
|
|
2566
|
|
|
// Will return a content instance with fields in "eng-GB" (versions prior to 6.0.0-beta9 returned "eng-US" also) |
2567
|
|
|
$reloadedContent = $this->contentService->loadContentByContentInfo( |
2568
|
|
|
$publishedContent->contentInfo, |
2569
|
|
|
[ |
2570
|
|
|
self::ENG_GB, |
2571
|
|
|
], |
2572
|
|
|
null, |
2573
|
|
|
true |
2574
|
|
|
); |
2575
|
|
|
|
2576
|
|
|
$actual = $this->normalizeFields($reloadedContent->getFields()); |
2577
|
|
|
|
2578
|
|
|
$expected = [ |
2579
|
|
|
new Field( |
2580
|
|
|
[ |
2581
|
|
|
'id' => 0, |
2582
|
|
|
'value' => true, |
2583
|
|
|
'languageCode' => self::ENG_GB, |
2584
|
|
|
'fieldDefIdentifier' => 'description', |
2585
|
|
|
'fieldTypeIdentifier' => 'ezrichtext', |
2586
|
|
|
] |
2587
|
|
|
), |
2588
|
|
|
new Field( |
2589
|
|
|
[ |
2590
|
|
|
'id' => 0, |
2591
|
|
|
'value' => true, |
2592
|
|
|
'languageCode' => self::ENG_GB, |
2593
|
|
|
'fieldDefIdentifier' => 'name', |
2594
|
|
|
'fieldTypeIdentifier' => 'ezstring', |
2595
|
|
|
] |
2596
|
|
|
), |
2597
|
|
|
]; |
2598
|
|
|
|
2599
|
|
|
$this->assertEquals($expected, $actual); |
2600
|
|
|
|
2601
|
|
|
// Will return a content instance with fields in main language "eng-US", as "fre-FR" does not exists |
2602
|
|
|
$reloadedContent = $this->contentService->loadContentByContentInfo( |
2603
|
|
|
$publishedContent->contentInfo, |
2604
|
|
|
[ |
2605
|
|
|
'fre-FR', |
2606
|
|
|
], |
2607
|
|
|
null, |
2608
|
|
|
true |
2609
|
|
|
); |
2610
|
|
|
|
2611
|
|
|
$actual = $this->normalizeFields($reloadedContent->getFields()); |
2612
|
|
|
|
2613
|
|
|
$expected = [ |
2614
|
|
|
new Field( |
2615
|
|
|
[ |
2616
|
|
|
'id' => 0, |
2617
|
|
|
'value' => true, |
2618
|
|
|
'languageCode' => self::ENG_US, |
2619
|
|
|
'fieldDefIdentifier' => 'description', |
2620
|
|
|
'fieldTypeIdentifier' => 'ezrichtext', |
2621
|
|
|
] |
2622
|
|
|
), |
2623
|
|
|
new Field( |
2624
|
|
|
[ |
2625
|
|
|
'id' => 0, |
2626
|
|
|
'value' => true, |
2627
|
|
|
'languageCode' => self::ENG_US, |
2628
|
|
|
'fieldDefIdentifier' => 'name', |
2629
|
|
|
'fieldTypeIdentifier' => 'ezstring', |
2630
|
|
|
] |
2631
|
|
|
), |
2632
|
|
|
]; |
2633
|
|
|
|
2634
|
|
|
$this->assertEquals($expected, $actual); |
2635
|
|
|
} |
2636
|
|
|
|
2637
|
|
|
/** |
2638
|
|
|
* Test for the loadContentByContentInfo() method. |
2639
|
|
|
* |
2640
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo($contentInfo, $languages, $versionNo) |
2641
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfo |
2642
|
|
|
*/ |
2643
|
|
|
public function testLoadContentByContentInfoWithVersionNumberParameter() |
2644
|
|
|
{ |
2645
|
|
|
$publishedContent = $this->createContentVersion1(); |
2646
|
|
|
|
2647
|
|
|
$this->contentService->createContentDraft($publishedContent->contentInfo); |
2648
|
|
|
|
2649
|
|
|
// This content instance is identical to $draftContent |
2650
|
|
|
$draftContentReloaded = $this->contentService->loadContentByContentInfo( |
2651
|
|
|
$publishedContent->contentInfo, |
2652
|
|
|
null, |
2653
|
|
|
2 |
2654
|
|
|
); |
2655
|
|
|
|
2656
|
|
|
$this->assertEquals( |
2657
|
|
|
2, |
2658
|
|
|
$draftContentReloaded->getVersionInfo()->versionNo |
2659
|
|
|
); |
2660
|
|
|
|
2661
|
|
|
// Check that ContentInfo contained in reloaded draft Content has correct main Location id set |
2662
|
|
|
$this->assertEquals( |
2663
|
|
|
$publishedContent->versionInfo->contentInfo->mainLocationId, |
2664
|
|
|
$draftContentReloaded->versionInfo->contentInfo->mainLocationId |
2665
|
|
|
); |
2666
|
|
|
} |
2667
|
|
|
|
2668
|
|
|
/** |
2669
|
|
|
* Test for the loadContentByContentInfo() method. |
2670
|
|
|
* |
2671
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo($contentInfo, $languages, $versionNo) |
2672
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfoWithVersionNumberParameter |
2673
|
|
|
*/ |
2674
|
|
|
public function testLoadContentByContentInfoThrowsNotFoundExceptionWithVersionNumberParameter() |
2675
|
|
|
{ |
2676
|
|
|
$content = $this->createContentVersion1(); |
2677
|
|
|
|
2678
|
|
|
$this->expectException(NotFoundException::class); |
2679
|
|
|
|
2680
|
|
|
// This call will fail with a "NotFoundException", because no content with versionNo = 2 exists. |
2681
|
|
|
$this->contentService->loadContentByContentInfo($content->contentInfo, null, 2); |
2682
|
|
|
} |
2683
|
|
|
|
2684
|
|
|
/** |
2685
|
|
|
* Test for the loadContent() method. |
2686
|
|
|
* |
2687
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages) |
2688
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
2689
|
|
|
*/ |
2690
|
|
|
public function testLoadContentWithSecondParameter() |
2691
|
|
|
{ |
2692
|
|
|
$draft = $this->createMultipleLanguageDraftVersion1(); |
2693
|
|
|
|
2694
|
|
|
// This draft contains those fields localized with "eng-GB" |
2695
|
|
|
$draftLocalized = $this->contentService->loadContent($draft->id, [self::ENG_GB], null, false); |
2696
|
|
|
|
2697
|
|
|
$this->assertLocaleFieldsEquals($draftLocalized->getFields(), self::ENG_GB); |
2698
|
|
|
|
2699
|
|
|
return $draft; |
2700
|
|
|
} |
2701
|
|
|
|
2702
|
|
|
/** |
2703
|
|
|
* Test for the loadContent() method using undefined translation. |
2704
|
|
|
* |
2705
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithSecondParameter |
2706
|
|
|
* |
2707
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $contentDraft |
2708
|
|
|
*/ |
2709
|
|
|
public function testLoadContentWithSecondParameterThrowsNotFoundException(Content $contentDraft) |
2710
|
|
|
{ |
2711
|
|
|
$this->expectException(NotFoundException::class); |
2712
|
|
|
|
2713
|
|
|
$this->contentService->loadContent($contentDraft->id, [self::GER_DE], null, false); |
2714
|
|
|
} |
2715
|
|
|
|
2716
|
|
|
/** |
2717
|
|
|
* Test for the loadContent() method. |
2718
|
|
|
* |
2719
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages, $versionNo) |
2720
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
2721
|
|
|
*/ |
2722
|
|
|
public function testLoadContentWithThirdParameter() |
2723
|
|
|
{ |
2724
|
|
|
$publishedContent = $this->createContentVersion1(); |
2725
|
|
|
|
2726
|
|
|
$this->contentService->createContentDraft($publishedContent->contentInfo); |
2727
|
|
|
|
2728
|
|
|
// This content instance is identical to $draftContent |
2729
|
|
|
$draftContentReloaded = $this->contentService->loadContent($publishedContent->id, null, 2); |
2730
|
|
|
|
2731
|
|
|
$this->assertEquals(2, $draftContentReloaded->getVersionInfo()->versionNo); |
2732
|
|
|
|
2733
|
|
|
// Check that ContentInfo contained in reloaded draft Content has correct main Location id set |
2734
|
|
|
$this->assertEquals( |
2735
|
|
|
$publishedContent->versionInfo->contentInfo->mainLocationId, |
2736
|
|
|
$draftContentReloaded->versionInfo->contentInfo->mainLocationId |
2737
|
|
|
); |
2738
|
|
|
} |
2739
|
|
|
|
2740
|
|
|
/** |
2741
|
|
|
* Test for the loadContent() method. |
2742
|
|
|
* |
2743
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages, $versionNo) |
2744
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithThirdParameter |
2745
|
|
|
*/ |
2746
|
|
|
public function testLoadContentThrowsNotFoundExceptionWithThirdParameter() |
2747
|
|
|
{ |
2748
|
|
|
$content = $this->createContentVersion1(); |
2749
|
|
|
|
2750
|
|
|
$this->expectException(NotFoundException::class); |
2751
|
|
|
|
2752
|
|
|
// This call will fail with a "NotFoundException", because for this content object no versionNo=2 exists. |
2753
|
|
|
$this->contentService->loadContent($content->id, null, 2); |
2754
|
|
|
} |
2755
|
|
|
|
2756
|
|
|
/** |
2757
|
|
|
* Test for the loadContentByRemoteId() method. |
2758
|
|
|
* |
2759
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId($remoteId, $languages) |
2760
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
2761
|
|
|
*/ |
2762
|
|
|
public function testLoadContentByRemoteIdWithSecondParameter() |
2763
|
|
|
{ |
2764
|
|
|
$draft = $this->createMultipleLanguageDraftVersion1(); |
2765
|
|
|
|
2766
|
|
|
$this->contentService->publishVersion($draft->versionInfo); |
2767
|
|
|
|
2768
|
|
|
// This draft contains those fields localized with "eng-GB" |
2769
|
|
|
$draftLocalized = $this->contentService->loadContentByRemoteId( |
2770
|
|
|
$draft->contentInfo->remoteId, |
2771
|
|
|
[self::ENG_GB], |
2772
|
|
|
null, |
2773
|
|
|
false |
2774
|
|
|
); |
2775
|
|
|
|
2776
|
|
|
$this->assertLocaleFieldsEquals($draftLocalized->getFields(), self::ENG_GB); |
2777
|
|
|
} |
2778
|
|
|
|
2779
|
|
|
/** |
2780
|
|
|
* Test for the loadContentByRemoteId() method. |
2781
|
|
|
* |
2782
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId($remoteId, $languages, $versionNo) |
2783
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
2784
|
|
|
*/ |
2785
|
|
|
public function testLoadContentByRemoteIdWithThirdParameter() |
2786
|
|
|
{ |
2787
|
|
|
$publishedContent = $this->createContentVersion1(); |
2788
|
|
|
|
2789
|
|
|
$this->contentService->createContentDraft($publishedContent->contentInfo); |
2790
|
|
|
|
2791
|
|
|
// This content instance is identical to $draftContent |
2792
|
|
|
$draftContentReloaded = $this->contentService->loadContentByRemoteId( |
2793
|
|
|
$publishedContent->contentInfo->remoteId, |
2794
|
|
|
null, |
2795
|
|
|
2 |
2796
|
|
|
); |
2797
|
|
|
|
2798
|
|
|
$this->assertEquals(2, $draftContentReloaded->getVersionInfo()->versionNo); |
2799
|
|
|
|
2800
|
|
|
// Check that ContentInfo contained in reloaded draft Content has correct main Location id set |
2801
|
|
|
$this->assertEquals( |
2802
|
|
|
$publishedContent->versionInfo->contentInfo->mainLocationId, |
2803
|
|
|
$draftContentReloaded->versionInfo->contentInfo->mainLocationId |
2804
|
|
|
); |
2805
|
|
|
} |
2806
|
|
|
|
2807
|
|
|
/** |
2808
|
|
|
* Test for the loadContentByRemoteId() method. |
2809
|
|
|
* |
2810
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId($remoteId, $languages, $versionNo) |
2811
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteIdWithThirdParameter |
2812
|
|
|
*/ |
2813
|
|
|
public function testLoadContentByRemoteIdThrowsNotFoundExceptionWithThirdParameter() |
2814
|
|
|
{ |
2815
|
|
|
$content = $this->createContentVersion1(); |
2816
|
|
|
|
2817
|
|
|
$this->expectException(NotFoundException::class); |
2818
|
|
|
|
2819
|
|
|
// This call will fail with a "NotFoundException", because for this content object no versionNo=2 exists. |
2820
|
|
|
$this->contentService->loadContentByRemoteId( |
2821
|
|
|
$content->contentInfo->remoteId, |
2822
|
|
|
null, |
2823
|
|
|
2 |
2824
|
|
|
); |
2825
|
|
|
} |
2826
|
|
|
|
2827
|
|
|
/** |
2828
|
|
|
* Test that retrieval of translated name field respects prioritized language list. |
2829
|
|
|
* |
2830
|
|
|
* @dataProvider getPrioritizedLanguageList |
2831
|
|
|
* @param string[]|null $languageCodes |
2832
|
|
|
*/ |
2833
|
|
|
public function testLoadContentWithPrioritizedLanguagesList($languageCodes) |
2834
|
|
|
{ |
2835
|
|
|
$content = $this->createContentVersion2(); |
2836
|
|
|
|
2837
|
|
|
$content = $this->contentService->loadContent($content->id, $languageCodes); |
2838
|
|
|
|
2839
|
|
|
$expectedName = $content->getVersionInfo()->getName( |
2840
|
|
|
isset($languageCodes[0]) ? $languageCodes[0] : null |
2841
|
|
|
); |
2842
|
|
|
$nameValue = $content->getFieldValue('name'); |
2843
|
|
|
/** @var \eZ\Publish\Core\FieldType\TextLine\Value $nameValue */ |
2844
|
|
|
self::assertEquals($expectedName, $nameValue->text); |
2845
|
|
|
self::assertEquals($expectedName, $content->getVersionInfo()->getName()); |
2846
|
|
|
// Also check value on shortcut method on content |
2847
|
|
|
self::assertEquals($expectedName, $content->getName()); |
2848
|
|
|
} |
2849
|
|
|
|
2850
|
|
|
/** |
2851
|
|
|
* @return array |
2852
|
|
|
*/ |
2853
|
|
|
public function getPrioritizedLanguageList() |
2854
|
|
|
{ |
2855
|
|
|
return [ |
2856
|
|
|
[[self::ENG_US]], |
2857
|
|
|
[[self::ENG_GB]], |
2858
|
|
|
[[self::ENG_GB, self::ENG_US]], |
2859
|
|
|
[[self::ENG_US, self::ENG_GB]], |
2860
|
|
|
]; |
2861
|
|
|
} |
2862
|
|
|
|
2863
|
|
|
/** |
2864
|
|
|
* Test for the deleteVersion() method. |
2865
|
|
|
* |
2866
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
2867
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
2868
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
2869
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
2870
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
2871
|
|
|
*/ |
2872
|
|
|
public function testDeleteVersion() |
2873
|
|
|
{ |
2874
|
|
|
$content = $this->createContentVersion1(); |
2875
|
|
|
|
2876
|
|
|
// Create new draft, because published or last version of the Content can't be deleted |
2877
|
|
|
$draft = $this->contentService->createContentDraft( |
2878
|
|
|
$content->getVersionInfo()->getContentInfo() |
2879
|
|
|
); |
2880
|
|
|
|
2881
|
|
|
// Delete the previously created draft |
2882
|
|
|
$this->contentService->deleteVersion($draft->getVersionInfo()); |
2883
|
|
|
|
2884
|
|
|
$versions = $this->contentService->loadVersions($content->getVersionInfo()->getContentInfo()); |
2885
|
|
|
|
2886
|
|
|
$this->assertCount(1, $versions); |
2887
|
|
|
$this->assertEquals( |
2888
|
|
|
$content->getVersionInfo()->id, |
2889
|
|
|
$versions[0]->id |
2890
|
|
|
); |
2891
|
|
|
} |
2892
|
|
|
|
2893
|
|
|
/** |
2894
|
|
|
* Test for the deleteVersion() method. |
2895
|
|
|
* |
2896
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
2897
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
2898
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
2899
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
2900
|
|
|
*/ |
2901
|
|
|
public function testDeleteVersionThrowsBadStateExceptionOnPublishedVersion() |
2902
|
|
|
{ |
2903
|
|
|
$content = $this->createContentVersion1(); |
2904
|
|
|
|
2905
|
|
|
$this->expectException(BadStateException::class); |
2906
|
|
|
|
2907
|
|
|
// This call will fail with a "BadStateException", because the content version is currently published. |
2908
|
|
|
$this->contentService->deleteVersion($content->getVersionInfo()); |
2909
|
|
|
} |
2910
|
|
|
|
2911
|
|
|
/** |
2912
|
|
|
* Test for the deleteVersion() method. |
2913
|
|
|
* |
2914
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
2915
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
2916
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
2917
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
2918
|
|
|
*/ |
2919
|
|
|
public function testDeleteVersionWorksIfOnlyVersionIsDraft() |
2920
|
|
|
{ |
2921
|
|
|
$draft = $this->createContentDraftVersion1(); |
2922
|
|
|
|
2923
|
|
|
$this->contentService->deleteVersion($draft->getVersionInfo()); |
2924
|
|
|
|
2925
|
|
|
$this->expectException(NotFoundException::class); |
2926
|
|
|
|
2927
|
|
|
// This call will fail with a "NotFound", because we allow to delete content if remaining version is draft. |
2928
|
|
|
// Can normally only happen if there where always only a draft to begin with, simplifies UI edit API usage. |
2929
|
|
|
$this->contentService->loadContent($draft->id); |
2930
|
|
|
} |
2931
|
|
|
|
2932
|
|
|
/** |
2933
|
|
|
* Test for the loadVersions() method. |
2934
|
|
|
* |
2935
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersions() |
2936
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
2937
|
|
|
* |
2938
|
|
|
* @return VersionInfo[] |
2939
|
|
|
*/ |
2940
|
|
|
public function testLoadVersions() |
2941
|
|
|
{ |
2942
|
|
|
$contentVersion2 = $this->createContentVersion2(); |
2943
|
|
|
|
2944
|
|
|
// Load versions of this ContentInfo instance |
2945
|
|
|
$versions = $this->contentService->loadVersions($contentVersion2->contentInfo); |
2946
|
|
|
|
2947
|
|
|
$expectedVersionsOrder = [ |
2948
|
|
|
$this->contentService->loadVersionInfo($contentVersion2->contentInfo, 1), |
2949
|
|
|
$this->contentService->loadVersionInfo($contentVersion2->contentInfo, 2), |
2950
|
|
|
]; |
2951
|
|
|
|
2952
|
|
|
$this->assertEquals($expectedVersionsOrder, $versions); |
2953
|
|
|
|
2954
|
|
|
return $versions; |
2955
|
|
|
} |
2956
|
|
|
|
2957
|
|
|
/** |
2958
|
|
|
* Test for the loadVersions() method. |
2959
|
|
|
* |
2960
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersions |
2961
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::loadVersions |
2962
|
|
|
* |
2963
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\VersionInfo[] $versions |
2964
|
|
|
*/ |
2965
|
|
|
public function testLoadVersionsSetsExpectedVersionInfo(array $versions) |
2966
|
|
|
{ |
2967
|
|
|
$this->assertCount(2, $versions); |
2968
|
|
|
|
2969
|
|
|
$expectedVersions = [ |
2970
|
|
|
[ |
2971
|
|
|
'versionNo' => 1, |
2972
|
|
|
'creatorId' => 14, |
2973
|
|
|
'status' => VersionInfo::STATUS_ARCHIVED, |
2974
|
|
|
'initialLanguageCode' => self::ENG_US, |
2975
|
|
|
'languageCodes' => [self::ENG_US], |
2976
|
|
|
], |
2977
|
|
|
[ |
2978
|
|
|
'versionNo' => 2, |
2979
|
|
|
'creatorId' => 10, |
2980
|
|
|
'status' => VersionInfo::STATUS_PUBLISHED, |
2981
|
|
|
'initialLanguageCode' => self::ENG_US, |
2982
|
|
|
'languageCodes' => [self::ENG_US, self::ENG_GB], |
2983
|
|
|
], |
2984
|
|
|
]; |
2985
|
|
|
|
2986
|
|
|
$this->assertPropertiesCorrect($expectedVersions[0], $versions[0]); |
2987
|
|
|
$this->assertPropertiesCorrect($expectedVersions[1], $versions[1]); |
2988
|
|
|
$this->assertEquals( |
2989
|
|
|
$versions[0]->creationDate->getTimestamp(), |
2990
|
|
|
$versions[1]->creationDate->getTimestamp(), |
2991
|
|
|
'Creation time did not match within delta of 2 seconds', |
2992
|
|
|
2 |
2993
|
|
|
); |
2994
|
|
|
$this->assertEquals( |
2995
|
|
|
$versions[0]->modificationDate->getTimestamp(), |
2996
|
|
|
$versions[1]->modificationDate->getTimestamp(), |
2997
|
|
|
'Creation time did not match within delta of 2 seconds', |
2998
|
|
|
2 |
2999
|
|
|
); |
3000
|
|
|
$this->assertTrue($versions[0]->isArchived()); |
3001
|
|
|
$this->assertFalse($versions[0]->isDraft()); |
3002
|
|
|
$this->assertFalse($versions[0]->isPublished()); |
3003
|
|
|
|
3004
|
|
|
$this->assertTrue($versions[1]->isPublished()); |
3005
|
|
|
$this->assertFalse($versions[1]->isDraft()); |
3006
|
|
|
$this->assertFalse($versions[1]->isArchived()); |
3007
|
|
|
} |
3008
|
|
|
|
3009
|
|
|
/** |
3010
|
|
|
* Test for the copyContent() method. |
3011
|
|
|
* |
3012
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::copyContent() |
3013
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
3014
|
|
|
* @group field-type |
3015
|
|
|
*/ |
3016
|
|
|
public function testCopyContent() |
3017
|
|
|
{ |
3018
|
|
|
$parentLocationId = $this->generateId('location', 56); |
3019
|
|
|
|
3020
|
|
|
$contentVersion2 = $this->createMultipleLanguageContentVersion2(); |
3021
|
|
|
|
3022
|
|
|
// Configure new target location |
3023
|
|
|
$targetLocationCreate = $this->locationService->newLocationCreateStruct($parentLocationId); |
3024
|
|
|
|
3025
|
|
|
$targetLocationCreate->priority = 42; |
3026
|
|
|
$targetLocationCreate->hidden = true; |
3027
|
|
|
$targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789'; |
3028
|
|
|
$targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
3029
|
|
|
$targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC; |
3030
|
|
|
|
3031
|
|
|
// Copy content with all versions and drafts |
3032
|
|
|
$contentCopied = $this->contentService->copyContent( |
3033
|
|
|
$contentVersion2->contentInfo, |
3034
|
|
|
$targetLocationCreate |
3035
|
|
|
); |
3036
|
|
|
|
3037
|
|
|
$this->assertInstanceOf( |
3038
|
|
|
Content::class, |
3039
|
|
|
$contentCopied |
3040
|
|
|
); |
3041
|
|
|
|
3042
|
|
|
$this->assertNotEquals( |
3043
|
|
|
$contentVersion2->contentInfo->remoteId, |
3044
|
|
|
$contentCopied->contentInfo->remoteId |
3045
|
|
|
); |
3046
|
|
|
|
3047
|
|
|
$this->assertNotEquals( |
3048
|
|
|
$contentVersion2->id, |
3049
|
|
|
$contentCopied->id |
3050
|
|
|
); |
3051
|
|
|
|
3052
|
|
|
$this->assertEquals( |
3053
|
|
|
2, |
3054
|
|
|
count($this->contentService->loadVersions($contentCopied->contentInfo)) |
3055
|
|
|
); |
3056
|
|
|
|
3057
|
|
|
$this->assertEquals(2, $contentCopied->getVersionInfo()->versionNo); |
3058
|
|
|
|
3059
|
|
|
$this->assertAllFieldsEquals($contentCopied->getFields()); |
3060
|
|
|
|
3061
|
|
|
$this->assertDefaultContentStates($contentCopied->contentInfo); |
3062
|
|
|
|
3063
|
|
|
$this->assertNotNull( |
3064
|
|
|
$contentCopied->contentInfo->mainLocationId, |
3065
|
|
|
'Expected main location to be set given we provided a LocationCreateStruct' |
3066
|
|
|
); |
3067
|
|
|
} |
3068
|
|
|
|
3069
|
|
|
/** |
3070
|
|
|
* Test for the copyContent() method with ezsettings.default.content.retain_owner_on_copy set to false |
3071
|
|
|
* See settings/test/integration_legacy.yml for service override. |
3072
|
|
|
* |
3073
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::copyContent() |
3074
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
3075
|
|
|
* @group field-type |
3076
|
|
|
*/ |
3077
|
|
|
public function testCopyContentWithNewOwner() |
3078
|
|
|
{ |
3079
|
|
|
$parentLocationId = $this->generateId('location', 56); |
3080
|
|
|
|
3081
|
|
|
$userService = $this->getRepository()->getUserService(); |
3082
|
|
|
|
3083
|
|
|
$newOwner = $this->createUser('new_owner', 'foo', 'bar'); |
3084
|
|
|
/** @var \eZ\Publish\API\Repository\Values\Content\Content $contentVersion2 */ |
3085
|
|
|
$contentVersion2 = $this->createContentDraftVersion1( |
3086
|
|
|
$parentLocationId, |
3087
|
|
|
self::FORUM_IDENTIFIER, |
3088
|
|
|
'name', |
3089
|
|
|
$newOwner |
3090
|
|
|
); |
3091
|
|
|
|
3092
|
|
|
// Configure new target location |
3093
|
|
|
$targetLocationCreate = $this->locationService->newLocationCreateStruct($parentLocationId); |
3094
|
|
|
|
3095
|
|
|
$targetLocationCreate->priority = 42; |
3096
|
|
|
$targetLocationCreate->hidden = true; |
3097
|
|
|
$targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789'; |
3098
|
|
|
$targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
3099
|
|
|
$targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC; |
3100
|
|
|
|
3101
|
|
|
// Copy content with all versions and drafts |
3102
|
|
|
$contentCopied = $this->contentService->copyContent( |
3103
|
|
|
$contentVersion2->contentInfo, |
3104
|
|
|
$targetLocationCreate |
3105
|
|
|
); |
3106
|
|
|
|
3107
|
|
|
$this->assertEquals( |
3108
|
|
|
$newOwner->id, |
3109
|
|
|
$contentVersion2->contentInfo->ownerId |
3110
|
|
|
); |
3111
|
|
|
$this->assertEquals( |
3112
|
|
|
$userService->loadUserByLogin('admin')->getUserId(), |
3113
|
|
|
$contentCopied->contentInfo->ownerId |
3114
|
|
|
); |
3115
|
|
|
} |
3116
|
|
|
|
3117
|
|
|
/** |
3118
|
|
|
* Test for the copyContent() method. |
3119
|
|
|
* |
3120
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::copyContent($contentInfo, $destinationLocationCreateStruct, $versionInfo) |
3121
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent |
3122
|
|
|
*/ |
3123
|
|
|
public function testCopyContentWithGivenVersion() |
3124
|
|
|
{ |
3125
|
|
|
$parentLocationId = $this->generateId('location', 56); |
3126
|
|
|
|
3127
|
|
|
$contentVersion2 = $this->createContentVersion2(); |
3128
|
|
|
|
3129
|
|
|
// Configure new target location |
3130
|
|
|
$targetLocationCreate = $this->locationService->newLocationCreateStruct($parentLocationId); |
3131
|
|
|
|
3132
|
|
|
$targetLocationCreate->priority = 42; |
3133
|
|
|
$targetLocationCreate->hidden = true; |
3134
|
|
|
$targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789'; |
3135
|
|
|
$targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
3136
|
|
|
$targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC; |
3137
|
|
|
|
3138
|
|
|
// Copy only the initial version |
3139
|
|
|
$contentCopied = $this->contentService->copyContent( |
3140
|
|
|
$contentVersion2->contentInfo, |
3141
|
|
|
$targetLocationCreate, |
3142
|
|
|
$this->contentService->loadVersionInfo($contentVersion2->contentInfo, 1) |
3143
|
|
|
); |
3144
|
|
|
|
3145
|
|
|
$this->assertInstanceOf( |
3146
|
|
|
Content::class, |
3147
|
|
|
$contentCopied |
3148
|
|
|
); |
3149
|
|
|
|
3150
|
|
|
$this->assertNotEquals( |
3151
|
|
|
$contentVersion2->contentInfo->remoteId, |
3152
|
|
|
$contentCopied->contentInfo->remoteId |
3153
|
|
|
); |
3154
|
|
|
|
3155
|
|
|
$this->assertNotEquals( |
3156
|
|
|
$contentVersion2->id, |
3157
|
|
|
$contentCopied->id |
3158
|
|
|
); |
3159
|
|
|
|
3160
|
|
|
$this->assertEquals( |
3161
|
|
|
1, |
3162
|
|
|
count($this->contentService->loadVersions($contentCopied->contentInfo)) |
3163
|
|
|
); |
3164
|
|
|
|
3165
|
|
|
$this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo); |
3166
|
|
|
|
3167
|
|
|
$this->assertNotNull( |
3168
|
|
|
$contentCopied->contentInfo->mainLocationId, |
3169
|
|
|
'Expected main location to be set given we provided a LocationCreateStruct' |
3170
|
|
|
); |
3171
|
|
|
} |
3172
|
|
|
|
3173
|
|
|
/** |
3174
|
|
|
* Test for the addRelation() method. |
3175
|
|
|
* |
3176
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
3177
|
|
|
* |
3178
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::addRelation() |
3179
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
3180
|
|
|
*/ |
3181
|
|
|
public function testAddRelation() |
3182
|
|
|
{ |
3183
|
|
|
$draft = $this->createContentDraftVersion1(); |
3184
|
|
|
|
3185
|
|
|
$media = $this->contentService->loadContentInfoByRemoteId(self::MEDIA_REMOTE_ID); |
3186
|
|
|
|
3187
|
|
|
// Create relation between new content object and "Media" page |
3188
|
|
|
$relation = $this->contentService->addRelation( |
3189
|
|
|
$draft->getVersionInfo(), |
3190
|
|
|
$media |
3191
|
|
|
); |
3192
|
|
|
|
3193
|
|
|
$this->assertInstanceOf( |
3194
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\Content\\Relation', |
3195
|
|
|
$relation |
3196
|
|
|
); |
3197
|
|
|
|
3198
|
|
|
return $this->contentService->loadRelations($draft->getVersionInfo()); |
3199
|
|
|
} |
3200
|
|
|
|
3201
|
|
|
/** |
3202
|
|
|
* Test for the addRelation() method. |
3203
|
|
|
* |
3204
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations |
3205
|
|
|
* |
3206
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::addRelation() |
3207
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
3208
|
|
|
*/ |
3209
|
|
|
public function testAddRelationAddsRelationToContent($relations) |
3210
|
|
|
{ |
3211
|
|
|
$this->assertEquals( |
3212
|
|
|
1, |
3213
|
|
|
count($relations) |
3214
|
|
|
); |
3215
|
|
|
} |
3216
|
|
|
|
3217
|
|
|
/** |
3218
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations |
3219
|
|
|
*/ |
3220
|
|
|
protected function assertExpectedRelations($relations) |
3221
|
|
|
{ |
3222
|
|
|
$this->assertEquals( |
3223
|
|
|
[ |
3224
|
|
|
'type' => Relation::COMMON, |
3225
|
|
|
'sourceFieldDefinitionIdentifier' => null, |
3226
|
|
|
'sourceContentInfo' => 'abcdef0123456789abcdef0123456789', |
3227
|
|
|
'destinationContentInfo' => self::MEDIA_REMOTE_ID, |
3228
|
|
|
], |
3229
|
|
|
[ |
3230
|
|
|
'type' => $relations[0]->type, |
3231
|
|
|
'sourceFieldDefinitionIdentifier' => $relations[0]->sourceFieldDefinitionIdentifier, |
3232
|
|
|
'sourceContentInfo' => $relations[0]->sourceContentInfo->remoteId, |
3233
|
|
|
'destinationContentInfo' => $relations[0]->destinationContentInfo->remoteId, |
3234
|
|
|
] |
3235
|
|
|
); |
3236
|
|
|
} |
3237
|
|
|
|
3238
|
|
|
/** |
3239
|
|
|
* Test for the addRelation() method. |
3240
|
|
|
* |
3241
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations |
3242
|
|
|
* |
3243
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::addRelation() |
3244
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
3245
|
|
|
*/ |
3246
|
|
|
public function testAddRelationSetsExpectedRelations($relations) |
3247
|
|
|
{ |
3248
|
|
|
$this->assertExpectedRelations($relations); |
3249
|
|
|
} |
3250
|
|
|
|
3251
|
|
|
/** |
3252
|
|
|
* Test for the createContentDraft() method. |
3253
|
|
|
* |
3254
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
3255
|
|
|
* |
3256
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
3257
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations |
3258
|
|
|
*/ |
3259
|
|
|
public function testCreateContentDraftWithRelations() |
3260
|
|
|
{ |
3261
|
|
|
$draft = $this->createContentDraftVersion1(); |
3262
|
|
|
$media = $this->contentService->loadContentInfoByRemoteId(self::MEDIA_REMOTE_ID); |
3263
|
|
|
|
3264
|
|
|
// Create relation between new content object and "Media" page |
3265
|
|
|
$this->contentService->addRelation( |
3266
|
|
|
$draft->getVersionInfo(), |
3267
|
|
|
$media |
3268
|
|
|
); |
3269
|
|
|
|
3270
|
|
|
$content = $this->contentService->publishVersion($draft->versionInfo); |
3271
|
|
|
$newDraft = $this->contentService->createContentDraft($content->contentInfo); |
3272
|
|
|
|
3273
|
|
|
return $this->contentService->loadRelations($newDraft->getVersionInfo()); |
3274
|
|
|
} |
3275
|
|
|
|
3276
|
|
|
/** |
3277
|
|
|
* Test for the createContentDraft() method. |
3278
|
|
|
* |
3279
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations |
3280
|
|
|
* |
3281
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
3282
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithRelations |
3283
|
|
|
*/ |
3284
|
|
|
public function testCreateContentDraftWithRelationsCreatesRelations($relations) |
3285
|
|
|
{ |
3286
|
|
|
$this->assertEquals( |
3287
|
|
|
1, |
3288
|
|
|
count($relations) |
3289
|
|
|
); |
3290
|
|
|
|
3291
|
|
|
return $relations; |
3292
|
|
|
} |
3293
|
|
|
|
3294
|
|
|
/** |
3295
|
|
|
* Test for the createContentDraft() method. |
3296
|
|
|
* |
3297
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations |
3298
|
|
|
* |
3299
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithRelationsCreatesRelations |
3300
|
|
|
*/ |
3301
|
|
|
public function testCreateContentDraftWithRelationsCreatesExpectedRelations($relations) |
3302
|
|
|
{ |
3303
|
|
|
$this->assertExpectedRelations($relations); |
3304
|
|
|
} |
3305
|
|
|
|
3306
|
|
|
/** |
3307
|
|
|
* Test for the addRelation() method. |
3308
|
|
|
* |
3309
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::addRelation() |
3310
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
3311
|
|
|
*/ |
3312
|
|
|
public function testAddRelationThrowsBadStateException() |
3313
|
|
|
{ |
3314
|
|
|
$content = $this->createContentVersion1(); |
3315
|
|
|
|
3316
|
|
|
$media = $this->contentService->loadContentInfoByRemoteId(self::MEDIA_REMOTE_ID); |
3317
|
|
|
|
3318
|
|
|
$this->expectException(BadStateException::class); |
3319
|
|
|
|
3320
|
|
|
// This call will fail with a "BadStateException", because content is published and not a draft. |
3321
|
|
|
$this->contentService->addRelation( |
3322
|
|
|
$content->getVersionInfo(), |
3323
|
|
|
$media |
3324
|
|
|
); |
3325
|
|
|
} |
3326
|
|
|
|
3327
|
|
|
/** |
3328
|
|
|
* Test for the loadRelations() method. |
3329
|
|
|
* |
3330
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadRelations() |
3331
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
3332
|
|
|
*/ |
3333
|
|
|
public function testLoadRelations() |
3334
|
|
|
{ |
3335
|
|
|
$draft = $this->createContentDraftVersion1(); |
3336
|
|
|
|
3337
|
|
|
$media = $this->contentService->loadContentInfoByRemoteId(self::MEDIA_REMOTE_ID); |
3338
|
|
|
$demoDesign = $this->contentService->loadContentInfoByRemoteId(self::DEMO_DESIGN_REMOTE_ID); |
3339
|
|
|
|
3340
|
|
|
// Create relation between new content object and "Media" page |
3341
|
|
|
$this->contentService->addRelation( |
3342
|
|
|
$draft->getVersionInfo(), |
3343
|
|
|
$media |
3344
|
|
|
); |
3345
|
|
|
|
3346
|
|
|
// Create another relation with the "Demo Design" page |
3347
|
|
|
$this->contentService->addRelation( |
3348
|
|
|
$draft->getVersionInfo(), |
3349
|
|
|
$demoDesign |
3350
|
|
|
); |
3351
|
|
|
|
3352
|
|
|
$relations = $this->contentService->loadRelations($draft->getVersionInfo()); |
3353
|
|
|
|
3354
|
|
|
usort( |
3355
|
|
|
$relations, |
3356
|
|
|
function ($rel1, $rel2) { |
3357
|
|
|
return strcasecmp( |
3358
|
|
|
$rel2->getDestinationContentInfo()->remoteId, |
3359
|
|
|
$rel1->getDestinationContentInfo()->remoteId |
3360
|
|
|
); |
3361
|
|
|
} |
3362
|
|
|
); |
3363
|
|
|
|
3364
|
|
|
$this->assertEquals( |
3365
|
|
|
[ |
3366
|
|
|
[ |
3367
|
|
|
'sourceContentInfo' => 'abcdef0123456789abcdef0123456789', |
3368
|
|
|
'destinationContentInfo' => self::MEDIA_REMOTE_ID, |
3369
|
|
|
], |
3370
|
|
|
[ |
3371
|
|
|
'sourceContentInfo' => 'abcdef0123456789abcdef0123456789', |
3372
|
|
|
'destinationContentInfo' => self::DEMO_DESIGN_REMOTE_ID, |
3373
|
|
|
], |
3374
|
|
|
], |
3375
|
|
|
[ |
3376
|
|
|
[ |
3377
|
|
|
'sourceContentInfo' => $relations[0]->sourceContentInfo->remoteId, |
3378
|
|
|
'destinationContentInfo' => $relations[0]->destinationContentInfo->remoteId, |
3379
|
|
|
], |
3380
|
|
|
[ |
3381
|
|
|
'sourceContentInfo' => $relations[1]->sourceContentInfo->remoteId, |
3382
|
|
|
'destinationContentInfo' => $relations[1]->destinationContentInfo->remoteId, |
3383
|
|
|
], |
3384
|
|
|
] |
3385
|
|
|
); |
3386
|
|
|
} |
3387
|
|
|
|
3388
|
|
|
/** |
3389
|
|
|
* Test for the loadRelations() method. |
3390
|
|
|
* |
3391
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadRelations() |
3392
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
3393
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations |
3394
|
|
|
*/ |
3395
|
|
|
public function testLoadRelationsSkipsArchivedContent() |
3396
|
|
|
{ |
3397
|
|
|
$trashService = $this->getRepository()->getTrashService(); |
3398
|
|
|
|
3399
|
|
|
$draft = $this->createContentDraftVersion1(); |
3400
|
|
|
|
3401
|
|
|
// Load other content objects |
3402
|
|
|
$media = $this->contentService->loadContentInfoByRemoteId(self::MEDIA_REMOTE_ID); |
3403
|
|
|
$demoDesign = $this->contentService->loadContentInfoByRemoteId(self::DEMO_DESIGN_REMOTE_ID); |
3404
|
|
|
|
3405
|
|
|
// Create relation between new content object and "Media" page |
3406
|
|
|
$this->contentService->addRelation( |
3407
|
|
|
$draft->getVersionInfo(), |
3408
|
|
|
$media |
3409
|
|
|
); |
3410
|
|
|
|
3411
|
|
|
// Create another relation with the "Demo Design" page |
3412
|
|
|
$this->contentService->addRelation( |
3413
|
|
|
$draft->getVersionInfo(), |
3414
|
|
|
$demoDesign |
3415
|
|
|
); |
3416
|
|
|
|
3417
|
|
|
$demoDesignLocation = $this->locationService->loadLocation($demoDesign->mainLocationId); |
3418
|
|
|
|
3419
|
|
|
// Trashing Content's last Location will change its status to archived, |
3420
|
|
|
// in this case relation towards it will not be loaded. |
3421
|
|
|
$trashService->trash($demoDesignLocation); |
3422
|
|
|
|
3423
|
|
|
// Load all relations |
3424
|
|
|
$relations = $this->contentService->loadRelations($draft->getVersionInfo()); |
3425
|
|
|
|
3426
|
|
|
$this->assertCount(1, $relations); |
3427
|
|
|
$this->assertEquals( |
3428
|
|
|
[ |
3429
|
|
|
[ |
3430
|
|
|
'sourceContentInfo' => 'abcdef0123456789abcdef0123456789', |
3431
|
|
|
'destinationContentInfo' => self::MEDIA_REMOTE_ID, |
3432
|
|
|
], |
3433
|
|
|
], |
3434
|
|
|
[ |
3435
|
|
|
[ |
3436
|
|
|
'sourceContentInfo' => $relations[0]->sourceContentInfo->remoteId, |
3437
|
|
|
'destinationContentInfo' => $relations[0]->destinationContentInfo->remoteId, |
3438
|
|
|
], |
3439
|
|
|
] |
3440
|
|
|
); |
3441
|
|
|
} |
3442
|
|
|
|
3443
|
|
|
/** |
3444
|
|
|
* Test for the loadRelations() method. |
3445
|
|
|
* |
3446
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadRelations() |
3447
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
3448
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations |
3449
|
|
|
*/ |
3450
|
|
|
public function testLoadRelationsSkipsDraftContent() |
3451
|
|
|
{ |
3452
|
|
|
$draft = $this->createContentDraftVersion1(); |
3453
|
|
|
|
3454
|
|
|
// Load other content objects |
3455
|
|
|
$media = $this->contentService->loadContentByRemoteId(self::MEDIA_REMOTE_ID); |
3456
|
|
|
$demoDesign = $this->contentService->loadContentInfoByRemoteId(self::DEMO_DESIGN_REMOTE_ID); |
3457
|
|
|
|
3458
|
|
|
// Create draft of "Media" page |
3459
|
|
|
$mediaDraft = $this->contentService->createContentDraft($media->contentInfo); |
3460
|
|
|
|
3461
|
|
|
// Create relation between "Media" page and new content object draft. |
3462
|
|
|
// This relation will not be loaded before the draft is published. |
3463
|
|
|
$this->contentService->addRelation( |
3464
|
|
|
$mediaDraft->getVersionInfo(), |
3465
|
|
|
$draft->getVersionInfo()->getContentInfo() |
3466
|
|
|
); |
3467
|
|
|
|
3468
|
|
|
// Create another relation with the "Demo Design" page |
3469
|
|
|
$this->contentService->addRelation( |
3470
|
|
|
$mediaDraft->getVersionInfo(), |
3471
|
|
|
$demoDesign |
3472
|
|
|
); |
3473
|
|
|
|
3474
|
|
|
$relations = $this->contentService->loadRelations($mediaDraft->getVersionInfo()); |
3475
|
|
|
|
3476
|
|
|
$this->assertCount(1, $relations); |
3477
|
|
|
$this->assertEquals( |
3478
|
|
|
[ |
3479
|
|
|
[ |
3480
|
|
|
'sourceContentInfo' => self::MEDIA_REMOTE_ID, |
3481
|
|
|
'destinationContentInfo' => self::DEMO_DESIGN_REMOTE_ID, |
3482
|
|
|
], |
3483
|
|
|
], |
3484
|
|
|
[ |
3485
|
|
|
[ |
3486
|
|
|
'sourceContentInfo' => $relations[0]->sourceContentInfo->remoteId, |
3487
|
|
|
'destinationContentInfo' => $relations[0]->destinationContentInfo->remoteId, |
3488
|
|
|
], |
3489
|
|
|
] |
3490
|
|
|
); |
3491
|
|
|
} |
3492
|
|
|
|
3493
|
|
|
/** |
3494
|
|
|
* Test for the loadReverseRelations() method. |
3495
|
|
|
* |
3496
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadReverseRelations() |
3497
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
3498
|
|
|
*/ |
3499
|
|
|
public function testLoadReverseRelations() |
3500
|
|
|
{ |
3501
|
|
|
$versionInfo = $this->createContentVersion1()->getVersionInfo(); |
3502
|
|
|
$contentInfo = $versionInfo->getContentInfo(); |
3503
|
|
|
|
3504
|
|
|
// Create some drafts |
3505
|
|
|
$mediaDraft = $this->contentService->createContentDraft( |
3506
|
|
|
$this->contentService->loadContentInfoByRemoteId(self::MEDIA_REMOTE_ID) |
3507
|
|
|
); |
3508
|
|
|
$demoDesignDraft = $this->contentService->createContentDraft( |
3509
|
|
|
$this->contentService->loadContentInfoByRemoteId(self::DEMO_DESIGN_REMOTE_ID) |
3510
|
|
|
); |
3511
|
|
|
|
3512
|
|
|
// Create relation between new content object and "Media" page |
3513
|
|
|
$relation1 = $this->contentService->addRelation( |
3514
|
|
|
$mediaDraft->getVersionInfo(), |
3515
|
|
|
$contentInfo |
3516
|
|
|
); |
3517
|
|
|
|
3518
|
|
|
// Create another relation with the "Demo Design" page |
3519
|
|
|
$relation2 = $this->contentService->addRelation( |
3520
|
|
|
$demoDesignDraft->getVersionInfo(), |
3521
|
|
|
$contentInfo |
3522
|
|
|
); |
3523
|
|
|
|
3524
|
|
|
// Publish drafts, so relations become active |
3525
|
|
|
$this->contentService->publishVersion($mediaDraft->getVersionInfo()); |
3526
|
|
|
$this->contentService->publishVersion($demoDesignDraft->getVersionInfo()); |
3527
|
|
|
|
3528
|
|
|
$relations = $this->contentService->loadRelations($versionInfo); |
3529
|
|
|
$reverseRelations = $this->contentService->loadReverseRelations($contentInfo); |
3530
|
|
|
|
3531
|
|
|
$this->assertEquals($contentInfo->id, $relation1->getDestinationContentInfo()->id); |
3532
|
|
|
$this->assertEquals($mediaDraft->id, $relation1->getSourceContentInfo()->id); |
3533
|
|
|
|
3534
|
|
|
$this->assertEquals($contentInfo->id, $relation2->getDestinationContentInfo()->id); |
3535
|
|
|
$this->assertEquals($demoDesignDraft->id, $relation2->getSourceContentInfo()->id); |
3536
|
|
|
|
3537
|
|
|
$this->assertEquals(0, count($relations)); |
3538
|
|
|
$this->assertEquals(2, count($reverseRelations)); |
3539
|
|
|
|
3540
|
|
|
usort( |
3541
|
|
|
$reverseRelations, |
3542
|
|
|
function ($rel1, $rel2) { |
3543
|
|
|
return strcasecmp( |
3544
|
|
|
$rel2->getSourceContentInfo()->remoteId, |
3545
|
|
|
$rel1->getSourceContentInfo()->remoteId |
3546
|
|
|
); |
3547
|
|
|
} |
3548
|
|
|
); |
3549
|
|
|
|
3550
|
|
|
$this->assertEquals( |
3551
|
|
|
[ |
3552
|
|
|
[ |
3553
|
|
|
'sourceContentInfo' => self::MEDIA_REMOTE_ID, |
3554
|
|
|
'destinationContentInfo' => 'abcdef0123456789abcdef0123456789', |
3555
|
|
|
], |
3556
|
|
|
[ |
3557
|
|
|
'sourceContentInfo' => self::DEMO_DESIGN_REMOTE_ID, |
3558
|
|
|
'destinationContentInfo' => 'abcdef0123456789abcdef0123456789', |
3559
|
|
|
], |
3560
|
|
|
], |
3561
|
|
|
[ |
3562
|
|
|
[ |
3563
|
|
|
'sourceContentInfo' => $reverseRelations[0]->sourceContentInfo->remoteId, |
3564
|
|
|
'destinationContentInfo' => $reverseRelations[0]->destinationContentInfo->remoteId, |
3565
|
|
|
], |
3566
|
|
|
[ |
3567
|
|
|
'sourceContentInfo' => $reverseRelations[1]->sourceContentInfo->remoteId, |
3568
|
|
|
'destinationContentInfo' => $reverseRelations[1]->destinationContentInfo->remoteId, |
3569
|
|
|
], |
3570
|
|
|
] |
3571
|
|
|
); |
3572
|
|
|
} |
3573
|
|
|
|
3574
|
|
|
/** |
3575
|
|
|
* Test for the loadReverseRelations() method. |
3576
|
|
|
* |
3577
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadReverseRelations() |
3578
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
3579
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadReverseRelations |
3580
|
|
|
*/ |
3581
|
|
|
public function testLoadReverseRelationsSkipsArchivedContent() |
3582
|
|
|
{ |
3583
|
|
|
$trashService = $this->getRepository()->getTrashService(); |
3584
|
|
|
|
3585
|
|
|
$versionInfo = $this->createContentVersion1()->getVersionInfo(); |
3586
|
|
|
$contentInfo = $versionInfo->getContentInfo(); |
3587
|
|
|
|
3588
|
|
|
// Create some drafts |
3589
|
|
|
$mediaDraft = $this->contentService->createContentDraft( |
3590
|
|
|
$this->contentService->loadContentInfoByRemoteId(self::MEDIA_REMOTE_ID) |
3591
|
|
|
); |
3592
|
|
|
$demoDesignDraft = $this->contentService->createContentDraft( |
3593
|
|
|
$this->contentService->loadContentInfoByRemoteId(self::DEMO_DESIGN_REMOTE_ID) |
3594
|
|
|
); |
3595
|
|
|
|
3596
|
|
|
// Create relation between new content object and "Media" page |
3597
|
|
|
$relation1 = $this->contentService->addRelation( |
3598
|
|
|
$mediaDraft->getVersionInfo(), |
3599
|
|
|
$contentInfo |
3600
|
|
|
); |
3601
|
|
|
|
3602
|
|
|
// Create another relation with the "Demo Design" page |
3603
|
|
|
$relation2 = $this->contentService->addRelation( |
3604
|
|
|
$demoDesignDraft->getVersionInfo(), |
3605
|
|
|
$contentInfo |
3606
|
|
|
); |
3607
|
|
|
|
3608
|
|
|
// Publish drafts, so relations become active |
3609
|
|
|
$this->contentService->publishVersion($mediaDraft->getVersionInfo()); |
3610
|
|
|
$this->contentService->publishVersion($demoDesignDraft->getVersionInfo()); |
3611
|
|
|
|
3612
|
|
|
$demoDesignLocation = $this->locationService->loadLocation($demoDesignDraft->contentInfo->mainLocationId); |
3613
|
|
|
|
3614
|
|
|
// Trashing Content's last Location will change its status to archived, |
3615
|
|
|
// in this case relation from it will not be loaded. |
3616
|
|
|
$trashService->trash($demoDesignLocation); |
3617
|
|
|
|
3618
|
|
|
// Load all relations |
3619
|
|
|
$relations = $this->contentService->loadRelations($versionInfo); |
3620
|
|
|
$reverseRelations = $this->contentService->loadReverseRelations($contentInfo); |
3621
|
|
|
|
3622
|
|
|
$this->assertEquals($contentInfo->id, $relation1->getDestinationContentInfo()->id); |
3623
|
|
|
$this->assertEquals($mediaDraft->id, $relation1->getSourceContentInfo()->id); |
3624
|
|
|
|
3625
|
|
|
$this->assertEquals($contentInfo->id, $relation2->getDestinationContentInfo()->id); |
3626
|
|
|
$this->assertEquals($demoDesignDraft->id, $relation2->getSourceContentInfo()->id); |
3627
|
|
|
|
3628
|
|
|
$this->assertEquals(0, count($relations)); |
3629
|
|
|
$this->assertEquals(1, count($reverseRelations)); |
3630
|
|
|
|
3631
|
|
|
$this->assertEquals( |
3632
|
|
|
[ |
3633
|
|
|
[ |
3634
|
|
|
'sourceContentInfo' => self::MEDIA_REMOTE_ID, |
3635
|
|
|
'destinationContentInfo' => 'abcdef0123456789abcdef0123456789', |
3636
|
|
|
], |
3637
|
|
|
], |
3638
|
|
|
[ |
3639
|
|
|
[ |
3640
|
|
|
'sourceContentInfo' => $reverseRelations[0]->sourceContentInfo->remoteId, |
3641
|
|
|
'destinationContentInfo' => $reverseRelations[0]->destinationContentInfo->remoteId, |
3642
|
|
|
], |
3643
|
|
|
] |
3644
|
|
|
); |
3645
|
|
|
} |
3646
|
|
|
|
3647
|
|
|
/** |
3648
|
|
|
* Test for the loadReverseRelations() method. |
3649
|
|
|
* |
3650
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadReverseRelations() |
3651
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
3652
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadReverseRelations |
3653
|
|
|
*/ |
3654
|
|
|
public function testLoadReverseRelationsSkipsDraftContent() |
3655
|
|
|
{ |
3656
|
|
|
// Load "Media" page Content |
3657
|
|
|
$media = $this->contentService->loadContentByRemoteId(self::MEDIA_REMOTE_ID); |
3658
|
|
|
|
3659
|
|
|
// Create some drafts |
3660
|
|
|
$newDraftVersionInfo = $this->createContentDraftVersion1()->getVersionInfo(); |
3661
|
|
|
$demoDesignDraft = $this->contentService->createContentDraft( |
3662
|
|
|
$this->contentService->loadContentInfoByRemoteId(self::DEMO_DESIGN_REMOTE_ID) |
3663
|
|
|
); |
3664
|
|
|
|
3665
|
|
|
// Create relation between "Media" page and new content object |
3666
|
|
|
$relation1 = $this->contentService->addRelation( |
3667
|
|
|
$newDraftVersionInfo, |
3668
|
|
|
$media->contentInfo |
3669
|
|
|
); |
3670
|
|
|
|
3671
|
|
|
// Create another relation with the "Demo Design" page |
3672
|
|
|
$relation2 = $this->contentService->addRelation( |
3673
|
|
|
$demoDesignDraft->getVersionInfo(), |
3674
|
|
|
$media->contentInfo |
3675
|
|
|
); |
3676
|
|
|
|
3677
|
|
|
// Publish drafts, so relations become active |
3678
|
|
|
$this->contentService->publishVersion($demoDesignDraft->getVersionInfo()); |
3679
|
|
|
// We will not publish new Content draft, therefore relation from it |
3680
|
|
|
// will not be loaded as reverse relation for "Media" page |
3681
|
|
|
|
3682
|
|
|
$relations = $this->contentService->loadRelations($media->versionInfo); |
3683
|
|
|
$reverseRelations = $this->contentService->loadReverseRelations($media->contentInfo); |
3684
|
|
|
|
3685
|
|
|
$this->assertEquals($media->contentInfo->id, $relation1->getDestinationContentInfo()->id); |
3686
|
|
|
$this->assertEquals($newDraftVersionInfo->contentInfo->id, $relation1->getSourceContentInfo()->id); |
3687
|
|
|
|
3688
|
|
|
$this->assertEquals($media->contentInfo->id, $relation2->getDestinationContentInfo()->id); |
3689
|
|
|
$this->assertEquals($demoDesignDraft->id, $relation2->getSourceContentInfo()->id); |
3690
|
|
|
|
3691
|
|
|
$this->assertEquals(0, count($relations)); |
3692
|
|
|
$this->assertEquals(1, count($reverseRelations)); |
3693
|
|
|
|
3694
|
|
|
$this->assertEquals( |
3695
|
|
|
[ |
3696
|
|
|
[ |
3697
|
|
|
'sourceContentInfo' => self::DEMO_DESIGN_REMOTE_ID, |
3698
|
|
|
'destinationContentInfo' => self::MEDIA_REMOTE_ID, |
3699
|
|
|
], |
3700
|
|
|
], |
3701
|
|
|
[ |
3702
|
|
|
[ |
3703
|
|
|
'sourceContentInfo' => $reverseRelations[0]->sourceContentInfo->remoteId, |
3704
|
|
|
'destinationContentInfo' => $reverseRelations[0]->destinationContentInfo->remoteId, |
3705
|
|
|
], |
3706
|
|
|
] |
3707
|
|
|
); |
3708
|
|
|
} |
3709
|
|
|
|
3710
|
|
|
/** |
3711
|
|
|
* Test for the deleteRelation() method. |
3712
|
|
|
* |
3713
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteRelation() |
3714
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations |
3715
|
|
|
*/ |
3716
|
|
|
public function testDeleteRelation() |
3717
|
|
|
{ |
3718
|
|
|
$draft = $this->createContentDraftVersion1(); |
3719
|
|
|
|
3720
|
|
|
$media = $this->contentService->loadContentInfoByRemoteId(self::MEDIA_REMOTE_ID); |
3721
|
|
|
$demoDesign = $this->contentService->loadContentInfoByRemoteId(self::DEMO_DESIGN_REMOTE_ID); |
3722
|
|
|
|
3723
|
|
|
// Establish some relations |
3724
|
|
|
$this->contentService->addRelation($draft->getVersionInfo(), $media); |
3725
|
|
|
$this->contentService->addRelation($draft->getVersionInfo(), $demoDesign); |
3726
|
|
|
|
3727
|
|
|
// Delete one of the currently created relations |
3728
|
|
|
$this->contentService->deleteRelation($draft->getVersionInfo(), $media); |
3729
|
|
|
|
3730
|
|
|
// The relations array now contains only one element |
3731
|
|
|
$relations = $this->contentService->loadRelations($draft->getVersionInfo()); |
3732
|
|
|
|
3733
|
|
|
$this->assertEquals(1, count($relations)); |
3734
|
|
|
} |
3735
|
|
|
|
3736
|
|
|
/** |
3737
|
|
|
* Test for the deleteRelation() method. |
3738
|
|
|
* |
3739
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteRelation() |
3740
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation |
3741
|
|
|
*/ |
3742
|
|
|
public function testDeleteRelationThrowsBadStateException() |
3743
|
|
|
{ |
3744
|
|
|
$content = $this->createContentVersion1(); |
3745
|
|
|
|
3746
|
|
|
// Load the destination object |
3747
|
|
|
$media = $this->contentService->loadContentInfoByRemoteId(self::MEDIA_REMOTE_ID); |
3748
|
|
|
|
3749
|
|
|
// Create a new draft |
3750
|
|
|
$draftVersion2 = $this->contentService->createContentDraft($content->contentInfo); |
3751
|
|
|
|
3752
|
|
|
// Add a relation |
3753
|
|
|
$this->contentService->addRelation($draftVersion2->getVersionInfo(), $media); |
3754
|
|
|
|
3755
|
|
|
// Publish new version |
3756
|
|
|
$contentVersion2 = $this->contentService->publishVersion( |
3757
|
|
|
$draftVersion2->getVersionInfo() |
3758
|
|
|
); |
3759
|
|
|
|
3760
|
|
|
$this->expectException(BadStateException::class); |
3761
|
|
|
|
3762
|
|
|
// This call will fail with a "BadStateException", because content is published and not a draft. |
3763
|
|
|
$this->contentService->deleteRelation( |
3764
|
|
|
$contentVersion2->getVersionInfo(), |
3765
|
|
|
$media |
3766
|
|
|
); |
3767
|
|
|
} |
3768
|
|
|
|
3769
|
|
|
/** |
3770
|
|
|
* Test for the deleteRelation() method. |
3771
|
|
|
* |
3772
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteRelation() |
3773
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation |
3774
|
|
|
*/ |
3775
|
|
|
public function testDeleteRelationThrowsInvalidArgumentException() |
3776
|
|
|
{ |
3777
|
|
|
$draft = $this->createContentDraftVersion1(); |
3778
|
|
|
|
3779
|
|
|
// Load the destination object |
3780
|
|
|
$media = $this->contentService->loadContentInfoByRemoteId(self::MEDIA_REMOTE_ID); |
3781
|
|
|
|
3782
|
|
|
// This call will fail with a "InvalidArgumentException", because no relation exists between $draft and $media. |
3783
|
|
|
$this->expectException(APIInvalidArgumentException::class); |
3784
|
|
|
$this->contentService->deleteRelation( |
3785
|
|
|
$draft->getVersionInfo(), |
3786
|
|
|
$media |
3787
|
|
|
); |
3788
|
|
|
} |
3789
|
|
|
|
3790
|
|
|
/** |
3791
|
|
|
* Test for the createContent() method. |
3792
|
|
|
* |
3793
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent() |
3794
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
3795
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
3796
|
|
|
*/ |
3797
|
|
|
public function testCreateContentInTransactionWithRollback() |
3798
|
|
|
{ |
3799
|
|
|
if ($this->isVersion4()) { |
3800
|
|
|
$this->markTestSkipped('This test requires eZ Publish 5'); |
3801
|
|
|
} |
3802
|
|
|
|
3803
|
|
|
$repository = $this->getRepository(); |
3804
|
|
|
|
3805
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
3806
|
|
|
|
3807
|
|
|
// Start a transaction |
3808
|
|
|
$repository->beginTransaction(); |
3809
|
|
|
|
3810
|
|
|
try { |
3811
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
3812
|
|
|
|
3813
|
|
|
// Get a content create struct and set mandatory properties |
3814
|
|
|
$contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
3815
|
|
|
$contentCreate->setField('name', 'Sindelfingen forum'); |
3816
|
|
|
|
3817
|
|
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
3818
|
|
|
$contentCreate->alwaysAvailable = true; |
3819
|
|
|
|
3820
|
|
|
// Create a new content object |
3821
|
|
|
$contentId = $this->contentService->createContent($contentCreate)->id; |
3822
|
|
|
} catch (Exception $e) { |
3823
|
|
|
// Cleanup hanging transaction on error |
3824
|
|
|
$repository->rollback(); |
3825
|
|
|
throw $e; |
3826
|
|
|
} |
3827
|
|
|
|
3828
|
|
|
// Rollback all changes |
3829
|
|
|
$repository->rollback(); |
3830
|
|
|
|
3831
|
|
|
try { |
3832
|
|
|
// This call will fail with a "NotFoundException" |
3833
|
|
|
$this->contentService->loadContent($contentId); |
3834
|
|
|
} catch (NotFoundException $e) { |
3835
|
|
|
// This is expected |
3836
|
|
|
return; |
3837
|
|
|
} |
3838
|
|
|
|
3839
|
|
|
$this->fail('Content object still exists after rollback.'); |
3840
|
|
|
} |
3841
|
|
|
|
3842
|
|
|
/** |
3843
|
|
|
* Test for the createContent() method. |
3844
|
|
|
* |
3845
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent() |
3846
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
3847
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
3848
|
|
|
*/ |
3849
|
|
|
public function testCreateContentInTransactionWithCommit() |
3850
|
|
|
{ |
3851
|
|
|
if ($this->isVersion4()) { |
3852
|
|
|
$this->markTestSkipped('This test requires eZ Publish 5'); |
3853
|
|
|
} |
3854
|
|
|
|
3855
|
|
|
$repository = $this->getRepository(); |
3856
|
|
|
|
3857
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
3858
|
|
|
|
3859
|
|
|
// Start a transaction |
3860
|
|
|
$repository->beginTransaction(); |
3861
|
|
|
|
3862
|
|
|
try { |
3863
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier(self::FORUM_IDENTIFIER); |
3864
|
|
|
|
3865
|
|
|
// Get a content create struct and set mandatory properties |
3866
|
|
|
$contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
3867
|
|
|
$contentCreate->setField('name', 'Sindelfingen forum'); |
3868
|
|
|
|
3869
|
|
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
3870
|
|
|
$contentCreate->alwaysAvailable = true; |
3871
|
|
|
|
3872
|
|
|
// Create a new content object |
3873
|
|
|
$contentId = $this->contentService->createContent($contentCreate)->id; |
3874
|
|
|
|
3875
|
|
|
// Commit changes |
3876
|
|
|
$repository->commit(); |
3877
|
|
|
} catch (Exception $e) { |
3878
|
|
|
// Cleanup hanging transaction on error |
3879
|
|
|
$repository->rollback(); |
3880
|
|
|
throw $e; |
3881
|
|
|
} |
3882
|
|
|
|
3883
|
|
|
// Load the new content object |
3884
|
|
|
$content = $this->contentService->loadContent($contentId); |
3885
|
|
|
|
3886
|
|
|
$this->assertEquals($contentId, $content->id); |
3887
|
|
|
} |
3888
|
|
|
|
3889
|
|
|
/** |
3890
|
|
|
* Test for the createContent() method. |
3891
|
|
|
* |
3892
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs) |
3893
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately |
3894
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentThrowsNotFoundException |
3895
|
|
|
*/ |
3896
|
|
|
public function testCreateContentWithLocationCreateParameterInTransactionWithRollback() |
3897
|
|
|
{ |
3898
|
|
|
$repository = $this->getRepository(); |
3899
|
|
|
|
3900
|
|
|
// Start a transaction |
3901
|
|
|
$repository->beginTransaction(); |
3902
|
|
|
|
3903
|
|
|
try { |
3904
|
|
|
$draft = $this->createContentDraftVersion1(); |
3905
|
|
|
} catch (Exception $e) { |
3906
|
|
|
// Cleanup hanging transaction on error |
3907
|
|
|
$repository->rollback(); |
3908
|
|
|
throw $e; |
3909
|
|
|
} |
3910
|
|
|
|
3911
|
|
|
$contentId = $draft->id; |
3912
|
|
|
|
3913
|
|
|
// Roleback the transaction |
3914
|
|
|
$repository->rollback(); |
3915
|
|
|
|
3916
|
|
|
try { |
3917
|
|
|
// This call will fail with a "NotFoundException" |
3918
|
|
|
$this->contentService->loadContent($contentId); |
3919
|
|
|
} catch (NotFoundException $e) { |
3920
|
|
|
return; |
3921
|
|
|
} |
3922
|
|
|
|
3923
|
|
|
$this->fail('Can still load content object after rollback.'); |
3924
|
|
|
} |
3925
|
|
|
|
3926
|
|
|
/** |
3927
|
|
|
* Test for the createContent() method. |
3928
|
|
|
* |
3929
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs) |
3930
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately |
3931
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentThrowsNotFoundException |
3932
|
|
|
*/ |
3933
|
|
|
public function testCreateContentWithLocationCreateParameterInTransactionWithCommit() |
3934
|
|
|
{ |
3935
|
|
|
$repository = $this->getRepository(); |
3936
|
|
|
|
3937
|
|
|
// Start a transaction |
3938
|
|
|
$repository->beginTransaction(); |
3939
|
|
|
|
3940
|
|
|
try { |
3941
|
|
|
$draft = $this->createContentDraftVersion1(); |
3942
|
|
|
|
3943
|
|
|
$contentId = $draft->id; |
3944
|
|
|
|
3945
|
|
|
// Roleback the transaction |
3946
|
|
|
$repository->commit(); |
3947
|
|
|
} catch (Exception $e) { |
3948
|
|
|
// Cleanup hanging transaction on error |
3949
|
|
|
$repository->rollback(); |
3950
|
|
|
throw $e; |
3951
|
|
|
} |
3952
|
|
|
|
3953
|
|
|
// Load the new content object |
3954
|
|
|
$content = $this->contentService->loadContent($contentId); |
3955
|
|
|
|
3956
|
|
|
$this->assertEquals($contentId, $content->id); |
3957
|
|
|
} |
3958
|
|
|
|
3959
|
|
|
/** |
3960
|
|
|
* Test for the createContentDraft() method. |
3961
|
|
|
* |
3962
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
3963
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
3964
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
3965
|
|
|
*/ |
3966
|
|
|
public function testCreateContentDraftInTransactionWithRollback() |
3967
|
|
|
{ |
3968
|
|
|
$repository = $this->getRepository(); |
3969
|
|
|
|
3970
|
|
|
$contentId = $this->generateId('object', self::ADMINISTRATORS_USER_GROUP_ID); |
3971
|
|
|
|
3972
|
|
|
// Load the user group content object |
3973
|
|
|
$content = $this->contentService->loadContent($contentId); |
3974
|
|
|
|
3975
|
|
|
// Start a new transaction |
3976
|
|
|
$repository->beginTransaction(); |
3977
|
|
|
|
3978
|
|
|
try { |
3979
|
|
|
// Create a new draft |
3980
|
|
|
$drafted = $this->contentService->createContentDraft($content->contentInfo); |
3981
|
|
|
|
3982
|
|
|
// Store version number for later reuse |
3983
|
|
|
$versionNo = $drafted->versionInfo->versionNo; |
3984
|
|
|
} catch (Exception $e) { |
3985
|
|
|
// Cleanup hanging transaction on error |
3986
|
|
|
$repository->rollback(); |
3987
|
|
|
throw $e; |
3988
|
|
|
} |
3989
|
|
|
|
3990
|
|
|
// Rollback |
3991
|
|
|
$repository->rollback(); |
3992
|
|
|
|
3993
|
|
|
try { |
3994
|
|
|
// This call will fail with a "NotFoundException" |
3995
|
|
|
$this->contentService->loadContent($contentId, null, $versionNo); |
3996
|
|
|
} catch (NotFoundException $e) { |
3997
|
|
|
return; |
3998
|
|
|
} |
3999
|
|
|
|
4000
|
|
|
$this->fail('Can still load content draft after rollback'); |
4001
|
|
|
} |
4002
|
|
|
|
4003
|
|
|
/** |
4004
|
|
|
* Test for the createContentDraft() method. |
4005
|
|
|
* |
4006
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
4007
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
4008
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
4009
|
|
|
*/ |
4010
|
|
|
public function testCreateContentDraftInTransactionWithCommit() |
4011
|
|
|
{ |
4012
|
|
|
$repository = $this->getRepository(); |
4013
|
|
|
|
4014
|
|
|
$contentId = $this->generateId('object', self::ADMINISTRATORS_USER_GROUP_ID); |
4015
|
|
|
|
4016
|
|
|
// Load the user group content object |
4017
|
|
|
$content = $this->contentService->loadContent($contentId); |
4018
|
|
|
|
4019
|
|
|
// Start a new transaction |
4020
|
|
|
$repository->beginTransaction(); |
4021
|
|
|
|
4022
|
|
|
try { |
4023
|
|
|
// Create a new draft |
4024
|
|
|
$drafted = $this->contentService->createContentDraft($content->contentInfo); |
4025
|
|
|
|
4026
|
|
|
// Store version number for later reuse |
4027
|
|
|
$versionNo = $drafted->versionInfo->versionNo; |
4028
|
|
|
|
4029
|
|
|
// Commit all changes |
4030
|
|
|
$repository->commit(); |
4031
|
|
|
} catch (Exception $e) { |
4032
|
|
|
// Cleanup hanging transaction on error |
4033
|
|
|
$repository->rollback(); |
4034
|
|
|
throw $e; |
4035
|
|
|
} |
4036
|
|
|
|
4037
|
|
|
$content = $this->contentService->loadContent($contentId, null, $versionNo); |
4038
|
|
|
|
4039
|
|
|
$this->assertEquals( |
4040
|
|
|
$versionNo, |
4041
|
|
|
$content->getVersionInfo()->versionNo |
4042
|
|
|
); |
4043
|
|
|
} |
4044
|
|
|
|
4045
|
|
|
/** |
4046
|
|
|
* Test for the publishVersion() method. |
4047
|
|
|
* |
4048
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
4049
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
4050
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
4051
|
|
|
*/ |
4052
|
|
|
public function testPublishVersionInTransactionWithRollback() |
4053
|
|
|
{ |
4054
|
|
|
$repository = $this->getRepository(); |
4055
|
|
|
|
4056
|
|
|
$contentId = $this->generateId('object', self::ADMINISTRATORS_USER_GROUP_ID); |
4057
|
|
|
|
4058
|
|
|
// Load the user group content object |
4059
|
|
|
$content = $this->contentService->loadContent($contentId); |
4060
|
|
|
|
4061
|
|
|
// Start a new transaction |
4062
|
|
|
$repository->beginTransaction(); |
4063
|
|
|
|
4064
|
|
|
try { |
4065
|
|
|
$draftVersion = $this->contentService->createContentDraft($content->contentInfo)->getVersionInfo(); |
4066
|
|
|
|
4067
|
|
|
// Publish a new version |
4068
|
|
|
$content = $this->contentService->publishVersion($draftVersion); |
4069
|
|
|
|
4070
|
|
|
// Store version number for later reuse |
4071
|
|
|
$versionNo = $content->versionInfo->versionNo; |
4072
|
|
|
} catch (Exception $e) { |
4073
|
|
|
// Cleanup hanging transaction on error |
4074
|
|
|
$repository->rollback(); |
4075
|
|
|
throw $e; |
4076
|
|
|
} |
4077
|
|
|
|
4078
|
|
|
// Rollback |
4079
|
|
|
$repository->rollback(); |
4080
|
|
|
|
4081
|
|
|
try { |
4082
|
|
|
// This call will fail with a "NotFoundException" |
4083
|
|
|
$this->contentService->loadContent($contentId, null, $versionNo); |
4084
|
|
|
} catch (NotFoundException $e) { |
4085
|
|
|
return; |
4086
|
|
|
} |
4087
|
|
|
|
4088
|
|
|
$this->fail('Can still load content draft after rollback'); |
4089
|
|
|
} |
4090
|
|
|
|
4091
|
|
|
/** |
4092
|
|
|
* Test for the publishVersion() method. |
4093
|
|
|
* |
4094
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
4095
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
4096
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
4097
|
|
|
*/ |
4098
|
|
|
public function testPublishVersionInTransactionWithCommit() |
4099
|
|
|
{ |
4100
|
|
|
$repository = $this->getRepository(); |
4101
|
|
|
|
4102
|
|
|
// Load the user group content object |
4103
|
|
|
$template = $this->contentService->loadContent(self::ADMINISTRATORS_USER_GROUP_ID); |
4104
|
|
|
|
4105
|
|
|
// Start a new transaction |
4106
|
|
|
$repository->beginTransaction(); |
4107
|
|
|
|
4108
|
|
|
try { |
4109
|
|
|
// Publish a new version |
4110
|
|
|
$content = $this->contentService->publishVersion( |
4111
|
|
|
$this->contentService->createContentDraft($template->contentInfo)->getVersionInfo() |
4112
|
|
|
); |
4113
|
|
|
|
4114
|
|
|
// Store version number for later reuse |
4115
|
|
|
$versionNo = $content->versionInfo->versionNo; |
4116
|
|
|
|
4117
|
|
|
// Commit all changes |
4118
|
|
|
$repository->commit(); |
4119
|
|
|
} catch (Exception $e) { |
4120
|
|
|
// Cleanup hanging transaction on error |
4121
|
|
|
$repository->rollback(); |
4122
|
|
|
throw $e; |
4123
|
|
|
} |
4124
|
|
|
|
4125
|
|
|
// Load current version info |
4126
|
|
|
$versionInfo = $this->contentService->loadVersionInfo($content->contentInfo); |
4127
|
|
|
|
4128
|
|
|
$this->assertEquals($versionNo, $versionInfo->versionNo); |
4129
|
|
|
} |
4130
|
|
|
|
4131
|
|
|
/** |
4132
|
|
|
* Test for the updateContent() method. |
4133
|
|
|
* |
4134
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContent() |
4135
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
4136
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
4137
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
4138
|
|
|
*/ |
4139
|
|
|
public function testUpdateContentInTransactionWithRollback() |
4140
|
|
|
{ |
4141
|
|
|
$repository = $this->getRepository(); |
4142
|
|
|
|
4143
|
|
|
$contentId = $this->generateId('object', self::ADMINISTRATORS_USER_GROUP_ID); |
4144
|
|
|
|
4145
|
|
|
// Create a new user group draft |
4146
|
|
|
$draft = $this->contentService->createContentDraft( |
4147
|
|
|
$this->contentService->loadContentInfo($contentId) |
4148
|
|
|
); |
4149
|
|
|
|
4150
|
|
|
// Get an update struct and change the group name |
4151
|
|
|
$contentUpdate = $this->contentService->newContentUpdateStruct(); |
4152
|
|
|
$contentUpdate->setField('name', self::ADMINISTRATORS_USER_GROUP_NAME, self::ENG_US); |
4153
|
|
|
|
4154
|
|
|
// Start a transaction |
4155
|
|
|
$repository->beginTransaction(); |
4156
|
|
|
|
4157
|
|
|
try { |
4158
|
|
|
// Update the group name |
4159
|
|
|
$draft = $this->contentService->updateContent( |
4160
|
|
|
$draft->getVersionInfo(), |
4161
|
|
|
$contentUpdate |
4162
|
|
|
); |
4163
|
|
|
|
4164
|
|
|
// Publish updated version |
4165
|
|
|
$this->contentService->publishVersion($draft->getVersionInfo()); |
4166
|
|
|
} catch (Exception $e) { |
4167
|
|
|
// Cleanup hanging transaction on error |
4168
|
|
|
$repository->rollback(); |
4169
|
|
|
throw $e; |
4170
|
|
|
} |
4171
|
|
|
|
4172
|
|
|
// Rollback all changes. |
4173
|
|
|
$repository->rollback(); |
4174
|
|
|
|
4175
|
|
|
// Name will still be "Administrator users" |
4176
|
|
|
$name = $this->contentService->loadContent($contentId)->getFieldValue('name'); |
4177
|
|
|
|
4178
|
|
|
$this->assertEquals('Administrator users', $name); |
4179
|
|
|
} |
4180
|
|
|
|
4181
|
|
|
/** |
4182
|
|
|
* Test for the updateContent() method. |
4183
|
|
|
* |
4184
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContent() |
4185
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
4186
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
4187
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
4188
|
|
|
*/ |
4189
|
|
|
public function testUpdateContentInTransactionWithCommit() |
4190
|
|
|
{ |
4191
|
|
|
$repository = $this->getRepository(); |
4192
|
|
|
|
4193
|
|
|
$contentId = $this->generateId('object', self::ADMINISTRATORS_USER_GROUP_ID); |
4194
|
|
|
|
4195
|
|
|
// Create a new user group draft |
4196
|
|
|
$draft = $this->contentService->createContentDraft( |
4197
|
|
|
$this->contentService->loadContentInfo($contentId) |
4198
|
|
|
); |
4199
|
|
|
|
4200
|
|
|
// Get an update struct and change the group name |
4201
|
|
|
$contentUpdate = $this->contentService->newContentUpdateStruct(); |
4202
|
|
|
$contentUpdate->setField('name', self::ADMINISTRATORS_USER_GROUP_NAME, self::ENG_US); |
4203
|
|
|
|
4204
|
|
|
// Start a transaction |
4205
|
|
|
$repository->beginTransaction(); |
4206
|
|
|
|
4207
|
|
|
try { |
4208
|
|
|
// Update the group name |
4209
|
|
|
$draft = $this->contentService->updateContent( |
4210
|
|
|
$draft->getVersionInfo(), |
4211
|
|
|
$contentUpdate |
4212
|
|
|
); |
4213
|
|
|
|
4214
|
|
|
// Publish updated version |
4215
|
|
|
$this->contentService->publishVersion($draft->getVersionInfo()); |
4216
|
|
|
|
4217
|
|
|
// Commit all changes. |
4218
|
|
|
$repository->commit(); |
4219
|
|
|
} catch (Exception $e) { |
4220
|
|
|
// Cleanup hanging transaction on error |
4221
|
|
|
$repository->rollback(); |
4222
|
|
|
throw $e; |
4223
|
|
|
} |
4224
|
|
|
|
4225
|
|
|
// Name is now "Administrators" |
4226
|
|
|
$name = $this->contentService->loadContent($contentId)->getFieldValue('name', self::ENG_US); |
4227
|
|
|
|
4228
|
|
|
$this->assertEquals(self::ADMINISTRATORS_USER_GROUP_NAME, $name); |
4229
|
|
|
} |
4230
|
|
|
|
4231
|
|
|
/** |
4232
|
|
|
* Test for the updateContentMetadata() method. |
4233
|
|
|
* |
4234
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
4235
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
4236
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
4237
|
|
|
*/ |
4238
|
|
|
public function testUpdateContentMetadataInTransactionWithRollback() |
4239
|
|
|
{ |
4240
|
|
|
$repository = $this->getRepository(); |
4241
|
|
|
|
4242
|
|
|
$contentId = $this->generateId('object', self::ADMINISTRATORS_USER_GROUP_ID); |
4243
|
|
|
|
4244
|
|
|
// Load a ContentInfo object |
4245
|
|
|
$contentInfo = $this->contentService->loadContentInfo($contentId); |
4246
|
|
|
|
4247
|
|
|
// Store remoteId for later testing |
4248
|
|
|
$remoteId = $contentInfo->remoteId; |
4249
|
|
|
|
4250
|
|
|
// Start a transaction |
4251
|
|
|
$repository->beginTransaction(); |
4252
|
|
|
|
4253
|
|
|
try { |
4254
|
|
|
// Get metadata update struct and change remoteId |
4255
|
|
|
$metadataUpdate = $this->contentService->newContentMetadataUpdateStruct(); |
4256
|
|
|
$metadataUpdate->remoteId = md5(microtime(true)); |
4257
|
|
|
|
4258
|
|
|
// Update the metadata of the published content object |
4259
|
|
|
$this->contentService->updateContentMetadata( |
4260
|
|
|
$contentInfo, |
4261
|
|
|
$metadataUpdate |
4262
|
|
|
); |
4263
|
|
|
} catch (Exception $e) { |
4264
|
|
|
// Cleanup hanging transaction on error |
4265
|
|
|
$repository->rollback(); |
4266
|
|
|
throw $e; |
4267
|
|
|
} |
4268
|
|
|
|
4269
|
|
|
// Rollback all changes. |
4270
|
|
|
$repository->rollback(); |
4271
|
|
|
|
4272
|
|
|
// Load current remoteId |
4273
|
|
|
$remoteIdReloaded = $this->contentService->loadContentInfo($contentId)->remoteId; |
4274
|
|
|
|
4275
|
|
|
$this->assertEquals($remoteId, $remoteIdReloaded); |
4276
|
|
|
} |
4277
|
|
|
|
4278
|
|
|
/** |
4279
|
|
|
* Test for the updateContentMetadata() method. |
4280
|
|
|
* |
4281
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
4282
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
4283
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
4284
|
|
|
*/ |
4285
|
|
|
public function testUpdateContentMetadataInTransactionWithCommit() |
4286
|
|
|
{ |
4287
|
|
|
$repository = $this->getRepository(); |
4288
|
|
|
|
4289
|
|
|
$contentId = $this->generateId('object', self::ADMINISTRATORS_USER_GROUP_ID); |
4290
|
|
|
|
4291
|
|
|
// Load a ContentInfo object |
4292
|
|
|
$contentInfo = $this->contentService->loadContentInfo($contentId); |
4293
|
|
|
|
4294
|
|
|
// Store remoteId for later testing |
4295
|
|
|
$remoteId = $contentInfo->remoteId; |
4296
|
|
|
|
4297
|
|
|
// Start a transaction |
4298
|
|
|
$repository->beginTransaction(); |
4299
|
|
|
|
4300
|
|
|
try { |
4301
|
|
|
// Get metadata update struct and change remoteId |
4302
|
|
|
$metadataUpdate = $this->contentService->newContentMetadataUpdateStruct(); |
4303
|
|
|
$metadataUpdate->remoteId = md5(microtime(true)); |
4304
|
|
|
|
4305
|
|
|
// Update the metadata of the published content object |
4306
|
|
|
$this->contentService->updateContentMetadata( |
4307
|
|
|
$contentInfo, |
4308
|
|
|
$metadataUpdate |
4309
|
|
|
); |
4310
|
|
|
|
4311
|
|
|
// Commit all changes. |
4312
|
|
|
$repository->commit(); |
4313
|
|
|
} catch (Exception $e) { |
4314
|
|
|
// Cleanup hanging transaction on error |
4315
|
|
|
$repository->rollback(); |
4316
|
|
|
throw $e; |
4317
|
|
|
} |
4318
|
|
|
|
4319
|
|
|
// Load current remoteId |
4320
|
|
|
$remoteIdReloaded = $this->contentService->loadContentInfo($contentId)->remoteId; |
4321
|
|
|
|
4322
|
|
|
$this->assertNotEquals($remoteId, $remoteIdReloaded); |
4323
|
|
|
} |
4324
|
|
|
|
4325
|
|
|
/** |
4326
|
|
|
* Test for the updateContentMetadata() method, and how cache + transactions play together. |
4327
|
|
|
* |
4328
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
4329
|
|
|
* @depends testUpdateContentMetadata |
4330
|
|
|
* @depends testLoadContentInfo |
4331
|
|
|
*/ |
4332
|
|
|
public function testUpdateContentMetadataCheckWithinTransaction() |
4333
|
|
|
{ |
4334
|
|
|
$repository = $this->getRepository(); |
4335
|
|
|
$contentService = $repository->getContentService(); |
4336
|
|
|
$contentId = $this->generateId('object', 12); |
4337
|
|
|
|
4338
|
|
|
// Load a ContentInfo object, and warmup cache |
4339
|
|
|
$contentInfo = $contentService->loadContentInfo($contentId); |
4340
|
|
|
|
4341
|
|
|
// Store remoteId for later testing |
4342
|
|
|
$remoteId = $contentInfo->remoteId; |
4343
|
|
|
|
4344
|
|
|
// Start a transaction |
4345
|
|
|
$repository->beginTransaction(); |
4346
|
|
|
|
4347
|
|
|
try { |
4348
|
|
|
// Get metadata update struct and change remoteId |
4349
|
|
|
$metadataUpdate = $contentService->newContentMetadataUpdateStruct(); |
4350
|
|
|
$metadataUpdate->remoteId = md5(microtime(true)); |
4351
|
|
|
|
4352
|
|
|
// Update the metadata of the published content object |
4353
|
|
|
$contentService->updateContentMetadata( |
4354
|
|
|
$contentInfo, |
4355
|
|
|
$metadataUpdate |
4356
|
|
|
); |
4357
|
|
|
|
4358
|
|
|
// Check that it's been updated |
4359
|
|
|
$remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId; |
4360
|
|
|
$this->assertNotEquals($remoteId, $remoteIdReloaded); |
4361
|
|
|
|
4362
|
|
|
// Commit all changes. |
4363
|
|
|
$repository->commit(); |
4364
|
|
|
} catch (Exception $e) { |
4365
|
|
|
// Cleanup hanging transaction on error |
4366
|
|
|
$repository->rollback(); |
4367
|
|
|
throw $e; |
4368
|
|
|
} |
4369
|
|
|
} |
4370
|
|
|
|
4371
|
|
|
/** |
4372
|
|
|
* Test for the deleteVersion() method. |
4373
|
|
|
* |
4374
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
4375
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
4376
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
4377
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts |
4378
|
|
|
*/ |
4379
|
|
|
public function testDeleteVersionInTransactionWithRollback() |
4380
|
|
|
{ |
4381
|
|
|
$repository = $this->getRepository(); |
4382
|
|
|
|
4383
|
|
|
$contentId = $this->generateId('object', self::ADMINISTRATORS_USER_GROUP_ID); |
4384
|
|
|
|
4385
|
|
|
// Start a new transaction |
4386
|
|
|
$repository->beginTransaction(); |
4387
|
|
|
|
4388
|
|
|
try { |
4389
|
|
|
// Create a new draft |
4390
|
|
|
$draft = $this->contentService->createContentDraft( |
4391
|
|
|
$this->contentService->loadContentInfo($contentId) |
4392
|
|
|
); |
4393
|
|
|
|
4394
|
|
|
$this->contentService->deleteVersion($draft->getVersionInfo()); |
4395
|
|
|
} catch (Exception $e) { |
4396
|
|
|
// Cleanup hanging transaction on error |
4397
|
|
|
$repository->rollback(); |
4398
|
|
|
throw $e; |
4399
|
|
|
} |
4400
|
|
|
|
4401
|
|
|
// Rollback all changes. |
4402
|
|
|
$repository->rollback(); |
4403
|
|
|
|
4404
|
|
|
// This array will be empty |
4405
|
|
|
$drafts = $this->contentService->loadContentDrafts(); |
4406
|
|
|
|
4407
|
|
|
$this->assertSame([], $drafts); |
4408
|
|
|
} |
4409
|
|
|
|
4410
|
|
|
/** |
4411
|
|
|
* Test for the deleteVersion() method. |
4412
|
|
|
* |
4413
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
4414
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
4415
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
4416
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts |
4417
|
|
|
*/ |
4418
|
|
|
public function testDeleteVersionInTransactionWithCommit() |
4419
|
|
|
{ |
4420
|
|
|
$repository = $this->getRepository(); |
4421
|
|
|
|
4422
|
|
|
$contentId = $this->generateId('object', self::ADMINISTRATORS_USER_GROUP_ID); |
4423
|
|
|
|
4424
|
|
|
// Start a new transaction |
4425
|
|
|
$repository->beginTransaction(); |
4426
|
|
|
|
4427
|
|
|
try { |
4428
|
|
|
// Create a new draft |
4429
|
|
|
$draft = $this->contentService->createContentDraft( |
4430
|
|
|
$this->contentService->loadContentInfo($contentId) |
4431
|
|
|
); |
4432
|
|
|
|
4433
|
|
|
$this->contentService->deleteVersion($draft->getVersionInfo()); |
4434
|
|
|
|
4435
|
|
|
// Commit all changes. |
4436
|
|
|
$repository->commit(); |
4437
|
|
|
} catch (Exception $e) { |
4438
|
|
|
// Cleanup hanging transaction on error |
4439
|
|
|
$repository->rollback(); |
4440
|
|
|
throw $e; |
4441
|
|
|
} |
4442
|
|
|
|
4443
|
|
|
// This array will contain no element |
4444
|
|
|
$drafts = $this->contentService->loadContentDrafts(); |
4445
|
|
|
|
4446
|
|
|
$this->assertSame([], $drafts); |
4447
|
|
|
} |
4448
|
|
|
|
4449
|
|
|
/** |
4450
|
|
|
* Test for the deleteContent() method. |
4451
|
|
|
* |
4452
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteContent() |
4453
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent |
4454
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
4455
|
|
|
*/ |
4456
|
|
|
public function testDeleteContentInTransactionWithRollback() |
4457
|
|
|
{ |
4458
|
|
|
$repository = $this->getRepository(); |
4459
|
|
|
|
4460
|
|
|
$contentId = $this->generateId('object', self::MEMBERS_USER_GROUP_ID); |
4461
|
|
|
|
4462
|
|
|
// Load a ContentInfo instance |
4463
|
|
|
$contentInfo = $this->contentService->loadContentInfo($contentId); |
4464
|
|
|
|
4465
|
|
|
// Start a new transaction |
4466
|
|
|
$repository->beginTransaction(); |
4467
|
|
|
|
4468
|
|
|
try { |
4469
|
|
|
// Delete content object |
4470
|
|
|
$this->contentService->deleteContent($contentInfo); |
4471
|
|
|
} catch (Exception $e) { |
4472
|
|
|
// Cleanup hanging transaction on error |
4473
|
|
|
$repository->rollback(); |
4474
|
|
|
throw $e; |
4475
|
|
|
} |
4476
|
|
|
|
4477
|
|
|
// Rollback all changes |
4478
|
|
|
$repository->rollback(); |
4479
|
|
|
|
4480
|
|
|
// This call will return the original content object |
4481
|
|
|
$contentInfo = $this->contentService->loadContentInfo($contentId); |
4482
|
|
|
|
4483
|
|
|
$this->assertEquals($contentId, $contentInfo->id); |
4484
|
|
|
} |
4485
|
|
|
|
4486
|
|
|
/** |
4487
|
|
|
* Test for the deleteContent() method. |
4488
|
|
|
* |
4489
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteContent() |
4490
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent |
4491
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
4492
|
|
|
*/ |
4493
|
|
|
public function testDeleteContentInTransactionWithCommit() |
4494
|
|
|
{ |
4495
|
|
|
$repository = $this->getRepository(); |
4496
|
|
|
|
4497
|
|
|
$contentId = $this->generateId('object', self::MEMBERS_USER_GROUP_ID); |
4498
|
|
|
|
4499
|
|
|
// Load a ContentInfo instance |
4500
|
|
|
$contentInfo = $this->contentService->loadContentInfo($contentId); |
4501
|
|
|
|
4502
|
|
|
// Start a new transaction |
4503
|
|
|
$repository->beginTransaction(); |
4504
|
|
|
|
4505
|
|
|
try { |
4506
|
|
|
// Delete content object |
4507
|
|
|
$this->contentService->deleteContent($contentInfo); |
4508
|
|
|
|
4509
|
|
|
// Commit all changes |
4510
|
|
|
$repository->commit(); |
4511
|
|
|
} catch (Exception $e) { |
4512
|
|
|
// Cleanup hanging transaction on error |
4513
|
|
|
$repository->rollback(); |
4514
|
|
|
throw $e; |
4515
|
|
|
} |
4516
|
|
|
|
4517
|
|
|
// Deleted content info is not found anymore |
4518
|
|
|
try { |
4519
|
|
|
$this->contentService->loadContentInfo($contentId); |
4520
|
|
|
} catch (NotFoundException $e) { |
4521
|
|
|
return; |
4522
|
|
|
} |
4523
|
|
|
|
4524
|
|
|
$this->fail('Can still load ContentInfo after commit.'); |
4525
|
|
|
} |
4526
|
|
|
|
4527
|
|
|
/** |
4528
|
|
|
* Test for the copyContent() method. |
4529
|
|
|
* |
4530
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::copyContent() |
4531
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent |
4532
|
|
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
4533
|
|
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
4534
|
|
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
4535
|
|
|
*/ |
4536
|
|
|
public function testCopyContentInTransactionWithRollback() |
4537
|
|
|
{ |
4538
|
|
|
$repository = $this->getRepository(); |
4539
|
|
|
|
4540
|
|
|
$contentId = $this->generateId('object', self::MEMBERS_USER_GROUP_ID); |
4541
|
|
|
$locationId = $this->generateId('location', self::ADMINISTRATORS_USER_GROUP_LOCATION_ID); |
4542
|
|
|
|
4543
|
|
|
// Load content object to copy |
4544
|
|
|
$content = $this->contentService->loadContent($contentId); |
4545
|
|
|
|
4546
|
|
|
// Create new target location |
4547
|
|
|
$locationCreate = $this->locationService->newLocationCreateStruct($locationId); |
4548
|
|
|
|
4549
|
|
|
// Start a new transaction |
4550
|
|
|
$repository->beginTransaction(); |
4551
|
|
|
|
4552
|
|
|
try { |
4553
|
|
|
// Copy content with all versions and drafts |
4554
|
|
|
$this->contentService->copyContent( |
4555
|
|
|
$content->contentInfo, |
4556
|
|
|
$locationCreate |
4557
|
|
|
); |
4558
|
|
|
} catch (Exception $e) { |
4559
|
|
|
// Cleanup hanging transaction on error |
4560
|
|
|
$repository->rollback(); |
4561
|
|
|
throw $e; |
4562
|
|
|
} |
4563
|
|
|
|
4564
|
|
|
// Rollback all changes |
4565
|
|
|
$repository->rollback(); |
4566
|
|
|
|
4567
|
|
|
$this->refreshSearch($repository); |
4568
|
|
|
|
4569
|
|
|
// This array will only contain a single admin user object |
4570
|
|
|
$locations = $this->locationService->loadLocationChildren( |
4571
|
|
|
$this->locationService->loadLocation($locationId) |
4572
|
|
|
)->locations; |
4573
|
|
|
|
4574
|
|
|
$this->assertEquals(1, count($locations)); |
4575
|
|
|
} |
4576
|
|
|
|
4577
|
|
|
/** |
4578
|
|
|
* Test for the copyContent() method. |
4579
|
|
|
* |
4580
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::copyContent() |
4581
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent |
4582
|
|
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
4583
|
|
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
4584
|
|
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
4585
|
|
|
*/ |
4586
|
|
|
public function testCopyContentInTransactionWithCommit() |
4587
|
|
|
{ |
4588
|
|
|
$repository = $this->getRepository(); |
4589
|
|
|
|
4590
|
|
|
$contentId = $this->generateId('object', self::MEMBERS_USER_GROUP_ID); |
4591
|
|
|
$locationId = $this->generateId('location', self::ADMINISTRATORS_USER_GROUP_LOCATION_ID); |
4592
|
|
|
|
4593
|
|
|
// Load content object to copy |
4594
|
|
|
$content = $this->contentService->loadContent($contentId); |
4595
|
|
|
|
4596
|
|
|
// Create new target location |
4597
|
|
|
$locationCreate = $this->locationService->newLocationCreateStruct($locationId); |
4598
|
|
|
|
4599
|
|
|
// Start a new transaction |
4600
|
|
|
$repository->beginTransaction(); |
4601
|
|
|
|
4602
|
|
|
try { |
4603
|
|
|
// Copy content with all versions and drafts |
4604
|
|
|
$this->contentService->copyContent( |
4605
|
|
|
$content->contentInfo, |
4606
|
|
|
$locationCreate |
4607
|
|
|
); |
4608
|
|
|
|
4609
|
|
|
// Commit all changes |
4610
|
|
|
$repository->commit(); |
4611
|
|
|
} catch (Exception $e) { |
4612
|
|
|
// Cleanup hanging transaction on error |
4613
|
|
|
$repository->rollback(); |
4614
|
|
|
throw $e; |
4615
|
|
|
} |
4616
|
|
|
|
4617
|
|
|
$this->refreshSearch($repository); |
4618
|
|
|
|
4619
|
|
|
// This will contain the admin user and the new child location |
4620
|
|
|
$locations = $this->locationService->loadLocationChildren( |
4621
|
|
|
$this->locationService->loadLocation($locationId) |
4622
|
|
|
)->locations; |
4623
|
|
|
|
4624
|
|
|
$this->assertEquals(2, count($locations)); |
4625
|
|
|
} |
4626
|
|
|
|
4627
|
|
|
public function testURLAliasesCreatedForNewContent() |
4628
|
|
|
{ |
4629
|
|
|
$urlAliasService = $this->getRepository()->getURLAliasService(); |
4630
|
|
|
|
4631
|
|
|
$draft = $this->createContentDraftVersion1(); |
4632
|
|
|
|
4633
|
|
|
// Automatically creates a new URLAlias for the content |
4634
|
|
|
$liveContent = $this->contentService->publishVersion($draft->getVersionInfo()); |
4635
|
|
|
|
4636
|
|
|
$location = $this->locationService->loadLocation( |
4637
|
|
|
$liveContent->getVersionInfo()->getContentInfo()->mainLocationId |
4638
|
|
|
); |
4639
|
|
|
|
4640
|
|
|
$aliases = $urlAliasService->listLocationAliases($location, false); |
4641
|
|
|
|
4642
|
|
|
$this->assertAliasesCorrect( |
4643
|
|
|
[ |
4644
|
|
|
'/Design/Plain-site/An-awesome-forum' => [ |
4645
|
|
|
'type' => URLAlias::LOCATION, |
4646
|
|
|
'destination' => $location->id, |
4647
|
|
|
'path' => '/Design/Plain-site/An-awesome-forum', |
4648
|
|
|
'languageCodes' => [self::ENG_US], |
4649
|
|
|
'isHistory' => false, |
4650
|
|
|
'isCustom' => false, |
4651
|
|
|
'forward' => false, |
4652
|
|
|
], |
4653
|
|
|
], |
4654
|
|
|
$aliases |
4655
|
|
|
); |
4656
|
|
|
} |
4657
|
|
|
|
4658
|
|
|
public function testURLAliasesCreatedForUpdatedContent() |
4659
|
|
|
{ |
4660
|
|
|
$urlAliasService = $this->getRepository()->getURLAliasService(); |
4661
|
|
|
|
4662
|
|
|
$draft = $this->createUpdatedDraftVersion2(); |
4663
|
|
|
|
4664
|
|
|
$location = $this->locationService->loadLocation( |
4665
|
|
|
$draft->getVersionInfo()->getContentInfo()->mainLocationId |
4666
|
|
|
); |
4667
|
|
|
|
4668
|
|
|
// Load and assert URL aliases before publishing updated Content, so that |
4669
|
|
|
// SPI cache is warmed up and cache invalidation is also tested. |
4670
|
|
|
$aliases = $urlAliasService->listLocationAliases($location, false); |
4671
|
|
|
|
4672
|
|
|
$this->assertAliasesCorrect( |
4673
|
|
|
[ |
4674
|
|
|
'/Design/Plain-site/An-awesome-forum' => [ |
4675
|
|
|
'type' => URLAlias::LOCATION, |
4676
|
|
|
'destination' => $location->id, |
4677
|
|
|
'path' => '/Design/Plain-site/An-awesome-forum', |
4678
|
|
|
'languageCodes' => [self::ENG_US], |
4679
|
|
|
'alwaysAvailable' => true, |
4680
|
|
|
'isHistory' => false, |
4681
|
|
|
'isCustom' => false, |
4682
|
|
|
'forward' => false, |
4683
|
|
|
], |
4684
|
|
|
], |
4685
|
|
|
$aliases |
4686
|
|
|
); |
4687
|
|
|
|
4688
|
|
|
// Automatically marks old aliases for the content as history |
4689
|
|
|
// and creates new aliases, based on the changes |
4690
|
|
|
$liveContent = $this->contentService->publishVersion($draft->getVersionInfo()); |
4691
|
|
|
|
4692
|
|
|
$location = $this->locationService->loadLocation( |
4693
|
|
|
$liveContent->getVersionInfo()->getContentInfo()->mainLocationId |
4694
|
|
|
); |
4695
|
|
|
|
4696
|
|
|
$aliases = $urlAliasService->listLocationAliases($location, false); |
4697
|
|
|
|
4698
|
|
|
$this->assertAliasesCorrect( |
4699
|
|
|
[ |
4700
|
|
|
'/Design/Plain-site/An-awesome-forum2' => [ |
4701
|
|
|
'type' => URLAlias::LOCATION, |
4702
|
|
|
'destination' => $location->id, |
4703
|
|
|
'path' => '/Design/Plain-site/An-awesome-forum2', |
4704
|
|
|
'languageCodes' => [self::ENG_US], |
4705
|
|
|
'alwaysAvailable' => true, |
4706
|
|
|
'isHistory' => false, |
4707
|
|
|
'isCustom' => false, |
4708
|
|
|
'forward' => false, |
4709
|
|
|
], |
4710
|
|
|
'/Design/Plain-site/An-awesome-forum23' => [ |
4711
|
|
|
'type' => URLAlias::LOCATION, |
4712
|
|
|
'destination' => $location->id, |
4713
|
|
|
'path' => '/Design/Plain-site/An-awesome-forum23', |
4714
|
|
|
'languageCodes' => [self::ENG_GB], |
4715
|
|
|
'alwaysAvailable' => true, |
4716
|
|
|
'isHistory' => false, |
4717
|
|
|
'isCustom' => false, |
4718
|
|
|
'forward' => false, |
4719
|
|
|
], |
4720
|
|
|
], |
4721
|
|
|
$aliases |
4722
|
|
|
); |
4723
|
|
|
} |
4724
|
|
|
|
4725
|
|
|
public function testCustomURLAliasesNotHistorizedOnUpdatedContent() |
4726
|
|
|
{ |
4727
|
|
|
$urlAliasService = $this->getRepository()->getURLAliasService(); |
4728
|
|
|
|
4729
|
|
|
$content = $this->createContentVersion1(); |
4730
|
|
|
|
4731
|
|
|
// Create a custom URL alias |
4732
|
|
|
$urlAliasService->createUrlAlias( |
4733
|
|
|
$this->locationService->loadLocation( |
4734
|
|
|
$content->getVersionInfo()->getContentInfo()->mainLocationId |
4735
|
|
|
), |
4736
|
|
|
'/my/fancy/story-about-ez-publish', |
4737
|
|
|
self::ENG_US |
4738
|
|
|
); |
4739
|
|
|
|
4740
|
|
|
$draftVersion2 = $this->contentService->createContentDraft($content->contentInfo); |
4741
|
|
|
|
4742
|
|
|
$contentUpdate = $this->contentService->newContentUpdateStruct(); |
4743
|
|
|
$contentUpdate->initialLanguageCode = self::ENG_US; |
4744
|
|
|
$contentUpdate->setField('name', 'Amazing Bielefeld forum'); |
4745
|
|
|
|
4746
|
|
|
$draftVersion2 = $this->contentService->updateContent( |
4747
|
|
|
$draftVersion2->getVersionInfo(), |
4748
|
|
|
$contentUpdate |
4749
|
|
|
); |
4750
|
|
|
|
4751
|
|
|
// Only marks auto-generated aliases as history |
4752
|
|
|
// the custom one is left untouched |
4753
|
|
|
$liveContent = $this->contentService->publishVersion($draftVersion2->getVersionInfo()); |
4754
|
|
|
|
4755
|
|
|
$location = $this->locationService->loadLocation( |
4756
|
|
|
$liveContent->getVersionInfo()->getContentInfo()->mainLocationId |
4757
|
|
|
); |
4758
|
|
|
|
4759
|
|
|
$aliases = $urlAliasService->listLocationAliases($location); |
4760
|
|
|
|
4761
|
|
|
$this->assertAliasesCorrect( |
4762
|
|
|
[ |
4763
|
|
|
'/my/fancy/story-about-ez-publish' => [ |
4764
|
|
|
'type' => URLAlias::LOCATION, |
4765
|
|
|
'destination' => $location->id, |
4766
|
|
|
'path' => '/my/fancy/story-about-ez-publish', |
4767
|
|
|
'languageCodes' => [self::ENG_US], |
4768
|
|
|
'isHistory' => false, |
4769
|
|
|
'isCustom' => true, |
4770
|
|
|
'forward' => false, |
4771
|
|
|
'alwaysAvailable' => false, |
4772
|
|
|
], |
4773
|
|
|
], |
4774
|
|
|
$aliases |
4775
|
|
|
); |
4776
|
|
|
} |
4777
|
|
|
|
4778
|
|
|
/** |
4779
|
|
|
* Test to ensure that old versions are not affected by updates to newer |
4780
|
|
|
* drafts. |
4781
|
|
|
*/ |
4782
|
|
|
public function testUpdatingDraftDoesNotUpdateOldVersions() |
4783
|
|
|
{ |
4784
|
|
|
$contentVersion2 = $this->createContentVersion2(); |
4785
|
|
|
|
4786
|
|
|
$loadedContent1 = $this->contentService->loadContent($contentVersion2->id, null, 1); |
4787
|
|
|
$loadedContent2 = $this->contentService->loadContent($contentVersion2->id, null, 2); |
4788
|
|
|
|
4789
|
|
|
$this->assertNotEquals( |
4790
|
|
|
$loadedContent1->getFieldValue('name', self::ENG_US), |
4791
|
|
|
$loadedContent2->getFieldValue('name', self::ENG_US) |
4792
|
|
|
); |
4793
|
|
|
} |
4794
|
|
|
|
4795
|
|
|
/** |
4796
|
|
|
* Test scenario with writer and publisher users. |
4797
|
|
|
* Writer can only create content. Publisher can publish this content. |
4798
|
|
|
*/ |
4799
|
|
|
public function testPublishWorkflow() |
4800
|
|
|
{ |
4801
|
|
|
$this->createRoleWithPolicies('Publisher', [ |
4802
|
|
|
['module' => 'content', 'function' => 'read'], |
4803
|
|
|
['module' => 'content', 'function' => 'create'], |
4804
|
|
|
['module' => 'content', 'function' => 'publish'], |
4805
|
|
|
]); |
4806
|
|
|
|
4807
|
|
|
$this->createRoleWithPolicies('Writer', [ |
4808
|
|
|
['module' => 'content', 'function' => 'read'], |
4809
|
|
|
['module' => 'content', 'function' => 'create'], |
4810
|
|
|
]); |
4811
|
|
|
|
4812
|
|
|
$writerUser = $this->createCustomUserWithLogin( |
4813
|
|
|
'writer', |
4814
|
|
|
'[email protected]', |
4815
|
|
|
self::WRITERS_USER_GROUP_NAME, |
4816
|
|
|
'Writer' |
4817
|
|
|
); |
4818
|
|
|
|
4819
|
|
|
$publisherUser = $this->createCustomUserWithLogin( |
4820
|
|
|
'publisher', |
4821
|
|
|
'[email protected]', |
4822
|
|
|
'Publishers', |
4823
|
|
|
'Publisher' |
4824
|
|
|
); |
4825
|
|
|
|
4826
|
|
|
$this->permissionResolver->setCurrentUserReference($writerUser); |
4827
|
|
|
$draft = $this->createContentDraftVersion1(); |
4828
|
|
|
|
4829
|
|
|
$this->permissionResolver->setCurrentUserReference($publisherUser); |
4830
|
|
|
$content = $this->contentService->publishVersion($draft->versionInfo); |
4831
|
|
|
|
4832
|
|
|
$this->contentService->loadContent($content->id); |
4833
|
|
|
} |
4834
|
|
|
|
4835
|
|
|
/** |
4836
|
|
|
* Test publish / content policy is required to be able to publish content. |
4837
|
|
|
*/ |
4838
|
|
|
public function testPublishContentWithoutPublishPolicyThrowsException() |
4839
|
|
|
{ |
4840
|
|
|
$this->createRoleWithPolicies('Writer', [ |
4841
|
|
|
['module' => 'content', 'function' => 'read'], |
4842
|
|
|
['module' => 'content', 'function' => 'create'], |
4843
|
|
|
['module' => 'content', 'function' => 'edit'], |
4844
|
|
|
]); |
4845
|
|
|
$writerUser = $this->createCustomUserWithLogin( |
4846
|
|
|
'writer', |
4847
|
|
|
'[email protected]', |
4848
|
|
|
self::WRITERS_USER_GROUP_NAME, |
4849
|
|
|
'Writer' |
4850
|
|
|
); |
4851
|
|
|
$this->permissionResolver->setCurrentUserReference($writerUser); |
4852
|
|
|
|
4853
|
|
|
$this->expectException(CoreUnauthorizedException::class); |
4854
|
|
|
$this->expectExceptionMessageRegExp('/User does not have access to \'publish\' \'content\'/'); |
4855
|
|
|
|
4856
|
|
|
$this->createContentVersion1(); |
4857
|
|
|
} |
4858
|
|
|
|
4859
|
|
|
/** |
4860
|
|
|
* Test removal of the specific translation from all the Versions of a Content Object. |
4861
|
|
|
* |
4862
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation |
4863
|
|
|
*/ |
4864
|
|
|
public function testDeleteTranslation() |
4865
|
|
|
{ |
4866
|
|
|
$content = $this->createContentVersion2(); |
4867
|
|
|
|
4868
|
|
|
// create multiple versions to exceed archive limit |
4869
|
|
|
for ($i = 0; $i < 5; ++$i) { |
4870
|
|
|
$contentDraft = $this->contentService->createContentDraft($content->contentInfo); |
4871
|
|
|
$contentUpdateStruct = $this->contentService->newContentUpdateStruct(); |
4872
|
|
|
$contentDraft = $this->contentService->updateContent( |
4873
|
|
|
$contentDraft->versionInfo, |
4874
|
|
|
$contentUpdateStruct |
4875
|
|
|
); |
4876
|
|
|
$this->contentService->publishVersion($contentDraft->versionInfo); |
4877
|
|
|
} |
4878
|
|
|
|
4879
|
|
|
$this->contentService->deleteTranslation($content->contentInfo, self::ENG_GB); |
4880
|
|
|
|
4881
|
|
|
$this->assertTranslationDoesNotExist(self::ENG_GB, $content->id); |
4882
|
|
|
} |
4883
|
|
|
|
4884
|
|
|
/** |
4885
|
|
|
* Test deleting a Translation which is initial for some Version, updates initialLanguageCode |
4886
|
|
|
* with mainLanguageCode (assuming they are different). |
4887
|
|
|
*/ |
4888
|
|
|
public function testDeleteTranslationUpdatesInitialLanguageCodeVersion() |
4889
|
|
|
{ |
4890
|
|
|
$content = $this->createContentVersion2(); |
4891
|
|
|
// create another, copied, version |
4892
|
|
|
$contentDraft = $this->contentService->updateContent( |
4893
|
|
|
$this->contentService->createContentDraft($content->contentInfo)->versionInfo, |
4894
|
|
|
$this->contentService->newContentUpdateStruct() |
4895
|
|
|
); |
4896
|
|
|
$publishedContent = $this->contentService->publishVersion($contentDraft->versionInfo); |
4897
|
|
|
|
4898
|
|
|
// remove first version with only one translation as it is not the subject of this test |
4899
|
|
|
$this->contentService->deleteVersion( |
4900
|
|
|
$this->contentService->loadVersionInfo($publishedContent->contentInfo, 1) |
4901
|
|
|
); |
4902
|
|
|
|
4903
|
|
|
// sanity check |
4904
|
|
|
self::assertEquals(self::ENG_US, $content->contentInfo->mainLanguageCode); |
4905
|
|
|
self::assertEquals(self::ENG_US, $content->versionInfo->initialLanguageCode); |
4906
|
|
|
|
4907
|
|
|
// update mainLanguageCode so it is different than initialLanguageCode for Version |
4908
|
|
|
$contentMetadataUpdateStruct = $this->contentService->newContentMetadataUpdateStruct(); |
4909
|
|
|
$contentMetadataUpdateStruct->mainLanguageCode = self::ENG_GB; |
4910
|
|
|
$content = $this->contentService->updateContentMetadata($publishedContent->contentInfo, $contentMetadataUpdateStruct); |
4911
|
|
|
|
4912
|
|
|
$this->contentService->deleteTranslation($content->contentInfo, self::ENG_US); |
4913
|
|
|
|
4914
|
|
|
$this->assertTranslationDoesNotExist(self::ENG_US, $content->id); |
4915
|
|
|
} |
4916
|
|
|
|
4917
|
|
|
/** |
4918
|
|
|
* Test removal of the specific translation properly updates languages of the URL alias. |
4919
|
|
|
* |
4920
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation |
4921
|
|
|
*/ |
4922
|
|
|
public function testDeleteTranslationUpdatesUrlAlias() |
4923
|
|
|
{ |
4924
|
|
|
$urlAliasService = $this->getRepository()->getURLAliasService(); |
4925
|
|
|
|
4926
|
|
|
$content = $this->createContentVersion2(); |
4927
|
|
|
$mainLocation = $this->locationService->loadLocation($content->contentInfo->mainLocationId); |
4928
|
|
|
|
4929
|
|
|
// create custom URL alias for Content main Location |
4930
|
|
|
$urlAliasService->createUrlAlias($mainLocation, '/my-custom-url', self::ENG_GB); |
4931
|
|
|
|
4932
|
|
|
// create secondary Location for Content |
4933
|
|
|
$secondaryLocation = $this->locationService->createLocation( |
4934
|
|
|
$content->contentInfo, |
4935
|
|
|
$this->locationService->newLocationCreateStruct(2) |
4936
|
|
|
); |
4937
|
|
|
|
4938
|
|
|
// create custom URL alias for Content secondary Location |
4939
|
|
|
$urlAliasService->createUrlAlias($secondaryLocation, '/my-secondary-url', self::ENG_GB); |
4940
|
|
|
|
4941
|
|
|
// delete Translation |
4942
|
|
|
$this->contentService->deleteTranslation($content->contentInfo, self::ENG_GB); |
4943
|
|
|
|
4944
|
|
|
foreach ([$mainLocation, $secondaryLocation] as $location) { |
4945
|
|
|
// check auto-generated URL aliases |
4946
|
|
|
foreach ($urlAliasService->listLocationAliases($location, false) as $alias) { |
4947
|
|
|
self::assertNotContains(self::ENG_GB, $alias->languageCodes); |
4948
|
|
|
} |
4949
|
|
|
|
4950
|
|
|
// check custom URL aliases |
4951
|
|
|
foreach ($urlAliasService->listLocationAliases($location) as $alias) { |
4952
|
|
|
self::assertNotContains(self::ENG_GB, $alias->languageCodes); |
4953
|
|
|
} |
4954
|
|
|
} |
4955
|
|
|
} |
4956
|
|
|
|
4957
|
|
|
/** |
4958
|
|
|
* Test removal of a main translation throws BadStateException. |
4959
|
|
|
* |
4960
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation |
4961
|
|
|
*/ |
4962
|
|
|
public function testDeleteTranslationMainLanguageThrowsBadStateException() |
4963
|
|
|
{ |
4964
|
|
|
$content = $this->createContentVersion2(); |
4965
|
|
|
|
4966
|
|
|
// delete first version which has only one translation |
4967
|
|
|
$this->contentService->deleteVersion($this->contentService->loadVersionInfo($content->contentInfo, 1)); |
4968
|
|
|
|
4969
|
|
|
// try to delete main translation |
4970
|
|
|
$this->expectException(BadStateException::class); |
4971
|
|
|
$this->expectExceptionMessage('Specified translation is the main translation of the Content Object'); |
4972
|
|
|
|
4973
|
|
|
$this->contentService->deleteTranslation($content->contentInfo, $content->contentInfo->mainLanguageCode); |
4974
|
|
|
} |
4975
|
|
|
|
4976
|
|
|
/** |
4977
|
|
|
* Test removal of a Translation is possible when some archived Versions have only this Translation. |
4978
|
|
|
* |
4979
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation |
4980
|
|
|
*/ |
4981
|
|
|
public function testDeleteTranslationDeletesSingleTranslationVersions() |
4982
|
|
|
{ |
4983
|
|
|
// content created by the createContentVersion1 method has eng-US translation only. |
4984
|
|
|
$content = $this->createContentVersion1(); |
4985
|
|
|
|
4986
|
|
|
// create new version and add eng-GB translation |
4987
|
|
|
$contentDraft = $this->contentService->createContentDraft($content->contentInfo); |
4988
|
|
|
$contentUpdateStruct = $this->contentService->newContentUpdateStruct(); |
4989
|
|
|
$contentUpdateStruct->setField('name', 'Awesome Board', self::ENG_GB); |
4990
|
|
|
$contentDraft = $this->contentService->updateContent($contentDraft->versionInfo, $contentUpdateStruct); |
4991
|
|
|
$publishedContent = $this->contentService->publishVersion($contentDraft->versionInfo); |
4992
|
|
|
|
4993
|
|
|
// update mainLanguageCode to avoid exception related to that |
4994
|
|
|
$contentMetadataUpdateStruct = $this->contentService->newContentMetadataUpdateStruct(); |
4995
|
|
|
$contentMetadataUpdateStruct->mainLanguageCode = self::ENG_GB; |
4996
|
|
|
|
4997
|
|
|
$content = $this->contentService->updateContentMetadata($publishedContent->contentInfo, $contentMetadataUpdateStruct); |
4998
|
|
|
|
4999
|
|
|
$this->contentService->deleteTranslation($content->contentInfo, self::ENG_US); |
5000
|
|
|
|
5001
|
|
|
$this->assertTranslationDoesNotExist(self::ENG_US, $content->id); |
5002
|
|
|
} |
5003
|
|
|
|
5004
|
|
|
/** |
5005
|
|
|
* Test removal of the translation by the user who is not allowed to delete a content |
5006
|
|
|
* throws UnauthorizedException. |
5007
|
|
|
* |
5008
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation |
5009
|
|
|
*/ |
5010
|
|
|
public function testDeleteTranslationThrowsUnauthorizedException() |
5011
|
|
|
{ |
5012
|
|
|
$content = $this->createContentVersion2(); |
5013
|
|
|
|
5014
|
|
|
// create user that can read/create/edit but cannot delete content |
5015
|
|
|
$this->createRoleWithPolicies('Writer', [ |
5016
|
|
|
['module' => 'content', 'function' => 'read'], |
5017
|
|
|
['module' => 'content', 'function' => 'versionread'], |
5018
|
|
|
['module' => 'content', 'function' => 'create'], |
5019
|
|
|
['module' => 'content', 'function' => 'edit'], |
5020
|
|
|
]); |
5021
|
|
|
$writerUser = $this->createCustomUserWithLogin( |
5022
|
|
|
'writer', |
5023
|
|
|
'[email protected]', |
5024
|
|
|
self::WRITERS_USER_GROUP_NAME, |
5025
|
|
|
'Writer' |
5026
|
|
|
); |
5027
|
|
|
$this->permissionResolver->setCurrentUserReference($writerUser); |
5028
|
|
|
|
5029
|
|
|
$this->expectException(UnauthorizedException::class); |
5030
|
|
|
$this->expectExceptionMessage('User does not have access to \'remove\' \'content\''); |
5031
|
|
|
|
5032
|
|
|
$this->contentService->deleteTranslation($content->contentInfo, self::ENG_GB); |
5033
|
|
|
} |
5034
|
|
|
|
5035
|
|
|
/** |
5036
|
|
|
* Test removal of a non-existent translation throws InvalidArgumentException. |
5037
|
|
|
* |
5038
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation |
5039
|
|
|
*/ |
5040
|
|
|
public function testDeleteTranslationThrowsInvalidArgumentException() |
5041
|
|
|
{ |
5042
|
|
|
// content created by the createContentVersion1 method has eng-US translation only. |
5043
|
|
|
$content = $this->createContentVersion1(); |
5044
|
|
|
|
5045
|
|
|
$this->expectException(APIInvalidArgumentException::class); |
5046
|
|
|
$this->expectExceptionMessage('Argument \'$languageCode\' is invalid: ger-DE does not exist in the Content item'); |
5047
|
|
|
|
5048
|
|
|
$this->contentService->deleteTranslation($content->contentInfo, self::GER_DE); |
5049
|
|
|
} |
5050
|
|
|
|
5051
|
|
|
/** |
5052
|
|
|
* Test deleting a Translation from Draft. |
5053
|
|
|
* |
5054
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft |
5055
|
|
|
*/ |
5056
|
|
|
public function testDeleteTranslationFromDraft() |
5057
|
|
|
{ |
5058
|
|
|
$languageCode = self::ENG_GB; |
5059
|
|
|
$content = $this->createMultipleLanguageContentVersion2(); |
5060
|
|
|
$draft = $this->contentService->createContentDraft($content->contentInfo); |
5061
|
|
|
$draft = $this->contentService->deleteTranslationFromDraft($draft->versionInfo, $languageCode); |
5062
|
|
|
$content = $this->contentService->publishVersion($draft->versionInfo); |
5063
|
|
|
|
5064
|
|
|
$loadedContent = $this->contentService->loadContent($content->id); |
5065
|
|
|
self::assertNotContains($languageCode, $loadedContent->versionInfo->languageCodes); |
5066
|
|
|
self::assertEmpty($loadedContent->getFieldsByLanguage($languageCode)); |
5067
|
|
|
} |
5068
|
|
|
|
5069
|
|
|
/** |
5070
|
|
|
* Get values for multilingual field. |
5071
|
|
|
* |
5072
|
|
|
* @return array |
5073
|
|
|
*/ |
5074
|
|
|
public function providerForDeleteTranslationFromDraftRemovesUrlAliasOnPublishing() |
5075
|
|
|
{ |
5076
|
|
|
return [ |
5077
|
|
|
[ |
5078
|
|
|
[self::ENG_US => 'US Name', self::ENG_GB => 'GB Name'], |
5079
|
|
|
], |
5080
|
|
|
[ |
5081
|
|
|
[self::ENG_US => 'Same Name', self::ENG_GB => 'Same Name'], |
5082
|
|
|
], |
5083
|
|
|
]; |
5084
|
|
|
} |
5085
|
|
|
|
5086
|
|
|
/** |
5087
|
|
|
* Test deleting a Translation from Draft removes previously stored URL aliases for published Content. |
5088
|
|
|
* |
5089
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft |
5090
|
|
|
* |
5091
|
|
|
* @dataProvider providerForDeleteTranslationFromDraftRemovesUrlAliasOnPublishing |
5092
|
|
|
* |
5093
|
|
|
* @param string[] $fieldValues translated field values |
5094
|
|
|
* |
5095
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
5096
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
5097
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
5098
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
5099
|
|
|
*/ |
5100
|
|
|
public function testDeleteTranslationFromDraftRemovesUrlAliasOnPublishing(array $fieldValues) |
5101
|
|
|
{ |
5102
|
|
|
$urlAliasService = $this->getRepository()->getURLAliasService(); |
5103
|
|
|
|
5104
|
|
|
// set language code to be removed |
5105
|
|
|
$languageCode = self::ENG_GB; |
5106
|
|
|
$draft = $this->createMultilingualContentDraft( |
5107
|
|
|
'folder', |
5108
|
|
|
2, |
5109
|
|
|
self::ENG_US, |
5110
|
|
|
[ |
5111
|
|
|
'name' => [ |
5112
|
|
|
self::ENG_GB => $fieldValues[self::ENG_GB], |
5113
|
|
|
self::ENG_US => $fieldValues[self::ENG_US], |
5114
|
|
|
], |
5115
|
|
|
] |
5116
|
|
|
); |
5117
|
|
|
$content = $this->contentService->publishVersion($draft->versionInfo); |
5118
|
|
|
|
5119
|
|
|
// create secondary location |
5120
|
|
|
$this->locationService->createLocation( |
5121
|
|
|
$content->contentInfo, |
5122
|
|
|
$this->locationService->newLocationCreateStruct(5) |
5123
|
|
|
); |
5124
|
|
|
|
5125
|
|
|
// sanity check |
5126
|
|
|
$locations = $this->locationService->loadLocations($content->contentInfo); |
5127
|
|
|
self::assertCount(2, $locations, 'Sanity check: Expected to find 2 Locations'); |
5128
|
|
|
foreach ($locations as $location) { |
5129
|
|
|
$urlAliasService->createUrlAlias($location, '/us-custom_' . $location->id, self::ENG_US); |
5130
|
|
|
$urlAliasService->createUrlAlias($location, '/gb-custom_' . $location->id, self::ENG_GB); |
5131
|
|
|
|
5132
|
|
|
// check default URL aliases |
5133
|
|
|
$aliases = $urlAliasService->listLocationAliases($location, false, $languageCode); |
5134
|
|
|
self::assertNotEmpty($aliases, 'Sanity check: URL alias for the translation does not exist'); |
5135
|
|
|
|
5136
|
|
|
// check custom URL aliases |
5137
|
|
|
$aliases = $urlAliasService->listLocationAliases($location, true, $languageCode); |
5138
|
|
|
self::assertNotEmpty($aliases, 'Sanity check: Custom URL alias for the translation does not exist'); |
5139
|
|
|
} |
5140
|
|
|
|
5141
|
|
|
// delete translation and publish new version |
5142
|
|
|
$draft = $this->contentService->createContentDraft($content->contentInfo); |
5143
|
|
|
$draft = $this->contentService->deleteTranslationFromDraft($draft->versionInfo, $languageCode); |
5144
|
|
|
$this->contentService->publishVersion($draft->versionInfo); |
5145
|
|
|
|
5146
|
|
|
// check that aliases does not exist |
5147
|
|
|
foreach ($locations as $location) { |
5148
|
|
|
// check default URL aliases |
5149
|
|
|
$aliases = $urlAliasService->listLocationAliases($location, false, $languageCode); |
5150
|
|
|
self::assertEmpty($aliases, 'URL alias for the deleted translation still exists'); |
5151
|
|
|
|
5152
|
|
|
// check custom URL aliases |
5153
|
|
|
$aliases = $urlAliasService->listLocationAliases($location, true, $languageCode); |
5154
|
|
|
self::assertEmpty($aliases, 'Custom URL alias for the deleted translation still exists'); |
5155
|
|
|
} |
5156
|
|
|
} |
5157
|
|
|
|
5158
|
|
|
/** |
5159
|
|
|
* Test that URL aliases for deleted Translations are properly archived. |
5160
|
|
|
*/ |
5161
|
|
|
public function testDeleteTranslationFromDraftArchivesUrlAliasOnPublishing() |
5162
|
|
|
{ |
5163
|
|
|
$urlAliasService = $this->getRepository()->getURLAliasService(); |
5164
|
|
|
|
5165
|
|
|
$content = $this->contentService->publishVersion( |
5166
|
|
|
$this->createMultilingualContentDraft( |
5167
|
|
|
'folder', |
5168
|
|
|
2, |
5169
|
|
|
self::ENG_US, |
5170
|
|
|
[ |
5171
|
|
|
'name' => [ |
5172
|
|
|
self::ENG_GB => 'BritishEnglishContent', |
5173
|
|
|
self::ENG_US => 'AmericanEnglishContent', |
5174
|
|
|
], |
5175
|
|
|
] |
5176
|
|
|
)->versionInfo |
5177
|
|
|
); |
5178
|
|
|
|
5179
|
|
|
$unrelatedContent = $this->contentService->publishVersion( |
5180
|
|
|
$this->createMultilingualContentDraft( |
5181
|
|
|
'folder', |
5182
|
|
|
2, |
5183
|
|
|
self::ENG_US, |
5184
|
|
|
[ |
5185
|
|
|
'name' => [ |
5186
|
|
|
self::ENG_GB => 'AnotherBritishContent', |
5187
|
|
|
self::ENG_US => 'AnotherAmericanContent', |
5188
|
|
|
], |
5189
|
|
|
] |
5190
|
|
|
)->versionInfo |
5191
|
|
|
); |
5192
|
|
|
|
5193
|
|
|
$urlAlias = $urlAliasService->lookup('/BritishEnglishContent'); |
5194
|
|
|
self::assertFalse($urlAlias->isHistory); |
5195
|
|
|
self::assertEquals($urlAlias->path, '/BritishEnglishContent'); |
5196
|
|
|
self::assertEquals($urlAlias->destination, $content->contentInfo->mainLocationId); |
5197
|
|
|
|
5198
|
|
|
$draft = $this->contentService->deleteTranslationFromDraft( |
5199
|
|
|
$this->contentService->createContentDraft($content->contentInfo)->versionInfo, |
5200
|
|
|
self::ENG_GB |
5201
|
|
|
); |
5202
|
|
|
$content = $this->contentService->publishVersion($draft->versionInfo); |
5203
|
|
|
|
5204
|
|
|
$urlAlias = $urlAliasService->lookup('/BritishEnglishContent'); |
5205
|
|
|
self::assertTrue($urlAlias->isHistory); |
5206
|
|
|
self::assertEquals($urlAlias->path, '/BritishEnglishContent'); |
5207
|
|
|
self::assertEquals($urlAlias->destination, $content->contentInfo->mainLocationId); |
5208
|
|
|
|
5209
|
|
|
$unrelatedUrlAlias = $urlAliasService->lookup('/AnotherBritishContent'); |
5210
|
|
|
self::assertFalse($unrelatedUrlAlias->isHistory); |
5211
|
|
|
self::assertEquals($unrelatedUrlAlias->path, '/AnotherBritishContent'); |
5212
|
|
|
self::assertEquals($unrelatedUrlAlias->destination, $unrelatedContent->contentInfo->mainLocationId); |
5213
|
|
|
} |
5214
|
|
|
|
5215
|
|
|
/** |
5216
|
|
|
* Test deleting a Translation from Draft which has single Translation throws BadStateException. |
5217
|
|
|
* |
5218
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft |
5219
|
|
|
*/ |
5220
|
|
|
public function testDeleteTranslationFromDraftThrowsBadStateExceptionOnSingleTranslation() |
5221
|
|
|
{ |
5222
|
|
|
// create Content with single Translation |
5223
|
|
|
$publishedContent = $this->contentService->publishVersion( |
5224
|
|
|
$this->createContentDraft( |
5225
|
|
|
self::FORUM_IDENTIFIER, |
5226
|
|
|
2, |
5227
|
|
|
['name' => 'Eng-US Version name'] |
5228
|
|
|
)->versionInfo |
5229
|
|
|
); |
5230
|
|
|
|
5231
|
|
|
// update mainLanguageCode to avoid exception related to trying to delete main Translation |
5232
|
|
|
$contentMetadataUpdateStruct = $this->contentService->newContentMetadataUpdateStruct(); |
5233
|
|
|
$contentMetadataUpdateStruct->mainLanguageCode = self::ENG_GB; |
5234
|
|
|
$publishedContent = $this->contentService->updateContentMetadata( |
5235
|
|
|
$publishedContent->contentInfo, |
5236
|
|
|
$contentMetadataUpdateStruct |
5237
|
|
|
); |
5238
|
|
|
|
5239
|
|
|
// create single Translation Version from the first one |
5240
|
|
|
$draft = $this->contentService->createContentDraft( |
5241
|
|
|
$publishedContent->contentInfo, |
5242
|
|
|
$publishedContent->versionInfo |
5243
|
|
|
); |
5244
|
|
|
|
5245
|
|
|
$this->expectException(BadStateException::class); |
5246
|
|
|
$this->expectExceptionMessage('Specified Translation is the only one Content Object Version has'); |
5247
|
|
|
|
5248
|
|
|
// attempt to delete Translation |
5249
|
|
|
$this->contentService->deleteTranslationFromDraft($draft->versionInfo, self::ENG_US); |
5250
|
|
|
} |
5251
|
|
|
|
5252
|
|
|
/** |
5253
|
|
|
* Test deleting the Main Translation from Draft throws BadStateException. |
5254
|
|
|
* |
5255
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft |
5256
|
|
|
*/ |
5257
|
|
|
public function testDeleteTranslationFromDraftThrowsBadStateExceptionOnMainTranslation() |
5258
|
|
|
{ |
5259
|
|
|
$mainLanguageCode = self::ENG_US; |
5260
|
|
|
$draft = $this->createMultilingualContentDraft( |
5261
|
|
|
self::FORUM_IDENTIFIER, |
5262
|
|
|
2, |
5263
|
|
|
$mainLanguageCode, |
5264
|
|
|
[ |
5265
|
|
|
'name' => [ |
5266
|
|
|
self::ENG_US => 'An awesome eng-US forum', |
5267
|
|
|
self::ENG_GB => 'An awesome eng-GB forum', |
5268
|
|
|
], |
5269
|
|
|
] |
5270
|
|
|
); |
5271
|
|
|
|
5272
|
|
|
$this->expectException(BadStateException::class); |
5273
|
|
|
$this->expectExceptionMessage('Specified Translation is the main Translation of the Content Object'); |
5274
|
|
|
|
5275
|
|
|
$this->contentService->deleteTranslationFromDraft($draft->versionInfo, $mainLanguageCode); |
5276
|
|
|
} |
5277
|
|
|
|
5278
|
|
|
/** |
5279
|
|
|
* Test deleting the Translation from Published Version throws BadStateException. |
5280
|
|
|
* |
5281
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft |
5282
|
|
|
*/ |
5283
|
|
|
public function testDeleteTranslationFromDraftThrowsBadStateExceptionOnPublishedVersion() |
5284
|
|
|
{ |
5285
|
|
|
$languageCode = self::ENG_US; |
5286
|
|
|
$content = $this->createMultipleLanguageContentVersion2(); |
5287
|
|
|
$draft = $this->contentService->createContentDraft($content->contentInfo); |
5288
|
|
|
$publishedContent = $this->contentService->publishVersion($draft->versionInfo); |
5289
|
|
|
|
5290
|
|
|
$this->expectException(BadStateException::class); |
5291
|
|
|
$this->expectExceptionMessage('Version is not a draft'); |
5292
|
|
|
|
5293
|
|
|
$this->contentService->deleteTranslationFromDraft($publishedContent->versionInfo, $languageCode); |
5294
|
|
|
} |
5295
|
|
|
|
5296
|
|
|
/** |
5297
|
|
|
* Test deleting a Translation from Draft throws UnauthorizedException if user cannot edit Content. |
5298
|
|
|
* |
5299
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft |
5300
|
|
|
*/ |
5301
|
|
|
public function testDeleteTranslationFromDraftThrowsUnauthorizedException() |
5302
|
|
|
{ |
5303
|
|
|
$languageCode = self::ENG_GB; |
5304
|
|
|
$content = $this->createMultipleLanguageContentVersion2(); |
5305
|
|
|
$draft = $this->contentService->createContentDraft($content->contentInfo); |
5306
|
|
|
|
5307
|
|
|
// create user that can read/create/delete but cannot edit or content |
5308
|
|
|
$this->createRoleWithPolicies('Writer', [ |
5309
|
|
|
['module' => 'content', 'function' => 'read'], |
5310
|
|
|
['module' => 'content', 'function' => 'versionread'], |
5311
|
|
|
['module' => 'content', 'function' => 'create'], |
5312
|
|
|
['module' => 'content', 'function' => 'delete'], |
5313
|
|
|
]); |
5314
|
|
|
$writerUser = $this->createCustomUserWithLogin( |
5315
|
|
|
'user', |
5316
|
|
|
'[email protected]', |
5317
|
|
|
self::WRITERS_USER_GROUP_NAME, |
5318
|
|
|
'Writer' |
5319
|
|
|
); |
5320
|
|
|
$this->permissionResolver->setCurrentUserReference($writerUser); |
5321
|
|
|
|
5322
|
|
|
$this->expectException(UnauthorizedException::class); |
5323
|
|
|
$this->expectExceptionMessage('User does not have access to \'edit\' \'content\''); |
5324
|
|
|
|
5325
|
|
|
$this->contentService->deleteTranslationFromDraft($draft->versionInfo, $languageCode); |
5326
|
|
|
} |
5327
|
|
|
|
5328
|
|
|
/** |
5329
|
|
|
* Test deleting a non-existent Translation from Draft throws InvalidArgumentException. |
5330
|
|
|
* |
5331
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft |
5332
|
|
|
*/ |
5333
|
|
|
public function testDeleteTranslationFromDraftThrowsInvalidArgumentException() |
5334
|
|
|
{ |
5335
|
|
|
$languageCode = self::GER_DE; |
5336
|
|
|
$content = $this->createMultipleLanguageContentVersion2(); |
5337
|
|
|
$draft = $this->contentService->createContentDraft($content->contentInfo); |
5338
|
|
|
$this->expectException(APIInvalidArgumentException::class); |
5339
|
|
|
$this->expectExceptionMessageRegExp('/The Version \(ContentId=\d+, VersionNo=\d+\) is not translated into ger-DE/'); |
5340
|
|
|
$this->contentService->deleteTranslationFromDraft($draft->versionInfo, $languageCode); |
5341
|
|
|
} |
5342
|
|
|
|
5343
|
|
|
/** |
5344
|
|
|
* Test loading list of Content items. |
5345
|
|
|
*/ |
5346
|
|
|
public function testLoadContentListByContentInfo() |
5347
|
|
|
{ |
5348
|
|
|
$allLocationsCount = $this->locationService->getAllLocationsCount(); |
5349
|
|
|
$contentInfoList = array_map( |
5350
|
|
|
function (Location $location) { |
5351
|
|
|
return $location->contentInfo; |
5352
|
|
|
}, |
5353
|
|
|
$this->locationService->loadAllLocations(0, $allLocationsCount) |
5354
|
|
|
); |
5355
|
|
|
|
5356
|
|
|
$contentList = $this->contentService->loadContentListByContentInfo($contentInfoList); |
5357
|
|
|
self::assertCount(count($contentInfoList), $contentList); |
5358
|
|
|
foreach ($contentList as $content) { |
5359
|
|
|
try { |
5360
|
|
|
$loadedContent = $this->contentService->loadContent($content->id); |
5361
|
|
|
self::assertEquals($loadedContent, $content, "Failed to properly bulk-load Content {$content->id}"); |
5362
|
|
|
} catch (NotFoundException $e) { |
5363
|
|
|
self::fail("Failed to load Content {$content->id}: {$e->getMessage()}"); |
5364
|
|
|
} catch (UnauthorizedException $e) { |
5365
|
|
|
self::fail("Failed to load Content {$content->id}: {$e->getMessage()}"); |
5366
|
|
|
} |
5367
|
|
|
} |
5368
|
|
|
} |
5369
|
|
|
|
5370
|
|
|
/** |
5371
|
|
|
* Test loading content versions after removing exactly two drafts. |
5372
|
|
|
* |
5373
|
|
|
* @see https://jira.ez.no/browse/EZP-30271 |
5374
|
|
|
* |
5375
|
|
|
* @covers \eZ\Publish\Core\Repository\ContentService::deleteVersion |
5376
|
|
|
*/ |
5377
|
|
|
public function testLoadVersionsAfterDeletingTwoDrafts() |
5378
|
|
|
{ |
5379
|
|
|
$content = $this->createFolder([self::ENG_GB => 'Foo'], 2); |
5380
|
|
|
|
5381
|
|
|
// First update and publish |
5382
|
|
|
$modifiedContent = $this->updateFolder($content, [self::ENG_GB => 'Foo1']); |
5383
|
|
|
$content = $this->contentService->publishVersion($modifiedContent->versionInfo); |
5384
|
|
|
|
5385
|
|
|
// Second update and publish |
5386
|
|
|
$modifiedContent = $this->updateFolder($content, [self::ENG_GB => 'Foo2']); |
5387
|
|
|
$content = $this->contentService->publishVersion($modifiedContent->versionInfo); |
5388
|
|
|
|
5389
|
|
|
// Create drafts |
5390
|
|
|
$this->updateFolder($content, [self::ENG_GB => 'Foo3']); |
5391
|
|
|
$this->updateFolder($content, [self::ENG_GB => 'Foo4']); |
5392
|
|
|
|
5393
|
|
|
$versions = $this->contentService->loadVersions($content->contentInfo); |
5394
|
|
|
|
5395
|
|
|
foreach ($versions as $key => $version) { |
5396
|
|
|
if ($version->isDraft()) { |
5397
|
|
|
$this->contentService->deleteVersion($version); |
5398
|
|
|
unset($versions[$key]); |
5399
|
|
|
} |
5400
|
|
|
} |
5401
|
|
|
|
5402
|
|
|
$this->assertEquals($versions, $this->contentService->loadVersions($content->contentInfo)); |
5403
|
|
|
} |
5404
|
|
|
|
5405
|
|
|
/** |
5406
|
|
|
* Tests loading list of content versions of status draft. |
5407
|
|
|
*/ |
5408
|
|
|
public function testLoadVersionsOfStatusDraft() |
5409
|
|
|
{ |
5410
|
|
|
$content = $this->createContentVersion1(); |
5411
|
|
|
|
5412
|
|
|
$this->contentService->createContentDraft($content->contentInfo); |
5413
|
|
|
$this->contentService->createContentDraft($content->contentInfo); |
5414
|
|
|
$this->contentService->createContentDraft($content->contentInfo); |
5415
|
|
|
|
5416
|
|
|
$versions = $this->contentService->loadVersions($content->contentInfo, VersionInfo::STATUS_DRAFT); |
5417
|
|
|
|
5418
|
|
|
$this->assertSame(\count($versions), 3); |
5419
|
|
|
} |
5420
|
|
|
|
5421
|
|
|
/** |
5422
|
|
|
* Tests loading list of content versions of status archived. |
5423
|
|
|
*/ |
5424
|
|
|
public function testLoadVersionsOfStatusArchived() |
5425
|
|
|
{ |
5426
|
|
|
$content = $this->createContentVersion1(); |
5427
|
|
|
|
5428
|
|
|
$draft1 = $this->contentService->createContentDraft($content->contentInfo); |
5429
|
|
|
$this->contentService->publishVersion($draft1->versionInfo); |
5430
|
|
|
|
5431
|
|
|
$draft2 = $this->contentService->createContentDraft($content->contentInfo); |
5432
|
|
|
$this->contentService->publishVersion($draft2->versionInfo); |
5433
|
|
|
|
5434
|
|
|
$versions = $this->contentService->loadVersions($content->contentInfo, VersionInfo::STATUS_ARCHIVED); |
5435
|
|
|
|
5436
|
|
|
$this->assertSame(\count($versions), 2); |
5437
|
|
|
} |
5438
|
|
|
|
5439
|
|
|
/** |
5440
|
|
|
* Asserts that all aliases defined in $expectedAliasProperties with the |
5441
|
|
|
* given properties are available in $actualAliases and not more. |
5442
|
|
|
* |
5443
|
|
|
* @param array $expectedAliasProperties |
5444
|
|
|
* @param array $actualAliases |
5445
|
|
|
*/ |
5446
|
|
|
private function assertAliasesCorrect(array $expectedAliasProperties, array $actualAliases) |
5447
|
|
|
{ |
5448
|
|
|
foreach ($actualAliases as $actualAlias) { |
5449
|
|
|
if (!isset($expectedAliasProperties[$actualAlias->path])) { |
5450
|
|
|
$this->fail( |
5451
|
|
|
sprintf( |
5452
|
|
|
'Alias with path "%s" in languages "%s" not expected.', |
5453
|
|
|
$actualAlias->path, |
5454
|
|
|
implode(', ', $actualAlias->languageCodes) |
5455
|
|
|
) |
5456
|
|
|
); |
5457
|
|
|
} |
5458
|
|
|
|
5459
|
|
|
foreach ($expectedAliasProperties[$actualAlias->path] as $propertyName => $propertyValue) { |
5460
|
|
|
$this->assertEquals( |
5461
|
|
|
$propertyValue, |
5462
|
|
|
$actualAlias->$propertyName, |
5463
|
|
|
sprintf( |
5464
|
|
|
'Property $%s incorrect on alias with path "%s" in languages "%s".', |
5465
|
|
|
$propertyName, |
5466
|
|
|
$actualAlias->path, |
5467
|
|
|
implode(', ', $actualAlias->languageCodes) |
5468
|
|
|
) |
5469
|
|
|
); |
5470
|
|
|
} |
5471
|
|
|
|
5472
|
|
|
unset($expectedAliasProperties[$actualAlias->path]); |
5473
|
|
|
} |
5474
|
|
|
|
5475
|
|
|
if (!empty($expectedAliasProperties)) { |
5476
|
|
|
$this->fail( |
5477
|
|
|
sprintf( |
5478
|
|
|
'Missing expected aliases with paths "%s".', |
5479
|
|
|
implode('", "', array_keys($expectedAliasProperties)) |
5480
|
|
|
) |
5481
|
|
|
); |
5482
|
|
|
} |
5483
|
|
|
} |
5484
|
|
|
|
5485
|
|
|
/** |
5486
|
|
|
* Asserts that the given fields are equal to the default fields fixture. |
5487
|
|
|
* |
5488
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Field[] $fields |
5489
|
|
|
*/ |
5490
|
|
|
private function assertAllFieldsEquals(array $fields) |
5491
|
|
|
{ |
5492
|
|
|
$actual = $this->normalizeFields($fields); |
5493
|
|
|
$expected = $this->normalizeFields($this->createFieldsFixture()); |
5494
|
|
|
|
5495
|
|
|
$this->assertEquals($expected, $actual); |
5496
|
|
|
} |
5497
|
|
|
|
5498
|
|
|
/** |
5499
|
|
|
* Asserts that the given fields are equal to a language filtered set of the |
5500
|
|
|
* default fields fixture. |
5501
|
|
|
* |
5502
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Field[] $fields |
5503
|
|
|
* @param string $languageCode |
5504
|
|
|
*/ |
5505
|
|
|
private function assertLocaleFieldsEquals(array $fields, $languageCode) |
5506
|
|
|
{ |
5507
|
|
|
$actual = $this->normalizeFields($fields); |
5508
|
|
|
|
5509
|
|
|
$expected = []; |
5510
|
|
|
foreach ($this->normalizeFields($this->createFieldsFixture()) as $field) { |
5511
|
|
|
if ($field->languageCode !== $languageCode) { |
5512
|
|
|
continue; |
5513
|
|
|
} |
5514
|
|
|
$expected[] = $field; |
5515
|
|
|
} |
5516
|
|
|
|
5517
|
|
|
$this->assertEquals($expected, $actual); |
5518
|
|
|
} |
5519
|
|
|
|
5520
|
|
|
/** |
5521
|
|
|
* This method normalizes a set of fields and returns a normalized set. |
5522
|
|
|
* |
5523
|
|
|
* Normalization means it resets the storage specific field id to zero and |
5524
|
|
|
* it sorts the field by their identifier and their language code. In |
5525
|
|
|
* addition, the field value is removed, since this one depends on the |
5526
|
|
|
* specific FieldType, which is tested in a dedicated integration test. |
5527
|
|
|
* |
5528
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Field[] $fields |
5529
|
|
|
* |
5530
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Field[] |
5531
|
|
|
*/ |
5532
|
|
|
private function normalizeFields(array $fields) |
5533
|
|
|
{ |
5534
|
|
|
$normalized = []; |
5535
|
|
|
foreach ($fields as $field) { |
5536
|
|
|
$normalized[] = new Field( |
5537
|
|
|
[ |
5538
|
|
|
'id' => 0, |
5539
|
|
|
'value' => $field->value !== null, |
5540
|
|
|
'languageCode' => $field->languageCode, |
5541
|
|
|
'fieldDefIdentifier' => $field->fieldDefIdentifier, |
5542
|
|
|
'fieldTypeIdentifier' => $field->fieldTypeIdentifier, |
5543
|
|
|
] |
5544
|
|
|
); |
5545
|
|
|
} |
5546
|
|
|
usort( |
5547
|
|
|
$normalized, |
5548
|
|
|
function ($field1, $field2) { |
5549
|
|
|
if (0 === ($return = strcasecmp($field1->fieldDefIdentifier, $field2->fieldDefIdentifier))) { |
5550
|
|
|
return strcasecmp($field1->languageCode, $field2->languageCode); |
5551
|
|
|
} |
5552
|
|
|
|
5553
|
|
|
return $return; |
5554
|
|
|
} |
5555
|
|
|
); |
5556
|
|
|
|
5557
|
|
|
return $normalized; |
5558
|
|
|
} |
5559
|
|
|
|
5560
|
|
|
/** |
5561
|
|
|
* Asserts that given Content has default ContentStates. |
5562
|
|
|
* |
5563
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
5564
|
|
|
*/ |
5565
|
|
|
private function assertDefaultContentStates(ContentInfo $contentInfo) |
5566
|
|
|
{ |
5567
|
|
|
$objectStateService = $this->getRepository()->getObjectStateService(); |
5568
|
|
|
|
5569
|
|
|
$objectStateGroups = $objectStateService->loadObjectStateGroups(); |
5570
|
|
|
|
5571
|
|
|
foreach ($objectStateGroups as $objectStateGroup) { |
5572
|
|
|
$contentState = $objectStateService->getContentState($contentInfo, $objectStateGroup); |
5573
|
|
|
foreach ($objectStateService->loadObjectStates($objectStateGroup) as $objectState) { |
5574
|
|
|
// Only check the first object state which is the default one. |
5575
|
|
|
$this->assertEquals( |
5576
|
|
|
$objectState, |
5577
|
|
|
$contentState |
5578
|
|
|
); |
5579
|
|
|
break; |
5580
|
|
|
} |
5581
|
|
|
} |
5582
|
|
|
} |
5583
|
|
|
|
5584
|
|
|
/** |
5585
|
|
|
* Assert that given Content has no references to a translation specified by the $languageCode. |
5586
|
|
|
* |
5587
|
|
|
* @param string $languageCode |
5588
|
|
|
* @param int $contentId |
5589
|
|
|
*/ |
5590
|
|
|
private function assertTranslationDoesNotExist($languageCode, $contentId) |
5591
|
|
|
{ |
5592
|
|
|
$content = $this->contentService->loadContent($contentId); |
5593
|
|
|
|
5594
|
|
|
foreach ($content->fields as $field) { |
5595
|
|
|
/** @var array $field */ |
5596
|
|
|
self::assertArrayNotHasKey($languageCode, $field); |
5597
|
|
|
self::assertNotEquals($languageCode, $content->contentInfo->mainLanguageCode); |
5598
|
|
|
self::assertArrayNotHasKey($languageCode, $content->versionInfo->getNames()); |
5599
|
|
|
self::assertNotEquals($languageCode, $content->versionInfo->initialLanguageCode); |
5600
|
|
|
self::assertNotContains($languageCode, $content->versionInfo->languageCodes); |
5601
|
|
|
} |
5602
|
|
|
foreach ($this->contentService->loadVersions($content->contentInfo) as $versionInfo) { |
5603
|
|
|
self::assertArrayNotHasKey($languageCode, $versionInfo->getNames()); |
5604
|
|
|
self::assertNotEquals($languageCode, $versionInfo->contentInfo->mainLanguageCode); |
5605
|
|
|
self::assertNotEquals($languageCode, $versionInfo->initialLanguageCode); |
5606
|
|
|
self::assertNotContains($languageCode, $versionInfo->languageCodes); |
5607
|
|
|
} |
5608
|
|
|
} |
5609
|
|
|
|
5610
|
|
|
/** |
5611
|
|
|
* Returns the default fixture of fields used in most tests. |
5612
|
|
|
* |
5613
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Field[] |
5614
|
|
|
*/ |
5615
|
|
|
private function createFieldsFixture() |
5616
|
|
|
{ |
5617
|
|
|
return [ |
5618
|
|
|
new Field( |
5619
|
|
|
[ |
5620
|
|
|
'id' => 0, |
5621
|
|
|
'value' => 'Foo', |
5622
|
|
|
'languageCode' => self::ENG_US, |
5623
|
|
|
'fieldDefIdentifier' => 'description', |
5624
|
|
|
'fieldTypeIdentifier' => 'ezrichtext', |
5625
|
|
|
] |
5626
|
|
|
), |
5627
|
|
|
new Field( |
5628
|
|
|
[ |
5629
|
|
|
'id' => 0, |
5630
|
|
|
'value' => 'Bar', |
5631
|
|
|
'languageCode' => self::ENG_GB, |
5632
|
|
|
'fieldDefIdentifier' => 'description', |
5633
|
|
|
'fieldTypeIdentifier' => 'ezrichtext', |
5634
|
|
|
] |
5635
|
|
|
), |
5636
|
|
|
new Field( |
5637
|
|
|
[ |
5638
|
|
|
'id' => 0, |
5639
|
|
|
'value' => 'An awesome multi-lang forum²', |
5640
|
|
|
'languageCode' => self::ENG_US, |
5641
|
|
|
'fieldDefIdentifier' => 'name', |
5642
|
|
|
'fieldTypeIdentifier' => 'ezstring', |
5643
|
|
|
] |
5644
|
|
|
), |
5645
|
|
|
new Field( |
5646
|
|
|
[ |
5647
|
|
|
'id' => 0, |
5648
|
|
|
'value' => 'An awesome multi-lang forum²³', |
5649
|
|
|
'languageCode' => self::ENG_GB, |
5650
|
|
|
'fieldDefIdentifier' => 'name', |
5651
|
|
|
'fieldTypeIdentifier' => 'ezstring', |
5652
|
|
|
] |
5653
|
|
|
), |
5654
|
|
|
]; |
5655
|
|
|
} |
5656
|
|
|
|
5657
|
|
|
/** |
5658
|
|
|
* Gets expected property values for the "Media" ContentInfo ValueObject. |
5659
|
|
|
* |
5660
|
|
|
* @return array |
5661
|
|
|
*/ |
5662
|
|
|
private function getExpectedMediaContentInfoProperties() |
5663
|
|
|
{ |
5664
|
|
|
return [ |
5665
|
|
|
'id' => self::MEDIA_CONTENT_ID, |
5666
|
|
|
'contentTypeId' => 1, |
5667
|
|
|
'name' => 'Media', |
5668
|
|
|
'sectionId' => 3, |
5669
|
|
|
'currentVersionNo' => 1, |
5670
|
|
|
'published' => true, |
5671
|
|
|
'ownerId' => 14, |
5672
|
|
|
'modificationDate' => $this->createDateTime(1060695457), |
5673
|
|
|
'publishedDate' => $this->createDateTime(1060695457), |
5674
|
|
|
'alwaysAvailable' => 1, |
5675
|
|
|
'remoteId' => self::MEDIA_REMOTE_ID, |
5676
|
|
|
'mainLanguageCode' => self::ENG_US, |
5677
|
|
|
'mainLocationId' => 43, |
5678
|
|
|
'status' => ContentInfo::STATUS_PUBLISHED, |
5679
|
|
|
]; |
5680
|
|
|
} |
5681
|
|
|
|
5682
|
|
|
/** |
5683
|
|
|
* @covers \eZ\Publish\API\Repository\ContentService::hideContent |
5684
|
|
|
* |
5685
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
5686
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
5687
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
5688
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException |
5689
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
5690
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
5691
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
5692
|
|
|
*/ |
5693
|
|
|
public function testHideContent(): void |
5694
|
|
|
{ |
5695
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
5696
|
|
|
|
5697
|
|
|
$locationCreateStructs = array_map( |
5698
|
|
|
function (Location $parentLocation) { |
5699
|
|
|
return $this->locationService->newLocationCreateStruct($parentLocation->id); |
5700
|
|
|
}, |
5701
|
|
|
$this->createParentLocationsForHideReveal(2) |
5702
|
|
|
); |
5703
|
|
|
|
5704
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
5705
|
|
|
|
5706
|
|
|
$contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
5707
|
|
|
$contentCreate->setField('name', 'Folder to hide'); |
5708
|
|
|
|
5709
|
|
|
$content = $this->contentService->createContent( |
5710
|
|
|
$contentCreate, |
5711
|
|
|
$locationCreateStructs |
5712
|
|
|
); |
5713
|
|
|
|
5714
|
|
|
$publishedContent = $this->contentService->publishVersion($content->versionInfo); |
5715
|
|
|
$locations = $this->locationService->loadLocations($publishedContent->contentInfo); |
5716
|
|
|
|
5717
|
|
|
// Sanity check |
5718
|
|
|
$this->assertCount(3, $locations); |
5719
|
|
|
$this->assertCount(0, $this->filterHiddenLocations($locations)); |
5720
|
|
|
|
5721
|
|
|
$this->contentService->hideContent($publishedContent->contentInfo); |
5722
|
|
|
|
5723
|
|
|
$locations = $this->locationService->loadLocations($publishedContent->contentInfo); |
5724
|
|
|
$this->assertCount(3, $locations); |
5725
|
|
|
$this->assertCount(3, $this->filterHiddenLocations($locations)); |
5726
|
|
|
} |
5727
|
|
|
|
5728
|
|
|
/** |
5729
|
|
|
* @covers \eZ\Publish\API\Repository\ContentService::revealContent |
5730
|
|
|
* |
5731
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException |
5732
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
5733
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
5734
|
|
|
*/ |
5735
|
|
|
public function testRevealContent() |
5736
|
|
|
{ |
5737
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
5738
|
|
|
|
5739
|
|
|
$locationCreateStructs = array_map( |
5740
|
|
|
function (Location $parentLocation) { |
5741
|
|
|
return $this->locationService->newLocationCreateStruct($parentLocation->id); |
5742
|
|
|
}, |
5743
|
|
|
$this->createParentLocationsForHideReveal(2) |
5744
|
|
|
); |
5745
|
|
|
|
5746
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
5747
|
|
|
|
5748
|
|
|
$contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
5749
|
|
|
$contentCreate->setField('name', 'Folder to hide'); |
5750
|
|
|
|
5751
|
|
|
$locationCreateStructs[0]->hidden = true; |
5752
|
|
|
|
5753
|
|
|
$content = $this->contentService->createContent( |
5754
|
|
|
$contentCreate, |
5755
|
|
|
$locationCreateStructs |
5756
|
|
|
); |
5757
|
|
|
|
5758
|
|
|
$publishedContent = $this->contentService->publishVersion($content->versionInfo); |
5759
|
|
|
$locations = $this->locationService->loadLocations($publishedContent->contentInfo); |
5760
|
|
|
|
5761
|
|
|
// Sanity check |
5762
|
|
|
$hiddenLocations = $this->filterHiddenLocations($locations); |
5763
|
|
|
$this->assertCount(3, $locations); |
5764
|
|
|
$this->assertCount(1, $hiddenLocations); |
5765
|
|
|
|
5766
|
|
|
$this->contentService->hideContent($publishedContent->contentInfo); |
5767
|
|
|
$this->assertCount( |
5768
|
|
|
3, |
5769
|
|
|
$this->filterHiddenLocations( |
5770
|
|
|
$this->locationService->loadLocations($publishedContent->contentInfo) |
5771
|
|
|
) |
5772
|
|
|
); |
5773
|
|
|
|
5774
|
|
|
$this->contentService->revealContent($publishedContent->contentInfo); |
5775
|
|
|
|
5776
|
|
|
$locations = $this->locationService->loadLocations($publishedContent->contentInfo); |
5777
|
|
|
$hiddenLocationsAfterReveal = $this->filterHiddenLocations($locations); |
5778
|
|
|
$this->assertCount(3, $locations); |
5779
|
|
|
$this->assertCount(1, $hiddenLocationsAfterReveal); |
5780
|
|
|
$this->assertEquals($hiddenLocations, $hiddenLocationsAfterReveal); |
5781
|
|
|
} |
5782
|
|
|
|
5783
|
|
|
/** |
5784
|
|
|
* @depends testRevealContent |
5785
|
|
|
*/ |
5786
|
|
|
public function testRevealContentWithHiddenParent() |
5787
|
|
|
{ |
5788
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
5789
|
|
|
|
5790
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
5791
|
|
|
|
5792
|
|
|
$contentNames = [ |
5793
|
|
|
'Parent Content', |
5794
|
|
|
'Child (Nesting 1)', |
5795
|
|
|
'Child (Nesting 2)', |
5796
|
|
|
'Child (Nesting 3)', |
5797
|
|
|
'Child (Nesting 4)', |
5798
|
|
|
]; |
5799
|
|
|
|
5800
|
|
|
$parentLocation = $this->locationService->newLocationCreateStruct( |
5801
|
|
|
$this->generateId('location', 2) |
5802
|
|
|
); |
5803
|
|
|
|
5804
|
|
|
/** @var Content[] $contents */ |
5805
|
|
|
$contents = []; |
5806
|
|
|
|
5807
|
|
|
foreach ($contentNames as $contentName) { |
5808
|
|
|
$contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
5809
|
|
|
$contentCreate->setField('name', $contentName); |
5810
|
|
|
|
5811
|
|
|
$content = $this->contentService->createContent($contentCreate, [$parentLocation]); |
5812
|
|
|
$contents[] = $publishedContent = $this->contentService->publishVersion($content->versionInfo); |
5813
|
|
|
|
5814
|
|
|
$parentLocation = $this->locationService->newLocationCreateStruct( |
5815
|
|
|
$this->generateId('location', $publishedContent->contentInfo->mainLocationId) |
5816
|
|
|
); |
5817
|
|
|
} |
5818
|
|
|
|
5819
|
|
|
$this->contentService->hideContent($contents[0]->contentInfo); |
5820
|
|
|
$this->contentService->hideContent($contents[2]->contentInfo); |
5821
|
|
|
$this->contentService->revealContent($contents[2]->contentInfo); |
5822
|
|
|
|
5823
|
|
|
$parentContent = $this->contentService->loadContent($contents[0]->id); |
5824
|
|
|
$parentLocation = $this->locationService->loadLocation($parentContent->contentInfo->mainLocationId); |
5825
|
|
|
$parentSublocations = $this->locationService->loadLocationList([ |
5826
|
|
|
$contents[1]->contentInfo->mainLocationId, |
5827
|
|
|
$contents[2]->contentInfo->mainLocationId, |
5828
|
|
|
$contents[3]->contentInfo->mainLocationId, |
5829
|
|
|
$contents[4]->contentInfo->mainLocationId, |
5830
|
|
|
]); |
5831
|
|
|
|
5832
|
|
|
// Parent remains invisible |
5833
|
|
|
self::assertTrue($parentLocation->invisible); |
5834
|
|
|
|
5835
|
|
|
// All parent sublocations remain invisible as well |
5836
|
|
|
foreach ($parentSublocations as $parentSublocation) { |
5837
|
|
|
self::assertTrue($parentSublocation->invisible); |
5838
|
|
|
} |
5839
|
|
|
} |
5840
|
|
|
|
5841
|
|
|
/** |
5842
|
|
|
* @depends testRevealContent |
5843
|
|
|
*/ |
5844
|
|
|
public function testRevealContentWithHiddenChildren() |
5845
|
|
|
{ |
5846
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
5847
|
|
|
|
5848
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
5849
|
|
|
|
5850
|
|
|
$contentNames = [ |
5851
|
|
|
'Parent Content', |
5852
|
|
|
'Child (Nesting 1)', |
5853
|
|
|
'Child (Nesting 2)', |
5854
|
|
|
'Child (Nesting 3)', |
5855
|
|
|
'Child (Nesting 4)', |
5856
|
|
|
]; |
5857
|
|
|
|
5858
|
|
|
$parentLocation = $this->locationService->newLocationCreateStruct( |
5859
|
|
|
$this->generateId('location', 2) |
5860
|
|
|
); |
5861
|
|
|
|
5862
|
|
|
/** @var Content[] $contents */ |
5863
|
|
|
$contents = []; |
5864
|
|
|
|
5865
|
|
|
foreach ($contentNames as $contentName) { |
5866
|
|
|
$contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
5867
|
|
|
$contentCreate->setField('name', $contentName); |
5868
|
|
|
|
5869
|
|
|
$content = $this->contentService->createContent($contentCreate, [$parentLocation]); |
5870
|
|
|
$contents[] = $publishedContent = $this->contentService->publishVersion($content->versionInfo); |
5871
|
|
|
|
5872
|
|
|
$parentLocation = $this->locationService->newLocationCreateStruct( |
5873
|
|
|
$this->generateId('location', $publishedContent->contentInfo->mainLocationId) |
5874
|
|
|
); |
5875
|
|
|
} |
5876
|
|
|
|
5877
|
|
|
$this->contentService->hideContent($contents[0]->contentInfo); |
5878
|
|
|
$this->contentService->hideContent($contents[2]->contentInfo); |
5879
|
|
|
$this->contentService->revealContent($contents[0]->contentInfo); |
5880
|
|
|
|
5881
|
|
|
$directChildContent = $this->contentService->loadContent($contents[1]->id); |
5882
|
|
|
$directChildLocation = $this->locationService->loadLocation($directChildContent->contentInfo->mainLocationId); |
5883
|
|
|
|
5884
|
|
|
$childContent = $this->contentService->loadContent($contents[2]->id); |
5885
|
|
|
$childLocation = $this->locationService->loadLocation($childContent->contentInfo->mainLocationId); |
5886
|
|
|
$childSublocations = $this->locationService->loadLocationList([ |
5887
|
|
|
$contents[3]->contentInfo->mainLocationId, |
5888
|
|
|
$contents[4]->contentInfo->mainLocationId, |
5889
|
|
|
]); |
5890
|
|
|
|
5891
|
|
|
// Direct child content is not hidden |
5892
|
|
|
self::assertFalse($directChildContent->contentInfo->isHidden); |
5893
|
|
|
|
5894
|
|
|
// Direct child content location is still invisible |
5895
|
|
|
self::assertFalse($directChildLocation->invisible); |
5896
|
|
|
|
5897
|
|
|
// Child content is still hidden |
5898
|
|
|
self::assertTrue($childContent->contentInfo->isHidden); |
5899
|
|
|
|
5900
|
|
|
// Child content location is still invisible |
5901
|
|
|
self::assertTrue($childLocation->invisible); |
5902
|
|
|
|
5903
|
|
|
// All childs sublocations remain invisible as well |
5904
|
|
|
foreach ($childSublocations as $childSublocation) { |
5905
|
|
|
self::assertTrue($childSublocation->invisible); |
5906
|
|
|
} |
5907
|
|
|
} |
5908
|
|
|
|
5909
|
|
|
public function testHideContentWithParentLocation() |
5910
|
|
|
{ |
5911
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
5912
|
|
|
|
5913
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
5914
|
|
|
|
5915
|
|
|
$contentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
5916
|
|
|
$contentCreate->setField('name', 'Parent'); |
5917
|
|
|
|
5918
|
|
|
$content = $this->contentService->createContent( |
5919
|
|
|
$contentCreate, |
5920
|
|
|
[ |
5921
|
|
|
$this->locationService->newLocationCreateStruct( |
5922
|
|
|
$this->generateId('location', 2) |
5923
|
|
|
), |
5924
|
|
|
] |
5925
|
|
|
); |
5926
|
|
|
|
5927
|
|
|
$publishedContent = $this->contentService->publishVersion($content->versionInfo); |
5928
|
|
|
|
5929
|
|
|
$this->contentService->hideContent($publishedContent->contentInfo); |
5930
|
|
|
|
5931
|
|
|
$locations = $this->locationService->loadLocations($publishedContent->contentInfo); |
5932
|
|
|
|
5933
|
|
|
$childContentCreate = $this->contentService->newContentCreateStruct($contentType, self::ENG_US); |
5934
|
|
|
$childContentCreate->setField('name', 'Child'); |
5935
|
|
|
|
5936
|
|
|
$childContent = $this->contentService->createContent( |
5937
|
|
|
$childContentCreate, |
5938
|
|
|
[ |
5939
|
|
|
$this->locationService->newLocationCreateStruct( |
5940
|
|
|
$locations[0]->id |
5941
|
|
|
), |
5942
|
|
|
] |
5943
|
|
|
); |
5944
|
|
|
|
5945
|
|
|
$publishedChildContent = $this->contentService->publishVersion($childContent->versionInfo); |
5946
|
|
|
|
5947
|
|
|
$childLocations = $this->locationService->loadLocations($publishedChildContent->contentInfo); |
5948
|
|
|
|
5949
|
|
|
$this->assertTrue($locations[0]->hidden); |
5950
|
|
|
$this->assertTrue($locations[0]->invisible); |
5951
|
|
|
|
5952
|
|
|
$this->assertFalse($childLocations[0]->hidden); |
5953
|
|
|
$this->assertTrue($childLocations[0]->invisible); |
5954
|
|
|
} |
5955
|
|
|
|
5956
|
|
|
public function testChangeContentName() |
5957
|
|
|
{ |
5958
|
|
|
$contentDraft = $this->createContentDraft( |
5959
|
|
|
'folder', |
5960
|
|
|
$this->generateId('location', 2), |
5961
|
|
|
[ |
5962
|
|
|
'name' => 'Marco', |
5963
|
|
|
] |
5964
|
|
|
); |
5965
|
|
|
|
5966
|
|
|
$publishedContent = $this->contentService->publishVersion($contentDraft->versionInfo); |
5967
|
|
|
$contentMetadataUpdateStruct = new ContentMetadataUpdateStruct([ |
5968
|
|
|
'name' => 'Polo', |
5969
|
|
|
]); |
5970
|
|
|
$this->contentService->updateContentMetadata($publishedContent->contentInfo, $contentMetadataUpdateStruct); |
5971
|
|
|
|
5972
|
|
|
$updatedContent = $this->contentService->loadContent($publishedContent->id); |
5973
|
|
|
|
5974
|
|
|
$this->assertEquals('Marco', $publishedContent->contentInfo->name); |
5975
|
|
|
$this->assertEquals('Polo', $updatedContent->contentInfo->name); |
5976
|
|
|
} |
5977
|
|
|
|
5978
|
|
|
public function testCopyTranslationsFromPublishedToDraft() |
5979
|
|
|
{ |
5980
|
|
|
$contentDraft = $this->createContentDraft( |
5981
|
|
|
'folder', |
5982
|
|
|
$this->generateId('location', 2), |
5983
|
|
|
[ |
5984
|
|
|
'name' => 'Folder US', |
5985
|
|
|
] |
5986
|
|
|
); |
5987
|
|
|
|
5988
|
|
|
$publishedContent = $this->contentService->publishVersion($contentDraft->versionInfo); |
5989
|
|
|
|
5990
|
|
|
$deDraft = $this->contentService->createContentDraft($publishedContent->contentInfo); |
5991
|
|
|
|
5992
|
|
|
$contentUpdateStruct = new ContentUpdateStruct([ |
5993
|
|
|
'initialLanguageCode' => self::GER_DE, |
5994
|
|
|
'fields' => $contentDraft->getFields(), |
5995
|
|
|
]); |
5996
|
|
|
|
5997
|
|
|
$contentUpdateStruct->setField('name', 'Folder GER', self::GER_DE); |
5998
|
|
|
|
5999
|
|
|
$deContent = $this->contentService->updateContent($deDraft->versionInfo, $contentUpdateStruct); |
6000
|
|
|
|
6001
|
|
|
$updatedContent = $this->contentService->loadContent($deContent->id, null, $deContent->versionInfo->versionNo); |
6002
|
|
|
$this->assertEquals( |
6003
|
|
|
[ |
6004
|
|
|
self::ENG_US => 'Folder US', |
6005
|
|
|
self::GER_DE => 'Folder GER', |
6006
|
|
|
], |
6007
|
|
|
$updatedContent->fields['name'] |
6008
|
|
|
); |
6009
|
|
|
|
6010
|
|
|
$gbDraft = $this->contentService->createContentDraft($publishedContent->contentInfo); |
6011
|
|
|
|
6012
|
|
|
$contentUpdateStruct = new ContentUpdateStruct([ |
6013
|
|
|
'initialLanguageCode' => self::ENG_GB, |
6014
|
|
|
'fields' => $contentDraft->getFields(), |
6015
|
|
|
]); |
6016
|
|
|
|
6017
|
|
|
$contentUpdateStruct->setField('name', 'Folder GB', self::ENG_GB); |
6018
|
|
|
|
6019
|
|
|
$gbContent = $this->contentService->updateContent($gbDraft->versionInfo, $contentUpdateStruct); |
6020
|
|
|
$this->contentService->publishVersion($gbDraft->versionInfo); |
6021
|
|
|
$updatedContent = $this->contentService->loadContent($gbContent->id, null, $gbContent->versionInfo->versionNo); |
6022
|
|
|
$this->assertEquals( |
6023
|
|
|
[ |
6024
|
|
|
self::ENG_US => 'Folder US', |
6025
|
|
|
self::ENG_GB => 'Folder GB', |
6026
|
|
|
], |
6027
|
|
|
$updatedContent->fields['name'] |
6028
|
|
|
); |
6029
|
|
|
|
6030
|
|
|
$dePublished = $this->contentService->publishVersion($deDraft->versionInfo); |
6031
|
|
|
$this->assertEquals( |
6032
|
|
|
[ |
6033
|
|
|
self::ENG_US => 'Folder US', |
6034
|
|
|
self::GER_DE => 'Folder GER', |
6035
|
|
|
self::ENG_GB => 'Folder GB', |
6036
|
|
|
], |
6037
|
|
|
$dePublished->fields['name'] |
6038
|
|
|
); |
6039
|
|
|
} |
6040
|
|
|
|
6041
|
|
|
/** |
6042
|
|
|
* Create structure of parent folders with Locations to be used for Content hide/reveal tests. |
6043
|
|
|
* |
6044
|
|
|
* @param int $parentLocationId |
6045
|
|
|
* |
6046
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Location[] A list of Locations aimed to be parents |
6047
|
|
|
* |
6048
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException |
6049
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
6050
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
6051
|
|
|
*/ |
6052
|
|
|
private function createParentLocationsForHideReveal(int $parentLocationId): array |
6053
|
|
|
{ |
6054
|
|
|
$parentFoldersLocationsIds = [ |
6055
|
|
|
$this->createFolder([self::ENG_US => 'P1'], $parentLocationId)->contentInfo->mainLocationId, |
6056
|
|
|
$this->createFolder([self::ENG_US => 'P2'], $parentLocationId)->contentInfo->mainLocationId, |
6057
|
|
|
$this->createFolder([self::ENG_US => 'P3'], $parentLocationId)->contentInfo->mainLocationId, |
6058
|
|
|
]; |
6059
|
|
|
|
6060
|
|
|
return array_values($this->locationService->loadLocationList($parentFoldersLocationsIds)); |
6061
|
|
|
} |
6062
|
|
|
|
6063
|
|
|
/** |
6064
|
|
|
* Filter Locations list by hidden only. |
6065
|
|
|
* |
6066
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Location[] $locations |
6067
|
|
|
* |
6068
|
|
|
* @return array |
6069
|
|
|
*/ |
6070
|
|
|
private function filterHiddenLocations(array $locations): array |
6071
|
|
|
{ |
6072
|
|
|
return array_values( |
6073
|
|
|
array_filter( |
6074
|
|
|
$locations, |
6075
|
|
|
function (Location $location) { |
6076
|
|
|
return $location->hidden; |
6077
|
|
|
} |
6078
|
|
|
) |
6079
|
|
|
); |
6080
|
|
|
} |
6081
|
|
|
|
6082
|
|
|
public function testPublishVersionWithSelectedLanguages() |
6083
|
|
|
{ |
6084
|
|
|
$publishedContent = $this->createFolder( |
6085
|
|
|
[ |
6086
|
|
|
self::ENG_US => 'Published US', |
6087
|
|
|
self::GER_DE => 'Published DE', |
6088
|
|
|
], |
6089
|
|
|
$this->generateId('location', 2) |
6090
|
|
|
); |
6091
|
|
|
|
6092
|
|
|
$draft = $this->contentService->createContentDraft($publishedContent->contentInfo); |
6093
|
|
|
$contentUpdateStruct = new ContentUpdateStruct([ |
6094
|
|
|
'initialLanguageCode' => self::ENG_US, |
6095
|
|
|
]); |
6096
|
|
|
$contentUpdateStruct->setField('name', 'Draft 1 US', self::ENG_US); |
6097
|
|
|
$contentUpdateStruct->setField('name', 'Draft 1 DE', self::GER_DE); |
6098
|
|
|
|
6099
|
|
|
$this->contentService->updateContent($draft->versionInfo, $contentUpdateStruct); |
6100
|
|
|
|
6101
|
|
|
$this->contentService->publishVersion($draft->versionInfo, [self::GER_DE]); |
6102
|
|
|
$content = $this->contentService->loadContent($draft->contentInfo->id); |
6103
|
|
|
$this->assertEquals( |
6104
|
|
|
[ |
6105
|
|
|
self::ENG_US => 'Published US', |
6106
|
|
|
self::GER_DE => 'Draft 1 DE', |
6107
|
|
|
], |
6108
|
|
|
$content->fields['name'] |
6109
|
|
|
); |
6110
|
|
|
} |
6111
|
|
|
|
6112
|
|
|
public function testCreateContentWithRomanianSpecialCharsInTitle() |
6113
|
|
|
{ |
6114
|
|
|
$baseName = 'ȘșțȚdfdf'; |
6115
|
|
|
$expectedPath = '/SstTdfdf'; |
6116
|
|
|
|
6117
|
|
|
$this->createFolder([self::ENG_US => $baseName], 2); |
6118
|
|
|
|
6119
|
|
|
$urlAliasService = $this->getRepository()->getURLAliasService(); |
6120
|
|
|
$urlAlias = $urlAliasService->lookup($expectedPath); |
6121
|
|
|
$this->assertSame($expectedPath, $urlAlias->path); |
6122
|
|
|
} |
6123
|
|
|
|
6124
|
|
|
/** |
6125
|
|
|
* @param int $amountOfDrafts |
6126
|
|
|
* |
6127
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
6128
|
|
|
*/ |
6129
|
|
|
private function createContentDrafts(int $amountOfDrafts): void |
6130
|
|
|
{ |
6131
|
|
|
if (0 >= $amountOfDrafts) { |
6132
|
|
|
throw new InvalidArgumentException('$amountOfDrafts', 'Must be greater then 0'); |
6133
|
|
|
} |
6134
|
|
|
|
6135
|
|
|
$publishedContent = $this->createContentVersion1(); |
6136
|
|
|
|
6137
|
|
|
for ($i = 1; $i <= $amountOfDrafts; ++$i) { |
6138
|
|
|
$this->contentService->createContentDraft($publishedContent->contentInfo); |
6139
|
|
|
} |
6140
|
|
|
} |
6141
|
|
|
|
6142
|
|
|
/** |
6143
|
|
|
* @param array $limitationValues |
6144
|
|
|
* |
6145
|
|
|
* @return \eZ\Publish\API\Repository\Values\User\User |
6146
|
|
|
* |
6147
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException |
6148
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
6149
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
6150
|
|
|
*/ |
6151
|
|
|
private function createUserWithVersionReadLimitations(array $limitationValues = []): User |
6152
|
|
|
{ |
6153
|
|
|
$limitations = [ |
6154
|
|
|
new LocationLimitation(['limitationValues' => $limitationValues]), |
6155
|
|
|
]; |
6156
|
|
|
|
6157
|
|
|
return $this->createUserWithPolicies( |
6158
|
|
|
'user', |
6159
|
|
|
[ |
6160
|
|
|
['module' => 'content', 'function' => 'versionread', 'limitations' => $limitations], |
6161
|
|
|
['module' => 'content', 'function' => 'create'], |
6162
|
|
|
['module' => 'content', 'function' => 'read'], |
6163
|
|
|
['module' => 'content', 'function' => 'edit'], |
6164
|
|
|
] |
6165
|
|
|
); |
6166
|
|
|
} |
6167
|
|
|
} |
6168
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.