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