Completed
Push — 7.4 ( dac298...2c8d90 )
by Łukasz
43:03 queued 22:45
created

ContentServiceTest   F

Complexity

Total Complexity 238

Size/Duplication

Total Lines 6156
Duplicated Lines 23.21 %

Coupling/Cohesion

Components 1
Dependencies 33

Importance

Changes 0
Metric Value
dl 1429
loc 6156
rs 0.8
c 0
b 0
f 0
wmc 238
lcom 1
cbo 33

170 Methods

Rating   Name   Duplication   Size   Complexity  
A testNewContentCreateStruct() 0 17 1
A testCreateContent() 0 28 2
A testCreateContentAndPublishWithPrivilegedAnonymousUser() 0 50 2
A testCreateContentSetsContentInfo() 0 6 1
A testCreateContentSetsExpectedContentInfo() 0 30 1
A testCreateContentSetsVersionInfo() 0 6 1
A testCreateContentSetsExpectedVersionInfo() 0 20 1
A testCreateContentSetsExpectedContentType() 0 20 1
A testCreateContentThrowsInvalidArgumentException() 0 34 2
A testCreateContentThrowsInvalidArgumentExceptionOnFieldTypeNotAccept() 19 19 1
A testCreateContentThrowsContentFieldValidationException() 0 20 1
A testCreateContentRequiredFieldMissing() 18 18 1
A testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately() 0 16 1
A testCreateContentThrowsInvalidArgumentExceptionWithLocationCreateParameter() 0 54 1
A testLoadContentInfo() 19 19 1
A testLoadContentInfoSetsExpectedContentInfo() 0 7 1
A testLoadContentInfoThrowsNotFoundException() 12 12 1
A testLoadContentInfoByRemoteId() 0 15 1
A testLoadContentInfoByRemoteIdSetsExpectedContentInfo() 21 21 1
A testLoadContentInfoByRemoteIdThrowsNotFoundException() 0 11 1
A testLoadVersionInfoById() 21 21 1
A testLoadVersionInfoByIdSetsExpectedVersionInfo() 0 25 1
A testLoadVersionInfoByIdThrowsNotFoundException() 12 12 1
A testLoadContentByVersionInfo() 0 25 1
A testLoadContent() 19 19 1
A testLoadContentThrowsNotFoundException() 12 12 1
A contentRemoteIdVersionLanguageProvider() 0 13 1
A testLoadContentByRemoteId() 0 19 3
A testLoadContentByRemoteIdThrowsNotFoundException() 0 12 1
A testPublishVersion() 0 18 1
A testPublishVersionSetsExpectedContentInfo() 0 30 1
A testPublishVersionSetsExpectedVersionInfo() 0 28 1
A testPublishVersionSetsExpectedContentType() 0 20 1
A testPublishVersionCreatesLocationsDefinedOnCreate() 0 20 1
A testCreateContentWithLocationCreateParameterCreatesExpectedLocation() 0 26 1
A testPublishVersionThrowsBadStateException() 17 17 1
A testPublishVersionDoesNotChangePublishedDate() 0 26 1
A testCreateContentDraft() 0 20 1
A testCreateContentDraftAndLoadAccess() 21 21 1
A testCreateContentDraftSetsExpectedProperties() 0 13 1
A testCreateContentDraftSetsContentInfo() 0 25 1
A testCreateContentDraftSetsVersionInfo() 0 24 1
A testNewContentUpdateStruct() 0 23 1
A testUpdateContent() 0 19 1
A testUpdateContentWithDifferentUser() 0 19 1
A testUpdateContentSetsExpectedFields() 0 45 1
A testUpdateContentThrowsBadStateException() 0 24 1
A testUpdateContentThrowsInvalidArgumentExceptionWhenFieldTypeDoesNotAccept() 22 22 1
A testUpdateContentWhenMandatoryFieldIsEmpty() 24 24 1
A testUpdateContentThrowsContentFieldValidationException() 0 24 1
A testUpdateContentValidatorIgnoresRequiredFieldsOfNotUpdatedLanguages() 0 47 1
A testUpdateContentWithNotUpdatingMandatoryField() 0 38 5
A testCreateContentDraftWithThirdParameter() 20 20 1
A testPublishVersionFromContentDraft() 26 26 1
A testPublishVersionFromContentDraftArchivesOldVersion() 26 26 1
A testPublishVersionFromContentDraftUpdatesContentInfoCurrentVersion() 0 8 1
A testPublishVersionFromOldContentDraftArchivesNewerVersionNo() 25 25 1
B testPublishVersionNotCreatingUnlimitedArchives() 0 62 1
A testNewContentMetadataUpdateStruct() 0 24 2
A testUpdateContentMetadata() 0 32 1
A testUpdateContentMetadataSetsExpectedProperties() 0 29 1
A testUpdateContentMetadataNotUpdatesContentVersion() 0 4 1
A testUpdateContentMetadataThrowsInvalidArgumentExceptionOnDuplicateRemoteId() 0 24 1
A testUpdateContentMetadataThrowsInvalidArgumentExceptionOnNoMetadataPropertiesSet() 0 12 1
A testDeleteContent() 21 21 2
A testDeleteContentWithEmptyBinaryField() 21 21 2
A testLoadContentDraftsReturnsEmptyArrayByDefault() 0 12 1
A testLoadContentDrafts() 0 44 1
A testLoadContentDraftsWithFirstParameter() 0 48 1
A testLoadVersionInfoWithSecondParameter() 0 23 1
A testLoadVersionInfoThrowsNotFoundExceptionWithSecondParameter() 0 14 1
A testLoadVersionInfoByIdWithSecondParameter() 0 28 1
A testLoadVersionInfoByIdWithSecondParameterSetsExpectedVersionInfo() 0 41 1
A testLoadVersionInfoByIdThrowsNotFoundExceptionWithSecondParameter() 14 14 1
B testLoadContentByVersionInfoWithSecondParameter() 17 82 4
B testLoadContentByContentInfoWithLanguageParameters() 0 135 1
A testLoadContentByContentInfoWithVersionNumberParameter() 30 30 1
A testLoadContentByContentInfoThrowsNotFoundExceptionWithVersionNumberParameter() 14 14 1
A testLoadContentWithSecondParameter() 17 17 1
A testLoadContentWithSecondParameterThrowsNotFoundException() 0 8 1
A testLoadContentWithThirdParameter() 23 23 1
A testLoadContentThrowsNotFoundExceptionWithThirdParameter() 14 14 1
A testLoadContentByRemoteIdWithSecondParameter() 22 22 1
A testLoadContentByRemoteIdWithThirdParameter() 27 27 1
A testLoadContentByRemoteIdThrowsNotFoundExceptionWithThirdParameter() 0 18 1
A testLoadContentWithPrioritizedLanguagesList() 0 20 2
A getPrioritizedLanguageList() 0 9 1
A testDeleteVersion() 0 26 1
A testDeleteVersionThrowsBadStateExceptionOnPublishedVersion() 0 14 1
A testDeleteVersionWorksIfOnlyVersionIsDraft() 0 16 1
A testLoadVersions() 0 22 1
A testLoadVersionsSetsExpectedVersionInfo() 0 43 1
B testCopyContent() 59 59 1
A testCopyContentWithNewOwner() 0 45 1
B testCopyContentWithThirdParameter() 56 56 1
A testAddRelation() 0 28 1
A testAddRelationAddsRelationToContent() 0 7 1
A assertExpectedRelations() 0 17 1
A testAddRelationSetsExpectedRelations() 0 4 1
A testCreateContentDraftWithRelations() 22 22 1
A testCreateContentDraftWithRelationsCreatesRelations() 0 9 1
A testCreateContentDraftWithRelationsCreatesExpectedRelations() 0 4 1
A testAddRelationThrowsBadStateException() 22 22 1
B testLoadRelations() 0 67 1
B testLoadRelationsSkipsArchivedContent() 0 58 1
A testLoadRelationsSkipsDraftContent() 0 54 1
B testLoadReverseRelations() 0 86 1
B testLoadReverseRelationsSkipsArchivedContent() 0 76 1
B testLoadReverseRelationsSkipsDraftContent() 0 68 1
A testDeleteRelation() 0 30 1
A testDeleteRelationThrowsBadStateException() 34 34 1
A testDeleteRelationThrowsInvalidArgumentException() 23 23 1
A testCreateContentInTransactionWithRollback() 0 47 4
A testCreateContentInTransactionWithCommit() 0 42 3
A testCreateContentWithLocationCreateParameterInTransactionWithRollback() 0 33 3
A testCreateContentWithLocationCreateParameterInTransactionWithCommit() 29 29 2
A testCreateContentDraftInTransactionWithRollback() 0 42 3
A testCreateContentDraftInTransactionWithCommit() 40 40 2
A testPublishVersionInTransactionWithRollback() 44 44 3
A testPublishVersionInTransactionWithCommit() 40 40 2
A testUpdateContentInTransactionWithRollback() 47 47 2
A testUpdateContentInTransactionWithCommit() 47 47 2
A testUpdateContentMetadataInTransactionWithRollback() 45 45 2
A testUpdateContentMetadataInTransactionWithCommit() 45 45 2
A testDeleteVersionInTransactionWithRollback() 0 36 2
A testDeleteVersionInTransactionWithCommit() 0 36 2
A testDeleteContentInTransactionWithRollback() 0 36 2
A testDeleteContentInTransactionWithCommit() 0 40 3
A testCopyContentInTransactionWithRollback() 50 50 2
A testCopyContentInTransactionWithCommit() 50 50 2
A testURLAliasesCreatedForNewContent() 0 36 1
B testURLAliasesCreatedForUpdatedContent() 0 72 1
B testCustomURLAliasesNotHistorizedOnUpdatedContent() 0 59 1
A testUpdatingDraftDoesNotUpdateOldVersions() 0 16 1
A testPublishWorkflow() 0 38 1
A testPublishContentWithoutPublishPolicyThrowsException() 0 19 1
A testDeleteTranslation() 21 21 2
A testDeleteTranslationUpdatesInitialLanguageCodeVersion() 0 31 1
A testDeleteTranslationUpdatesUrlAlias() 0 37 4
A testDeleteTranslationMainLanguageThrowsBadStateException() 0 12 1
A testDeleteTranslationDeletesSingleTranslationVersions() 0 24 1
A testDeleteTranslationThrowsUnauthorizedException() 0 23 1
A testDeleteTranslationThrowsInvalidArgumentException() 0 8 1
A testDeleteTranslationFromDraft() 0 15 1
A providerForDeleteTranslationFromDraftRemovesUrlAliasOnPublishing() 0 11 1
B testDeleteTranslationFromDraftRemovesUrlAliasOnPublishing() 0 60 3
B testDeleteTranslationFromDraftArchivesUrlAliasOnPublishing() 0 55 1
A testDeleteTranslationFromDraftThrowsBadStateExceptionOnSingleTranslation() 0 31 1
A testDeleteTranslationFromDraftThrowsBadStateExceptionOnMainTranslation() 0 19 1
A testDeleteTranslationFromDraftThrowsBadStateExceptionOnPublishedVersion() 11 11 1
A testDeleteTranslationFromDraftThrowsUnauthorizedException() 0 26 1
A testDeleteTranslationFromDraftThrowsInvalidArgumentException() 0 10 1
A testLoadContentListByContentInfo() 0 27 4
A testLoadVersionInfo() 22 22 1
A testLoadContentByContentInfo() 22 22 1
A testCreateContentDraftLoadVersionInfoStillLoadsPublishedVersion() 18 18 1
A testCreateContentDraftLoadContentStillLoadsPublishedVersion() 18 18 1
A testCreateContentDraftLoadContentByRemoteIdStillLoadsPublishedVersion() 18 18 1
A testCreateContentDraftLoadContentByContentInfoStillLoadsPublishedVersion() 18 18 1
A testCreateContentDraftWithSecondParameter() 18 18 1
A assertAliasesCorrect() 0 38 5
A assertAllFieldsEquals() 0 7 1
A assertLocaleFieldsEquals() 0 14 3
A normalizeFields() 18 27 4
A createLocaleFieldsFixture() 0 11 4
A assertDefaultContentStates() 19 19 3
A assertTranslationDoesNotExist() 0 22 3
A createFieldsFixture() 0 41 1
A getExpectedMediaContentInfoProperties() 19 19 1
A testLoadVersionsAfterDeletingTwoDrafts() 0 30 3

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ContentServiceTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ContentServiceTest, and based on these observations, apply Extract Interface, too.

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\Exceptions\UnauthorizedException;
13
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
14
use eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct;
15
use eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct;
16
use eZ\Publish\API\Repository\Values\Content\Field;
17
use eZ\Publish\API\Repository\Values\Content\Location;
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 DOMDocument;
26
use Exception;
27
28
/**
29
 * Test case for operations in the ContentService using in memory storage.
30
 *
31
 * @see \eZ\Publish\API\Repository\ContentService
32
 * @group content
33
 */
34
class ContentServiceTest extends BaseContentServiceTest
35
{
36
    /**
37
     * Test for the newContentCreateStruct() method.
38
     *
39
     * @see \eZ\Publish\API\Repository\ContentService::newContentCreateStruct()
40
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeByIdentifier
41
     * @group user
42
     * @group field-type
43
     */
44
    public function testNewContentCreateStruct()
45
    {
46
        $repository = $this->getRepository();
47
48
        /* BEGIN: Use Case */
49
        // Create a content type
50
        $contentTypeService = $repository->getContentTypeService();
51
52
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
53
54
        $contentService = $repository->getContentService();
55
56
        $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US');
57
        /* END: Use Case */
58
59
        $this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\ContentCreateStruct', $contentCreate);
60
    }
61
62
    /**
63
     * Test for the createContent() method.
64
     *
65
     * @return \eZ\Publish\API\Repository\Values\Content\Content
66
     *
67
     * @see \eZ\Publish\API\Repository\ContentService::createContent()
68
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentCreateStruct
69
     * @group user
70
     * @group field-type
71
     */
72
    public function testCreateContent()
73
    {
74
        if ($this->isVersion4()) {
75
            $this->markTestSkipped('This test requires eZ Publish 5');
76
        }
77
78
        $repository = $this->getRepository();
79
80
        /* BEGIN: Use Case */
81
        $contentTypeService = $repository->getContentTypeService();
82
83
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
84
85
        $contentService = $repository->getContentService();
86
87
        $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US');
88
        $contentCreate->setField('name', 'My awesome forum');
89
90
        $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789';
91
        $contentCreate->alwaysAvailable = true;
92
93
        $content = $contentService->createContent($contentCreate);
94
        /* END: Use Case */
95
96
        $this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content', $content);
97
98
        return $content;
99
    }
100
101
    /**
102
     * Test for the createContent() method.
103
     *
104
     * Tests made for issue #EZP-20955 where Anonymous user is granted access to create content
105
     * and should have access to do that.
106
     *
107
     * @return \eZ\Publish\API\Repository\Values\Content\Content
108
     *
109
     * @see \eZ\Publish\API\Repository\ContentService::createContent()
110
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentCreateStruct
111
     * @group user
112
     * @group field-type
113
     */
114
    public function testCreateContentAndPublishWithPrivilegedAnonymousUser()
115
    {
116
        if ($this->isVersion4()) {
117
            $this->markTestSkipped('This test requires eZ Publish 5');
118
        }
119
120
        $anonymousUserId = $this->generateId('user', 10);
121
122
        $repository = $this->getRepository();
123
        $contentService = $repository->getContentService();
124
        $contentTypeService = $repository->getContentTypeService();
125
        $locationService = $repository->getLocationService();
126
        $roleService = $repository->getRoleService();
127
128
        // Give Anonymous user role additional rights
129
        $role = $roleService->loadRoleByIdentifier('Anonymous');
130
        $roleDraft = $roleService->createRoleDraft($role);
131
        $policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'create');
132
        $policyCreateStruct->addLimitation(new SectionLimitation(array('limitationValues' => array(1))));
133
        $policyCreateStruct->addLimitation(new LocationLimitation(array('limitationValues' => array(2))));
134
        $policyCreateStruct->addLimitation(new ContentTypeLimitation(array('limitationValues' => array(1))));
135
        $roleDraft = $roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct);
136
137
        $policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'publish');
138
        $policyCreateStruct->addLimitation(new SectionLimitation(array('limitationValues' => array(1))));
139
        $policyCreateStruct->addLimitation(new LocationLimitation(array('limitationValues' => array(2))));
140
        $policyCreateStruct->addLimitation(new ContentTypeLimitation(array('limitationValues' => array(1))));
141
        $roleDraft = $roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct);
142
        $roleService->publishRoleDraft($roleDraft);
143
144
        // Set Anonymous user as current
145
        $repository->getPermissionResolver()->setCurrentUserReference($repository->getUserService()->loadUser($anonymousUserId));
146
147
        // Create a new content object:
148
        $contentCreate = $contentService->newContentCreateStruct(
149
            $contentTypeService->loadContentTypeByIdentifier('folder'),
150
            'eng-GB'
151
        );
152
153
        $contentCreate->setField('name', 'Folder 1');
154
155
        $content = $contentService->createContent(
156
            $contentCreate,
157
            array($locationService->newLocationCreateStruct(2))
158
        );
159
160
        $contentService->publishVersion(
161
            $content->getVersionInfo()
162
        );
163
    }
164
165
    /**
166
     * Test for the createContent() method.
167
     *
168
     * @param \eZ\Publish\API\Repository\Values\Content\Content $content
169
     *
170
     * @return \eZ\Publish\API\Repository\Values\Content\Content
171
     *
172
     * @see \eZ\Publish\API\Repository\ContentService::createContent()
173
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
174
     */
175
    public function testCreateContentSetsContentInfo($content)
176
    {
177
        $this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo', $content->contentInfo);
178
179
        return $content;
180
    }
181
182
    /**
183
     * Test for the createContent() method.
184
     *
185
     * @param \eZ\Publish\API\Repository\Values\Content\Content $content
186
     *
187
     * @see \eZ\Publish\API\Repository\ContentService::createContent()
188
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentSetsContentInfo
189
     */
190
    public function testCreateContentSetsExpectedContentInfo($content)
191
    {
192
        $this->assertEquals(
193
            array(
194
                $content->id,
195
                28, // id of content type "forum"
196
                true,
197
                1,
198
                'abcdef0123456789abcdef0123456789',
199
                'eng-US',
200
                $this->getRepository()->getCurrentUser()->id,
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::getCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. Get current user. Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}

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.

Loading history...
201
                false,
202
                null,
203
                // Main Location id for unpublished Content should be null
204
                null,
205
            ),
206
            array(
207
                $content->contentInfo->id,
208
                $content->contentInfo->contentTypeId,
209
                $content->contentInfo->alwaysAvailable,
210
                $content->contentInfo->currentVersionNo,
211
                $content->contentInfo->remoteId,
212
                $content->contentInfo->mainLanguageCode,
213
                $content->contentInfo->ownerId,
214
                $content->contentInfo->published,
215
                $content->contentInfo->publishedDate,
216
                $content->contentInfo->mainLocationId,
217
            )
218
        );
219
    }
220
221
    /**
222
     * Test for the createContent() method.
223
     *
224
     * @param \eZ\Publish\API\Repository\Values\Content\Content $content
225
     *
226
     * @return \eZ\Publish\API\Repository\Values\Content\Content
227
     *
228
     * @see \eZ\Publish\API\Repository\ContentService::createContent()
229
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
230
     */
231
    public function testCreateContentSetsVersionInfo($content)
232
    {
233
        $this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo', $content->getVersionInfo());
234
235
        return $content;
236
    }
237
238
    /**
239
     * Test for the createContent() method.
240
     *
241
     * @param \eZ\Publish\API\Repository\Values\Content\Content $content
242
     *
243
     * @see \eZ\Publish\API\Repository\ContentService::createContent()
244
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentSetsVersionInfo
245
     */
246
    public function testCreateContentSetsExpectedVersionInfo($content)
247
    {
248
        $this->assertEquals(
249
            array(
250
                'status' => VersionInfo::STATUS_DRAFT,
251
                'versionNo' => 1,
252
                'creatorId' => $this->getRepository()->getCurrentUser()->id,
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::getCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. Get current user. Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}

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.

Loading history...
253
                'initialLanguageCode' => 'eng-US',
254
            ),
255
            array(
256
                'status' => $content->getVersionInfo()->status,
257
                'versionNo' => $content->getVersionInfo()->versionNo,
258
                'creatorId' => $content->getVersionInfo()->creatorId,
259
                'initialLanguageCode' => $content->getVersionInfo()->initialLanguageCode,
260
            )
261
        );
262
        $this->assertTrue($content->getVersionInfo()->isDraft());
263
        $this->assertFalse($content->getVersionInfo()->isPublished());
264
        $this->assertFalse($content->getVersionInfo()->isArchived());
265
    }
266
267
    /**
268
     * Test for the createContent() method.
269
     *
270
     * @param \eZ\Publish\API\Repository\Values\Content\Content $content
271
     *
272
     * @see \eZ\Publish\API\Repository\ContentService::createContent()
273
     * @depends testCreateContent
274
     */
275
    public function testCreateContentSetsExpectedContentType($content)
276
    {
277
        $contentType = $content->getContentType();
278
279
        $this->assertEquals(
280
            [
281
                $contentType->id,
282
                // Won't match as it's set to true in createContentDraftVersion1()
283
                //$contentType->defaultAlwaysAvailable,
284
                //$contentType->defaultSortField,
285
                //$contentType->defaultSortOrder,
286
            ],
287
            [
288
                $content->contentInfo->contentTypeId,
289
                //$content->contentInfo->alwaysAvailable,
290
                //$location->sortField,
291
                //$location->sortOrder,
292
            ]
293
        );
294
    }
295
296
    /**
297
     * Test for the createContent() method.
298
     *
299
     * @see \eZ\Publish\API\Repository\ContentService::createContent()
300
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
301
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
302
     */
303
    public function testCreateContentThrowsInvalidArgumentException()
304
    {
305
        if ($this->isVersion4()) {
306
            $this->markTestSkipped('This test requires eZ Publish 5');
307
        }
308
309
        $repository = $this->getRepository();
310
311
        /* BEGIN: Use Case */
312
        $contentTypeService = $repository->getContentTypeService();
313
        $contentService = $repository->getContentService();
314
315
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
316
317
        $contentCreate1 = $contentService->newContentCreateStruct($contentType, 'eng-US');
318
        $contentCreate1->setField('name', 'An awesome Sidelfingen forum');
319
320
        $contentCreate1->remoteId = 'abcdef0123456789abcdef0123456789';
321
        $contentCreate1->alwaysAvailable = true;
322
323
        $draft = $contentService->createContent($contentCreate1);
324
        $contentService->publishVersion($draft->versionInfo);
325
326
        $contentCreate2 = $contentService->newContentCreateStruct($contentType, 'eng-GB');
327
        $contentCreate2->setField('name', 'An awesome Bielefeld forum');
328
329
        $contentCreate2->remoteId = 'abcdef0123456789abcdef0123456789';
330
        $contentCreate2->alwaysAvailable = false;
331
332
        // This call will fail with an "InvalidArgumentException", because the
333
        // remoteId is already in use.
334
        $contentService->createContent($contentCreate2);
335
        /* END: Use Case */
336
    }
337
338
    /**
339
     * Test for the createContent() method.
340
     *
341
     * @see \eZ\Publish\API\Repository\ContentService::createContent()
342
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
343
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
344
     */
345 View Code Duplication
    public function testCreateContentThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
346
    {
347
        $repository = $this->getRepository();
348
349
        /* BEGIN: Use Case */
350
        $contentTypeService = $repository->getContentTypeService();
351
        $contentService = $repository->getContentService();
352
353
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
354
355
        $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US');
356
        // The name field does only accept strings and null as its values
357
        $contentCreate->setField('name', new \stdClass());
358
359
        // Throws InvalidArgumentException since the name field is filled
360
        // improperly
361
        $draft = $contentService->createContent($contentCreate);
0 ignored issues
show
Unused Code introduced by
$draft is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
362
        /* END: Use Case */
363
    }
364
365
    /**
366
     * Test for the createContent() method.
367
     *
368
     * @see \eZ\Publish\API\Repository\ContentService::createContent()
369
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
370
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
371
     */
372
    public function testCreateContentThrowsContentFieldValidationException()
373
    {
374
        $repository = $this->getRepository();
375
376
        /* BEGIN: Use Case */
377
        $contentTypeService = $repository->getContentTypeService();
378
        $contentService = $repository->getContentService();
379
380
        $contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
381
382
        $contentCreate1 = $contentService->newContentCreateStruct($contentType, 'eng-US');
383
        $contentCreate1->setField('name', 'An awesome Sidelfingen folder');
384
        // Violates string length constraint
385
        $contentCreate1->setField('short_name', str_repeat('a', 200));
386
387
        // Throws ContentFieldValidationException, since short_name does not pass
388
        // validation of the string length validator
389
        $draft = $contentService->createContent($contentCreate1);
0 ignored issues
show
Unused Code introduced by
$draft is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
390
        /* END: Use Case */
391
    }
392
393
    /**
394
     * Test for the createContent() method.
395
     *
396
     * @see \eZ\Publish\API\Repository\ContentService::createContent()
397
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
398
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
399
     */
400 View Code Duplication
    public function testCreateContentRequiredFieldMissing()
401
    {
402
        $repository = $this->getRepository();
403
404
        /* BEGIN: Use Case */
405
        $contentTypeService = $repository->getContentTypeService();
406
        $contentService = $repository->getContentService();
407
408
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
409
410
        $contentCreate1 = $contentService->newContentCreateStruct($contentType, 'eng-US');
411
        // Required field "name" is not set
412
413
        // Throws a ContentFieldValidationException, since a required field is
414
        // missing
415
        $draft = $contentService->createContent($contentCreate1);
0 ignored issues
show
Unused Code introduced by
$draft is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
416
        /* END: Use Case */
417
    }
418
419
    /**
420
     * Test for the createContent() method.
421
     *
422
     * NOTE: We have bidirectional dependencies between the ContentService and
423
     * the LocationService, so that we cannot use PHPUnit's test dependencies
424
     * here.
425
     *
426
     * @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs)
427
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation
428
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationByRemoteId
429
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
430
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
431
     * @group user
432
     */
433
    public function testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately()
434
    {
435
        $repository = $this->getRepository();
436
437
        $locationService = $repository->getLocationService();
438
439
        /* BEGIN: Use Case */
440
        $draft = $this->createContentDraftVersion1();
0 ignored issues
show
Unused Code introduced by
$draft is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
441
442
        // The location will not have been created, yet, so this throws an
443
        // exception
444
        $location = $locationService->loadLocationByRemoteId(
0 ignored issues
show
Unused Code introduced by
$location is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
445
            '0123456789abcdef0123456789abcdef'
446
        );
447
        /* END: Use Case */
448
    }
449
450
    /**
451
     * Test for the createContent() method.
452
     *
453
     * @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs)
454
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
455
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately
456
     */
457
    public function testCreateContentThrowsInvalidArgumentExceptionWithLocationCreateParameter()
458
    {
459
        $repository = $this->getRepository();
460
461
        $parentLocationId = $this->generateId('location', 56);
462
        /* BEGIN: Use Case */
463
        // $parentLocationId is a valid location ID
464
465
        $contentService = $repository->getContentService();
466
        $contentTypeService = $repository->getContentTypeService();
467
        $locationService = $repository->getLocationService();
468
469
        // Load content type
470
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
471
472
        // Configure new locations
473
        $locationCreate1 = $locationService->newLocationCreateStruct($parentLocationId);
474
475
        $locationCreate1->priority = 23;
476
        $locationCreate1->hidden = true;
477
        $locationCreate1->remoteId = '0123456789abcdef0123456789aaaaaa';
478
        $locationCreate1->sortField = Location::SORT_FIELD_NODE_ID;
479
        $locationCreate1->sortOrder = Location::SORT_ORDER_DESC;
480
481
        $locationCreate2 = $locationService->newLocationCreateStruct($parentLocationId);
482
483
        $locationCreate2->priority = 42;
484
        $locationCreate2->hidden = true;
485
        $locationCreate2->remoteId = '0123456789abcdef0123456789bbbbbb';
486
        $locationCreate2->sortField = Location::SORT_FIELD_NODE_ID;
487
        $locationCreate2->sortOrder = Location::SORT_ORDER_DESC;
488
489
        // Configure new content object
490
        $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US');
491
492
        $contentCreate->setField('name', 'A awesome Sindelfingen forum');
493
        $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789';
494
        $contentCreate->alwaysAvailable = true;
495
496
        // Create new content object under the specified location
497
        $draft = $contentService->createContent(
498
            $contentCreate,
499
            array($locationCreate1)
500
        );
501
        $contentService->publishVersion($draft->versionInfo);
502
503
        // This call will fail with an "InvalidArgumentException", because the
504
        // Content remoteId already exists,
505
        $contentService->createContent(
506
            $contentCreate,
507
            array($locationCreate2)
508
        );
509
        /* END: Use Case */
510
    }
511
512
    /**
513
     * Test for the loadContentInfo() method.
514
     *
515
     * @see \eZ\Publish\API\Repository\ContentService::loadContentInfo()
516
     * @group user
517
     */
518 View Code Duplication
    public function testLoadContentInfo()
519
    {
520
        $repository = $this->getRepository();
521
522
        $mediaFolderId = $this->generateId('object', 41);
523
        /* BEGIN: Use Case */
524
        $contentService = $repository->getContentService();
525
526
        // Load the ContentInfo for "Media" folder
527
        $contentInfo = $contentService->loadContentInfo($mediaFolderId);
528
        /* END: Use Case */
529
530
        $this->assertInstanceOf(
531
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo',
532
            $contentInfo
533
        );
534
535
        return $contentInfo;
536
    }
537
538
    /**
539
     * Test for the returned value of the loadContentInfo() method.
540
     *
541
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
542
     * @covers \eZ\Publish\API\Repository\ContentService::loadContentInfo
543
     *
544
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
545
     */
546
    public function testLoadContentInfoSetsExpectedContentInfo(ContentInfo $contentInfo)
547
    {
548
        $this->assertPropertiesCorrectUnsorted(
549
            $this->getExpectedMediaContentInfoProperties(),
550
            $contentInfo
551
        );
552
    }
553
554
    /**
555
     * Test for the loadContentInfo() method.
556
     *
557
     * @see \eZ\Publish\API\Repository\ContentService::loadContentInfo()
558
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
559
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
560
     */
561 View Code Duplication
    public function testLoadContentInfoThrowsNotFoundException()
562
    {
563
        $repository = $this->getRepository();
564
565
        $nonExistentContentId = $this->generateId('object', self::DB_INT_MAX);
566
        /* BEGIN: Use Case */
567
        $contentService = $repository->getContentService();
568
569
        // This call will fail with a NotFoundException
570
        $contentService->loadContentInfo($nonExistentContentId);
571
        /* END: Use Case */
572
    }
573
574
    /**
575
     * Test for the loadContentInfoByRemoteId() method.
576
     *
577
     * @see \eZ\Publish\API\Repository\ContentService::loadContentInfoByRemoteId()
578
     */
579
    public function testLoadContentInfoByRemoteId()
580
    {
581
        $repository = $this->getRepository();
582
583
        /* BEGIN: Use Case */
584
        $contentService = $repository->getContentService();
585
586
        // Load the ContentInfo for "Media" folder
587
        $contentInfo = $contentService->loadContentInfoByRemoteId('faaeb9be3bd98ed09f606fc16d144eca');
588
        /* END: Use Case */
589
590
        $this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo', $contentInfo);
591
592
        return $contentInfo;
593
    }
594
595
    /**
596
     * Test for the returned value of the loadContentInfoByRemoteId() method.
597
     *
598
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfoByRemoteId
599
     * @covers \eZ\Publish\API\Repository\ContentService::loadContentInfoByRemoteId
600
     *
601
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
602
     */
603 View Code Duplication
    public function testLoadContentInfoByRemoteIdSetsExpectedContentInfo(ContentInfo $contentInfo)
604
    {
605
        $this->assertPropertiesCorrectUnsorted(
606
            [
607
                'id' => 10,
608
                'contentTypeId' => 4,
609
                'name' => 'Anonymous User',
610
                'sectionId' => 2,
611
                'currentVersionNo' => 2,
612
                'published' => true,
613
                'ownerId' => 14,
614
                'modificationDate' => $this->createDateTime(1072180405),
615
                'publishedDate' => $this->createDateTime(1033920665),
616
                'alwaysAvailable' => 1,
617
                'remoteId' => 'faaeb9be3bd98ed09f606fc16d144eca',
618
                'mainLanguageCode' => 'eng-US',
619
                'mainLocationId' => 45,
620
            ],
621
            $contentInfo
622
        );
623
    }
624
625
    /**
626
     * Test for the loadContentInfoByRemoteId() method.
627
     *
628
     * @see \eZ\Publish\API\Repository\ContentService::loadContentInfoByRemoteId()
629
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
630
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfoByRemoteId
631
     */
632
    public function testLoadContentInfoByRemoteIdThrowsNotFoundException()
633
    {
634
        $repository = $this->getRepository();
635
636
        /* BEGIN: Use Case */
637
        $contentService = $repository->getContentService();
638
639
        // This call will fail with a NotFoundException
640
        $contentService->loadContentInfoByRemoteId('abcdefghijklmnopqrstuvwxyz0123456789');
641
        /* END: Use Case */
642
    }
643
644
    /**
645
     * Test for the loadVersionInfo() method.
646
     *
647
     * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo()
648
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
649
     * @group user
650
     */
651 View Code Duplication
    public function testLoadVersionInfo()
652
    {
653
        $repository = $this->getRepository();
654
655
        $mediaFolderId = $this->generateId('object', 41);
656
        /* BEGIN: Use Case */
657
        // $mediaFolderId contains the ID of the "Media" folder
658
659
        $contentService = $repository->getContentService();
660
661
        // Load the ContentInfo for "Media" folder
662
        $contentInfo = $contentService->loadContentInfo($mediaFolderId);
663
664
        // Now load the current version info of the "Media" folder
665
        $versionInfo = $contentService->loadVersionInfo($contentInfo);
666
        /* END: Use Case */
667
668
        $this->assertInstanceOf(
669
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo',
670
            $versionInfo
671
        );
672
    }
673
674
    /**
675
     * Test for the loadVersionInfoById() method.
676
     *
677
     * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById()
678
     */
679 View Code Duplication
    public function testLoadVersionInfoById()
680
    {
681
        $repository = $this->getRepository();
682
683
        $mediaFolderId = $this->generateId('object', 41);
684
        /* BEGIN: Use Case */
685
        // $mediaFolderId contains the ID of the "Media" folder
686
687
        $contentService = $repository->getContentService();
688
689
        // Load the VersionInfo for "Media" folder
690
        $versionInfo = $contentService->loadVersionInfoById($mediaFolderId);
691
        /* END: Use Case */
692
693
        $this->assertInstanceOf(
694
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo',
695
            $versionInfo
696
        );
697
698
        return $versionInfo;
699
    }
700
701
    /**
702
     * Test for the returned value of the loadVersionInfoById() method.
703
     *
704
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoById
705
     * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById
706
     *
707
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
708
     */
709
    public function testLoadVersionInfoByIdSetsExpectedVersionInfo(VersionInfo $versionInfo)
710
    {
711
        $this->assertPropertiesCorrect(
712
            [
713
                'names' => [
714
                    'eng-US' => 'Media',
715
                ],
716
                'contentInfo' => new ContentInfo($this->getExpectedMediaContentInfoProperties()),
717
                'id' => 472,
718
                'versionNo' => 1,
719
                'modificationDate' => $this->createDateTime(1060695457),
720
                'creatorId' => 14,
721
                'creationDate' => $this->createDateTime(1060695450),
722
                'status' => VersionInfo::STATUS_PUBLISHED,
723
                'initialLanguageCode' => 'eng-US',
724
                'languageCodes' => [
725
                    'eng-US',
726
                ],
727
            ],
728
            $versionInfo
729
        );
730
        $this->assertTrue($versionInfo->isPublished());
731
        $this->assertFalse($versionInfo->isDraft());
732
        $this->assertFalse($versionInfo->isArchived());
733
    }
734
735
    /**
736
     * Test for the loadVersionInfoById() method.
737
     *
738
     * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById()
739
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
740
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoById
741
     */
742 View Code Duplication
    public function testLoadVersionInfoByIdThrowsNotFoundException()
743
    {
744
        $repository = $this->getRepository();
745
746
        $nonExistentContentId = $this->generateId('object', self::DB_INT_MAX);
747
        /* BEGIN: Use Case */
748
        $contentService = $repository->getContentService();
749
750
        // This call will fail with a "NotFoundException"
751
        $contentService->loadVersionInfoById($nonExistentContentId);
752
        /* END: Use Case */
753
    }
754
755
    /**
756
     * Test for the loadContentByContentInfo() method.
757
     *
758
     * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo()
759
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
760
     */
761 View Code Duplication
    public function testLoadContentByContentInfo()
762
    {
763
        $repository = $this->getRepository();
764
765
        $mediaFolderId = $this->generateId('object', 41);
766
        /* BEGIN: Use Case */
767
        // $mediaFolderId contains the ID of the "Media" folder
768
769
        $contentService = $repository->getContentService();
770
771
        // Load the ContentInfo for "Media" folder
772
        $contentInfo = $contentService->loadContentInfo($mediaFolderId);
773
774
        // Now load the current content version for the info instance
775
        $content = $contentService->loadContentByContentInfo($contentInfo);
776
        /* END: Use Case */
777
778
        $this->assertInstanceOf(
779
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
780
            $content
781
        );
782
    }
783
784
    /**
785
     * Test for the loadContentByVersionInfo() method.
786
     *
787
     * @see \eZ\Publish\API\Repository\ContentService::loadContentByVersionInfo()
788
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
789
     */
790
    public function testLoadContentByVersionInfo()
791
    {
792
        $repository = $this->getRepository();
793
794
        $mediaFolderId = $this->generateId('object', 41);
795
        /* BEGIN: Use Case */
796
        // $mediaFolderId contains the ID of the "Media" folder
797
798
        $contentService = $repository->getContentService();
799
800
        // Load the ContentInfo for "Media" folder
801
        $contentInfo = $contentService->loadContentInfo($mediaFolderId);
802
803
        // Load the current VersionInfo
804
        $versionInfo = $contentService->loadVersionInfo($contentInfo);
805
806
        // Now load the current content version for the info instance
807
        $content = $contentService->loadContentByVersionInfo($versionInfo);
808
        /* END: Use Case */
809
810
        $this->assertInstanceOf(
811
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
812
            $content
813
        );
814
    }
815
816
    /**
817
     * Test for the loadContent() method.
818
     *
819
     * @see \eZ\Publish\API\Repository\ContentService::loadContent()
820
     * @group user
821
     * @group field-type
822
     */
823 View Code Duplication
    public function testLoadContent()
824
    {
825
        $repository = $this->getRepository();
826
827
        $mediaFolderId = $this->generateId('object', 41);
828
        /* BEGIN: Use Case */
829
        // $mediaFolderId contains the ID of the "Media" folder
830
831
        $contentService = $repository->getContentService();
832
833
        // Load the Content for "Media" folder, any language and current version
834
        $content = $contentService->loadContent($mediaFolderId);
835
        /* END: Use Case */
836
837
        $this->assertInstanceOf(
838
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
839
            $content
840
        );
841
    }
842
843
    /**
844
     * Test for the loadContent() method.
845
     *
846
     * @see \eZ\Publish\API\Repository\ContentService::loadContent()
847
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
848
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
849
     */
850 View Code Duplication
    public function testLoadContentThrowsNotFoundException()
851
    {
852
        $repository = $this->getRepository();
853
854
        $nonExistentContentId = $this->generateId('object', self::DB_INT_MAX);
855
        /* BEGIN: Use Case */
856
        $contentService = $repository->getContentService();
857
858
        // This call will fail with a "NotFoundException"
859
        $contentService->loadContent($nonExistentContentId);
860
        /* END: Use Case */
861
    }
862
863
    /**
864
     * Data provider for testLoadContentByRemoteId().
865
     *
866
     * @return array
867
     */
868
    public function contentRemoteIdVersionLanguageProvider()
869
    {
870
        return [
871
            ['f5c88a2209584891056f987fd965b0ba', null, null],
872
            ['f5c88a2209584891056f987fd965b0ba', ['eng-US'], null],
873
            ['f5c88a2209584891056f987fd965b0ba', null, 1],
874
            ['f5c88a2209584891056f987fd965b0ba', ['eng-US'], 1],
875
            ['a6e35cbcb7cd6ae4b691f3eee30cd262', null, null],
876
            ['a6e35cbcb7cd6ae4b691f3eee30cd262', ['eng-US'], null],
877
            ['a6e35cbcb7cd6ae4b691f3eee30cd262', null, 1],
878
            ['a6e35cbcb7cd6ae4b691f3eee30cd262', ['eng-US'], 1],
879
        ];
880
    }
881
882
    /**
883
     * Test for the loadContentByRemoteId() method.
884
     *
885
     * @covers \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId
886
     * @dataProvider contentRemoteIdVersionLanguageProvider
887
     *
888
     * @param string $remoteId
889
     * @param array|null $languages
890
     * @param int $versionNo
891
     */
892
    public function testLoadContentByRemoteId($remoteId, $languages, $versionNo)
893
    {
894
        $repository = $this->getRepository();
895
896
        $contentService = $repository->getContentService();
897
898
        $content = $contentService->loadContentByRemoteId($remoteId, $languages, $versionNo);
899
900
        $this->assertInstanceOf(
901
            Content::class,
902
            $content
903
        );
904
905
        $this->assertEquals($remoteId, $content->contentInfo->remoteId);
906
        if ($languages !== null) {
907
            $this->assertEquals($languages, $content->getVersionInfo()->languageCodes);
908
        }
909
        $this->assertEquals($versionNo ?: 1, $content->getVersionInfo()->versionNo);
910
    }
911
912
    /**
913
     * Test for the loadContentByRemoteId() method.
914
     *
915
     * @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId()
916
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
917
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteId
918
     */
919
    public function testLoadContentByRemoteIdThrowsNotFoundException()
920
    {
921
        $repository = $this->getRepository();
922
923
        /* BEGIN: Use Case */
924
        $contentService = $repository->getContentService();
925
926
        // This call will fail with a "NotFoundException", because no content
927
        // object exists for the given remoteId
928
        $contentService->loadContentByRemoteId('a1b1c1d1e1f1a2b2c2d2e2f2a3b3c3d3');
929
        /* END: Use Case */
930
    }
931
932
    /**
933
     * Test for the publishVersion() method.
934
     *
935
     * @return \eZ\Publish\API\Repository\Values\Content\Content
936
     *
937
     * @see \eZ\Publish\API\Repository\ContentService::publishVersion()
938
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
939
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
940
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
941
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately
942
     * @group user
943
     * @group field-type
944
     */
945
    public function testPublishVersion()
946
    {
947
        $time = time();
948
        /* BEGIN: Use Case */
949
        $content = $this->createContentVersion1();
950
        /* END: Use Case */
951
952
        $this->assertInstanceOf(Content::class, $content);
953
        $this->assertTrue($content->contentInfo->published);
954
        $this->assertEquals(VersionInfo::STATUS_PUBLISHED, $content->versionInfo->status);
955
        $this->assertGreaterThanOrEqual($time, $content->contentInfo->publishedDate->getTimestamp());
956
        $this->assertGreaterThanOrEqual($time, $content->contentInfo->modificationDate->getTimestamp());
957
        $this->assertTrue($content->versionInfo->isPublished());
958
        $this->assertFalse($content->versionInfo->isDraft());
959
        $this->assertFalse($content->versionInfo->isArchived());
960
961
        return $content;
962
    }
963
964
    /**
965
     * Test for the publishVersion() method.
966
     *
967
     * @param \eZ\Publish\API\Repository\Values\Content\Content $content
968
     *
969
     * @see \eZ\Publish\API\Repository\ContentService::publishVersion()
970
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
971
     */
972
    public function testPublishVersionSetsExpectedContentInfo($content)
973
    {
974
        $this->assertEquals(
975
            array(
976
                $content->id,
977
                true,
978
                1,
979
                'abcdef0123456789abcdef0123456789',
980
                'eng-US',
981
                $this->getRepository()->getCurrentUser()->id,
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::getCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. Get current user. Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}

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.

Loading history...
982
                true,
983
            ),
984
            array(
985
                $content->contentInfo->id,
986
                $content->contentInfo->alwaysAvailable,
987
                $content->contentInfo->currentVersionNo,
988
                $content->contentInfo->remoteId,
989
                $content->contentInfo->mainLanguageCode,
990
                $content->contentInfo->ownerId,
991
                $content->contentInfo->published,
992
            )
993
        );
994
995
        $this->assertNotNull($content->contentInfo->mainLocationId);
996
        $date = new \DateTime('1984/01/01');
997
        $this->assertGreaterThan(
998
            $date->getTimestamp(),
999
            $content->contentInfo->publishedDate->getTimestamp()
1000
        );
1001
    }
1002
1003
    /**
1004
     * Test for the publishVersion() method.
1005
     *
1006
     * @param \eZ\Publish\API\Repository\Values\Content\Content $content
1007
     *
1008
     * @see \eZ\Publish\API\Repository\ContentService::publishVersion()
1009
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
1010
     */
1011
    public function testPublishVersionSetsExpectedVersionInfo($content)
1012
    {
1013
        $this->assertEquals(
1014
            array(
1015
                $this->getRepository()->getCurrentUser()->id,
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::getCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. Get current user. Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}

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.

Loading history...
1016
                'eng-US',
1017
                VersionInfo::STATUS_PUBLISHED,
1018
                1,
1019
            ),
1020
            array(
1021
                $content->getVersionInfo()->creatorId,
1022
                $content->getVersionInfo()->initialLanguageCode,
1023
                $content->getVersionInfo()->status,
1024
                $content->getVersionInfo()->versionNo,
1025
            )
1026
        );
1027
1028
        $date = new \DateTime('1984/01/01');
1029
        $this->assertGreaterThan(
1030
            $date->getTimestamp(),
1031
            $content->getVersionInfo()->modificationDate->getTimestamp()
1032
        );
1033
1034
        $this->assertNotNull($content->getVersionInfo()->modificationDate);
1035
        $this->assertTrue($content->getVersionInfo()->isPublished());
1036
        $this->assertFalse($content->getVersionInfo()->isDraft());
1037
        $this->assertFalse($content->getVersionInfo()->isArchived());
1038
    }
1039
1040
    /**
1041
     * Test for the publishVersion() method.
1042
     *
1043
     * @param \eZ\Publish\API\Repository\Values\Content\Content $content
1044
     *
1045
     * @see \eZ\Publish\API\Repository\ContentService::publishVersion()
1046
     * @depends testPublishVersion
1047
     */
1048
    public function testPublishVersionSetsExpectedContentType($content)
1049
    {
1050
        $contentType = $content->getContentType();
1051
1052
        $this->assertEquals(
1053
            [
1054
                $contentType->id,
1055
                // won't be a match as it's set to true in createContentDraftVersion1()
1056
                //$contentType->defaultAlwaysAvailable,
1057
                //$contentType->defaultSortField,
1058
                //$contentType->defaultSortOrder,
1059
            ],
1060
            [
1061
                $content->contentInfo->contentTypeId,
1062
                //$content->contentInfo->alwaysAvailable,
1063
                //$location->sortField,
1064
                //$location->sortOrder,
1065
            ]
1066
        );
1067
    }
1068
1069
    /**
1070
     * Test for the publishVersion() method.
1071
     *
1072
     * @return \eZ\Publish\API\Repository\Values\Content\Content
1073
     *
1074
     * @see \eZ\Publish\API\Repository\ContentService::publishVersion()
1075
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately
1076
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
1077
     */
1078
    public function testPublishVersionCreatesLocationsDefinedOnCreate()
1079
    {
1080
        $repository = $this->getRepository();
1081
1082
        /* BEGIN: Use Case */
1083
        $content = $this->createContentVersion1();
1084
        /* END: Use Case */
1085
1086
        $locationService = $repository->getLocationService();
1087
        $location = $locationService->loadLocationByRemoteId(
1088
            '0123456789abcdef0123456789abcdef'
1089
        );
1090
1091
        $this->assertEquals(
1092
            $location->getContentInfo(),
1093
            $content->getVersionInfo()->getContentInfo()
1094
        );
1095
1096
        return array($content, $location);
1097
    }
1098
1099
    /**
1100
     * Test for the publishVersion() method.
1101
     *
1102
     * @see \eZ\Publish\API\Repository\ContentService::publishVersion()
1103
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionCreatesLocationsDefinedOnCreate
1104
     */
1105
    public function testCreateContentWithLocationCreateParameterCreatesExpectedLocation(array $testData)
1106
    {
1107
        /** @var \eZ\Publish\API\Repository\Values\Content\Content $content */
1108
        /** @var \eZ\Publish\API\Repository\Values\Content\Location $location */
1109
        list($content, $location) = $testData;
1110
1111
        $parentLocationId = $this->generateId('location', 56);
1112
        $parentLocation = $this->getRepository()->getLocationService()->loadLocation($parentLocationId);
1113
        $mainLocationId = $content->getVersionInfo()->getContentInfo()->mainLocationId;
1114
1115
        $this->assertPropertiesCorrect(
1116
            array(
1117
                'id' => $mainLocationId,
1118
                'priority' => 23,
1119
                'hidden' => true,
1120
                'invisible' => true,
1121
                'remoteId' => '0123456789abcdef0123456789abcdef',
1122
                'parentLocationId' => $parentLocationId,
1123
                'pathString' => $parentLocation->pathString . $mainLocationId . '/',
1124
                'depth' => $parentLocation->depth + 1,
1125
                'sortField' => Location::SORT_FIELD_NODE_ID,
1126
                'sortOrder' => Location::SORT_ORDER_DESC,
1127
            ),
1128
            $location
1129
        );
1130
    }
1131
1132
    /**
1133
     * Test for the publishVersion() method.
1134
     *
1135
     * @see \eZ\Publish\API\Repository\ContentService::publishVersion()
1136
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
1137
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
1138
     */
1139 View Code Duplication
    public function testPublishVersionThrowsBadStateException()
1140
    {
1141
        $repository = $this->getRepository();
1142
1143
        $contentService = $repository->getContentService();
1144
1145
        /* BEGIN: Use Case */
1146
        $draft = $this->createContentDraftVersion1();
1147
1148
        // Publish the content draft
1149
        $contentService->publishVersion($draft->getVersionInfo());
1150
1151
        // This call will fail with a "BadStateException", because the version
1152
        // is already published.
1153
        $contentService->publishVersion($draft->getVersionInfo());
1154
        /* END: Use Case */
1155
    }
1156
1157
    /**
1158
     * Test that publishVersion() does not affect publishedDate (assuming previous version exists).
1159
     *
1160
     * @covers \eZ\Publish\API\Repository\ContentService::publishVersion
1161
     */
1162
    public function testPublishVersionDoesNotChangePublishedDate()
1163
    {
1164
        $repository = $this->getRepository();
1165
1166
        $contentService = $repository->getContentService();
1167
1168
        $publishedContent = $this->createContentVersion1();
1169
1170
        // force timestamps to differ
1171
        sleep(1);
1172
1173
        $contentDraft = $contentService->createContentDraft($publishedContent->contentInfo);
1174
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
1175
        $contentUpdateStruct->setField('name', 'New name');
1176
        $contentDraft = $contentService->updateContent($contentDraft->versionInfo, $contentUpdateStruct);
1177
        $republishedContent = $contentService->publishVersion($contentDraft->versionInfo);
1178
1179
        $this->assertEquals(
1180
            $publishedContent->contentInfo->publishedDate->getTimestamp(),
1181
            $republishedContent->contentInfo->publishedDate->getTimestamp()
1182
        );
1183
        $this->assertGreaterThan(
1184
            $publishedContent->contentInfo->modificationDate->getTimestamp(),
1185
            $republishedContent->contentInfo->modificationDate->getTimestamp()
1186
        );
1187
    }
1188
1189
    /**
1190
     * Test for the createContentDraft() method.
1191
     *
1192
     * @return \eZ\Publish\API\Repository\Values\Content\Content
1193
     *
1194
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
1195
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
1196
     * @group user
1197
     */
1198
    public function testCreateContentDraft()
1199
    {
1200
        $repository = $this->getRepository();
1201
1202
        $contentService = $repository->getContentService();
1203
1204
        /* BEGIN: Use Case */
1205
        $content = $this->createContentVersion1();
1206
1207
        // Now we create a new draft from the published content
1208
        $draftedContent = $contentService->createContentDraft($content->contentInfo);
1209
        /* END: Use Case */
1210
1211
        $this->assertInstanceOf(
1212
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
1213
            $draftedContent
1214
        );
1215
1216
        return $draftedContent;
1217
    }
1218
1219
    /**
1220
     * Test for the createContentDraft() method.
1221
     *
1222
     * Test that editor has access to edit own draft.
1223
     * Note: Editors have access to version_read, which is needed to load content drafts.
1224
     *
1225
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
1226
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
1227
     * @group user
1228
     */
1229 View Code Duplication
    public function testCreateContentDraftAndLoadAccess()
1230
    {
1231
        $repository = $this->getRepository();
1232
1233
        /* BEGIN: Use Case */
1234
        $user = $this->createUserVersion1();
1235
1236
        // Set new editor as user
1237
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

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.

Loading history...
1238
1239
        // Create draft
1240
        $draft = $this->createContentDraftVersion1(2, 'folder');
1241
1242
        // Try to load the draft
1243
        $contentService = $repository->getContentService();
1244
        $loadedDraft = $contentService->loadContent($draft->id);
1245
1246
        /* END: Use Case */
1247
1248
        $this->assertEquals($draft->id, $loadedDraft->id);
1249
    }
1250
1251
    /**
1252
     * Test for the createContentDraft() method.
1253
     *
1254
     * @param \eZ\Publish\API\Repository\Values\Content\Content $draft
1255
     *
1256
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
1257
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
1258
     */
1259
    public function testCreateContentDraftSetsExpectedProperties($draft)
1260
    {
1261
        $this->assertEquals(
1262
            array(
1263
                'fieldCount' => 2,
1264
                'relationCount' => 0,
1265
            ),
1266
            array(
1267
                'fieldCount' => count($draft->getFields()),
1268
                'relationCount' => count($this->getRepository()->getContentService()->loadRelations($draft->getVersionInfo())),
1269
            )
1270
        );
1271
    }
1272
1273
    /**
1274
     * Test for the createContentDraft() method.
1275
     *
1276
     * @param \eZ\Publish\API\Repository\Values\Content\Content $draft
1277
     *
1278
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
1279
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
1280
     */
1281
    public function testCreateContentDraftSetsContentInfo($draft)
1282
    {
1283
        $contentInfo = $draft->contentInfo;
1284
1285
        $this->assertEquals(
1286
            array(
1287
                $draft->id,
1288
                true,
1289
                1,
1290
                'eng-US',
1291
                $this->getRepository()->getCurrentUser()->id,
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::getCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. Get current user. Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}

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.

Loading history...
1292
                'abcdef0123456789abcdef0123456789',
1293
                1,
1294
            ),
1295
            array(
1296
                $contentInfo->id,
1297
                $contentInfo->alwaysAvailable,
1298
                $contentInfo->currentVersionNo,
1299
                $contentInfo->mainLanguageCode,
1300
                $contentInfo->ownerId,
1301
                $contentInfo->remoteId,
1302
                $contentInfo->sectionId,
1303
            )
1304
        );
1305
    }
1306
1307
    /**
1308
     * Test for the createContentDraft() method.
1309
     *
1310
     * @param \eZ\Publish\API\Repository\Values\Content\Content $draft
1311
     *
1312
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
1313
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
1314
     */
1315
    public function testCreateContentDraftSetsVersionInfo($draft)
1316
    {
1317
        $versionInfo = $draft->getVersionInfo();
1318
1319
        $this->assertEquals(
1320
            array(
1321
                'creatorId' => $this->getRepository()->getCurrentUser()->id,
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::getCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. Get current user. Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}

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.

Loading history...
1322
                'initialLanguageCode' => 'eng-US',
1323
                'languageCodes' => array(0 => 'eng-US'),
1324
                'status' => VersionInfo::STATUS_DRAFT,
1325
                'versionNo' => 2,
1326
            ),
1327
            array(
1328
                'creatorId' => $versionInfo->creatorId,
1329
                'initialLanguageCode' => $versionInfo->initialLanguageCode,
1330
                'languageCodes' => $versionInfo->languageCodes,
1331
                'status' => $versionInfo->status,
1332
                'versionNo' => $versionInfo->versionNo,
1333
            )
1334
        );
1335
        $this->assertTrue($versionInfo->isDraft());
1336
        $this->assertFalse($versionInfo->isPublished());
1337
        $this->assertFalse($versionInfo->isArchived());
1338
    }
1339
1340
    /**
1341
     * Test for the createContentDraft() method.
1342
     *
1343
     * @param \eZ\Publish\API\Repository\Values\Content\Content $draft
1344
     *
1345
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
1346
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
1347
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
1348
     */
1349 View Code Duplication
    public function testCreateContentDraftLoadVersionInfoStillLoadsPublishedVersion($draft)
0 ignored issues
show
Unused Code introduced by
The parameter $draft is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1350
    {
1351
        $repository = $this->getRepository();
1352
1353
        $contentService = $repository->getContentService();
1354
1355
        /* BEGIN: Use Case */
1356
        $content = $this->createContentVersion1();
1357
1358
        // Now we create a new draft from the published content
1359
        $contentService->createContentDraft($content->contentInfo);
1360
1361
        // This call will still load the published version
1362
        $versionInfoPublished = $contentService->loadVersionInfo($content->contentInfo);
1363
        /* END: Use Case */
1364
1365
        $this->assertEquals(1, $versionInfoPublished->versionNo);
1366
    }
1367
1368
    /**
1369
     * Test for the createContentDraft() method.
1370
     *
1371
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
1372
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
1373
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
1374
     */
1375 View Code Duplication
    public function testCreateContentDraftLoadContentStillLoadsPublishedVersion()
1376
    {
1377
        $repository = $this->getRepository();
1378
1379
        $contentService = $repository->getContentService();
1380
1381
        /* BEGIN: Use Case */
1382
        $content = $this->createContentVersion1();
1383
1384
        // Now we create a new draft from the published content
1385
        $contentService->createContentDraft($content->contentInfo);
1386
1387
        // This call will still load the published content version
1388
        $contentPublished = $contentService->loadContent($content->id);
1389
        /* END: Use Case */
1390
1391
        $this->assertEquals(1, $contentPublished->getVersionInfo()->versionNo);
1392
    }
1393
1394
    /**
1395
     * Test for the createContentDraft() method.
1396
     *
1397
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
1398
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteId
1399
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
1400
     */
1401 View Code Duplication
    public function testCreateContentDraftLoadContentByRemoteIdStillLoadsPublishedVersion()
1402
    {
1403
        $repository = $this->getRepository();
1404
1405
        $contentService = $repository->getContentService();
1406
1407
        /* BEGIN: Use Case */
1408
        $content = $this->createContentVersion1();
1409
1410
        // Now we create a new draft from the published content
1411
        $contentService->createContentDraft($content->contentInfo);
1412
1413
        // This call will still load the published content version
1414
        $contentPublished = $contentService->loadContentByRemoteId('abcdef0123456789abcdef0123456789');
1415
        /* END: Use Case */
1416
1417
        $this->assertEquals(1, $contentPublished->getVersionInfo()->versionNo);
1418
    }
1419
1420
    /**
1421
     * Test for the createContentDraft() method.
1422
     *
1423
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
1424
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfo
1425
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
1426
     */
1427 View Code Duplication
    public function testCreateContentDraftLoadContentByContentInfoStillLoadsPublishedVersion()
1428
    {
1429
        $repository = $this->getRepository();
1430
1431
        $contentService = $repository->getContentService();
1432
1433
        /* BEGIN: Use Case */
1434
        $content = $this->createContentVersion1();
1435
1436
        // Now we create a new draft from the published content
1437
        $contentService->createContentDraft($content->contentInfo);
1438
1439
        // This call will still load the published content version
1440
        $contentPublished = $contentService->loadContentByContentInfo($content->contentInfo);
1441
        /* END: Use Case */
1442
1443
        $this->assertEquals(1, $contentPublished->getVersionInfo()->versionNo);
1444
    }
1445
1446
    /**
1447
     * Test for the newContentUpdateStruct() method.
1448
     *
1449
     * @covers \eZ\Publish\API\Repository\ContentService::newContentUpdateStruct
1450
     * @group user
1451
     */
1452
    public function testNewContentUpdateStruct()
1453
    {
1454
        $repository = $this->getRepository();
1455
1456
        /* BEGIN: Use Case */
1457
        $contentService = $repository->getContentService();
1458
1459
        $updateStruct = $contentService->newContentUpdateStruct();
1460
        /* END: Use Case */
1461
1462
        $this->assertInstanceOf(
1463
            ContentUpdateStruct::class,
1464
            $updateStruct
1465
        );
1466
1467
        $this->assertPropertiesCorrect(
1468
            [
1469
                'initialLanguageCode' => null,
1470
                'fields' => [],
1471
            ],
1472
            $updateStruct
1473
        );
1474
    }
1475
1476
    /**
1477
     * Test for the updateContent() method.
1478
     *
1479
     * @return \eZ\Publish\API\Repository\Values\Content\Content
1480
     *
1481
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1482
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentUpdateStruct
1483
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
1484
     * @group user
1485
     * @group field-type
1486
     */
1487
    public function testUpdateContent()
1488
    {
1489
        /* BEGIN: Use Case */
1490
        $draftVersion2 = $this->createUpdatedDraftVersion2();
1491
        /* END: Use Case */
1492
1493
        $this->assertInstanceOf(
1494
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
1495
            $draftVersion2
1496
        );
1497
1498
        $this->assertEquals(
1499
            $this->generateId('user', 10),
1500
            $draftVersion2->versionInfo->creatorId,
1501
            'creatorId is not properly set on new Version'
1502
        );
1503
1504
        return $draftVersion2;
1505
    }
1506
1507
    /**
1508
     * Test for the updateContent_WithDifferentUser() method.
1509
     *
1510
     * @return \eZ\Publish\API\Repository\Values\Content\Content
1511
     *
1512
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1513
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentUpdateStruct
1514
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
1515
     * @group user
1516
     * @group field-type
1517
     */
1518
    public function testUpdateContentWithDifferentUser()
1519
    {
1520
        /* BEGIN: Use Case */
1521
        $arrayWithDraftVersion2 = $this->createUpdatedDraftVersion2NotAdmin();
1522
        /* END: Use Case */
1523
1524
        $this->assertInstanceOf(
1525
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
1526
            $arrayWithDraftVersion2[0]
1527
        );
1528
1529
        $this->assertEquals(
1530
            $this->generateId('user', $arrayWithDraftVersion2[1]),
1531
            $arrayWithDraftVersion2[0]->versionInfo->creatorId,
1532
            'creatorId is not properly set on new Version'
1533
        );
1534
1535
        return $arrayWithDraftVersion2[0];
1536
    }
1537
1538
    /**
1539
     * Test for the updateContent() method.
1540
     *
1541
     * @param \eZ\Publish\API\Repository\Values\Content\Content $content
1542
     *
1543
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1544
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1545
     */
1546
    public function testUpdateContentSetsExpectedFields($content)
1547
    {
1548
        $actual = $this->normalizeFields($content->getFields());
1549
1550
        $expected = array(
1551
            new Field(
1552
                array(
1553
                    'id' => 0,
1554
                    'value' => true,
1555
                    'languageCode' => 'eng-GB',
1556
                    'fieldDefIdentifier' => 'description',
1557
                    'fieldTypeIdentifier' => 'ezrichtext',
1558
                )
1559
            ),
1560
            new Field(
1561
                array(
1562
                    'id' => 0,
1563
                    'value' => true,
1564
                    'languageCode' => 'eng-US',
1565
                    'fieldDefIdentifier' => 'description',
1566
                    'fieldTypeIdentifier' => 'ezrichtext',
1567
                )
1568
            ),
1569
            new Field(
1570
                array(
1571
                    'id' => 0,
1572
                    'value' => true,
1573
                    'languageCode' => 'eng-GB',
1574
                    'fieldDefIdentifier' => 'name',
1575
                    'fieldTypeIdentifier' => 'ezstring',
1576
                )
1577
            ),
1578
            new Field(
1579
                array(
1580
                    'id' => 0,
1581
                    'value' => true,
1582
                    'languageCode' => 'eng-US',
1583
                    'fieldDefIdentifier' => 'name',
1584
                    'fieldTypeIdentifier' => 'ezstring',
1585
                )
1586
            ),
1587
        );
1588
1589
        $this->assertEquals($expected, $actual);
1590
    }
1591
1592
    /**
1593
     * Test for the updateContent() method.
1594
     *
1595
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1596
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
1597
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1598
     */
1599
    public function testUpdateContentThrowsBadStateException()
1600
    {
1601
        $repository = $this->getRepository();
1602
1603
        $contentService = $repository->getContentService();
1604
1605
        /* BEGIN: Use Case */
1606
        $content = $this->createContentVersion1();
1607
1608
        // Now create an update struct and modify some fields
1609
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
1610
        $contentUpdateStruct->setField('title', 'An awesome² story about ezp.');
1611
        $contentUpdateStruct->setField('title', 'An awesome²³ story about ezp.', 'eng-GB');
1612
1613
        $contentUpdateStruct->initialLanguageCode = 'eng-US';
1614
1615
        // This call will fail with a "BadStateException", because $publishedContent
1616
        // is not a draft.
1617
        $contentService->updateContent(
1618
            $content->getVersionInfo(),
1619
            $contentUpdateStruct
1620
        );
1621
        /* END: Use Case */
1622
    }
1623
1624
    /**
1625
     * Test for the updateContent() method.
1626
     *
1627
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1628
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1629
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1630
     */
1631 View Code Duplication
    public function testUpdateContentThrowsInvalidArgumentExceptionWhenFieldTypeDoesNotAccept()
1632
    {
1633
        $repository = $this->getRepository();
1634
1635
        $contentService = $repository->getContentService();
1636
1637
        /* BEGIN: Use Case */
1638
        $draft = $this->createContentDraftVersion1();
1639
1640
        // Now create an update struct and modify some fields
1641
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
1642
        // The name field does not accept a stdClass object as its input
1643
        $contentUpdateStruct->setField('name', new \stdClass(), 'eng-US');
1644
1645
        // Throws an InvalidArgumentException, since the value for field "name"
1646
        // is not accepted
1647
        $contentService->updateContent(
1648
            $draft->getVersionInfo(),
1649
            $contentUpdateStruct
1650
        );
1651
        /* END: Use Case */
1652
    }
1653
1654
    /**
1655
     * Test for the updateContent() method.
1656
     *
1657
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1658
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
1659
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1660
     */
1661 View Code Duplication
    public function testUpdateContentWhenMandatoryFieldIsEmpty()
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 and set a mandatory field to null
1671
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
1672
        $contentUpdateStruct->setField('name', null);
1673
1674
        // Don't set this, then the above call without languageCode will fail
1675
        $contentUpdateStruct->initialLanguageCode = 'eng-US';
1676
1677
        // This call will fail with a "ContentFieldValidationException", because the
1678
        // mandatory "name" field is empty.
1679
        $contentService->updateContent(
1680
            $draft->getVersionInfo(),
1681
            $contentUpdateStruct
1682
        );
1683
        /* END: Use Case */
1684
    }
1685
1686
    /**
1687
     * Test for the updateContent() method.
1688
     *
1689
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1690
     * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
1691
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1692
     */
1693
    public function testUpdateContentThrowsContentFieldValidationException()
1694
    {
1695
        $repository = $this->getRepository();
1696
1697
        /* BEGIN: Use Case */
1698
        $contentTypeService = $repository->getContentTypeService();
1699
        $contentService = $repository->getContentService();
1700
1701
        $contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
1702
1703
        $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US');
1704
        $contentCreate->setField('name', 'An awesome Sidelfingen folder');
1705
1706
        $draft = $contentService->createContent($contentCreate);
1707
1708
        $contentUpdate = $contentService->newContentUpdateStruct();
1709
        // Violates string length constraint
1710
        $contentUpdate->setField('short_name', str_repeat('a', 200), 'eng-US');
1711
1712
        // Throws ContentFieldValidationException because the string length
1713
        // validation of the field "short_name" fails
1714
        $contentService->updateContent($draft->getVersionInfo(), $contentUpdate);
1715
        /* END: Use Case */
1716
    }
1717
1718
    /**
1719
     * Test for the updateContent() method.
1720
     *
1721
     * @covers \eZ\Publish\API\Repository\ContentService::updateContent()
1722
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1723
     */
1724
    public function testUpdateContentValidatorIgnoresRequiredFieldsOfNotUpdatedLanguages()
1725
    {
1726
        $repository = $this->getRepository();
1727
        /* BEGIN: Use Case */
1728
        $contentTypeService = $repository->getContentTypeService();
1729
        $contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
1730
1731
        // Create multilangual content
1732
        $contentService = $repository->getContentService();
1733
        $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US');
1734
        $contentCreate->setField('name', 'An awesome Sidelfingen folder', 'eng-US');
1735
        $contentCreate->setField('name', 'An awesome Sidelfingen folder', 'eng-GB');
1736
1737
        $contentDraft = $contentService->createContent($contentCreate);
1738
1739
        // 2. Update content type definition
1740
        $contentTypeDraft = $contentTypeService->createContentTypeDraft($contentType);
1741
1742
        $fieldDefinition = $contentType->getFieldDefinition('description');
1743
        $fieldDefinitionUpdate = $contentTypeService->newFieldDefinitionUpdateStruct();
1744
        $fieldDefinitionUpdate->identifier = 'description';
1745
        $fieldDefinitionUpdate->isRequired = true;
1746
1747
        $contentTypeService->updateFieldDefinition(
1748
            $contentTypeDraft,
1749
            $fieldDefinition,
1750
            $fieldDefinitionUpdate
1751
        );
1752
        $contentTypeService->publishContentTypeDraft($contentTypeDraft);
1753
1754
        // 3. Update only eng-US translation
1755
        $description = new DOMDocument();
1756
        $description->loadXML(<<<XML
1757
<?xml version="1.0" encoding="UTF-8"?>
1758
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml" xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" version="5.0-variant ezpublish-1.0">
1759
    <para>Lorem ipsum dolor</para>
1760
</section>
1761
XML
1762
        );
1763
1764
        $contentUpdate = $contentService->newContentUpdateStruct();
1765
        $contentUpdate->setField('name', 'An awesome Sidelfingen folder (updated)', 'eng-US');
1766
        $contentUpdate->setField('description', $description);
1767
1768
        $contentService->updateContent($contentDraft->getVersionInfo(), $contentUpdate);
1769
        /* END: Use Case */
1770
    }
1771
1772
    /**
1773
     * Test for the updateContent() method.
1774
     *
1775
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
1776
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1777
     */
1778
    public function testUpdateContentWithNotUpdatingMandatoryField()
1779
    {
1780
        $repository = $this->getRepository();
1781
1782
        $contentService = $repository->getContentService();
1783
1784
        /* BEGIN: Use Case */
1785
        $draft = $this->createContentDraftVersion1();
1786
1787
        // Now create an update struct which does not overwrite mandatory
1788
        // fields
1789
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
1790
        $contentUpdateStruct->setField(
1791
            'description',
1792
            '<?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"/>'
1793
        );
1794
1795
        // Don't set this, then the above call without languageCode will fail
1796
        $contentUpdateStruct->initialLanguageCode = 'eng-US';
1797
1798
        // This will only update the "description" field in the "eng-US"
1799
        // language
1800
        $updatedDraft = $contentService->updateContent(
1801
            $draft->getVersionInfo(),
1802
            $contentUpdateStruct
1803
        );
1804
        /* END: Use Case */
1805
1806
        foreach ($updatedDraft->getFields() as $field) {
1807
            if ($field->languageCode === 'eng-US' && $field->fieldDefIdentifier === 'name' && $field->value !== null) {
1808
                // Found field
1809
                return;
1810
            }
1811
        }
1812
        $this->fail(
1813
            'Field with identifier "name" in language "eng-US" could not be found or has empty value.'
1814
        );
1815
    }
1816
1817
    /**
1818
     * Test for the createContentDraft() method.
1819
     *
1820
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft($contentInfo, $versionInfo)
1821
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1822
     */
1823 View Code Duplication
    public function testCreateContentDraftWithSecondParameter()
1824
    {
1825
        $repository = $this->getRepository();
1826
1827
        $contentService = $repository->getContentService();
1828
1829
        /* BEGIN: Use Case */
1830
        $contentVersion2 = $this->createContentVersion2();
1831
1832
        // Now we create a new draft from the initial version
1833
        $draftedContentReloaded = $contentService->createContentDraft(
1834
            $contentVersion2->contentInfo,
1835
            $contentVersion2->getVersionInfo()
1836
        );
1837
        /* END: Use Case */
1838
1839
        $this->assertEquals(3, $draftedContentReloaded->getVersionInfo()->versionNo);
1840
    }
1841
1842
    /**
1843
     * Test for the createContentDraft() method with third parameter.
1844
     *
1845
     * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft
1846
     */
1847 View Code Duplication
    public function testCreateContentDraftWithThirdParameter()
1848
    {
1849
        $repository = $this->getRepository();
1850
1851
        $contentService = $repository->getContentService();
1852
1853
        $content = $contentService->loadContent(4);
1854
        $user = $this->createUserVersion1();
1855
1856
        $draftContent = $contentService->createContentDraft(
1857
            $content->contentInfo,
1858
            $content->getVersionInfo(),
1859
            $user
1860
        );
1861
1862
        $this->assertInstanceOf(
1863
            Content::class,
1864
            $draftContent
1865
        );
1866
    }
1867
1868
    /**
1869
     * Test for the publishVersion() method.
1870
     *
1871
     * @see \eZ\Publish\API\Repository\ContentService::publishVersion()
1872
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
1873
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
1874
     */
1875 View Code Duplication
    public function testPublishVersionFromContentDraft()
1876
    {
1877
        $repository = $this->getRepository();
1878
1879
        $contentService = $repository->getContentService();
1880
1881
        /* BEGIN: Use Case */
1882
        $contentVersion2 = $this->createContentVersion2();
1883
        /* END: Use Case */
1884
1885
        $versionInfo = $contentService->loadVersionInfo($contentVersion2->contentInfo);
1886
1887
        $this->assertEquals(
1888
            array(
1889
                'status' => VersionInfo::STATUS_PUBLISHED,
1890
                'versionNo' => 2,
1891
            ),
1892
            array(
1893
                'status' => $versionInfo->status,
1894
                'versionNo' => $versionInfo->versionNo,
1895
            )
1896
        );
1897
        $this->assertTrue($versionInfo->isPublished());
1898
        $this->assertFalse($versionInfo->isDraft());
1899
        $this->assertFalse($versionInfo->isArchived());
1900
    }
1901
1902
    /**
1903
     * Test for the publishVersion() method.
1904
     *
1905
     * @see \eZ\Publish\API\Repository\ContentService::publishVersion()
1906
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
1907
     */
1908 View Code Duplication
    public function testPublishVersionFromContentDraftArchivesOldVersion()
1909
    {
1910
        $repository = $this->getRepository();
1911
1912
        $contentService = $repository->getContentService();
1913
1914
        /* BEGIN: Use Case */
1915
        $contentVersion2 = $this->createContentVersion2();
1916
        /* END: Use Case */
1917
1918
        $versionInfo = $contentService->loadVersionInfo($contentVersion2->contentInfo, 1);
1919
1920
        $this->assertEquals(
1921
            array(
1922
                'status' => VersionInfo::STATUS_ARCHIVED,
1923
                'versionNo' => 1,
1924
            ),
1925
            array(
1926
                'status' => $versionInfo->status,
1927
                'versionNo' => $versionInfo->versionNo,
1928
            )
1929
        );
1930
        $this->assertTrue($versionInfo->isArchived());
1931
        $this->assertFalse($versionInfo->isDraft());
1932
        $this->assertFalse($versionInfo->isPublished());
1933
    }
1934
1935
    /**
1936
     * Test for the publishVersion() method.
1937
     *
1938
     * @see \eZ\Publish\API\Repository\ContentService::publishVersion()
1939
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
1940
     */
1941
    public function testPublishVersionFromContentDraftUpdatesContentInfoCurrentVersion()
1942
    {
1943
        /* BEGIN: Use Case */
1944
        $contentVersion2 = $this->createContentVersion2();
1945
        /* END: Use Case */
1946
1947
        $this->assertEquals(2, $contentVersion2->contentInfo->currentVersionNo);
1948
    }
1949
1950
    /**
1951
     * Test for the publishVersion() method.
1952
     *
1953
     * @see \eZ\Publish\API\Repository\ContentService::publishVersion()
1954
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
1955
     */
1956 View Code Duplication
    public function testPublishVersionFromOldContentDraftArchivesNewerVersionNo()
1957
    {
1958
        $repository = $this->getRepository();
1959
1960
        $contentService = $repository->getContentService();
1961
1962
        /* BEGIN: Use Case */
1963
        $content = $this->createContentVersion1();
1964
1965
        // Create a new draft with versionNo = 2
1966
        $draftedContentVersion2 = $contentService->createContentDraft($content->contentInfo);
1967
1968
        // Create another new draft with versionNo = 3
1969
        $draftedContentVersion3 = $contentService->createContentDraft($content->contentInfo);
1970
1971
        // Publish draft with versionNo = 3
1972
        $contentService->publishVersion($draftedContentVersion3->getVersionInfo());
1973
1974
        // Publish the first draft with versionNo = 2
1975
        // currentVersionNo is now 2, versionNo 3 will be archived
1976
        $publishedDraft = $contentService->publishVersion($draftedContentVersion2->getVersionInfo());
1977
        /* END: Use Case */
1978
1979
        $this->assertEquals(2, $publishedDraft->contentInfo->currentVersionNo);
1980
    }
1981
1982
    /**
1983
     * Test for the publishVersion() method, and that it creates limited archives.
1984
     *
1985
     * @todo Adapt this when per content type archive limited is added on repository Content Type model.
1986
     * @see \eZ\Publish\API\Repository\ContentService::publishVersion()
1987
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
1988
     */
1989
    public function testPublishVersionNotCreatingUnlimitedArchives()
1990
    {
1991
        $repository = $this->getRepository();
1992
1993
        $contentService = $repository->getContentService();
1994
1995
        $content = $this->createContentVersion1();
1996
1997
        // load first to make sure list gets updated also (cache)
1998
        $versionInfoList = $contentService->loadVersions($content->contentInfo);
1999
        $this->assertEquals(1, count($versionInfoList));
2000
        $this->assertEquals(1, $versionInfoList[0]->versionNo);
2001
2002
        // Create a new draft with versionNo = 2
2003
        $draftedContentVersion = $contentService->createContentDraft($content->contentInfo);
2004
        $contentService->publishVersion($draftedContentVersion->getVersionInfo());
2005
2006
        // Create a new draft with versionNo = 3
2007
        $draftedContentVersion = $contentService->createContentDraft($content->contentInfo);
2008
        $contentService->publishVersion($draftedContentVersion->getVersionInfo());
2009
2010
        // Create a new draft with versionNo = 4
2011
        $draftedContentVersion = $contentService->createContentDraft($content->contentInfo);
2012
        $contentService->publishVersion($draftedContentVersion->getVersionInfo());
2013
2014
        // Create a new draft with versionNo = 5
2015
        $draftedContentVersion = $contentService->createContentDraft($content->contentInfo);
2016
        $contentService->publishVersion($draftedContentVersion->getVersionInfo());
2017
2018
        // Create a new draft with versionNo = 6
2019
        $draftedContentVersion = $contentService->createContentDraft($content->contentInfo);
2020
        $contentService->publishVersion($draftedContentVersion->getVersionInfo());
2021
2022
        // Create a new draft with versionNo = 7
2023
        $draftedContentVersion = $contentService->createContentDraft($content->contentInfo);
2024
        $contentService->publishVersion($draftedContentVersion->getVersionInfo());
2025
2026
        $versionInfoList = $contentService->loadVersions($content->contentInfo);
2027
2028
        $this->assertEquals(6, count($versionInfoList));
2029
        $this->assertEquals(2, $versionInfoList[0]->versionNo);
2030
        $this->assertEquals(7, $versionInfoList[5]->versionNo);
2031
2032
        $this->assertEquals(
2033
            [
2034
                VersionInfo::STATUS_ARCHIVED,
2035
                VersionInfo::STATUS_ARCHIVED,
2036
                VersionInfo::STATUS_ARCHIVED,
2037
                VersionInfo::STATUS_ARCHIVED,
2038
                VersionInfo::STATUS_ARCHIVED,
2039
                VersionInfo::STATUS_PUBLISHED,
2040
            ],
2041
            [
2042
                $versionInfoList[0]->status,
2043
                $versionInfoList[1]->status,
2044
                $versionInfoList[2]->status,
2045
                $versionInfoList[3]->status,
2046
                $versionInfoList[4]->status,
2047
                $versionInfoList[5]->status,
2048
            ]
2049
        );
2050
    }
2051
2052
    /**
2053
     * Test for the newContentMetadataUpdateStruct() method.
2054
     *
2055
     * @covers \eZ\Publish\API\Repository\ContentService::newContentMetadataUpdateStruct
2056
     * @group user
2057
     */
2058
    public function testNewContentMetadataUpdateStruct()
2059
    {
2060
        $repository = $this->getRepository();
2061
2062
        /* BEGIN: Use Case */
2063
        $contentService = $repository->getContentService();
2064
2065
        // Creates a new metadata update struct
2066
        $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
2067
2068
        foreach ($metadataUpdate as $propertyName => $propertyValue) {
0 ignored issues
show
Bug introduced by
The expression $metadataUpdate of type object<eZ\Publish\API\Re...ntMetadataUpdateStruct> is not traversable.
Loading history...
2069
            $this->assertNull($propertyValue, "Property '{$propertyName}' initial value should be null'");
2070
        }
2071
2072
        $metadataUpdate->remoteId = 'aaaabbbbccccddddeeeeffff11112222';
2073
        $metadataUpdate->mainLanguageCode = 'eng-GB';
2074
        $metadataUpdate->alwaysAvailable = false;
2075
        /* END: Use Case */
2076
2077
        $this->assertInstanceOf(
2078
            ContentMetadataUpdateStruct::class,
2079
            $metadataUpdate
2080
        );
2081
    }
2082
2083
    /**
2084
     * Test for the updateContentMetadata() method.
2085
     *
2086
     * @return \eZ\Publish\API\Repository\Values\Content\Content
2087
     *
2088
     * @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata()
2089
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
2090
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentMetadataUpdateStruct
2091
     * @group user
2092
     */
2093
    public function testUpdateContentMetadata()
2094
    {
2095
        $repository = $this->getRepository();
2096
2097
        $contentService = $repository->getContentService();
2098
2099
        /* BEGIN: Use Case */
2100
        $content = $this->createContentVersion1();
2101
2102
        // Creates a metadata update struct
2103
        $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
2104
2105
        $metadataUpdate->remoteId = 'aaaabbbbccccddddeeeeffff11112222';
2106
        $metadataUpdate->mainLanguageCode = 'eng-GB';
2107
        $metadataUpdate->alwaysAvailable = false;
2108
        $metadataUpdate->publishedDate = $this->createDateTime(441759600); // 1984/01/01
2109
        $metadataUpdate->modificationDate = $this->createDateTime(441759600); // 1984/01/01
2110
2111
        // Update the metadata of the published content object
2112
        $content = $contentService->updateContentMetadata(
2113
            $content->contentInfo,
2114
            $metadataUpdate
2115
        );
2116
        /* END: Use Case */
2117
2118
        $this->assertInstanceOf(
2119
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
2120
            $content
2121
        );
2122
2123
        return $content;
2124
    }
2125
2126
    /**
2127
     * Test for the updateContentMetadata() method.
2128
     *
2129
     * @param \eZ\Publish\API\Repository\Values\Content\Content $content
2130
     *
2131
     * @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata()
2132
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
2133
     */
2134
    public function testUpdateContentMetadataSetsExpectedProperties($content)
2135
    {
2136
        $contentInfo = $content->contentInfo;
2137
2138
        $this->assertEquals(
2139
            array(
2140
                'remoteId' => 'aaaabbbbccccddddeeeeffff11112222',
2141
                'sectionId' => $this->generateId('section', 1),
2142
                'alwaysAvailable' => false,
2143
                'currentVersionNo' => 1,
2144
                'mainLanguageCode' => 'eng-GB',
2145
                'modificationDate' => $this->createDateTime(441759600),
2146
                'ownerId' => $this->getRepository()->getCurrentUser()->id,
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::getCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. Get current user. Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}

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.

Loading history...
2147
                'published' => true,
2148
                'publishedDate' => $this->createDateTime(441759600),
2149
            ),
2150
            array(
2151
                'remoteId' => $contentInfo->remoteId,
2152
                'sectionId' => $contentInfo->sectionId,
2153
                'alwaysAvailable' => $contentInfo->alwaysAvailable,
2154
                'currentVersionNo' => $contentInfo->currentVersionNo,
2155
                'mainLanguageCode' => $contentInfo->mainLanguageCode,
2156
                'modificationDate' => $contentInfo->modificationDate,
2157
                'ownerId' => $contentInfo->ownerId,
2158
                'published' => $contentInfo->published,
2159
                'publishedDate' => $contentInfo->publishedDate,
2160
            )
2161
        );
2162
    }
2163
2164
    /**
2165
     * Test for the updateContentMetadata() method.
2166
     *
2167
     * @param \eZ\Publish\API\Repository\Values\Content\Content $content
2168
     *
2169
     * @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata()
2170
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
2171
     */
2172
    public function testUpdateContentMetadataNotUpdatesContentVersion($content)
2173
    {
2174
        $this->assertEquals(1, $content->getVersionInfo()->versionNo);
2175
    }
2176
2177
    /**
2178
     * Test for the updateContentMetadata() method.
2179
     *
2180
     * @covers \eZ\Publish\API\Repository\ContentService::updateContentMetadata()
2181
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2182
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
2183
     */
2184
    public function testUpdateContentMetadataThrowsInvalidArgumentExceptionOnDuplicateRemoteId()
2185
    {
2186
        $repository = $this->getRepository();
2187
2188
        $contentService = $repository->getContentService();
2189
2190
        /* BEGIN: Use Case */
2191
        // RemoteId of the "Media" page of an eZ Publish demo installation
2192
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
2193
2194
        $content = $this->createContentVersion1();
2195
2196
        // Creates a metadata update struct
2197
        $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
2198
        $metadataUpdate->remoteId = $mediaRemoteId;
2199
2200
        // This call will fail with an "InvalidArgumentException", because the
2201
        // specified remoteId is already used by the "Media" page.
2202
        $contentService->updateContentMetadata(
2203
            $content->contentInfo,
2204
            $metadataUpdate
2205
        );
2206
        /* END: Use Case */
2207
    }
2208
2209
    /**
2210
     * Test for the updateContentMetadata() method.
2211
     *
2212
     * @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata
2213
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2214
     */
2215
    public function testUpdateContentMetadataThrowsInvalidArgumentExceptionOnNoMetadataPropertiesSet()
2216
    {
2217
        $repository = $this->getRepository();
2218
2219
        $contentService = $repository->getContentService();
2220
2221
        $contentInfo = $contentService->loadContentInfo(4);
2222
        $contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct();
2223
2224
        // Throws an exception because no properties are set in $contentMetadataUpdateStruct
2225
        $contentService->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct);
2226
    }
2227
2228
    /**
2229
     * Test for the deleteContent() method.
2230
     *
2231
     * @see \eZ\Publish\API\Repository\ContentService::deleteContent()
2232
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2233
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
2234
     */
2235 View Code Duplication
    public function testDeleteContent()
2236
    {
2237
        $repository = $this->getRepository();
2238
2239
        $contentService = $repository->getContentService();
2240
        $locationService = $repository->getLocationService();
2241
2242
        /* BEGIN: Use Case */
2243
        $contentVersion2 = $this->createContentVersion2();
2244
2245
        // Load the locations for this content object
2246
        $locations = $locationService->loadLocations($contentVersion2->contentInfo);
2247
2248
        // This will delete the content, all versions and the associated locations
2249
        $contentService->deleteContent($contentVersion2->contentInfo);
2250
        /* END: Use Case */
2251
2252
        foreach ($locations as $location) {
2253
            $locationService->loadLocation($location->id);
2254
        }
2255
    }
2256
2257
    /**
2258
     * Test for the deleteContent() method.
2259
     *
2260
     * Test for issue EZP-21057:
2261
     * "contentService: Unable to delete a content with an empty file attribute"
2262
     *
2263
     * @see \eZ\Publish\API\Repository\ContentService::deleteContent()
2264
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2265
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
2266
     */
2267 View Code Duplication
    public function testDeleteContentWithEmptyBinaryField()
2268
    {
2269
        $repository = $this->getRepository();
2270
2271
        $contentService = $repository->getContentService();
2272
        $locationService = $repository->getLocationService();
2273
2274
        /* BEGIN: Use Case */
2275
        $contentVersion = $this->createContentVersion1EmptyBinaryField();
2276
2277
        // Load the locations for this content object
2278
        $locations = $locationService->loadLocations($contentVersion->contentInfo);
2279
2280
        // This will delete the content, all versions and the associated locations
2281
        $contentService->deleteContent($contentVersion->contentInfo);
2282
        /* END: Use Case */
2283
2284
        foreach ($locations as $location) {
2285
            $locationService->loadLocation($location->id);
2286
        }
2287
    }
2288
2289
    /**
2290
     * Test for the loadContentDrafts() method.
2291
     *
2292
     * @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts()
2293
     */
2294
    public function testLoadContentDraftsReturnsEmptyArrayByDefault()
2295
    {
2296
        $repository = $this->getRepository();
2297
2298
        /* BEGIN: Use Case */
2299
        $contentService = $repository->getContentService();
2300
2301
        $contentDrafts = $contentService->loadContentDrafts();
2302
        /* END: Use Case */
2303
2304
        $this->assertSame(array(), $contentDrafts);
2305
    }
2306
2307
    /**
2308
     * Test for the loadContentDrafts() method.
2309
     *
2310
     * @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts()
2311
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
2312
     */
2313
    public function testLoadContentDrafts()
2314
    {
2315
        $repository = $this->getRepository();
2316
2317
        /* BEGIN: Use Case */
2318
        // Remote ids of the "Media" and the "eZ Publish Demo Design ..." page
2319
        // of a eZ Publish demo installation.
2320
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
2321
        $demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f';
2322
2323
        $contentService = $repository->getContentService();
2324
2325
        // "Media" content object
2326
        $mediaContentInfo = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
2327
2328
        // "eZ Publish Demo Design ..." content object
2329
        $demoDesignContentInfo = $contentService->loadContentInfoByRemoteId($demoDesignRemoteId);
2330
2331
        // Create some drafts
2332
        $contentService->createContentDraft($mediaContentInfo);
2333
        $contentService->createContentDraft($demoDesignContentInfo);
2334
2335
        // Now $contentDrafts should contain two drafted versions
2336
        $draftedVersions = $contentService->loadContentDrafts();
2337
        /* END: Use Case */
2338
2339
        $actual = array(
2340
            $draftedVersions[0]->status,
2341
            $draftedVersions[0]->getContentInfo()->remoteId,
2342
            $draftedVersions[1]->status,
2343
            $draftedVersions[1]->getContentInfo()->remoteId,
2344
        );
2345
        sort($actual, SORT_STRING);
2346
2347
        $this->assertEquals(
2348
            array(
2349
                VersionInfo::STATUS_DRAFT,
2350
                VersionInfo::STATUS_DRAFT,
2351
                $demoDesignRemoteId,
2352
                $mediaRemoteId,
2353
            ),
2354
            $actual
2355
        );
2356
    }
2357
2358
    /**
2359
     * Test for the loadContentDrafts() method.
2360
     *
2361
     * @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts($user)
2362
     */
2363
    public function testLoadContentDraftsWithFirstParameter()
2364
    {
2365
        $repository = $this->getRepository();
2366
2367
        /* BEGIN: Use Case */
2368
        $user = $this->createUserVersion1();
2369
2370
        // Get current user
2371
        $oldCurrentUser = $repository->getCurrentUser();
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::getCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. Get current user. Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}

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.

Loading history...
2372
2373
        // Set new editor as user
2374
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

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.

Loading history...
2375
2376
        // Remote id of the "Media" content object in an eZ Publish demo installation.
2377
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
2378
2379
        $contentService = $repository->getContentService();
2380
2381
        // "Media" content object
2382
        $mediaContentInfo = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
2383
2384
        // Create a content draft
2385
        $contentService->createContentDraft($mediaContentInfo);
2386
2387
        // Reset to previous current user
2388
        $repository->setCurrentUser($oldCurrentUser);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

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.

Loading history...
2389
2390
        // Now $contentDrafts for the previous current user and the new user
2391
        $newCurrentUserDrafts = $contentService->loadContentDrafts($user);
2392
        $oldCurrentUserDrafts = $contentService->loadContentDrafts($oldCurrentUser);
2393
        /* END: Use Case */
2394
2395
        $this->assertSame(array(), $oldCurrentUserDrafts);
2396
2397
        $this->assertEquals(
2398
            array(
2399
                VersionInfo::STATUS_DRAFT,
2400
                $mediaRemoteId,
2401
            ),
2402
            array(
2403
                $newCurrentUserDrafts[0]->status,
2404
                $newCurrentUserDrafts[0]->getContentInfo()->remoteId,
2405
            )
2406
        );
2407
        $this->assertTrue($newCurrentUserDrafts[0]->isDraft());
2408
        $this->assertFalse($newCurrentUserDrafts[0]->isArchived());
2409
        $this->assertFalse($newCurrentUserDrafts[0]->isPublished());
2410
    }
2411
2412
    /**
2413
     * Test for the loadVersionInfo() method.
2414
     *
2415
     * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo($contentInfo, $versionNo)
2416
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
2417
     */
2418
    public function testLoadVersionInfoWithSecondParameter()
2419
    {
2420
        $repository = $this->getRepository();
2421
2422
        $contentService = $repository->getContentService();
2423
2424
        /* BEGIN: Use Case */
2425
        $publishedContent = $this->createContentVersion1();
2426
2427
        $draftContent = $contentService->createContentDraft($publishedContent->contentInfo);
0 ignored issues
show
Unused Code introduced by
$draftContent is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2428
2429
        // Will return the VersionInfo of the $draftContent
2430
        $versionInfo = $contentService->loadVersionInfoById($publishedContent->id, 2);
2431
        /* END: Use Case */
2432
2433
        $this->assertEquals(2, $versionInfo->versionNo);
2434
2435
        // Check that ContentInfo contained in VersionInfo has correct main Location id set
2436
        $this->assertEquals(
2437
            $publishedContent->getVersionInfo()->getContentInfo()->mainLocationId,
2438
            $versionInfo->getContentInfo()->mainLocationId
2439
        );
2440
    }
2441
2442
    /**
2443
     * Test for the loadVersionInfo() method.
2444
     *
2445
     * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo($contentInfo, $versionNo)
2446
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2447
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoWithSecondParameter
2448
     */
2449
    public function testLoadVersionInfoThrowsNotFoundExceptionWithSecondParameter()
2450
    {
2451
        $repository = $this->getRepository();
2452
2453
        $contentService = $repository->getContentService();
2454
2455
        /* BEGIN: Use Case */
2456
        $draft = $this->createContentDraftVersion1();
2457
2458
        // This call will fail with a "NotFoundException", because not versionNo
2459
        // 2 exists for this content object.
2460
        $contentService->loadVersionInfo($draft->contentInfo, 2);
2461
        /* END: Use Case */
2462
    }
2463
2464
    /**
2465
     * Test for the loadVersionInfoById() method.
2466
     *
2467
     * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById($contentId, $versionNo)
2468
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoWithSecondParameter
2469
     */
2470
    public function testLoadVersionInfoByIdWithSecondParameter()
2471
    {
2472
        $repository = $this->getRepository();
2473
2474
        $contentService = $repository->getContentService();
2475
2476
        /* BEGIN: Use Case */
2477
        $publishedContent = $this->createContentVersion1();
2478
2479
        $draftContent = $contentService->createContentDraft($publishedContent->contentInfo);
2480
2481
        // Will return the VersionInfo of the $draftContent
2482
        $versionInfo = $contentService->loadVersionInfoById($publishedContent->id, 2);
2483
        /* END: Use Case */
2484
2485
        $this->assertEquals(2, $versionInfo->versionNo);
2486
2487
        // Check that ContentInfo contained in VersionInfo has correct main Location id set
2488
        $this->assertEquals(
2489
            $publishedContent->getVersionInfo()->getContentInfo()->mainLocationId,
2490
            $versionInfo->getContentInfo()->mainLocationId
2491
        );
2492
2493
        return [
2494
            'versionInfo' => $versionInfo,
2495
            'draftContent' => $draftContent,
2496
        ];
2497
    }
2498
2499
    /**
2500
     * Test for the returned value of the loadVersionInfoById() method.
2501
     *
2502
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoByIdWithSecondParameter
2503
     * @covers \eZ\Publish\API\Repository\ContentService::loadVersionInfoById
2504
     *
2505
     * @param array $data
2506
     */
2507
    public function testLoadVersionInfoByIdWithSecondParameterSetsExpectedVersionInfo(array $data)
2508
    {
2509
        /** @var \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo */
2510
        $versionInfo = $data['versionInfo'];
2511
        /** @var \eZ\Publish\API\Repository\Values\Content\Content $draftContent */
2512
        $draftContent = $data['draftContent'];
2513
2514
        $this->assertPropertiesCorrect(
2515
            [
2516
                'names' => [
2517
                    'eng-US' => 'An awesome forum',
2518
                ],
2519
                'contentInfo' => new ContentInfo([
2520
                    'id' => $draftContent->contentInfo->id,
2521
                    'contentTypeId' => 28,
2522
                    'name' => 'An awesome forum',
2523
                    'sectionId' => 1,
2524
                    'currentVersionNo' => 1,
2525
                    'published' => true,
2526
                    'ownerId' => 14,
2527
                    // this Content Object is created at the test runtime
2528
                    'modificationDate' => $versionInfo->contentInfo->modificationDate,
2529
                    'publishedDate' => $versionInfo->contentInfo->publishedDate,
2530
                    'alwaysAvailable' => 1,
2531
                    'remoteId' => 'abcdef0123456789abcdef0123456789',
2532
                    'mainLanguageCode' => 'eng-US',
2533
                    'mainLocationId' => $draftContent->contentInfo->mainLocationId,
2534
                    'status' => ContentInfo::STATUS_PUBLISHED,
2535
                ]),
2536
                'id' => $draftContent->versionInfo->id,
2537
                'versionNo' => 2,
2538
                'creatorId' => 14,
2539
                'status' => 0,
2540
                'initialLanguageCode' => 'eng-US',
2541
                'languageCodes' => [
2542
                    'eng-US',
2543
                ],
2544
            ],
2545
            $versionInfo
2546
        );
2547
    }
2548
2549
    /**
2550
     * Test for the loadVersionInfoById() method.
2551
     *
2552
     * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById($contentId, $versionNo)
2553
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2554
     */
2555 View Code Duplication
    public function testLoadVersionInfoByIdThrowsNotFoundExceptionWithSecondParameter()
2556
    {
2557
        $repository = $this->getRepository();
2558
2559
        $contentService = $repository->getContentService();
2560
2561
        /* BEGIN: Use Case */
2562
        $content = $this->createContentVersion1();
2563
2564
        // This call will fail with a "NotFoundException", because not versionNo
2565
        // 2 exists for this content object.
2566
        $contentService->loadVersionInfoById($content->id, 2);
2567
        /* END: Use Case */
2568
    }
2569
2570
    /**
2571
     * Test for the loadContentByVersionInfo() method.
2572
     *
2573
     * @see \eZ\Publish\API\Repository\ContentService::loadContentByVersionInfo($versionInfo, $languages)
2574
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
2575
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByVersionInfo
2576
     */
2577
    public function testLoadContentByVersionInfoWithSecondParameter()
2578
    {
2579
        $repository = $this->getRepository();
2580
2581
        $sectionId = $this->generateId('section', 1);
2582
        /* BEGIN: Use Case */
2583
        $contentTypeService = $repository->getContentTypeService();
2584
2585
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
2586
2587
        $contentService = $repository->getContentService();
2588
2589
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
2590
2591
        $contentCreateStruct->setField('name', 'Sindelfingen forum²');
2592
2593
        $contentCreateStruct->setField('name', 'Sindelfingen forum²³', 'eng-GB');
2594
2595
        $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789';
2596
        // $sectionId contains the ID of section 1
2597
        $contentCreateStruct->sectionId = $sectionId;
2598
        $contentCreateStruct->alwaysAvailable = true;
2599
2600
        // Create a new content draft
2601
        $content = $contentService->createContent($contentCreateStruct);
2602
2603
        // Now publish this draft
2604
        $publishedContent = $contentService->publishVersion($content->getVersionInfo());
2605
2606
        // Will return a content instance with fields in "eng-US"
2607
        $reloadedContent = $contentService->loadContentByVersionInfo(
2608
            $publishedContent->getVersionInfo(),
2609
            array(
2610
                'eng-GB',
2611
            ),
2612
            false
2613
        );
2614
        /* END: Use Case */
2615
2616
        $actual = array();
2617 View Code Duplication
        foreach ($reloadedContent->getFields() as $field) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2618
            $actual[] = new Field(
2619
                array(
2620
                    'id' => 0,
2621
                    'value' => ($field->value !== null ? true : null), // Actual value tested by FieldType integration tests
2622
                    'languageCode' => $field->languageCode,
2623
                    'fieldDefIdentifier' => $field->fieldDefIdentifier,
2624
                )
2625
            );
2626
        }
2627
        usort(
2628
            $actual,
2629 View Code Duplication
            function ($field1, $field2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2630
                if (0 === ($return = strcasecmp($field1->fieldDefIdentifier, $field2->fieldDefIdentifier))) {
2631
                    return strcasecmp($field1->languageCode, $field2->languageCode);
2632
                }
2633
2634
                return $return;
2635
            }
2636
        );
2637
2638
        $expected = array(
2639
            new Field(
2640
                array(
2641
                    'id' => 0,
2642
                    'value' => true,
2643
                    'languageCode' => 'eng-GB',
2644
                    'fieldDefIdentifier' => 'description',
2645
                )
2646
            ),
2647
            new Field(
2648
                array(
2649
                    'id' => 0,
2650
                    'value' => true,
2651
                    'languageCode' => 'eng-GB',
2652
                    'fieldDefIdentifier' => 'name',
2653
                )
2654
            ),
2655
        );
2656
2657
        $this->assertEquals($expected, $actual);
2658
    }
2659
2660
    /**
2661
     * Test for the loadContentByContentInfo() method.
2662
     *
2663
     * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo($contentInfo, $languages)
2664
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfo
2665
     */
2666
    public function testLoadContentByContentInfoWithLanguageParameters()
2667
    {
2668
        $repository = $this->getRepository();
2669
2670
        $sectionId = $this->generateId('section', 1);
2671
        /* BEGIN: Use Case */
2672
        $contentTypeService = $repository->getContentTypeService();
2673
2674
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
2675
2676
        $contentService = $repository->getContentService();
2677
2678
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
2679
2680
        $contentCreateStruct->setField('name', 'Sindelfingen forum²');
2681
2682
        $contentCreateStruct->setField('name', 'Sindelfingen forum²³', 'eng-GB');
2683
2684
        $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789';
2685
        // $sectionId contains the ID of section 1
2686
        $contentCreateStruct->sectionId = $sectionId;
2687
        $contentCreateStruct->alwaysAvailable = true;
2688
2689
        // Create a new content draft
2690
        $content = $contentService->createContent($contentCreateStruct);
2691
2692
        // Now publish this draft
2693
        $publishedContent = $contentService->publishVersion($content->getVersionInfo());
2694
2695
        // Will return a content instance with fields in "eng-US"
2696
        $reloadedContent = $contentService->loadContentByContentInfo(
2697
            $publishedContent->contentInfo,
2698
            array(
2699
                'eng-US',
2700
            ),
2701
            null,
2702
            false
2703
        );
2704
        /* END: Use Case */
2705
2706
        $actual = $this->normalizeFields($reloadedContent->getFields());
2707
2708
        $expected = array(
2709
            new Field(
2710
                array(
2711
                    'id' => 0,
2712
                    'value' => true,
2713
                    'languageCode' => 'eng-US',
2714
                    'fieldDefIdentifier' => 'description',
2715
                    'fieldTypeIdentifier' => 'ezrichtext',
2716
                )
2717
            ),
2718
            new Field(
2719
                array(
2720
                    'id' => 0,
2721
                    'value' => true,
2722
                    'languageCode' => 'eng-US',
2723
                    'fieldDefIdentifier' => 'name',
2724
                    'fieldTypeIdentifier' => 'ezstring',
2725
                )
2726
            ),
2727
        );
2728
2729
        $this->assertEquals($expected, $actual);
2730
2731
        // Will return a content instance with fields in "eng-GB" (versions prior to 6.0.0-beta9 returned "eng-US" also)
2732
        $reloadedContent = $contentService->loadContentByContentInfo(
2733
            $publishedContent->contentInfo,
2734
            array(
2735
                'eng-GB',
2736
            ),
2737
            null,
2738
            true
2739
        );
2740
2741
        $actual = $this->normalizeFields($reloadedContent->getFields());
2742
2743
        $expected = array(
2744
            new Field(
2745
                array(
2746
                    'id' => 0,
2747
                    'value' => true,
2748
                    'languageCode' => 'eng-GB',
2749
                    'fieldDefIdentifier' => 'description',
2750
                    'fieldTypeIdentifier' => 'ezrichtext',
2751
                )
2752
            ),
2753
            new Field(
2754
                array(
2755
                    'id' => 0,
2756
                    'value' => true,
2757
                    'languageCode' => 'eng-GB',
2758
                    'fieldDefIdentifier' => 'name',
2759
                    'fieldTypeIdentifier' => 'ezstring',
2760
                )
2761
            ),
2762
        );
2763
2764
        $this->assertEquals($expected, $actual);
2765
2766
        // Will return a content instance with fields in main language "eng-US", as "fre-FR" does not exists
2767
        $reloadedContent = $contentService->loadContentByContentInfo(
2768
            $publishedContent->contentInfo,
2769
            array(
2770
                'fre-FR',
2771
            ),
2772
            null,
2773
            true
2774
        );
2775
2776
        $actual = $this->normalizeFields($reloadedContent->getFields());
2777
2778
        $expected = array(
2779
            new Field(
2780
                array(
2781
                    'id' => 0,
2782
                    'value' => true,
2783
                    'languageCode' => 'eng-US',
2784
                    'fieldDefIdentifier' => 'description',
2785
                    'fieldTypeIdentifier' => 'ezrichtext',
2786
                )
2787
            ),
2788
            new Field(
2789
                array(
2790
                    'id' => 0,
2791
                    'value' => true,
2792
                    'languageCode' => 'eng-US',
2793
                    'fieldDefIdentifier' => 'name',
2794
                    'fieldTypeIdentifier' => 'ezstring',
2795
                )
2796
            ),
2797
        );
2798
2799
        $this->assertEquals($expected, $actual);
2800
    }
2801
2802
    /**
2803
     * Test for the loadContentByContentInfo() method.
2804
     *
2805
     * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo($contentInfo, $languages, $versionNo)
2806
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfo
2807
     */
2808 View Code Duplication
    public function testLoadContentByContentInfoWithVersionNumberParameter()
2809
    {
2810
        $repository = $this->getRepository();
2811
2812
        $contentService = $repository->getContentService();
2813
2814
        /* BEGIN: Use Case */
2815
        $publishedContent = $this->createContentVersion1();
2816
2817
        $draftContent = $contentService->createContentDraft($publishedContent->contentInfo);
0 ignored issues
show
Unused Code introduced by
$draftContent is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2818
2819
        // This content instance is identical to $draftContent
2820
        $draftContentReloaded = $contentService->loadContentByContentInfo(
2821
            $publishedContent->contentInfo,
2822
            null,
2823
            2
2824
        );
2825
        /* END: Use Case */
2826
2827
        $this->assertEquals(
2828
            2,
2829
            $draftContentReloaded->getVersionInfo()->versionNo
2830
        );
2831
2832
        // Check that ContentInfo contained in reloaded draft Content has correct main Location id set
2833
        $this->assertEquals(
2834
            $publishedContent->versionInfo->contentInfo->mainLocationId,
2835
            $draftContentReloaded->versionInfo->contentInfo->mainLocationId
2836
        );
2837
    }
2838
2839
    /**
2840
     * Test for the loadContentByContentInfo() method.
2841
     *
2842
     * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo($contentInfo, $languages, $versionNo)
2843
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2844
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfoWithVersionNumberParameter
2845
     */
2846 View Code Duplication
    public function testLoadContentByContentInfoThrowsNotFoundExceptionWithVersionNumberParameter()
2847
    {
2848
        $repository = $this->getRepository();
2849
2850
        $contentService = $repository->getContentService();
2851
2852
        /* BEGIN: Use Case */
2853
        $content = $this->createContentVersion1();
2854
2855
        // This call will fail with a "NotFoundException", because no content
2856
        // with versionNo = 2 exists.
2857
        $contentService->loadContentByContentInfo($content->contentInfo, null, 2);
2858
        /* END: Use Case */
2859
    }
2860
2861
    /**
2862
     * Test for the loadContent() method.
2863
     *
2864
     * @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages)
2865
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
2866
     */
2867 View Code Duplication
    public function testLoadContentWithSecondParameter()
2868
    {
2869
        $repository = $this->getRepository();
2870
2871
        $contentService = $repository->getContentService();
2872
2873
        /* BEGIN: Use Case */
2874
        $draft = $this->createMultipleLanguageDraftVersion1();
2875
2876
        // This draft contains those fields localized with "eng-GB"
2877
        $draftLocalized = $contentService->loadContent($draft->id, array('eng-GB'), null, false);
2878
        /* END: Use Case */
2879
2880
        $this->assertLocaleFieldsEquals($draftLocalized->getFields(), 'eng-GB');
2881
2882
        return $draft;
2883
    }
2884
2885
    /**
2886
     * Test for the loadContent() method using undefined translation.
2887
     *
2888
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithSecondParameter
2889
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2890
     *
2891
     * @param \eZ\Publish\API\Repository\Values\Content\Content $contentDraft
2892
     */
2893
    public function testLoadContentWithSecondParameterThrowsNotFoundException(Content $contentDraft)
2894
    {
2895
        $repository = $this->getRepository();
2896
2897
        $contentService = $repository->getContentService();
2898
2899
        $contentService->loadContent($contentDraft->id, array('ger-DE'), null, false);
2900
    }
2901
2902
    /**
2903
     * Test for the loadContent() method.
2904
     *
2905
     * @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages, $versionNo)
2906
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
2907
     */
2908 View Code Duplication
    public function testLoadContentWithThirdParameter()
2909
    {
2910
        $repository = $this->getRepository();
2911
2912
        $contentService = $repository->getContentService();
2913
2914
        /* BEGIN: Use Case */
2915
        $publishedContent = $this->createContentVersion1();
2916
2917
        $draftContent = $contentService->createContentDraft($publishedContent->contentInfo);
0 ignored issues
show
Unused Code introduced by
$draftContent is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2918
2919
        // This content instance is identical to $draftContent
2920
        $draftContentReloaded = $contentService->loadContent($publishedContent->id, null, 2);
2921
        /* END: Use Case */
2922
2923
        $this->assertEquals(2, $draftContentReloaded->getVersionInfo()->versionNo);
2924
2925
        // Check that ContentInfo contained in reloaded draft Content has correct main Location id set
2926
        $this->assertEquals(
2927
            $publishedContent->versionInfo->contentInfo->mainLocationId,
2928
            $draftContentReloaded->versionInfo->contentInfo->mainLocationId
2929
        );
2930
    }
2931
2932
    /**
2933
     * Test for the loadContent() method.
2934
     *
2935
     * @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages, $versionNo)
2936
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
2937
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithThirdParameter
2938
     */
2939 View Code Duplication
    public function testLoadContentThrowsNotFoundExceptionWithThirdParameter()
2940
    {
2941
        $repository = $this->getRepository();
2942
2943
        $contentService = $repository->getContentService();
2944
2945
        /* BEGIN: Use Case */
2946
        $content = $this->createContentVersion1();
2947
2948
        // This call will fail with a "NotFoundException", because for this
2949
        // content object no versionNo=2 exists.
2950
        $contentService->loadContent($content->id, null, 2);
2951
        /* END: Use Case */
2952
    }
2953
2954
    /**
2955
     * Test for the loadContentByRemoteId() method.
2956
     *
2957
     * @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId($remoteId, $languages)
2958
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
2959
     */
2960 View Code Duplication
    public function testLoadContentByRemoteIdWithSecondParameter()
2961
    {
2962
        $repository = $this->getRepository();
2963
2964
        $contentService = $repository->getContentService();
2965
2966
        /* BEGIN: Use Case */
2967
        $draft = $this->createMultipleLanguageDraftVersion1();
2968
2969
        $contentService->publishVersion($draft->versionInfo);
2970
2971
        // This draft contains those fields localized with "eng-GB"
2972
        $draftLocalized = $contentService->loadContentByRemoteId(
2973
            $draft->contentInfo->remoteId,
2974
            array('eng-GB'),
2975
            null,
2976
            false
2977
        );
2978
        /* END: Use Case */
2979
2980
        $this->assertLocaleFieldsEquals($draftLocalized->getFields(), 'eng-GB');
2981
    }
2982
2983
    /**
2984
     * Test for the loadContentByRemoteId() method.
2985
     *
2986
     * @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId($remoteId, $languages, $versionNo)
2987
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
2988
     */
2989 View Code Duplication
    public function testLoadContentByRemoteIdWithThirdParameter()
2990
    {
2991
        $repository = $this->getRepository();
2992
2993
        $contentService = $repository->getContentService();
2994
2995
        /* BEGIN: Use Case */
2996
        $publishedContent = $this->createContentVersion1();
2997
2998
        $draftContent = $contentService->createContentDraft($publishedContent->contentInfo);
0 ignored issues
show
Unused Code introduced by
$draftContent is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2999
3000
        // This content instance is identical to $draftContent
3001
        $draftContentReloaded = $contentService->loadContentByRemoteId(
3002
            $publishedContent->contentInfo->remoteId,
3003
            null,
3004
            2
3005
        );
3006
        /* END: Use Case */
3007
3008
        $this->assertEquals(2, $draftContentReloaded->getVersionInfo()->versionNo);
3009
3010
        // Check that ContentInfo contained in reloaded draft Content has correct main Location id set
3011
        $this->assertEquals(
3012
            $publishedContent->versionInfo->contentInfo->mainLocationId,
3013
            $draftContentReloaded->versionInfo->contentInfo->mainLocationId
3014
        );
3015
    }
3016
3017
    /**
3018
     * Test for the loadContentByRemoteId() method.
3019
     *
3020
     * @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId($remoteId, $languages, $versionNo)
3021
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
3022
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteIdWithThirdParameter
3023
     */
3024
    public function testLoadContentByRemoteIdThrowsNotFoundExceptionWithThirdParameter()
3025
    {
3026
        $repository = $this->getRepository();
3027
3028
        $contentService = $repository->getContentService();
3029
3030
        /* BEGIN: Use Case */
3031
        $content = $this->createContentVersion1();
3032
3033
        // This call will fail with a "NotFoundException", because for this
3034
        // content object no versionNo=2 exists.
3035
        $contentService->loadContentByRemoteId(
3036
            $content->contentInfo->remoteId,
3037
            null,
3038
            2
3039
        );
3040
        /* END: Use Case */
3041
    }
3042
3043
    /**
3044
     * Test that retrieval of translated name field respects prioritized language list.
3045
     *
3046
     * @dataProvider getPrioritizedLanguageList
3047
     * @param string[]|null $languageCodes
3048
     */
3049
    public function testLoadContentWithPrioritizedLanguagesList($languageCodes)
3050
    {
3051
        $repository = $this->getRepository();
3052
3053
        $contentService = $repository->getContentService();
3054
3055
        $content = $this->createContentVersion2();
3056
3057
        $content = $contentService->loadContent($content->id, $languageCodes);
3058
3059
        $expectedName = $content->getVersionInfo()->getName(
3060
            isset($languageCodes[0]) ? $languageCodes[0] : null
3061
        );
3062
        $nameValue = $content->getFieldValue('name');
3063
        /** @var \eZ\Publish\Core\FieldType\TextLine\Value $nameValue */
3064
        self::assertEquals($expectedName, $nameValue->text);
3065
        self::assertEquals($expectedName, $content->getVersionInfo()->getName());
3066
        // Also check value on shortcut method on content
3067
        self::assertEquals($expectedName, $content->getName());
3068
    }
3069
3070
    /**
3071
     * @return array
3072
     */
3073
    public function getPrioritizedLanguageList()
3074
    {
3075
        return [
3076
            [['eng-US']],
3077
            [['eng-GB']],
3078
            [['eng-GB', 'eng-US']],
3079
            [['eng-US', 'eng-GB']],
3080
        ];
3081
    }
3082
3083
    /**
3084
     * Test for the deleteVersion() method.
3085
     *
3086
     * @see \eZ\Publish\API\Repository\ContentService::deleteVersion()
3087
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
3088
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
3089
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
3090
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
3091
     */
3092
    public function testDeleteVersion()
3093
    {
3094
        $repository = $this->getRepository();
3095
3096
        $contentService = $repository->getContentService();
3097
3098
        /* BEGIN: Use Case */
3099
        $content = $this->createContentVersion1();
3100
3101
        // Create new draft, because published or last version of the Content can't be deleted
3102
        $draft = $contentService->createContentDraft(
3103
            $content->getVersionInfo()->getContentInfo()
3104
        );
3105
3106
        // Delete the previously created draft
3107
        $contentService->deleteVersion($draft->getVersionInfo());
3108
        /* END: Use Case */
3109
3110
        $versions = $contentService->loadVersions($content->getVersionInfo()->getContentInfo());
3111
3112
        $this->assertCount(1, $versions);
3113
        $this->assertEquals(
3114
            $content->getVersionInfo()->id,
3115
            $versions[0]->id
3116
        );
3117
    }
3118
3119
    /**
3120
     * Test for the deleteVersion() method.
3121
     *
3122
     * @see \eZ\Publish\API\Repository\ContentService::deleteVersion()
3123
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
3124
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
3125
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
3126
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
3127
     */
3128
    public function testDeleteVersionThrowsBadStateExceptionOnPublishedVersion()
3129
    {
3130
        $repository = $this->getRepository();
3131
3132
        $contentService = $repository->getContentService();
3133
3134
        /* BEGIN: Use Case */
3135
        $content = $this->createContentVersion1();
3136
3137
        // This call will fail with a "BadStateException", because the content
3138
        // version is currently published.
3139
        $contentService->deleteVersion($content->getVersionInfo());
3140
        /* END: Use Case */
3141
    }
3142
3143
    /**
3144
     * Test for the deleteVersion() method.
3145
     *
3146
     * @see \eZ\Publish\API\Repository\ContentService::deleteVersion()
3147
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
3148
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
3149
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
3150
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
3151
     */
3152
    public function testDeleteVersionWorksIfOnlyVersionIsDraft()
3153
    {
3154
        $repository = $this->getRepository();
3155
3156
        $contentService = $repository->getContentService();
3157
3158
        /* BEGIN: Use Case */
3159
        $draft = $this->createContentDraftVersion1();
3160
3161
        $contentService->deleteVersion($draft->getVersionInfo());
3162
3163
        // This call will fail with a "NotFound", because we allow to delete content if remaining version is draft.
3164
        // Can normally only happen if there where always only a draft to begin with, simplifies UI edit API usage.
3165
        $contentService->loadContent($draft->id);
3166
        /* END: Use Case */
3167
    }
3168
3169
    /**
3170
     * Test for the loadVersions() method.
3171
     *
3172
     * @see \eZ\Publish\API\Repository\ContentService::loadVersions()
3173
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
3174
     *
3175
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[]
3176
     */
3177
    public function testLoadVersions()
3178
    {
3179
        $repository = $this->getRepository();
3180
3181
        $contentService = $repository->getContentService();
3182
3183
        /* BEGIN: Use Case */
3184
        $contentVersion2 = $this->createContentVersion2();
3185
3186
        // Load versions of this ContentInfo instance
3187
        $versions = $contentService->loadVersions($contentVersion2->contentInfo);
3188
        /* END: Use Case */
3189
3190
        $expectedVersionsOrder = [
3191
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 1),
3192
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 2),
3193
        ];
3194
3195
        $this->assertEquals($expectedVersionsOrder, $versions);
3196
3197
        return $versions;
3198
    }
3199
3200
    /**
3201
     * Test for the loadVersions() method.
3202
     *
3203
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersions
3204
     * @covers \eZ\Publish\Core\Repository\ContentService::loadVersions
3205
     *
3206
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo[] $versions
3207
     */
3208
    public function testLoadVersionsSetsExpectedVersionInfo(array $versions)
3209
    {
3210
        $this->assertCount(2, $versions);
3211
3212
        $expectedVersions = [
3213
            [
3214
                'versionNo' => 1,
3215
                'creatorId' => 14,
3216
                'status' => VersionInfo::STATUS_ARCHIVED,
3217
                'initialLanguageCode' => 'eng-US',
3218
                'languageCodes' => ['eng-US'],
3219
            ],
3220
            [
3221
                'versionNo' => 2,
3222
                'creatorId' => 10,
3223
                'status' => VersionInfo::STATUS_PUBLISHED,
3224
                'initialLanguageCode' => 'eng-US',
3225
                'languageCodes' => ['eng-US', 'eng-GB'],
3226
            ],
3227
        ];
3228
3229
        $this->assertPropertiesCorrect($expectedVersions[0], $versions[0]);
3230
        $this->assertPropertiesCorrect($expectedVersions[1], $versions[1]);
3231
        $this->assertEquals(
3232
            $versions[0]->creationDate->getTimestamp(),
3233
            $versions[1]->creationDate->getTimestamp(),
3234
            'Creation time did not match within delta of 2 seconds',
3235
            2
3236
        );
3237
        $this->assertEquals(
3238
            $versions[0]->modificationDate->getTimestamp(),
3239
            $versions[1]->modificationDate->getTimestamp(),
3240
            'Creation time did not match within delta of 2 seconds',
3241
            2
3242
        );
3243
        $this->assertTrue($versions[0]->isArchived());
3244
        $this->assertFalse($versions[0]->isDraft());
3245
        $this->assertFalse($versions[0]->isPublished());
3246
3247
        $this->assertTrue($versions[1]->isPublished());
3248
        $this->assertFalse($versions[1]->isDraft());
3249
        $this->assertFalse($versions[1]->isArchived());
3250
    }
3251
3252
    /**
3253
     * Test for the copyContent() method.
3254
     *
3255
     * @see \eZ\Publish\API\Repository\ContentService::copyContent()
3256
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
3257
     * @group field-type
3258
     */
3259 View Code Duplication
    public function testCopyContent()
3260
    {
3261
        $parentLocationId = $this->generateId('location', 56);
3262
3263
        $repository = $this->getRepository();
3264
3265
        $contentService = $repository->getContentService();
3266
        $locationService = $repository->getLocationService();
3267
3268
        /* BEGIN: Use Case */
3269
        $contentVersion2 = $this->createMultipleLanguageContentVersion2();
3270
3271
        // Configure new target location
3272
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3273
3274
        $targetLocationCreate->priority = 42;
3275
        $targetLocationCreate->hidden = true;
3276
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3277
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3278
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3279
3280
        // Copy content with all versions and drafts
3281
        $contentCopied = $contentService->copyContent(
3282
            $contentVersion2->contentInfo,
3283
            $targetLocationCreate
3284
        );
3285
        /* END: Use Case */
3286
3287
        $this->assertInstanceOf(
3288
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3289
            $contentCopied
3290
        );
3291
3292
        $this->assertNotEquals(
3293
            $contentVersion2->contentInfo->remoteId,
3294
            $contentCopied->contentInfo->remoteId
3295
        );
3296
3297
        $this->assertNotEquals(
3298
            $contentVersion2->id,
3299
            $contentCopied->id
3300
        );
3301
3302
        $this->assertEquals(
3303
            2,
3304
            count($contentService->loadVersions($contentCopied->contentInfo))
3305
        );
3306
3307
        $this->assertEquals(2, $contentCopied->getVersionInfo()->versionNo);
3308
3309
        $this->assertAllFieldsEquals($contentCopied->getFields());
3310
3311
        $this->assertDefaultContentStates($contentCopied->contentInfo);
3312
3313
        $this->assertNotNull(
3314
            $contentCopied->contentInfo->mainLocationId,
3315
            'Expected main location to be set given we provided a LocationCreateStruct'
3316
        );
3317
    }
3318
3319
    /**
3320
     * Test for the copyContent() method with ezsettings.default.content.retain_owner_on_copy set to false
3321
     * See settings/test/integration_legacy.yml for service override.
3322
     *
3323
     * @see \eZ\Publish\API\Repository\ContentService::copyContent()
3324
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
3325
     * @group field-type
3326
     */
3327
    public function testCopyContentWithNewOwner()
3328
    {
3329
        $parentLocationId = $this->generateId('location', 56);
3330
3331
        $repository = $this->getRepository();
3332
3333
        $contentService = $repository->getContentService();
3334
        $locationService = $repository->getLocationService();
3335
        $userService = $repository->getUserService();
3336
3337
        $newOwner = $this->createUser('new_owner', 'foo', 'bar');
3338
        /* BEGIN: Use Case */
3339
        /** @var \eZ\Publish\API\Repository\Values\Content\Content $contentVersion2 */
3340
        $contentVersion2 = $this->createContentDraftVersion1(
3341
            $parentLocationId,
3342
            'forum',
3343
            'name',
3344
            $newOwner
3345
        );
3346
3347
        // Configure new target location
3348
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3349
3350
        $targetLocationCreate->priority = 42;
3351
        $targetLocationCreate->hidden = true;
3352
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3353
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3354
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3355
3356
        // Copy content with all versions and drafts
3357
        $contentCopied = $contentService->copyContent(
3358
            $contentVersion2->contentInfo,
3359
            $targetLocationCreate
3360
        );
3361
        /* END: Use Case */
3362
3363
        $this->assertEquals(
3364
            $newOwner->id,
3365
            $contentVersion2->contentInfo->ownerId
3366
        );
3367
        $this->assertEquals(
3368
            $userService->loadUserByLogin('admin')->getUserId(),
3369
            $contentCopied->contentInfo->ownerId
3370
        );
3371
    }
3372
3373
    /**
3374
     * Test for the copyContent() method.
3375
     *
3376
     * @see \eZ\Publish\API\Repository\ContentService::copyContent($contentInfo, $destinationLocationCreateStruct, $versionInfo)
3377
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent
3378
     *
3379
     * @todo Fix to more descriptive name
3380
     */
3381 View Code Duplication
    public function testCopyContentWithThirdParameter()
3382
    {
3383
        $parentLocationId = $this->generateId('location', 56);
3384
3385
        $repository = $this->getRepository();
3386
3387
        $contentService = $repository->getContentService();
3388
        $locationService = $repository->getLocationService();
3389
3390
        /* BEGIN: Use Case */
3391
        $contentVersion2 = $this->createContentVersion2();
3392
3393
        // Configure new target location
3394
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3395
3396
        $targetLocationCreate->priority = 42;
3397
        $targetLocationCreate->hidden = true;
3398
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3399
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3400
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3401
3402
        // Copy only the initial version
3403
        $contentCopied = $contentService->copyContent(
3404
            $contentVersion2->contentInfo,
3405
            $targetLocationCreate,
3406
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 1)
3407
        );
3408
        /* END: Use Case */
3409
3410
        $this->assertInstanceOf(
3411
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3412
            $contentCopied
3413
        );
3414
3415
        $this->assertNotEquals(
3416
            $contentVersion2->contentInfo->remoteId,
3417
            $contentCopied->contentInfo->remoteId
3418
        );
3419
3420
        $this->assertNotEquals(
3421
            $contentVersion2->id,
3422
            $contentCopied->id
3423
        );
3424
3425
        $this->assertEquals(
3426
            1,
3427
            count($contentService->loadVersions($contentCopied->contentInfo))
3428
        );
3429
3430
        $this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo);
3431
3432
        $this->assertNotNull(
3433
            $contentCopied->contentInfo->mainLocationId,
3434
            'Expected main location to be set given we provided a LocationCreateStruct'
3435
        );
3436
    }
3437
3438
    /**
3439
     * Test for the addRelation() method.
3440
     *
3441
     * @return \eZ\Publish\API\Repository\Values\Content\Content
3442
     *
3443
     * @see \eZ\Publish\API\Repository\ContentService::addRelation()
3444
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
3445
     */
3446
    public function testAddRelation()
3447
    {
3448
        $repository = $this->getRepository();
3449
3450
        $contentService = $repository->getContentService();
3451
3452
        /* BEGIN: Use Case */
3453
        // RemoteId of the "Media" content of an eZ Publish demo installation
3454
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3455
3456
        $draft = $this->createContentDraftVersion1();
3457
3458
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3459
3460
        // Create relation between new content object and "Media" page
3461
        $relation = $contentService->addRelation(
3462
            $draft->getVersionInfo(),
3463
            $media
3464
        );
3465
        /* END: Use Case */
3466
3467
        $this->assertInstanceOf(
3468
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Relation',
3469
            $relation
3470
        );
3471
3472
        return $contentService->loadRelations($draft->getVersionInfo());
3473
    }
3474
3475
    /**
3476
     * Test for the addRelation() method.
3477
     *
3478
     * @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations
3479
     *
3480
     * @see \eZ\Publish\API\Repository\ContentService::addRelation()
3481
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation
3482
     */
3483
    public function testAddRelationAddsRelationToContent($relations)
3484
    {
3485
        $this->assertEquals(
3486
            1,
3487
            count($relations)
3488
        );
3489
    }
3490
3491
    /**
3492
     * @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations
3493
     */
3494
    protected function assertExpectedRelations($relations)
3495
    {
3496
        $this->assertEquals(
3497
            array(
3498
                'type' => Relation::COMMON,
3499
                'sourceFieldDefinitionIdentifier' => null,
3500
                'sourceContentInfo' => 'abcdef0123456789abcdef0123456789',
3501
                'destinationContentInfo' => 'a6e35cbcb7cd6ae4b691f3eee30cd262',
3502
            ),
3503
            array(
3504
                'type' => $relations[0]->type,
3505
                'sourceFieldDefinitionIdentifier' => $relations[0]->sourceFieldDefinitionIdentifier,
3506
                'sourceContentInfo' => $relations[0]->sourceContentInfo->remoteId,
3507
                'destinationContentInfo' => $relations[0]->destinationContentInfo->remoteId,
3508
            )
3509
        );
3510
    }
3511
3512
    /**
3513
     * Test for the addRelation() method.
3514
     *
3515
     * @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations
3516
     *
3517
     * @see \eZ\Publish\API\Repository\ContentService::addRelation()
3518
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation
3519
     */
3520
    public function testAddRelationSetsExpectedRelations($relations)
3521
    {
3522
        $this->assertExpectedRelations($relations);
3523
    }
3524
3525
    /**
3526
     * Test for the createContentDraft() method.
3527
     *
3528
     * @return \eZ\Publish\API\Repository\Values\Content\Relation[]
3529
     *
3530
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
3531
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations
3532
     */
3533 View Code Duplication
    public function testCreateContentDraftWithRelations()
3534
    {
3535
        $repository = $this->getRepository();
3536
3537
        $contentService = $repository->getContentService();
3538
3539
        // RemoteId of the "Media" content of an eZ Publish demo installation
3540
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3541
        $draft = $this->createContentDraftVersion1();
3542
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3543
3544
        // Create relation between new content object and "Media" page
3545
        $contentService->addRelation(
3546
            $draft->getVersionInfo(),
3547
            $media
3548
        );
3549
3550
        $content = $contentService->publishVersion($draft->versionInfo);
3551
        $newDraft = $contentService->createContentDraft($content->contentInfo);
3552
3553
        return $contentService->loadRelations($newDraft->getVersionInfo());
3554
    }
3555
3556
    /**
3557
     * Test for the createContentDraft() method.
3558
     *
3559
     * @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations
3560
     *
3561
     * @return \eZ\Publish\API\Repository\Values\Content\Relation[]
3562
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithRelations
3563
     */
3564
    public function testCreateContentDraftWithRelationsCreatesRelations($relations)
3565
    {
3566
        $this->assertEquals(
3567
            1,
3568
            count($relations)
3569
        );
3570
3571
        return $relations;
3572
    }
3573
3574
    /**
3575
     * Test for the createContentDraft() method.
3576
     *
3577
     * @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations
3578
     *
3579
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithRelationsCreatesRelations
3580
     */
3581
    public function testCreateContentDraftWithRelationsCreatesExpectedRelations($relations)
3582
    {
3583
        $this->assertExpectedRelations($relations);
3584
    }
3585
3586
    /**
3587
     * Test for the addRelation() method.
3588
     *
3589
     * @see \eZ\Publish\API\Repository\ContentService::addRelation()
3590
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
3591
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation
3592
     */
3593 View Code Duplication
    public function testAddRelationThrowsBadStateException()
3594
    {
3595
        $repository = $this->getRepository();
3596
3597
        $contentService = $repository->getContentService();
3598
3599
        /* BEGIN: Use Case */
3600
        // RemoteId of the "Media" page of an eZ Publish demo installation
3601
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3602
3603
        $content = $this->createContentVersion1();
3604
3605
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3606
3607
        // This call will fail with a "BadStateException", because content is
3608
        // published and not a draft.
3609
        $contentService->addRelation(
3610
            $content->getVersionInfo(),
3611
            $media
3612
        );
3613
        /* END: Use Case */
3614
    }
3615
3616
    /**
3617
     * Test for the loadRelations() method.
3618
     *
3619
     * @see \eZ\Publish\API\Repository\ContentService::loadRelations()
3620
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation
3621
     */
3622
    public function testLoadRelations()
3623
    {
3624
        $repository = $this->getRepository();
3625
3626
        $contentService = $repository->getContentService();
3627
3628
        /* BEGIN: Use Case */
3629
        // Remote ids of the "Media" and the "eZ Publish Demo Design ..." page
3630
        // of a eZ Publish demo installation.
3631
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3632
        $demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f';
3633
3634
        $draft = $this->createContentDraftVersion1();
3635
3636
        // Load other content objects
3637
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3638
        $demoDesign = $contentService->loadContentInfoByRemoteId($demoDesignRemoteId);
3639
3640
        // Create relation between new content object and "Media" page
3641
        $contentService->addRelation(
3642
            $draft->getVersionInfo(),
3643
            $media
3644
        );
3645
3646
        // Create another relation with the "Demo Design" page
3647
        $contentService->addRelation(
3648
            $draft->getVersionInfo(),
3649
            $demoDesign
3650
        );
3651
3652
        // Load all relations
3653
        $relations = $contentService->loadRelations($draft->getVersionInfo());
3654
        /* END: Use Case */
3655
3656
        usort(
3657
            $relations,
3658
            function ($rel1, $rel2) {
3659
                return strcasecmp(
3660
                    $rel2->getDestinationContentInfo()->remoteId,
3661
                    $rel1->getDestinationContentInfo()->remoteId
3662
                );
3663
            }
3664
        );
3665
3666
        $this->assertEquals(
3667
            array(
3668
                array(
3669
                    'sourceContentInfo' => 'abcdef0123456789abcdef0123456789',
3670
                    'destinationContentInfo' => 'a6e35cbcb7cd6ae4b691f3eee30cd262',
3671
                ),
3672
                array(
3673
                    'sourceContentInfo' => 'abcdef0123456789abcdef0123456789',
3674
                    'destinationContentInfo' => '8b8b22fe3c6061ed500fbd2b377b885f',
3675
                ),
3676
            ),
3677
            array(
3678
                array(
3679
                    'sourceContentInfo' => $relations[0]->sourceContentInfo->remoteId,
3680
                    'destinationContentInfo' => $relations[0]->destinationContentInfo->remoteId,
3681
                ),
3682
                array(
3683
                    'sourceContentInfo' => $relations[1]->sourceContentInfo->remoteId,
3684
                    'destinationContentInfo' => $relations[1]->destinationContentInfo->remoteId,
3685
                ),
3686
            )
3687
        );
3688
    }
3689
3690
    /**
3691
     * Test for the loadRelations() method.
3692
     *
3693
     * @see \eZ\Publish\API\Repository\ContentService::loadRelations()
3694
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation
3695
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations
3696
     */
3697
    public function testLoadRelationsSkipsArchivedContent()
3698
    {
3699
        $repository = $this->getRepository();
3700
3701
        $contentService = $repository->getContentService();
3702
3703
        /* BEGIN: Use Case */
3704
        $trashService = $repository->getTrashService();
3705
        $locationService = $repository->getLocationService();
3706
        // Remote ids of the "Media" and the "eZ Publish Demo Design ..." page
3707
        // of a eZ Publish demo installation.
3708
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3709
        $demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f';
3710
3711
        $draft = $this->createContentDraftVersion1();
3712
3713
        // Load other content objects
3714
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3715
        $demoDesign = $contentService->loadContentInfoByRemoteId($demoDesignRemoteId);
3716
3717
        // Create relation between new content object and "Media" page
3718
        $contentService->addRelation(
3719
            $draft->getVersionInfo(),
3720
            $media
3721
        );
3722
3723
        // Create another relation with the "Demo Design" page
3724
        $contentService->addRelation(
3725
            $draft->getVersionInfo(),
3726
            $demoDesign
3727
        );
3728
3729
        $demoDesignLocation = $locationService->loadLocation($demoDesign->mainLocationId);
3730
3731
        // Trashing Content's last Location will change its status to archived,
3732
        // in this case relation towards it will not be loaded.
3733
        $trashService->trash($demoDesignLocation);
3734
3735
        // Load all relations
3736
        $relations = $contentService->loadRelations($draft->getVersionInfo());
3737
        /* END: Use Case */
3738
3739
        $this->assertCount(1, $relations);
3740
        $this->assertEquals(
3741
            array(
3742
                array(
3743
                    'sourceContentInfo' => 'abcdef0123456789abcdef0123456789',
3744
                    'destinationContentInfo' => 'a6e35cbcb7cd6ae4b691f3eee30cd262',
3745
                ),
3746
            ),
3747
            array(
3748
                array(
3749
                    'sourceContentInfo' => $relations[0]->sourceContentInfo->remoteId,
3750
                    'destinationContentInfo' => $relations[0]->destinationContentInfo->remoteId,
3751
                ),
3752
            )
3753
        );
3754
    }
3755
3756
    /**
3757
     * Test for the loadRelations() method.
3758
     *
3759
     * @see \eZ\Publish\API\Repository\ContentService::loadRelations()
3760
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation
3761
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations
3762
     */
3763
    public function testLoadRelationsSkipsDraftContent()
3764
    {
3765
        $repository = $this->getRepository();
3766
3767
        $contentService = $repository->getContentService();
3768
3769
        /* BEGIN: Use Case */
3770
        // Remote ids of the "Media" and the "eZ Publish Demo Design ..." page
3771
        // of a eZ Publish demo installation.
3772
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3773
        $demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f';
3774
3775
        $draft = $this->createContentDraftVersion1();
3776
3777
        // Load other content objects
3778
        $media = $contentService->loadContentByRemoteId($mediaRemoteId);
3779
        $demoDesign = $contentService->loadContentInfoByRemoteId($demoDesignRemoteId);
3780
3781
        // Create draft of "Media" page
3782
        $mediaDraft = $contentService->createContentDraft($media->contentInfo);
3783
3784
        // Create relation between "Media" page and new content object draft.
3785
        // This relation will not be loaded before the draft is published.
3786
        $contentService->addRelation(
3787
            $mediaDraft->getVersionInfo(),
3788
            $draft->getVersionInfo()->getContentInfo()
3789
        );
3790
3791
        // Create another relation with the "Demo Design" page
3792
        $contentService->addRelation(
3793
            $mediaDraft->getVersionInfo(),
3794
            $demoDesign
3795
        );
3796
3797
        // Load all relations
3798
        $relations = $contentService->loadRelations($mediaDraft->getVersionInfo());
3799
        /* END: Use Case */
3800
3801
        $this->assertCount(1, $relations);
3802
        $this->assertEquals(
3803
            array(
3804
                array(
3805
                    'sourceContentInfo' => 'a6e35cbcb7cd6ae4b691f3eee30cd262',
3806
                    'destinationContentInfo' => '8b8b22fe3c6061ed500fbd2b377b885f',
3807
                ),
3808
            ),
3809
            array(
3810
                array(
3811
                    'sourceContentInfo' => $relations[0]->sourceContentInfo->remoteId,
3812
                    'destinationContentInfo' => $relations[0]->destinationContentInfo->remoteId,
3813
                ),
3814
            )
3815
        );
3816
    }
3817
3818
    /**
3819
     * Test for the loadReverseRelations() method.
3820
     *
3821
     * @see \eZ\Publish\API\Repository\ContentService::loadReverseRelations()
3822
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation
3823
     */
3824
    public function testLoadReverseRelations()
3825
    {
3826
        $repository = $this->getRepository();
3827
3828
        $contentService = $repository->getContentService();
3829
3830
        /* BEGIN: Use Case */
3831
        // Remote ids of the "Media" and the "eZ Publish Demo Design ..." page
3832
        // of a eZ Publish demo installation.
3833
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3834
        $demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f';
3835
3836
        $versionInfo = $this->createContentVersion1()->getVersionInfo();
3837
        $contentInfo = $versionInfo->getContentInfo();
3838
3839
        // Create some drafts
3840
        $mediaDraft = $contentService->createContentDraft(
3841
            $contentService->loadContentInfoByRemoteId($mediaRemoteId)
3842
        );
3843
        $demoDesignDraft = $contentService->createContentDraft(
3844
            $contentService->loadContentInfoByRemoteId($demoDesignRemoteId)
3845
        );
3846
3847
        // Create relation between new content object and "Media" page
3848
        $relation1 = $contentService->addRelation(
3849
            $mediaDraft->getVersionInfo(),
3850
            $contentInfo
3851
        );
3852
3853
        // Create another relation with the "Demo Design" page
3854
        $relation2 = $contentService->addRelation(
3855
            $demoDesignDraft->getVersionInfo(),
3856
            $contentInfo
3857
        );
3858
3859
        // Publish drafts, so relations become active
3860
        $contentService->publishVersion($mediaDraft->getVersionInfo());
3861
        $contentService->publishVersion($demoDesignDraft->getVersionInfo());
3862
3863
        // Load all relations
3864
        $relations = $contentService->loadRelations($versionInfo);
3865
        $reverseRelations = $contentService->loadReverseRelations($contentInfo);
3866
        /* END: Use Case */
3867
3868
        $this->assertEquals($contentInfo->id, $relation1->getDestinationContentInfo()->id);
3869
        $this->assertEquals($mediaDraft->id, $relation1->getSourceContentInfo()->id);
3870
3871
        $this->assertEquals($contentInfo->id, $relation2->getDestinationContentInfo()->id);
3872
        $this->assertEquals($demoDesignDraft->id, $relation2->getSourceContentInfo()->id);
3873
3874
        $this->assertEquals(0, count($relations));
3875
        $this->assertEquals(2, count($reverseRelations));
3876
3877
        usort(
3878
            $reverseRelations,
3879
            function ($rel1, $rel2) {
3880
                return strcasecmp(
3881
                    $rel2->getSourceContentInfo()->remoteId,
3882
                    $rel1->getSourceContentInfo()->remoteId
3883
                );
3884
            }
3885
        );
3886
3887
        $this->assertEquals(
3888
            array(
3889
                array(
3890
                    'sourceContentInfo' => 'a6e35cbcb7cd6ae4b691f3eee30cd262',
3891
                    'destinationContentInfo' => 'abcdef0123456789abcdef0123456789',
3892
                ),
3893
                array(
3894
                    'sourceContentInfo' => '8b8b22fe3c6061ed500fbd2b377b885f',
3895
                    'destinationContentInfo' => 'abcdef0123456789abcdef0123456789',
3896
                ),
3897
            ),
3898
            array(
3899
                array(
3900
                    'sourceContentInfo' => $reverseRelations[0]->sourceContentInfo->remoteId,
3901
                    'destinationContentInfo' => $reverseRelations[0]->destinationContentInfo->remoteId,
3902
                ),
3903
                array(
3904
                    'sourceContentInfo' => $reverseRelations[1]->sourceContentInfo->remoteId,
3905
                    'destinationContentInfo' => $reverseRelations[1]->destinationContentInfo->remoteId,
3906
                ),
3907
            )
3908
        );
3909
    }
3910
3911
    /**
3912
     * Test for the loadReverseRelations() method.
3913
     *
3914
     * @see \eZ\Publish\API\Repository\ContentService::loadReverseRelations()
3915
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation
3916
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadReverseRelations
3917
     */
3918
    public function testLoadReverseRelationsSkipsArchivedContent()
3919
    {
3920
        $repository = $this->getRepository();
3921
3922
        $contentService = $repository->getContentService();
3923
3924
        /* BEGIN: Use Case */
3925
        $trashService = $repository->getTrashService();
3926
        $locationService = $repository->getLocationService();
3927
        // Remote ids of the "Media" and the "eZ Publish Demo Design ..." page
3928
        // of a eZ Publish demo installation.
3929
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3930
        $demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f';
3931
3932
        $versionInfo = $this->createContentVersion1()->getVersionInfo();
3933
        $contentInfo = $versionInfo->getContentInfo();
3934
3935
        // Create some drafts
3936
        $mediaDraft = $contentService->createContentDraft(
3937
            $contentService->loadContentInfoByRemoteId($mediaRemoteId)
3938
        );
3939
        $demoDesignDraft = $contentService->createContentDraft(
3940
            $contentService->loadContentInfoByRemoteId($demoDesignRemoteId)
3941
        );
3942
3943
        // Create relation between new content object and "Media" page
3944
        $relation1 = $contentService->addRelation(
3945
            $mediaDraft->getVersionInfo(),
3946
            $contentInfo
3947
        );
3948
3949
        // Create another relation with the "Demo Design" page
3950
        $relation2 = $contentService->addRelation(
3951
            $demoDesignDraft->getVersionInfo(),
3952
            $contentInfo
3953
        );
3954
3955
        // Publish drafts, so relations become active
3956
        $contentService->publishVersion($mediaDraft->getVersionInfo());
3957
        $contentService->publishVersion($demoDesignDraft->getVersionInfo());
3958
3959
        $demoDesignLocation = $locationService->loadLocation($demoDesignDraft->contentInfo->mainLocationId);
3960
3961
        // Trashing Content's last Location will change its status to archived,
3962
        // in this case relation from it will not be loaded.
3963
        $trashService->trash($demoDesignLocation);
3964
3965
        // Load all relations
3966
        $relations = $contentService->loadRelations($versionInfo);
3967
        $reverseRelations = $contentService->loadReverseRelations($contentInfo);
3968
        /* END: Use Case */
3969
3970
        $this->assertEquals($contentInfo->id, $relation1->getDestinationContentInfo()->id);
3971
        $this->assertEquals($mediaDraft->id, $relation1->getSourceContentInfo()->id);
3972
3973
        $this->assertEquals($contentInfo->id, $relation2->getDestinationContentInfo()->id);
3974
        $this->assertEquals($demoDesignDraft->id, $relation2->getSourceContentInfo()->id);
3975
3976
        $this->assertEquals(0, count($relations));
3977
        $this->assertEquals(1, count($reverseRelations));
3978
3979
        $this->assertEquals(
3980
            array(
3981
                array(
3982
                    'sourceContentInfo' => 'a6e35cbcb7cd6ae4b691f3eee30cd262',
3983
                    'destinationContentInfo' => 'abcdef0123456789abcdef0123456789',
3984
                ),
3985
            ),
3986
            array(
3987
                array(
3988
                    'sourceContentInfo' => $reverseRelations[0]->sourceContentInfo->remoteId,
3989
                    'destinationContentInfo' => $reverseRelations[0]->destinationContentInfo->remoteId,
3990
                ),
3991
            )
3992
        );
3993
    }
3994
3995
    /**
3996
     * Test for the loadReverseRelations() method.
3997
     *
3998
     * @see \eZ\Publish\API\Repository\ContentService::loadReverseRelations()
3999
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation
4000
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadReverseRelations
4001
     */
4002
    public function testLoadReverseRelationsSkipsDraftContent()
4003
    {
4004
        $repository = $this->getRepository();
4005
4006
        $contentService = $repository->getContentService();
4007
4008
        /* BEGIN: Use Case */
4009
        // Remote ids of the "Media" and the "eZ Publish Demo Design ..." page
4010
        // of a eZ Publish demo installation.
4011
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
4012
        $demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f';
4013
4014
        // Load "Media" page Content
4015
        $media = $contentService->loadContentByRemoteId($mediaRemoteId);
4016
4017
        // Create some drafts
4018
        $newDraftVersionInfo = $this->createContentDraftVersion1()->getVersionInfo();
4019
        $demoDesignDraft = $contentService->createContentDraft(
4020
            $contentService->loadContentInfoByRemoteId($demoDesignRemoteId)
4021
        );
4022
4023
        // Create relation between "Media" page and new content object
4024
        $relation1 = $contentService->addRelation(
4025
            $newDraftVersionInfo,
4026
            $media->contentInfo
4027
        );
4028
4029
        // Create another relation with the "Demo Design" page
4030
        $relation2 = $contentService->addRelation(
4031
            $demoDesignDraft->getVersionInfo(),
4032
            $media->contentInfo
4033
        );
4034
4035
        // Publish drafts, so relations become active
4036
        $contentService->publishVersion($demoDesignDraft->getVersionInfo());
4037
        // We will not publish new Content draft, therefore relation from it
4038
        // will not be loaded as reverse relation for "Media" page
4039
        //$contentService->publishVersion( $newDraftVersionInfo );
4040
4041
        // Load all relations
4042
        $relations = $contentService->loadRelations($media->versionInfo);
4043
        $reverseRelations = $contentService->loadReverseRelations($media->contentInfo);
4044
        /* END: Use Case */
4045
4046
        $this->assertEquals($media->contentInfo->id, $relation1->getDestinationContentInfo()->id);
4047
        $this->assertEquals($newDraftVersionInfo->contentInfo->id, $relation1->getSourceContentInfo()->id);
4048
4049
        $this->assertEquals($media->contentInfo->id, $relation2->getDestinationContentInfo()->id);
4050
        $this->assertEquals($demoDesignDraft->id, $relation2->getSourceContentInfo()->id);
4051
4052
        $this->assertEquals(0, count($relations));
4053
        $this->assertEquals(1, count($reverseRelations));
4054
4055
        $this->assertEquals(
4056
            array(
4057
                array(
4058
                    'sourceContentInfo' => '8b8b22fe3c6061ed500fbd2b377b885f',
4059
                    'destinationContentInfo' => 'a6e35cbcb7cd6ae4b691f3eee30cd262',
4060
                ),
4061
            ),
4062
            array(
4063
                array(
4064
                    'sourceContentInfo' => $reverseRelations[0]->sourceContentInfo->remoteId,
4065
                    'destinationContentInfo' => $reverseRelations[0]->destinationContentInfo->remoteId,
4066
                ),
4067
            )
4068
        );
4069
    }
4070
4071
    /**
4072
     * Test for the deleteRelation() method.
4073
     *
4074
     * @see \eZ\Publish\API\Repository\ContentService::deleteRelation()
4075
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations
4076
     */
4077
    public function testDeleteRelation()
4078
    {
4079
        $repository = $this->getRepository();
4080
4081
        $contentService = $repository->getContentService();
4082
4083
        /* BEGIN: Use Case */
4084
        // Remote ids of the "Media" and the "Demo Design" page of a eZ Publish
4085
        // demo installation.
4086
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
4087
        $demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f';
4088
4089
        $draft = $this->createContentDraftVersion1();
4090
4091
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
4092
        $demoDesign = $contentService->loadContentInfoByRemoteId($demoDesignRemoteId);
4093
4094
        // Establish some relations
4095
        $contentService->addRelation($draft->getVersionInfo(), $media);
4096
        $contentService->addRelation($draft->getVersionInfo(), $demoDesign);
4097
4098
        // Delete one of the currently created relations
4099
        $contentService->deleteRelation($draft->getVersionInfo(), $media);
4100
4101
        // The relations array now contains only one element
4102
        $relations = $contentService->loadRelations($draft->getVersionInfo());
4103
        /* END: Use Case */
4104
4105
        $this->assertEquals(1, count($relations));
4106
    }
4107
4108
    /**
4109
     * Test for the deleteRelation() method.
4110
     *
4111
     * @see \eZ\Publish\API\Repository\ContentService::deleteRelation()
4112
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
4113
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
4114
     */
4115 View Code Duplication
    public function testDeleteRelationThrowsBadStateException()
4116
    {
4117
        $repository = $this->getRepository();
4118
4119
        $contentService = $repository->getContentService();
4120
4121
        /* BEGIN: Use Case */
4122
        // RemoteId of the "Media" page of an eZ Publish demo installation
4123
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
4124
4125
        $content = $this->createContentVersion1();
4126
4127
        // Load the destination object
4128
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
4129
4130
        // Create a new draft
4131
        $draftVersion2 = $contentService->createContentDraft($content->contentInfo);
4132
4133
        // Add a relation
4134
        $contentService->addRelation($draftVersion2->getVersionInfo(), $media);
4135
4136
        // Publish new version
4137
        $contentVersion2 = $contentService->publishVersion(
4138
            $draftVersion2->getVersionInfo()
4139
        );
4140
4141
        // This call will fail with a "BadStateException", because content is
4142
        // published and not a draft.
4143
        $contentService->deleteRelation(
4144
            $contentVersion2->getVersionInfo(),
4145
            $media
4146
        );
4147
        /* END: Use Case */
4148
    }
4149
4150
    /**
4151
     * Test for the deleteRelation() method.
4152
     *
4153
     * @see \eZ\Publish\API\Repository\ContentService::deleteRelation()
4154
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
4155
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
4156
     */
4157 View Code Duplication
    public function testDeleteRelationThrowsInvalidArgumentException()
4158
    {
4159
        $repository = $this->getRepository();
4160
4161
        $contentService = $repository->getContentService();
4162
4163
        /* BEGIN: Use Case */
4164
        // RemoteId of the "Media" page of an eZ Publish demo installation
4165
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
4166
4167
        $draft = $this->createContentDraftVersion1();
4168
4169
        // Load the destination object
4170
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
4171
4172
        // This call will fail with a "InvalidArgumentException", because no
4173
        // relation exists between $draft and $media.
4174
        $contentService->deleteRelation(
4175
            $draft->getVersionInfo(),
4176
            $media
4177
        );
4178
        /* END: Use Case */
4179
    }
4180
4181
    /**
4182
     * Test for the createContent() method.
4183
     *
4184
     * @see \eZ\Publish\API\Repository\ContentService::createContent()
4185
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
4186
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4187
     */
4188
    public function testCreateContentInTransactionWithRollback()
4189
    {
4190
        if ($this->isVersion4()) {
4191
            $this->markTestSkipped('This test requires eZ Publish 5');
4192
        }
4193
4194
        $repository = $this->getRepository();
4195
4196
        /* BEGIN: Use Case */
4197
        $contentTypeService = $repository->getContentTypeService();
4198
        $contentService = $repository->getContentService();
4199
4200
        // Start a transaction
4201
        $repository->beginTransaction();
4202
4203
        try {
4204
            $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
4205
4206
            // Get a content create struct and set mandatory properties
4207
            $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US');
4208
            $contentCreate->setField('name', 'Sindelfingen forum');
4209
4210
            $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789';
4211
            $contentCreate->alwaysAvailable = true;
4212
4213
            // Create a new content object
4214
            $contentId = $contentService->createContent($contentCreate)->id;
4215
        } catch (Exception $e) {
4216
            // Cleanup hanging transaction on error
4217
            $repository->rollback();
4218
            throw $e;
4219
        }
4220
4221
        // Rollback all changes
4222
        $repository->rollback();
4223
4224
        try {
4225
            // This call will fail with a "NotFoundException"
4226
            $contentService->loadContent($contentId);
4227
        } catch (NotFoundException $e) {
4228
            // This is expected
4229
            return;
4230
        }
4231
        /* END: Use Case */
4232
4233
        $this->fail('Content object still exists after rollback.');
4234
    }
4235
4236
    /**
4237
     * Test for the createContent() method.
4238
     *
4239
     * @see \eZ\Publish\API\Repository\ContentService::createContent()
4240
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
4241
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4242
     */
4243
    public function testCreateContentInTransactionWithCommit()
4244
    {
4245
        if ($this->isVersion4()) {
4246
            $this->markTestSkipped('This test requires eZ Publish 5');
4247
        }
4248
4249
        $repository = $this->getRepository();
4250
4251
        /* BEGIN: Use Case */
4252
        $contentTypeService = $repository->getContentTypeService();
4253
        $contentService = $repository->getContentService();
4254
4255
        // Start a transaction
4256
        $repository->beginTransaction();
4257
4258
        try {
4259
            $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
4260
4261
            // Get a content create struct and set mandatory properties
4262
            $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US');
4263
            $contentCreate->setField('name', 'Sindelfingen forum');
4264
4265
            $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789';
4266
            $contentCreate->alwaysAvailable = true;
4267
4268
            // Create a new content object
4269
            $contentId = $contentService->createContent($contentCreate)->id;
4270
4271
            // Commit changes
4272
            $repository->commit();
4273
        } catch (Exception $e) {
4274
            // Cleanup hanging transaction on error
4275
            $repository->rollback();
4276
            throw $e;
4277
        }
4278
4279
        // Load the new content object
4280
        $content = $contentService->loadContent($contentId);
4281
        /* END: Use Case */
4282
4283
        $this->assertEquals($contentId, $content->id);
4284
    }
4285
4286
    /**
4287
     * Test for the createContent() method.
4288
     *
4289
     * @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs)
4290
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately
4291
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentThrowsNotFoundException
4292
     */
4293
    public function testCreateContentWithLocationCreateParameterInTransactionWithRollback()
4294
    {
4295
        $repository = $this->getRepository();
4296
4297
        $contentService = $repository->getContentService();
4298
4299
        /* BEGIN: Use Case */
4300
        // Start a transaction
4301
        $repository->beginTransaction();
4302
4303
        try {
4304
            $draft = $this->createContentDraftVersion1();
4305
        } catch (Exception $e) {
4306
            // Cleanup hanging transaction on error
4307
            $repository->rollback();
4308
            throw $e;
4309
        }
4310
4311
        $contentId = $draft->id;
4312
4313
        // Roleback the transaction
4314
        $repository->rollback();
4315
4316
        try {
4317
            // This call will fail with a "NotFoundException"
4318
            $contentService->loadContent($contentId);
4319
        } catch (NotFoundException $e) {
4320
            return;
4321
        }
4322
        /* END: Use Case */
4323
4324
        $this->fail('Can still load content object after rollback.');
4325
    }
4326
4327
    /**
4328
     * Test for the createContent() method.
4329
     *
4330
     * @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs)
4331
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately
4332
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentThrowsNotFoundException
4333
     */
4334 View Code Duplication
    public function testCreateContentWithLocationCreateParameterInTransactionWithCommit()
4335
    {
4336
        $repository = $this->getRepository();
4337
4338
        $contentService = $repository->getContentService();
4339
4340
        /* BEGIN: Use Case */
4341
        // Start a transaction
4342
        $repository->beginTransaction();
4343
4344
        try {
4345
            $draft = $this->createContentDraftVersion1();
4346
4347
            $contentId = $draft->id;
4348
4349
            // Roleback the transaction
4350
            $repository->commit();
4351
        } catch (Exception $e) {
4352
            // Cleanup hanging transaction on error
4353
            $repository->rollback();
4354
            throw $e;
4355
        }
4356
4357
        // Load the new content object
4358
        $content = $contentService->loadContent($contentId);
4359
        /* END: Use Case */
4360
4361
        $this->assertEquals($contentId, $content->id);
4362
    }
4363
4364
    /**
4365
     * Test for the createContentDraft() method.
4366
     *
4367
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
4368
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
4369
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4370
     */
4371
    public function testCreateContentDraftInTransactionWithRollback()
4372
    {
4373
        $repository = $this->getRepository();
4374
4375
        $contentId = $this->generateId('object', 12);
4376
        /* BEGIN: Use Case */
4377
        // $contentId is the ID of the "Administrator users" user group
4378
4379
        // Get the content service
4380
        $contentService = $repository->getContentService();
4381
4382
        // Load the user group content object
4383
        $content = $contentService->loadContent($contentId);
4384
4385
        // Start a new transaction
4386
        $repository->beginTransaction();
4387
4388
        try {
4389
            // Create a new draft
4390
            $drafted = $contentService->createContentDraft($content->contentInfo);
4391
4392
            // Store version number for later reuse
4393
            $versionNo = $drafted->versionInfo->versionNo;
4394
        } catch (Exception $e) {
4395
            // Cleanup hanging transaction on error
4396
            $repository->rollback();
4397
            throw $e;
4398
        }
4399
4400
        // Rollback
4401
        $repository->rollback();
4402
4403
        try {
4404
            // This call will fail with a "NotFoundException"
4405
            $contentService->loadContent($contentId, null, $versionNo);
4406
        } catch (NotFoundException $e) {
4407
            return;
4408
        }
4409
        /* END: Use Case */
4410
4411
        $this->fail('Can still load content draft after rollback');
4412
    }
4413
4414
    /**
4415
     * Test for the createContentDraft() method.
4416
     *
4417
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
4418
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
4419
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4420
     */
4421 View Code Duplication
    public function testCreateContentDraftInTransactionWithCommit()
4422
    {
4423
        $repository = $this->getRepository();
4424
4425
        $contentId = $this->generateId('object', 12);
4426
        /* BEGIN: Use Case */
4427
        // $contentId is the ID of the "Administrator users" user group
4428
4429
        // Get the content service
4430
        $contentService = $repository->getContentService();
4431
4432
        // Load the user group content object
4433
        $content = $contentService->loadContent($contentId);
4434
4435
        // Start a new transaction
4436
        $repository->beginTransaction();
4437
4438
        try {
4439
            // Create a new draft
4440
            $drafted = $contentService->createContentDraft($content->contentInfo);
4441
4442
            // Store version number for later reuse
4443
            $versionNo = $drafted->versionInfo->versionNo;
4444
4445
            // Commit all changes
4446
            $repository->commit();
4447
        } catch (Exception $e) {
4448
            // Cleanup hanging transaction on error
4449
            $repository->rollback();
4450
            throw $e;
4451
        }
4452
4453
        $content = $contentService->loadContent($contentId, null, $versionNo);
4454
        /* END: Use Case */
4455
4456
        $this->assertEquals(
4457
            $versionNo,
4458
            $content->getVersionInfo()->versionNo
4459
        );
4460
    }
4461
4462
    /**
4463
     * Test for the publishVersion() method.
4464
     *
4465
     * @see \eZ\Publish\API\Repository\ContentService::publishVersion()
4466
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4467
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4468
     */
4469 View Code Duplication
    public function testPublishVersionInTransactionWithRollback()
4470
    {
4471
        $repository = $this->getRepository();
4472
4473
        $contentId = $this->generateId('object', 12);
4474
        /* BEGIN: Use Case */
4475
        // $contentId is the ID of the "Administrator users" user group
4476
4477
        // Get the content service
4478
        $contentService = $repository->getContentService();
4479
4480
        // Load the user group content object
4481
        $content = $contentService->loadContent($contentId);
4482
4483
        // Start a new transaction
4484
        $repository->beginTransaction();
4485
4486
        try {
4487
            $draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo();
4488
4489
            // Publish a new version
4490
            $content = $contentService->publishVersion($draftVersion);
4491
4492
            // Store version number for later reuse
4493
            $versionNo = $content->versionInfo->versionNo;
4494
        } catch (Exception $e) {
4495
            // Cleanup hanging transaction on error
4496
            $repository->rollback();
4497
            throw $e;
4498
        }
4499
4500
        // Rollback
4501
        $repository->rollback();
4502
4503
        try {
4504
            // This call will fail with a "NotFoundException"
4505
            $contentService->loadContent($contentId, null, $versionNo);
4506
        } catch (NotFoundException $e) {
4507
            return;
4508
        }
4509
        /* END: Use Case */
4510
4511
        $this->fail('Can still load content draft after rollback');
4512
    }
4513
4514
    /**
4515
     * Test for the publishVersion() method.
4516
     *
4517
     * @see \eZ\Publish\API\Repository\ContentService::publishVersion()
4518
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4519
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
4520
     */
4521 View Code Duplication
    public function testPublishVersionInTransactionWithCommit()
4522
    {
4523
        $repository = $this->getRepository();
4524
4525
        /* BEGIN: Use Case */
4526
        // ID of the "Administrator users" user group
4527
        $contentId = 12;
4528
4529
        // Get the content service
4530
        $contentService = $repository->getContentService();
4531
4532
        // Load the user group content object
4533
        $template = $contentService->loadContent($contentId);
4534
4535
        // Start a new transaction
4536
        $repository->beginTransaction();
4537
4538
        try {
4539
            // Publish a new version
4540
            $content = $contentService->publishVersion(
4541
                $contentService->createContentDraft($template->contentInfo)->getVersionInfo()
4542
            );
4543
4544
            // Store version number for later reuse
4545
            $versionNo = $content->versionInfo->versionNo;
4546
4547
            // Commit all changes
4548
            $repository->commit();
4549
        } catch (Exception $e) {
4550
            // Cleanup hanging transaction on error
4551
            $repository->rollback();
4552
            throw $e;
4553
        }
4554
4555
        // Load current version info
4556
        $versionInfo = $contentService->loadVersionInfo($content->contentInfo);
4557
        /* END: Use Case */
4558
4559
        $this->assertEquals($versionNo, $versionInfo->versionNo);
4560
    }
4561
4562
    /**
4563
     * Test for the updateContent() method.
4564
     *
4565
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
4566
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
4567
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4568
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4569
     */
4570 View Code Duplication
    public function testUpdateContentInTransactionWithRollback()
4571
    {
4572
        $repository = $this->getRepository();
4573
4574
        $contentId = $this->generateId('object', 12);
4575
        /* BEGIN: Use Case */
4576
        // $contentId is the ID of the "Administrator users" user group
4577
4578
        // Load content service
4579
        $contentService = $repository->getContentService();
4580
4581
        // Create a new user group draft
4582
        $draft = $contentService->createContentDraft(
4583
            $contentService->loadContentInfo($contentId)
4584
        );
4585
4586
        // Get an update struct and change the group name
4587
        $contentUpdate = $contentService->newContentUpdateStruct();
4588
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4589
4590
        // Start a transaction
4591
        $repository->beginTransaction();
4592
4593
        try {
4594
            // Update the group name
4595
            $draft = $contentService->updateContent(
4596
                $draft->getVersionInfo(),
4597
                $contentUpdate
4598
            );
4599
4600
            // Publish updated version
4601
            $contentService->publishVersion($draft->getVersionInfo());
4602
        } catch (Exception $e) {
4603
            // Cleanup hanging transaction on error
4604
            $repository->rollback();
4605
            throw $e;
4606
        }
4607
4608
        // Rollback all changes.
4609
        $repository->rollback();
4610
4611
        // Name will still be "Administrator users"
4612
        $name = $contentService->loadContent($contentId)->getFieldValue('name');
4613
        /* END: Use Case */
4614
4615
        $this->assertEquals('Administrator users', $name);
4616
    }
4617
4618
    /**
4619
     * Test for the updateContent() method.
4620
     *
4621
     * @see \eZ\Publish\API\Repository\ContentService::updateContent()
4622
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent
4623
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4624
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4625
     */
4626 View Code Duplication
    public function testUpdateContentInTransactionWithCommit()
4627
    {
4628
        $repository = $this->getRepository();
4629
4630
        $contentId = $this->generateId('object', 12);
4631
        /* BEGIN: Use Case */
4632
        // $contentId is the ID of the "Administrator users" user group
4633
4634
        // Load content service
4635
        $contentService = $repository->getContentService();
4636
4637
        // Create a new user group draft
4638
        $draft = $contentService->createContentDraft(
4639
            $contentService->loadContentInfo($contentId)
4640
        );
4641
4642
        // Get an update struct and change the group name
4643
        $contentUpdate = $contentService->newContentUpdateStruct();
4644
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4645
4646
        // Start a transaction
4647
        $repository->beginTransaction();
4648
4649
        try {
4650
            // Update the group name
4651
            $draft = $contentService->updateContent(
4652
                $draft->getVersionInfo(),
4653
                $contentUpdate
4654
            );
4655
4656
            // Publish updated version
4657
            $contentService->publishVersion($draft->getVersionInfo());
4658
4659
            // Commit all changes.
4660
            $repository->commit();
4661
        } catch (Exception $e) {
4662
            // Cleanup hanging transaction on error
4663
            $repository->rollback();
4664
            throw $e;
4665
        }
4666
4667
        // Name is now "Administrators"
4668
        $name = $contentService->loadContent($contentId)->getFieldValue('name', 'eng-US');
4669
        /* END: Use Case */
4670
4671
        $this->assertEquals('Administrators', $name);
4672
    }
4673
4674
    /**
4675
     * Test for the updateContentMetadata() method.
4676
     *
4677
     * @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata()
4678
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4679
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4680
     */
4681 View Code Duplication
    public function testUpdateContentMetadataInTransactionWithRollback()
4682
    {
4683
        $repository = $this->getRepository();
4684
4685
        $contentId = $this->generateId('object', 12);
4686
        /* BEGIN: Use Case */
4687
        // $contentId is the ID of the "Administrator users" user group
4688
4689
        // Get the content service
4690
        $contentService = $repository->getContentService();
4691
4692
        // Load a ContentInfo object
4693
        $contentInfo = $contentService->loadContentInfo($contentId);
4694
4695
        // Store remoteId for later testing
4696
        $remoteId = $contentInfo->remoteId;
4697
4698
        // Start a transaction
4699
        $repository->beginTransaction();
4700
4701
        try {
4702
            // Get metadata update struct and change remoteId
4703
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4704
            $metadataUpdate->remoteId = md5(microtime(true));
4705
4706
            // Update the metadata of the published content object
4707
            $contentService->updateContentMetadata(
4708
                $contentInfo,
4709
                $metadataUpdate
4710
            );
4711
        } catch (Exception $e) {
4712
            // Cleanup hanging transaction on error
4713
            $repository->rollback();
4714
            throw $e;
4715
        }
4716
4717
        // Rollback all changes.
4718
        $repository->rollback();
4719
4720
        // Load current remoteId
4721
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4722
        /* END: Use Case */
4723
4724
        $this->assertEquals($remoteId, $remoteIdReloaded);
4725
    }
4726
4727
    /**
4728
     * Test for the updateContentMetadata() method.
4729
     *
4730
     * @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata()
4731
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4732
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4733
     */
4734 View Code Duplication
    public function testUpdateContentMetadataInTransactionWithCommit()
4735
    {
4736
        $repository = $this->getRepository();
4737
4738
        $contentId = $this->generateId('object', 12);
4739
        /* BEGIN: Use Case */
4740
        // $contentId is the ID of the "Administrator users" user group
4741
4742
        // Get the content service
4743
        $contentService = $repository->getContentService();
4744
4745
        // Load a ContentInfo object
4746
        $contentInfo = $contentService->loadContentInfo($contentId);
4747
4748
        // Store remoteId for later testing
4749
        $remoteId = $contentInfo->remoteId;
4750
4751
        // Start a transaction
4752
        $repository->beginTransaction();
4753
4754
        try {
4755
            // Get metadata update struct and change remoteId
4756
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4757
            $metadataUpdate->remoteId = md5(microtime(true));
4758
4759
            // Update the metadata of the published content object
4760
            $contentService->updateContentMetadata(
4761
                $contentInfo,
4762
                $metadataUpdate
4763
            );
4764
4765
            // Commit all changes.
4766
            $repository->commit();
4767
        } catch (Exception $e) {
4768
            // Cleanup hanging transaction on error
4769
            $repository->rollback();
4770
            throw $e;
4771
        }
4772
4773
        // Load current remoteId
4774
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4775
        /* END: Use Case */
4776
4777
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4778
    }
4779
4780
    /**
4781
     * Test for the deleteVersion() method.
4782
     *
4783
     * @see \eZ\Publish\API\Repository\ContentService::deleteVersion()
4784
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
4785
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4786
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts
4787
     */
4788
    public function testDeleteVersionInTransactionWithRollback()
4789
    {
4790
        $repository = $this->getRepository();
4791
4792
        $contentId = $this->generateId('object', 12);
4793
        /* BEGIN: Use Case */
4794
        // $contentId is the ID of the "Administrator users" user group
4795
4796
        // Get the content service
4797
        $contentService = $repository->getContentService();
4798
4799
        // Start a new transaction
4800
        $repository->beginTransaction();
4801
4802
        try {
4803
            // Create a new draft
4804
            $draft = $contentService->createContentDraft(
4805
                $contentService->loadContentInfo($contentId)
4806
            );
4807
4808
            $contentService->deleteVersion($draft->getVersionInfo());
4809
        } catch (Exception $e) {
4810
            // Cleanup hanging transaction on error
4811
            $repository->rollback();
4812
            throw $e;
4813
        }
4814
4815
        // Rollback all changes.
4816
        $repository->rollback();
4817
4818
        // This array will be empty
4819
        $drafts = $contentService->loadContentDrafts();
4820
        /* END: Use Case */
4821
4822
        $this->assertSame(array(), $drafts);
4823
    }
4824
4825
    /**
4826
     * Test for the deleteVersion() method.
4827
     *
4828
     * @see \eZ\Publish\API\Repository\ContentService::deleteVersion()
4829
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
4830
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4831
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts
4832
     */
4833
    public function testDeleteVersionInTransactionWithCommit()
4834
    {
4835
        $repository = $this->getRepository();
4836
4837
        $contentId = $this->generateId('object', 12);
4838
        /* BEGIN: Use Case */
4839
        // $contentId is the ID of the "Administrator users" user group
4840
4841
        // Get the content service
4842
        $contentService = $repository->getContentService();
4843
4844
        // Start a new transaction
4845
        $repository->beginTransaction();
4846
4847
        try {
4848
            // Create a new draft
4849
            $draft = $contentService->createContentDraft(
4850
                $contentService->loadContentInfo($contentId)
4851
            );
4852
4853
            $contentService->deleteVersion($draft->getVersionInfo());
4854
4855
            // Commit all changes.
4856
            $repository->commit();
4857
        } catch (Exception $e) {
4858
            // Cleanup hanging transaction on error
4859
            $repository->rollback();
4860
            throw $e;
4861
        }
4862
4863
        // This array will contain no element
4864
        $drafts = $contentService->loadContentDrafts();
4865
        /* END: Use Case */
4866
4867
        $this->assertSame(array(), $drafts);
4868
    }
4869
4870
    /**
4871
     * Test for the deleteContent() method.
4872
     *
4873
     * @see \eZ\Publish\API\Repository\ContentService::deleteContent()
4874
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent
4875
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4876
     */
4877
    public function testDeleteContentInTransactionWithRollback()
4878
    {
4879
        $repository = $this->getRepository();
4880
4881
        $contentId = $this->generateId('object', 11);
4882
        /* BEGIN: Use Case */
4883
        // $contentId is the ID of the "Members" user group in an eZ Publish
4884
        // demo installation
4885
4886
        // Get content service
4887
        $contentService = $repository->getContentService();
4888
4889
        // Load a ContentInfo instance
4890
        $contentInfo = $contentService->loadContentInfo($contentId);
4891
4892
        // Start a new transaction
4893
        $repository->beginTransaction();
4894
4895
        try {
4896
            // Delete content object
4897
            $contentService->deleteContent($contentInfo);
4898
        } catch (Exception $e) {
4899
            // Cleanup hanging transaction on error
4900
            $repository->rollback();
4901
            throw $e;
4902
        }
4903
4904
        // Rollback all changes
4905
        $repository->rollback();
4906
4907
        // This call will return the original content object
4908
        $contentInfo = $contentService->loadContentInfo($contentId);
4909
        /* END: Use Case */
4910
4911
        $this->assertEquals($contentId, $contentInfo->id);
4912
    }
4913
4914
    /**
4915
     * Test for the deleteContent() method.
4916
     *
4917
     * @see \eZ\Publish\API\Repository\ContentService::deleteContent()
4918
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent
4919
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4920
     */
4921
    public function testDeleteContentInTransactionWithCommit()
4922
    {
4923
        $repository = $this->getRepository();
4924
4925
        $contentId = $this->generateId('object', 11);
4926
        /* BEGIN: Use Case */
4927
        // $contentId is the ID of the "Members" user group in an eZ Publish
4928
        // demo installation
4929
4930
        // Get content service
4931
        $contentService = $repository->getContentService();
4932
4933
        // Load a ContentInfo instance
4934
        $contentInfo = $contentService->loadContentInfo($contentId);
4935
4936
        // Start a new transaction
4937
        $repository->beginTransaction();
4938
4939
        try {
4940
            // Delete content object
4941
            $contentService->deleteContent($contentInfo);
4942
4943
            // Commit all changes
4944
            $repository->commit();
4945
        } catch (Exception $e) {
4946
            // Cleanup hanging transaction on error
4947
            $repository->rollback();
4948
            throw $e;
4949
        }
4950
4951
        // Deleted content info is not found anymore
4952
        try {
4953
            $contentService->loadContentInfo($contentId);
4954
        } catch (NotFoundException $e) {
4955
            return;
4956
        }
4957
        /* END: Use Case */
4958
4959
        $this->fail('Can still load ContentInfo after commit.');
4960
    }
4961
4962
    /**
4963
     * Test for the copyContent() method.
4964
     *
4965
     * @see \eZ\Publish\API\Repository\ContentService::copyContent()
4966
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent
4967
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct
4968
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4969
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4970
     */
4971 View Code Duplication
    public function testCopyContentInTransactionWithRollback()
4972
    {
4973
        $repository = $this->getRepository();
4974
4975
        $contentId = $this->generateId('object', 11);
4976
        $locationId = $this->generateId('location', 13);
4977
        /* BEGIN: Use Case */
4978
        // $contentId is the ID of the "Members" user group in an eZ Publish
4979
        // demo installation
4980
4981
        // $locationId is the ID of the "Administrator users" group location
4982
4983
        // Get services
4984
        $contentService = $repository->getContentService();
4985
        $locationService = $repository->getLocationService();
4986
4987
        // Load content object to copy
4988
        $content = $contentService->loadContent($contentId);
4989
4990
        // Create new target location
4991
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4992
4993
        // Start a new transaction
4994
        $repository->beginTransaction();
4995
4996
        try {
4997
            // Copy content with all versions and drafts
4998
            $contentService->copyContent(
4999
                $content->contentInfo,
5000
                $locationCreate
5001
            );
5002
        } catch (Exception $e) {
5003
            // Cleanup hanging transaction on error
5004
            $repository->rollback();
5005
            throw $e;
5006
        }
5007
5008
        // Rollback all changes
5009
        $repository->rollback();
5010
5011
        $this->refreshSearch($repository);
5012
5013
        // This array will only contain a single admin user object
5014
        $locations = $locationService->loadLocationChildren(
5015
            $locationService->loadLocation($locationId)
5016
        )->locations;
5017
        /* END: Use Case */
5018
5019
        $this->assertEquals(1, count($locations));
5020
    }
5021
5022
    /**
5023
     * Test for the copyContent() method.
5024
     *
5025
     * @see \eZ\Publish\API\Repository\ContentService::copyContent()
5026
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent
5027
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct
5028
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
5029
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
5030
     */
5031 View Code Duplication
    public function testCopyContentInTransactionWithCommit()
5032
    {
5033
        $repository = $this->getRepository();
5034
5035
        $contentId = $this->generateId('object', 11);
5036
        $locationId = $this->generateId('location', 13);
5037
        /* BEGIN: Use Case */
5038
        // $contentId is the ID of the "Members" user group in an eZ Publish
5039
        // demo installation
5040
5041
        // $locationId is the ID of the "Administrator users" group location
5042
5043
        // Get services
5044
        $contentService = $repository->getContentService();
5045
        $locationService = $repository->getLocationService();
5046
5047
        // Load content object to copy
5048
        $content = $contentService->loadContent($contentId);
5049
5050
        // Create new target location
5051
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
5052
5053
        // Start a new transaction
5054
        $repository->beginTransaction();
5055
5056
        try {
5057
            // Copy content with all versions and drafts
5058
            $contentCopied = $contentService->copyContent(
0 ignored issues
show
Unused Code introduced by
$contentCopied is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
5059
                $content->contentInfo,
5060
                $locationCreate
5061
            );
5062
5063
            // Commit all changes
5064
            $repository->commit();
5065
        } catch (Exception $e) {
5066
            // Cleanup hanging transaction on error
5067
            $repository->rollback();
5068
            throw $e;
5069
        }
5070
5071
        $this->refreshSearch($repository);
5072
5073
        // This will contain the admin user and the new child location
5074
        $locations = $locationService->loadLocationChildren(
5075
            $locationService->loadLocation($locationId)
5076
        )->locations;
5077
        /* END: Use Case */
5078
5079
        $this->assertEquals(2, count($locations));
5080
    }
5081
5082
    public function testURLAliasesCreatedForNewContent()
5083
    {
5084
        $repository = $this->getRepository();
5085
5086
        $contentService = $repository->getContentService();
5087
        $locationService = $repository->getLocationService();
5088
        $urlAliasService = $repository->getURLAliasService();
5089
5090
        /* BEGIN: Use Case */
5091
        $draft = $this->createContentDraftVersion1();
5092
5093
        // Automatically creates a new URLAlias for the content
5094
        $liveContent = $contentService->publishVersion($draft->getVersionInfo());
5095
        /* END: Use Case */
5096
5097
        $location = $locationService->loadLocation(
5098
            $liveContent->getVersionInfo()->getContentInfo()->mainLocationId
5099
        );
5100
5101
        $aliases = $urlAliasService->listLocationAliases($location, false);
5102
5103
        $this->assertAliasesCorrect(
5104
            array(
5105
                '/Design/Plain-site/An-awesome-forum' => array(
5106
                    'type' => URLAlias::LOCATION,
5107
                    'destination' => $location->id,
5108
                    'path' => '/Design/Plain-site/An-awesome-forum',
5109
                    'languageCodes' => array('eng-US'),
5110
                    'isHistory' => false,
5111
                    'isCustom' => false,
5112
                    'forward' => false,
5113
                ),
5114
            ),
5115
            $aliases
5116
        );
5117
    }
5118
5119
    public function testURLAliasesCreatedForUpdatedContent()
5120
    {
5121
        $repository = $this->getRepository();
5122
5123
        $contentService = $repository->getContentService();
5124
        $locationService = $repository->getLocationService();
5125
        $urlAliasService = $repository->getURLAliasService();
5126
5127
        /* BEGIN: Use Case */
5128
        $draft = $this->createUpdatedDraftVersion2();
5129
5130
        $location = $locationService->loadLocation(
5131
            $draft->getVersionInfo()->getContentInfo()->mainLocationId
5132
        );
5133
5134
        // Load and assert URL aliases before publishing updated Content, so that
5135
        // SPI cache is warmed up and cache invalidation is also tested.
5136
        $aliases = $urlAliasService->listLocationAliases($location, false);
5137
5138
        $this->assertAliasesCorrect(
5139
            array(
5140
                '/Design/Plain-site/An-awesome-forum' => array(
5141
                    'type' => URLAlias::LOCATION,
5142
                    'destination' => $location->id,
5143
                    'path' => '/Design/Plain-site/An-awesome-forum',
5144
                    'languageCodes' => array('eng-US'),
5145
                    'alwaysAvailable' => true,
5146
                    'isHistory' => false,
5147
                    'isCustom' => false,
5148
                    'forward' => false,
5149
                ),
5150
            ),
5151
            $aliases
5152
        );
5153
5154
        // Automatically marks old aliases for the content as history
5155
        // and creates new aliases, based on the changes
5156
        $liveContent = $contentService->publishVersion($draft->getVersionInfo());
5157
        /* END: Use Case */
5158
5159
        $location = $locationService->loadLocation(
5160
            $liveContent->getVersionInfo()->getContentInfo()->mainLocationId
5161
        );
5162
5163
        $aliases = $urlAliasService->listLocationAliases($location, false);
5164
5165
        $this->assertAliasesCorrect(
5166
            array(
5167
                '/Design/Plain-site/An-awesome-forum2' => array(
5168
                    'type' => URLAlias::LOCATION,
5169
                    'destination' => $location->id,
5170
                    'path' => '/Design/Plain-site/An-awesome-forum2',
5171
                    'languageCodes' => array('eng-US'),
5172
                    'alwaysAvailable' => true,
5173
                    'isHistory' => false,
5174
                    'isCustom' => false,
5175
                    'forward' => false,
5176
                ),
5177
                '/Design/Plain-site/An-awesome-forum23' => array(
5178
                    'type' => URLAlias::LOCATION,
5179
                    'destination' => $location->id,
5180
                    'path' => '/Design/Plain-site/An-awesome-forum23',
5181
                    'languageCodes' => array('eng-GB'),
5182
                    'alwaysAvailable' => true,
5183
                    'isHistory' => false,
5184
                    'isCustom' => false,
5185
                    'forward' => false,
5186
                ),
5187
            ),
5188
            $aliases
5189
        );
5190
    }
5191
5192
    public function testCustomURLAliasesNotHistorizedOnUpdatedContent()
5193
    {
5194
        $repository = $this->getRepository();
5195
5196
        $contentService = $repository->getContentService();
5197
5198
        /* BEGIN: Use Case */
5199
        $urlAliasService = $repository->getURLAliasService();
5200
        $locationService = $repository->getLocationService();
5201
5202
        $content = $this->createContentVersion1();
5203
5204
        // Create a custom URL alias
5205
        $urlAliasService->createUrlAlias(
5206
            $locationService->loadLocation(
5207
                $content->getVersionInfo()->getContentInfo()->mainLocationId
5208
            ),
5209
            '/my/fancy/story-about-ez-publish',
5210
            'eng-US'
5211
        );
5212
5213
        $draftVersion2 = $contentService->createContentDraft($content->contentInfo);
5214
5215
        $contentUpdate = $contentService->newContentUpdateStruct();
5216
        $contentUpdate->initialLanguageCode = 'eng-US';
5217
        $contentUpdate->setField('name', 'Amazing Bielefeld forum');
5218
5219
        $draftVersion2 = $contentService->updateContent(
5220
            $draftVersion2->getVersionInfo(),
5221
            $contentUpdate
5222
        );
5223
5224
        // Only marks auto-generated aliases as history
5225
        // the custom one is left untouched
5226
        $liveContent = $contentService->publishVersion($draftVersion2->getVersionInfo());
5227
        /* END: Use Case */
5228
5229
        $location = $locationService->loadLocation(
5230
            $liveContent->getVersionInfo()->getContentInfo()->mainLocationId
5231
        );
5232
5233
        $aliases = $urlAliasService->listLocationAliases($location);
5234
5235
        $this->assertAliasesCorrect(
5236
            array(
5237
                '/my/fancy/story-about-ez-publish' => array(
5238
                    'type' => URLAlias::LOCATION,
5239
                    'destination' => $location->id,
5240
                    'path' => '/my/fancy/story-about-ez-publish',
5241
                    'languageCodes' => array('eng-US'),
5242
                    'isHistory' => false,
5243
                    'isCustom' => true,
5244
                    'forward' => false,
5245
                    'alwaysAvailable' => false,
5246
                ),
5247
            ),
5248
            $aliases
5249
        );
5250
    }
5251
5252
    /**
5253
     * Test to ensure that old versions are not affected by updates to newer
5254
     * drafts.
5255
     */
5256
    public function testUpdatingDraftDoesNotUpdateOldVersions()
5257
    {
5258
        $repository = $this->getRepository();
5259
5260
        $contentService = $repository->getContentService();
5261
5262
        $contentVersion2 = $this->createContentVersion2();
5263
5264
        $loadedContent1 = $contentService->loadContent($contentVersion2->id, null, 1);
5265
        $loadedContent2 = $contentService->loadContent($contentVersion2->id, null, 2);
5266
5267
        $this->assertNotEquals(
5268
            $loadedContent1->getFieldValue('name', 'eng-US'),
5269
            $loadedContent2->getFieldValue('name', 'eng-US')
5270
        );
5271
    }
5272
5273
    /**
5274
     * Test scenario with writer and publisher users.
5275
     * Writer can only create content. Publisher can publish this content.
5276
     */
5277
    public function testPublishWorkflow()
5278
    {
5279
        $repository = $this->getRepository();
5280
        $contentService = $repository->getContentService();
5281
5282
        $this->createRoleWithPolicies('Publisher', [
5283
            ['module' => 'content', 'function' => 'read'],
5284
            ['module' => 'content', 'function' => 'create'],
5285
            ['module' => 'content', 'function' => 'publish'],
5286
        ]);
5287
5288
        $this->createRoleWithPolicies('Writer', [
5289
            ['module' => 'content', 'function' => 'read'],
5290
            ['module' => 'content', 'function' => 'create'],
5291
        ]);
5292
5293
        $writerUser = $this->createCustomUserWithLogin(
5294
            'writer',
5295
            '[email protected]',
5296
            'Writers',
5297
            'Writer'
5298
        );
5299
5300
        $publisherUser = $this->createCustomUserWithLogin(
5301
            'publisher',
5302
            '[email protected]',
5303
            'Publishers',
5304
            'Publisher'
5305
        );
5306
5307
        $repository->getPermissionResolver()->setCurrentUserReference($writerUser);
5308
        $draft = $this->createContentDraftVersion1();
5309
5310
        $repository->getPermissionResolver()->setCurrentUserReference($publisherUser);
5311
        $content = $contentService->publishVersion($draft->versionInfo);
5312
5313
        $contentService->loadContent($content->id);
5314
    }
5315
5316
    /**
5317
     * Test publish / content policy is required to be able to publish content.
5318
     *
5319
     * @expectedException \eZ\Publish\Core\Base\Exceptions\UnauthorizedException
5320
     * @expectedExceptionMessageRegExp /User does not have access to 'publish' 'content'/
5321
     */
5322
    public function testPublishContentWithoutPublishPolicyThrowsException()
5323
    {
5324
        $repository = $this->getRepository();
5325
5326
        $this->createRoleWithPolicies('Writer', [
5327
            ['module' => 'content', 'function' => 'read'],
5328
            ['module' => 'content', 'function' => 'create'],
5329
            ['module' => 'content', 'function' => 'edit'],
5330
        ]);
5331
        $writerUser = $this->createCustomUserWithLogin(
5332
            'writer',
5333
            '[email protected]',
5334
            'Writers',
5335
            'Writer'
5336
        );
5337
        $repository->getPermissionResolver()->setCurrentUserReference($writerUser);
5338
5339
        $this->createContentVersion1();
5340
    }
5341
5342
    /**
5343
     * Test removal of the specific translation from all the Versions of a Content Object.
5344
     *
5345
     * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation
5346
     */
5347 View Code Duplication
    public function testDeleteTranslation()
5348
    {
5349
        $repository = $this->getRepository();
5350
        $contentService = $repository->getContentService();
5351
        $content = $this->createContentVersion2();
5352
5353
        // create multiple versions to exceed archive limit
5354
        for ($i = 0; $i < 5; ++$i) {
5355
            $contentDraft = $contentService->createContentDraft($content->contentInfo);
5356
            $contentUpdateStruct = $contentService->newContentUpdateStruct();
5357
            $contentDraft = $contentService->updateContent(
5358
                $contentDraft->versionInfo,
5359
                $contentUpdateStruct
5360
            );
5361
            $contentService->publishVersion($contentDraft->versionInfo);
5362
        }
5363
5364
        $contentService->deleteTranslation($content->contentInfo, 'eng-GB');
5365
5366
        $this->assertTranslationDoesNotExist('eng-GB', $content->id);
5367
    }
5368
5369
    /**
5370
     * Test deleting a Translation which is initial for some Version, updates initialLanguageCode
5371
     * with mainLanguageCode (assuming they are different).
5372
     */
5373
    public function testDeleteTranslationUpdatesInitialLanguageCodeVersion()
5374
    {
5375
        $repository = $this->getRepository();
5376
        $contentService = $repository->getContentService();
5377
5378
        $content = $this->createContentVersion2();
5379
        // create another, copied, version
5380
        $contentDraft = $contentService->updateContent(
5381
            $contentService->createContentDraft($content->contentInfo)->versionInfo,
5382
            $contentService->newContentUpdateStruct()
5383
        );
5384
        $publishedContent = $contentService->publishVersion($contentDraft->versionInfo);
5385
5386
        // remove first version with only one translation as it is not the subject of this test
5387
        $contentService->deleteVersion(
5388
            $contentService->loadVersionInfo($publishedContent->contentInfo, 1)
5389
        );
5390
5391
        // sanity check
5392
        self::assertEquals('eng-US', $content->contentInfo->mainLanguageCode);
5393
        self::assertEquals('eng-US', $content->versionInfo->initialLanguageCode);
5394
5395
        // update mainLanguageCode so it is different than initialLanguageCode for Version
5396
        $contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct();
5397
        $contentMetadataUpdateStruct->mainLanguageCode = 'eng-GB';
5398
        $content = $contentService->updateContentMetadata($publishedContent->contentInfo, $contentMetadataUpdateStruct);
5399
5400
        $contentService->deleteTranslation($content->contentInfo, 'eng-US');
5401
5402
        $this->assertTranslationDoesNotExist('eng-US', $content->id);
5403
    }
5404
5405
    /**
5406
     * Test removal of the specific translation properly updates languages of the URL alias.
5407
     *
5408
     * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation
5409
     */
5410
    public function testDeleteTranslationUpdatesUrlAlias()
5411
    {
5412
        $repository = $this->getRepository();
5413
        $contentService = $repository->getContentService();
5414
        $locationService = $repository->getLocationService();
5415
        $urlAliasService = $repository->getURLAliasService();
5416
5417
        $content = $this->createContentVersion2();
5418
        $mainLocation = $locationService->loadLocation($content->contentInfo->mainLocationId);
5419
5420
        // create custom URL alias for Content main Location
5421
        $urlAliasService->createUrlAlias($mainLocation, '/my-custom-url', 'eng-GB');
5422
5423
        // create secondary Location for Content
5424
        $secondaryLocation = $locationService->createLocation(
5425
            $content->contentInfo,
5426
            $locationService->newLocationCreateStruct(2)
5427
        );
5428
5429
        // create custom URL alias for Content secondary Location
5430
        $urlAliasService->createUrlAlias($secondaryLocation, '/my-secondary-url', 'eng-GB');
5431
5432
        // delete Translation
5433
        $contentService->deleteTranslation($content->contentInfo, 'eng-GB');
5434
5435
        foreach ([$mainLocation, $secondaryLocation] as $location) {
5436
            // check auto-generated URL aliases
5437
            foreach ($urlAliasService->listLocationAliases($location, false) as $alias) {
5438
                self::assertNotContains('eng-GB', $alias->languageCodes);
5439
            }
5440
5441
            // check custom URL aliases
5442
            foreach ($urlAliasService->listLocationAliases($location) as $alias) {
5443
                self::assertNotContains('eng-GB', $alias->languageCodes);
5444
            }
5445
        }
5446
    }
5447
5448
    /**
5449
     * Test removal of a main translation throws BadStateException.
5450
     *
5451
     * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation
5452
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
5453
     * @expectedExceptionMessage Specified translation is the main translation of the Content Object
5454
     */
5455
    public function testDeleteTranslationMainLanguageThrowsBadStateException()
5456
    {
5457
        $repository = $this->getRepository();
5458
        $contentService = $repository->getContentService();
5459
        $content = $this->createContentVersion2();
5460
5461
        // delete first version which has only one translation
5462
        $contentService->deleteVersion($contentService->loadVersionInfo($content->contentInfo, 1));
5463
5464
        // try to delete main translation
5465
        $contentService->deleteTranslation($content->contentInfo, $content->contentInfo->mainLanguageCode);
5466
    }
5467
5468
    /**
5469
     * Test removal of a Translation is possible when some archived Versions have only this Translation.
5470
     *
5471
     * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation
5472
     */
5473
    public function testDeleteTranslationDeletesSingleTranslationVersions()
5474
    {
5475
        $repository = $this->getRepository();
5476
        $contentService = $repository->getContentService();
5477
        // content created by the createContentVersion1 method has eng-US translation only.
5478
        $content = $this->createContentVersion1();
5479
5480
        // create new version and add eng-GB translation
5481
        $contentDraft = $contentService->createContentDraft($content->contentInfo);
5482
        $contentUpdateStruct = $contentService->newContentUpdateStruct();
5483
        $contentUpdateStruct->setField('name', 'Awesome Board', 'eng-GB');
5484
        $contentDraft = $contentService->updateContent($contentDraft->versionInfo, $contentUpdateStruct);
5485
        $publishedContent = $contentService->publishVersion($contentDraft->versionInfo);
5486
5487
        // update mainLanguageCode to avoid exception related to that
5488
        $contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct();
5489
        $contentMetadataUpdateStruct->mainLanguageCode = 'eng-GB';
5490
5491
        $content = $contentService->updateContentMetadata($publishedContent->contentInfo, $contentMetadataUpdateStruct);
5492
5493
        $contentService->deleteTranslation($content->contentInfo, 'eng-US');
5494
5495
        $this->assertTranslationDoesNotExist('eng-US', $content->id);
5496
    }
5497
5498
    /**
5499
     * Test removal of the translation by the user who is not allowed to delete a content
5500
     * throws UnauthorizedException.
5501
     *
5502
     * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation
5503
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
5504
     * @expectedExceptionMessage User does not have access to 'remove' 'content'
5505
     */
5506
    public function testDeleteTranslationThrowsUnauthorizedException()
5507
    {
5508
        $repository = $this->getRepository();
5509
        $contentService = $repository->getContentService();
5510
5511
        $content = $this->createContentVersion2();
5512
5513
        // create user that can read/create/edit but cannot delete content
5514
        $this->createRoleWithPolicies('Writer', [
5515
            ['module' => 'content', 'function' => 'read'],
5516
            ['module' => 'content', 'function' => 'versionread'],
5517
            ['module' => 'content', 'function' => 'create'],
5518
            ['module' => 'content', 'function' => 'edit'],
5519
        ]);
5520
        $writerUser = $this->createCustomUserWithLogin(
5521
            'writer',
5522
            '[email protected]',
5523
            'Writers',
5524
            'Writer'
5525
        );
5526
        $repository->getPermissionResolver()->setCurrentUserReference($writerUser);
5527
        $contentService->deleteTranslation($content->contentInfo, 'eng-GB');
5528
    }
5529
5530
    /**
5531
     * Test removal of a non-existent translation throws InvalidArgumentException.
5532
     *
5533
     * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslation
5534
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
5535
     * @expectedExceptionMessage Argument '$languageCode' is invalid: ger-DE does not exist in the Content item
5536
     */
5537
    public function testDeleteTranslationThrowsInvalidArgumentException()
5538
    {
5539
        $repository = $this->getRepository();
5540
        $contentService = $repository->getContentService();
5541
        // content created by the createContentVersion1 method has eng-US translation only.
5542
        $content = $this->createContentVersion1();
5543
        $contentService->deleteTranslation($content->contentInfo, 'ger-DE');
5544
    }
5545
5546
    /**
5547
     * Test deleting a Translation from Draft.
5548
     *
5549
     * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft
5550
     */
5551
    public function testDeleteTranslationFromDraft()
5552
    {
5553
        $repository = $this->getRepository();
5554
        $contentService = $repository->getContentService();
5555
5556
        $languageCode = 'eng-GB';
5557
        $content = $this->createMultipleLanguageContentVersion2();
5558
        $draft = $contentService->createContentDraft($content->contentInfo);
5559
        $draft = $contentService->deleteTranslationFromDraft($draft->versionInfo, $languageCode);
5560
        $content = $contentService->publishVersion($draft->versionInfo);
5561
5562
        $loadedContent = $contentService->loadContent($content->id);
5563
        self::assertNotContains($languageCode, $loadedContent->versionInfo->languageCodes);
5564
        self::assertEmpty($loadedContent->getFieldsByLanguage($languageCode));
5565
    }
5566
5567
    /**
5568
     * Get values for multilingual field.
5569
     *
5570
     * @return array
5571
     */
5572
    public function providerForDeleteTranslationFromDraftRemovesUrlAliasOnPublishing()
5573
    {
5574
        return [
5575
            [
5576
                ['eng-US' => 'US Name', 'eng-GB' => 'GB Name'],
5577
            ],
5578
            [
5579
                ['eng-US' => 'Same Name', 'eng-GB' => 'Same Name'],
5580
            ],
5581
        ];
5582
    }
5583
5584
    /**
5585
     * Test deleting a Translation from Draft removes previously stored URL aliases for published Content.
5586
     *
5587
     * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft
5588
     *
5589
     * @dataProvider providerForDeleteTranslationFromDraftRemovesUrlAliasOnPublishing
5590
     *
5591
     * @param string[] $fieldValues translated field values
5592
     *
5593
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException
5594
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
5595
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
5596
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
5597
     */
5598
    public function testDeleteTranslationFromDraftRemovesUrlAliasOnPublishing(array $fieldValues)
5599
    {
5600
        $repository = $this->getRepository();
5601
        $contentService = $repository->getContentService();
5602
        $locationService = $repository->getLocationService();
5603
        $urlAliasService = $repository->getURLAliasService();
5604
5605
        // set language code to be removed
5606
        $languageCode = 'eng-GB';
5607
        $draft = $this->createMultilingualContentDraft(
5608
            'folder',
5609
            2,
5610
            'eng-US',
5611
            [
5612
                'name' => [
5613
                    'eng-GB' => $fieldValues['eng-GB'],
5614
                    'eng-US' => $fieldValues['eng-US'],
5615
                ],
5616
            ]
5617
        );
5618
        $content = $contentService->publishVersion($draft->versionInfo);
5619
5620
        // create secondary location
5621
        $locationService->createLocation(
5622
            $content->contentInfo,
5623
            $locationService->newLocationCreateStruct(5)
5624
        );
5625
5626
        // sanity check
5627
        $locations = $locationService->loadLocations($content->contentInfo);
5628
        self::assertCount(2, $locations, 'Sanity check: Expected to find 2 Locations');
5629
        foreach ($locations as $location) {
5630
            $urlAliasService->createUrlAlias($location, '/us-custom_' . $location->id, 'eng-US');
5631
            $urlAliasService->createUrlAlias($location, '/gb-custom_' . $location->id, 'eng-GB');
5632
5633
            // check default URL aliases
5634
            $aliases = $urlAliasService->listLocationAliases($location, false, $languageCode);
5635
            self::assertNotEmpty($aliases, 'Sanity check: URL alias for the translation does not exist');
5636
5637
            // check custom URL aliases
5638
            $aliases = $urlAliasService->listLocationAliases($location, true, $languageCode);
5639
            self::assertNotEmpty($aliases, 'Sanity check: Custom URL alias for the translation does not exist');
5640
        }
5641
5642
        // delete translation and publish new version
5643
        $draft = $contentService->createContentDraft($content->contentInfo);
5644
        $draft = $contentService->deleteTranslationFromDraft($draft->versionInfo, $languageCode);
5645
        $contentService->publishVersion($draft->versionInfo);
5646
5647
        // check that aliases does not exist
5648
        foreach ($locations as $location) {
5649
            // check default URL aliases
5650
            $aliases = $urlAliasService->listLocationAliases($location, false, $languageCode);
5651
            self::assertEmpty($aliases, 'URL alias for the deleted translation still exists');
5652
5653
            // check custom URL aliases
5654
            $aliases = $urlAliasService->listLocationAliases($location, true, $languageCode);
5655
            self::assertEmpty($aliases, 'Custom URL alias for the deleted translation still exists');
5656
        }
5657
    }
5658
5659
    /**
5660
     * Test that URL aliases for deleted Translations are properly archived.
5661
     */
5662
    public function testDeleteTranslationFromDraftArchivesUrlAliasOnPublishing()
5663
    {
5664
        $repository = $this->getRepository();
5665
        $contentService = $repository->getContentService();
5666
        $urlAliasService = $repository->getURLAliasService();
5667
5668
        $content = $contentService->publishVersion(
5669
            $this->createMultilingualContentDraft(
5670
                'folder',
5671
                2,
5672
                'eng-US',
5673
                [
5674
                    'name' => [
5675
                        'eng-GB' => 'BritishEnglishContent',
5676
                        'eng-US' => 'AmericanEnglishContent',
5677
                    ],
5678
                ]
5679
            )->versionInfo
5680
        );
5681
5682
        $unrelatedContent = $contentService->publishVersion(
5683
            $this->createMultilingualContentDraft(
5684
                'folder',
5685
                2,
5686
                'eng-US',
5687
                [
5688
                    'name' => [
5689
                        'eng-GB' => 'AnotherBritishContent',
5690
                        'eng-US' => 'AnotherAmericanContent',
5691
                    ],
5692
                ]
5693
            )->versionInfo
5694
        );
5695
5696
        $urlAlias = $urlAliasService->lookup('/BritishEnglishContent');
5697
        self::assertFalse($urlAlias->isHistory);
5698
        self::assertEquals($urlAlias->path, '/BritishEnglishContent');
5699
        self::assertEquals($urlAlias->destination, $content->contentInfo->mainLocationId);
5700
5701
        $draft = $contentService->deleteTranslationFromDraft(
5702
            $contentService->createContentDraft($content->contentInfo)->versionInfo,
5703
            'eng-GB'
5704
        );
5705
        $content = $contentService->publishVersion($draft->versionInfo);
5706
5707
        $urlAlias = $urlAliasService->lookup('/BritishEnglishContent');
5708
        self::assertTrue($urlAlias->isHistory);
5709
        self::assertEquals($urlAlias->path, '/BritishEnglishContent');
5710
        self::assertEquals($urlAlias->destination, $content->contentInfo->mainLocationId);
5711
5712
        $unrelatedUrlAlias = $urlAliasService->lookup('/AnotherBritishContent');
5713
        self::assertFalse($unrelatedUrlAlias->isHistory);
5714
        self::assertEquals($unrelatedUrlAlias->path, '/AnotherBritishContent');
5715
        self::assertEquals($unrelatedUrlAlias->destination, $unrelatedContent->contentInfo->mainLocationId);
5716
    }
5717
5718
    /**
5719
     * Test deleting a Translation from Draft which has single Translation throws BadStateException.
5720
     *
5721
     * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft
5722
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
5723
     * @expectedExceptionMessage Specified Translation is the only one Content Object Version has
5724
     */
5725
    public function testDeleteTranslationFromDraftThrowsBadStateExceptionOnSingleTranslation()
5726
    {
5727
        $repository = $this->getRepository();
5728
        $contentService = $repository->getContentService();
5729
5730
        // create Content with single Translation
5731
        $publishedContent = $contentService->publishVersion(
5732
            $this->createContentDraft(
5733
                'forum',
5734
                2,
5735
                ['name' => 'Eng-US Version name']
5736
            )->versionInfo
5737
        );
5738
5739
        // update mainLanguageCode to avoid exception related to trying to delete main Translation
5740
        $contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct();
5741
        $contentMetadataUpdateStruct->mainLanguageCode = 'eng-GB';
5742
        $publishedContent = $contentService->updateContentMetadata(
5743
            $publishedContent->contentInfo,
5744
            $contentMetadataUpdateStruct
5745
        );
5746
5747
        // create single Translation Version from the first one
5748
        $draft = $contentService->createContentDraft(
5749
            $publishedContent->contentInfo,
5750
            $publishedContent->versionInfo
5751
        );
5752
5753
        // attempt to delete Translation
5754
        $contentService->deleteTranslationFromDraft($draft->versionInfo, 'eng-US');
5755
    }
5756
5757
    /**
5758
     * Test deleting the Main Translation from Draft throws BadStateException.
5759
     *
5760
     * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft
5761
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
5762
     * @expectedExceptionMessage Specified Translation is the main Translation of the Content Object
5763
     */
5764
    public function testDeleteTranslationFromDraftThrowsBadStateExceptionOnMainTranslation()
5765
    {
5766
        $repository = $this->getRepository();
5767
        $contentService = $repository->getContentService();
5768
5769
        $mainLanguageCode = 'eng-US';
5770
        $draft = $this->createMultilingualContentDraft(
5771
            'forum',
5772
            2,
5773
            $mainLanguageCode,
5774
            [
5775
                'name' => [
5776
                    'eng-US' => 'An awesome eng-US forum',
5777
                    'eng-GB' => 'An awesome eng-GB forum',
5778
                ],
5779
            ]
5780
        );
5781
        $contentService->deleteTranslationFromDraft($draft->versionInfo, $mainLanguageCode);
5782
    }
5783
5784
    /**
5785
     * Test deleting the Translation from Published Version throws BadStateException.
5786
     *
5787
     * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft
5788
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
5789
     * @expectedExceptionMessage Version is not a draft
5790
     */
5791 View Code Duplication
    public function testDeleteTranslationFromDraftThrowsBadStateExceptionOnPublishedVersion()
5792
    {
5793
        $repository = $this->getRepository();
5794
        $contentService = $repository->getContentService();
5795
5796
        $languageCode = 'eng-US';
5797
        $content = $this->createMultipleLanguageContentVersion2();
5798
        $draft = $contentService->createContentDraft($content->contentInfo);
5799
        $publishedContent = $contentService->publishVersion($draft->versionInfo);
5800
        $contentService->deleteTranslationFromDraft($publishedContent->versionInfo, $languageCode);
5801
    }
5802
5803
    /**
5804
     * Test deleting a Translation from Draft throws UnauthorizedException if user cannot edit Content.
5805
     *
5806
     * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft
5807
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
5808
     * @expectedExceptionMessage User does not have access to 'edit' 'content'
5809
     */
5810
    public function testDeleteTranslationFromDraftThrowsUnauthorizedException()
5811
    {
5812
        $repository = $this->getRepository();
5813
        $contentService = $repository->getContentService();
5814
5815
        $languageCode = 'eng-GB';
5816
        $content = $this->createMultipleLanguageContentVersion2();
5817
        $draft = $contentService->createContentDraft($content->contentInfo);
5818
5819
        // create user that can read/create/delete but cannot edit or content
5820
        $this->createRoleWithPolicies('Writer', [
5821
            ['module' => 'content', 'function' => 'read'],
5822
            ['module' => 'content', 'function' => 'versionread'],
5823
            ['module' => 'content', 'function' => 'create'],
5824
            ['module' => 'content', 'function' => 'delete'],
5825
        ]);
5826
        $writerUser = $this->createCustomUserWithLogin(
5827
            'user',
5828
            '[email protected]',
5829
            'Writers',
5830
            'Writer'
5831
        );
5832
        $repository->getPermissionResolver()->setCurrentUserReference($writerUser);
5833
5834
        $contentService->deleteTranslationFromDraft($draft->versionInfo, $languageCode);
5835
    }
5836
5837
    /**
5838
     * Test deleting a non-existent Translation from Draft throws InvalidArgumentException.
5839
     *
5840
     * @covers \eZ\Publish\Core\Repository\ContentService::deleteTranslationFromDraft
5841
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
5842
     * @expectedExceptionMessageRegExp /The Version \(ContentId=\d+, VersionNo=\d+\) is not translated into ger-DE/
5843
     */
5844
    public function testDeleteTranslationFromDraftThrowsInvalidArgumentException()
5845
    {
5846
        $repository = $this->getRepository();
5847
        $contentService = $repository->getContentService();
5848
5849
        $languageCode = 'ger-DE';
5850
        $content = $this->createMultipleLanguageContentVersion2();
5851
        $draft = $contentService->createContentDraft($content->contentInfo);
5852
        $contentService->deleteTranslationFromDraft($draft->versionInfo, $languageCode);
5853
    }
5854
5855
    /**
5856
     * Test loading list of Content items.
5857
     */
5858
    public function testLoadContentListByContentInfo()
5859
    {
5860
        $repository = $this->getRepository();
5861
        $contentService = $repository->getContentService();
5862
        $locationService = $repository->getLocationService();
5863
5864
        $allLocationsCount = $locationService->getAllLocationsCount();
5865
        $contentInfoList = array_map(
5866
            function (Location $location) {
5867
                return $location->contentInfo;
5868
            },
5869
            $locationService->loadAllLocations(0, $allLocationsCount)
5870
        );
5871
5872
        $contentList = $contentService->loadContentListByContentInfo($contentInfoList);
5873
        self::assertCount(count($contentInfoList), $contentList);
5874
        foreach ($contentList as $content) {
5875
            try {
5876
                $loadedContent = $contentService->loadContent($content->id);
5877
                self::assertEquals($loadedContent, $content, "Failed to properly bulk-load Content {$content->id}");
5878
            } catch (NotFoundException $e) {
5879
                self::fail("Failed to load Content {$content->id}: {$e->getMessage()}");
5880
            } catch (UnauthorizedException $e) {
5881
                self::fail("Failed to load Content {$content->id}: {$e->getMessage()}");
5882
            }
5883
        }
5884
    }
5885
5886
    /**
5887
     * Test loading content versions after removing exactly two drafts.
5888
     *
5889
     * @see https://jira.ez.no/browse/EZP-30271
5890
     *
5891
     * @covers \eZ\Publish\Core\Repository\ContentService::deleteVersion
5892
     */
5893
    public function testLoadVersionsAfterDeletingTwoDrafts()
5894
    {
5895
        $repository = $this->getRepository();
5896
        $contentService = $repository->getContentService();
5897
5898
        $content = $this->createFolder(['eng-GB' => 'Foo'], 2);
5899
5900
        // First update and publish
5901
        $modifiedContent = $this->updateFolder($content, ['eng-GB' => 'Foo1']);
5902
        $content = $contentService->publishVersion($modifiedContent->versionInfo);
5903
5904
        // Second update and publish
5905
        $modifiedContent = $this->updateFolder($content, ['eng-GB' => 'Foo2']);
5906
        $content = $contentService->publishVersion($modifiedContent->versionInfo);
5907
5908
        // Create drafts
5909
        $this->updateFolder($content, ['eng-GB' => 'Foo3']);
5910
        $this->updateFolder($content, ['eng-GB' => 'Foo4']);
5911
5912
        $versions = $contentService->loadVersions($content->contentInfo);
5913
5914
        foreach ($versions as $key => $version) {
5915
            if ($version->isDraft()) {
5916
                $contentService->deleteVersion($version);
5917
                unset($versions[$key]);
5918
            }
5919
        }
5920
5921
        $this->assertEquals($versions, $contentService->loadVersions($content->contentInfo));
5922
    }
5923
5924
    /**
5925
     * Asserts that all aliases defined in $expectedAliasProperties with the
5926
     * given properties are available in $actualAliases and not more.
5927
     *
5928
     * @param array $expectedAliasProperties
5929
     * @param array $actualAliases
5930
     */
5931
    private function assertAliasesCorrect(array $expectedAliasProperties, array $actualAliases)
5932
    {
5933
        foreach ($actualAliases as $actualAlias) {
5934
            if (!isset($expectedAliasProperties[$actualAlias->path])) {
5935
                $this->fail(
5936
                    sprintf(
5937
                        'Alias with path "%s" in languages "%s" not expected.',
5938
                        $actualAlias->path,
5939
                        implode(', ', $actualAlias->languageCodes)
5940
                    )
5941
                );
5942
            }
5943
5944
            foreach ($expectedAliasProperties[$actualAlias->path] as $propertyName => $propertyValue) {
5945
                $this->assertEquals(
5946
                    $propertyValue,
5947
                    $actualAlias->$propertyName,
5948
                    sprintf(
5949
                        'Property $%s incorrect on alias with path "%s" in languages "%s".',
5950
                        $propertyName,
5951
                        $actualAlias->path,
5952
                        implode(', ', $actualAlias->languageCodes)
5953
                    )
5954
                );
5955
            }
5956
5957
            unset($expectedAliasProperties[$actualAlias->path]);
5958
        }
5959
5960
        if (!empty($expectedAliasProperties)) {
5961
            $this->fail(
5962
                sprintf(
5963
                    'Missing expected aliases with paths "%s".',
5964
                    implode('", "', array_keys($expectedAliasProperties))
5965
                )
5966
            );
5967
        }
5968
    }
5969
5970
    /**
5971
     * Asserts that the given fields are equal to the default fields fixture.
5972
     *
5973
     * @param \eZ\Publish\API\Repository\Values\Content\Field[] $fields
5974
     */
5975
    private function assertAllFieldsEquals(array $fields)
5976
    {
5977
        $actual = $this->normalizeFields($fields);
5978
        $expected = $this->normalizeFields($this->createFieldsFixture());
5979
5980
        $this->assertEquals($expected, $actual);
5981
    }
5982
5983
    /**
5984
     * Asserts that the given fields are equal to a language filtered set of the
5985
     * default fields fixture.
5986
     *
5987
     * @param \eZ\Publish\API\Repository\Values\Content\Field[] $fields
5988
     * @param string $languageCode
5989
     */
5990
    private function assertLocaleFieldsEquals(array $fields, $languageCode)
5991
    {
5992
        $actual = $this->normalizeFields($fields);
5993
5994
        $expected = array();
5995
        foreach ($this->normalizeFields($this->createFieldsFixture()) as $field) {
5996
            if ($field->languageCode !== $languageCode) {
5997
                continue;
5998
            }
5999
            $expected[] = $field;
6000
        }
6001
6002
        $this->assertEquals($expected, $actual);
6003
    }
6004
6005
    /**
6006
     * This method normalizes a set of fields and returns a normalized set.
6007
     *
6008
     * Normalization means it resets the storage specific field id to zero and
6009
     * it sorts the field by their identifier and their language code. In
6010
     * addition, the field value is removed, since this one depends on the
6011
     * specific FieldType, which is tested in a dedicated integration test.
6012
     *
6013
     * @param \eZ\Publish\API\Repository\Values\Content\Field[] $fields
6014
     *
6015
     * @return \eZ\Publish\API\Repository\Values\Content\Field[]
6016
     */
6017
    private function normalizeFields(array $fields)
6018
    {
6019
        $normalized = array();
6020 View Code Duplication
        foreach ($fields as $field) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6021
            $normalized[] = new Field(
6022
                array(
6023
                    'id' => 0,
6024
                    'value' => ($field->value !== null ? true : null),
6025
                    'languageCode' => $field->languageCode,
6026
                    'fieldDefIdentifier' => $field->fieldDefIdentifier,
6027
                    'fieldTypeIdentifier' => $field->fieldTypeIdentifier,
6028
                )
6029
            );
6030
        }
6031
        usort(
6032
            $normalized,
6033 View Code Duplication
            function ($field1, $field2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6034
                if (0 === ($return = strcasecmp($field1->fieldDefIdentifier, $field2->fieldDefIdentifier))) {
6035
                    return strcasecmp($field1->languageCode, $field2->languageCode);
6036
                }
6037
6038
                return $return;
6039
            }
6040
        );
6041
6042
        return $normalized;
6043
    }
6044
6045
    /**
6046
     * Returns a filtered set of the default fields fixture.
6047
     *
6048
     * @param string $languageCode
6049
     *
6050
     * @return \eZ\Publish\API\Repository\Values\Content\Field[]
6051
     */
6052
    private function createLocaleFieldsFixture($languageCode)
6053
    {
6054
        $fields = array();
6055
        foreach ($this->createFieldsFixture() as $field) {
6056
            if (null === $field->languageCode || $languageCode === $field->languageCode) {
6057
                $fields[] = $field;
6058
            }
6059
        }
6060
6061
        return $fields;
6062
    }
6063
6064
    /**
6065
     * Asserts that given Content has default ContentStates.
6066
     *
6067
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
6068
     */
6069 View Code Duplication
    private function assertDefaultContentStates(ContentInfo $contentInfo)
6070
    {
6071
        $repository = $this->getRepository();
6072
        $objectStateService = $repository->getObjectStateService();
6073
6074
        $objectStateGroups = $objectStateService->loadObjectStateGroups();
6075
6076
        foreach ($objectStateGroups as $objectStateGroup) {
6077
            $contentState = $objectStateService->getContentState($contentInfo, $objectStateGroup);
6078
            foreach ($objectStateService->loadObjectStates($objectStateGroup) as $objectState) {
6079
                // Only check the first object state which is the default one.
6080
                $this->assertEquals(
6081
                    $objectState,
6082
                    $contentState
6083
                );
6084
                break;
6085
            }
6086
        }
6087
    }
6088
6089
    /**
6090
     * Assert that given Content has no references to a translation specified by the $languageCode.
6091
     *
6092
     * @param string $languageCode
6093
     * @param int $contentId
6094
     */
6095
    private function assertTranslationDoesNotExist($languageCode, $contentId)
6096
    {
6097
        $repository = $this->getRepository();
6098
        $contentService = $repository->getContentService();
6099
6100
        $content = $contentService->loadContent($contentId);
6101
6102
        foreach ($content->fields as $fieldIdentifier => $field) {
6103
            /** @var array $field */
6104
            self::assertArrayNotHasKey($languageCode, $field);
6105
            self::assertNotEquals($languageCode, $content->contentInfo->mainLanguageCode);
6106
            self::assertArrayNotHasKey($languageCode, $content->versionInfo->getNames());
6107
            self::assertNotEquals($languageCode, $content->versionInfo->initialLanguageCode);
6108
            self::assertNotContains($languageCode, $content->versionInfo->languageCodes);
6109
        }
6110
        foreach ($contentService->loadVersions($content->contentInfo) as $versionInfo) {
6111
            self::assertArrayNotHasKey($languageCode, $versionInfo->getNames());
6112
            self::assertNotEquals($languageCode, $versionInfo->contentInfo->mainLanguageCode);
6113
            self::assertNotEquals($languageCode, $versionInfo->initialLanguageCode);
6114
            self::assertNotContains($languageCode, $versionInfo->languageCodes);
6115
        }
6116
    }
6117
6118
    /**
6119
     * Returns the default fixture of fields used in most tests.
6120
     *
6121
     * @return \eZ\Publish\API\Repository\Values\Content\Field[]
6122
     */
6123
    private function createFieldsFixture()
6124
    {
6125
        return array(
6126
            new Field(
6127
                array(
6128
                    'id' => 0,
6129
                    'value' => 'Foo',
6130
                    'languageCode' => 'eng-US',
6131
                    'fieldDefIdentifier' => 'description',
6132
                    'fieldTypeIdentifier' => 'ezrichtext',
6133
                )
6134
            ),
6135
            new Field(
6136
                array(
6137
                    'id' => 0,
6138
                    'value' => 'Bar',
6139
                    'languageCode' => 'eng-GB',
6140
                    'fieldDefIdentifier' => 'description',
6141
                    'fieldTypeIdentifier' => 'ezrichtext',
6142
                )
6143
            ),
6144
            new Field(
6145
                array(
6146
                    'id' => 0,
6147
                    'value' => 'An awesome multi-lang forum²',
6148
                    'languageCode' => 'eng-US',
6149
                    'fieldDefIdentifier' => 'name',
6150
                    'fieldTypeIdentifier' => 'ezstring',
6151
                )
6152
            ),
6153
            new Field(
6154
                array(
6155
                    'id' => 0,
6156
                    'value' => 'An awesome multi-lang forum²³',
6157
                    'languageCode' => 'eng-GB',
6158
                    'fieldDefIdentifier' => 'name',
6159
                    'fieldTypeIdentifier' => 'ezstring',
6160
                )
6161
            ),
6162
        );
6163
    }
6164
6165
    /**
6166
     * Gets expected property values for the "Media" ContentInfo ValueObject.
6167
     *
6168
     * @return array
6169
     */
6170 View Code Duplication
    private function getExpectedMediaContentInfoProperties()
6171
    {
6172
        return [
6173
            'id' => 41,
6174
            'contentTypeId' => 1,
6175
            'name' => 'Media',
6176
            'sectionId' => 3,
6177
            'currentVersionNo' => 1,
6178
            'published' => true,
6179
            'ownerId' => 14,
6180
            'modificationDate' => $this->createDateTime(1060695457),
6181
            'publishedDate' => $this->createDateTime(1060695457),
6182
            'alwaysAvailable' => 1,
6183
            'remoteId' => 'a6e35cbcb7cd6ae4b691f3eee30cd262',
6184
            'mainLanguageCode' => 'eng-US',
6185
            'mainLocationId' => 43,
6186
            'status' => ContentInfo::STATUS_PUBLISHED,
6187
        ];
6188
    }
6189
}
6190