99namespace Ibexa \Tests \Integration \Core \Repository \ContentService ;
1010
1111use DateTime ;
12+ use Ibexa \Contracts \Core \Repository \Values \Content \Content ;
1213use Ibexa \Contracts \Core \Repository \Values \ContentType \FieldDefinitionCreateStruct ;
1314use Ibexa \Core \Repository \Values \Content \ContentUpdateStruct ;
1415use Ibexa \Tests \Integration \Core \RepositoryTestCase ;
@@ -31,21 +32,9 @@ public function testCopyNonTranslatableFieldsFromPublishedVersionToDraft(): void
3132 $ this ->createNonTranslatableContentType ();
3233
3334 $ contentService = self ::getContentService ();
34- $ contentTypeService = self ::getContentTypeService ();
35- $ locationService = self ::getLocationService ();
3635
3736 // Creating start content in eng-US language
38- $ contentType = $ contentTypeService ->loadContentTypeByIdentifier (self ::CONTENT_TYPE_IDENTIFIER );
39- $ mainLanguageCode = self ::ENG_US ;
40- $ contentCreateStruct = $ contentService ->newContentCreateStruct ($ contentType , $ mainLanguageCode );
41- $ contentCreateStruct ->setField ('title ' , 'Test title ' );
42-
43- $ contentDraft = $ contentService ->createContent (
44- $ contentCreateStruct ,
45- [
46- $ locationService ->newLocationCreateStruct (2 ),
47- ]
48- );
37+ $ contentDraft = $ this ->createEngDraft ();
4938 $ publishedContent = $ contentService ->publishVersion ($ contentDraft ->getVersionInfo ());
5039
5140 // Creating a draft in ger-DE language with the only field updated being 'title'
@@ -79,11 +68,123 @@ public function testCopyNonTranslatableFieldsFromPublishedVersionToDraft(): void
7968
8069 // Loading main content
8170 $ mainPublishedContent = $ contentService ->loadContent ($ engContent ->id );
71+ $ bodyField = $ mainPublishedContent ->getField ('body ' );
72+ $ bodyFieldValue = $ bodyField !== null ? $ bodyField ->getValue () : null ;
73+
74+ self ::assertSame ($ expectedBodyValue , $ bodyFieldValue ->text );
75+ }
76+
77+ /**
78+ * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception
79+ */
80+ public function testCopyNonTranslatableFieldsTwoParallelDrafts (): void
81+ {
82+ $ this ->createNonTranslatableContentType ();
83+
84+ $ contentService = self ::getContentService ();
85+
86+ // Creating start content in eng-US language
87+ $ contentDraft = $ this ->createEngDraft ();
88+ $ publishedContent = $ contentService ->publishVersion ($ contentDraft ->getVersionInfo ());
89+
90+ // Creating two drafts at the same time
91+ $ usDraft = $ contentService ->createContentDraft ($ publishedContent ->contentInfo );
92+ $ gerDraft = $ contentService ->createContentDraft ($ publishedContent ->contentInfo );
93+
94+ // Publishing the draft in eng-US language
95+ $ contentUpdateStruct = new ContentUpdateStruct ([
96+ 'initialLanguageCode ' => self ::ENG_US ,
97+ 'fields ' => $ usDraft ->getFields (),
98+ ]);
99+ $ contentUpdateStruct ->setField ('title ' , 'Title v2 ' , self ::ENG_US );
100+ $ contentUpdateStruct ->setField ('body ' , 'Nontranslatable body v2 ' , self ::ENG_US );
101+ $ usContent = $ contentService ->updateContent ($ usDraft ->getVersionInfo (), $ contentUpdateStruct );
102+ $ contentService ->publishVersion ($ usContent ->getVersionInfo ());
103+
104+ // Publishing the draft in ger-DE language
105+ $ contentUpdateStruct = new ContentUpdateStruct ([
106+ 'initialLanguageCode ' => self ::GER_DE ,
107+ 'fields ' => $ gerDraft ->getFields (),
108+ ]);
109+ $ contentUpdateStruct ->setField ('title ' , 'Title ger ' , self ::GER_DE );
110+ $ gerContent = $ contentService ->updateContent ($ gerDraft ->getVersionInfo (), $ contentUpdateStruct );
111+ $ contentService ->publishVersion ($ gerContent ->getVersionInfo ());
112+
113+ // Loading main content
114+ $ mainPublishedContent = $ contentService ->loadContent ($ gerContent ->id );
82115 $ bodyFieldValue = $ mainPublishedContent ->getField ('body ' )->getValue ();
83116
117+ self ::assertSame ('Nontranslatable body v2 ' , $ bodyFieldValue ->text );
118+ }
119+
120+ /**
121+ * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception
122+ */
123+ public function testCopyNonTranslatableFieldsOverridesNonMainLanguageDrafts (): void
124+ {
125+ $ this ->createNonTranslatableContentType ();
126+
127+ $ contentService = self ::getContentService ();
128+
129+ // Creating start content in eng-US language
130+ $ contentDraft = $ this ->createEngDraft ();
131+ $ publishedContent = $ contentService ->publishVersion ($ contentDraft ->getVersionInfo ());
132+
133+ // Creating a draft in ger-DE language with the only field updated being 'title'
134+ $ gerDraft = $ contentService ->createContentDraft ($ publishedContent ->contentInfo );
135+
136+ $ contentUpdateStruct = new ContentUpdateStruct ([
137+ 'initialLanguageCode ' => self ::GER_DE ,
138+ 'fields ' => $ contentDraft ->getFields (),
139+ ]);
140+
141+ $ contentUpdateStruct ->setField ('title ' , 'Folder GER ' , self ::GER_DE );
142+ $ gerContent = $ contentService ->updateContent ($ gerDraft ->getVersionInfo (), $ contentUpdateStruct );
143+ $ publishedContent = $ contentService ->publishVersion ($ gerContent ->getVersionInfo ());
144+
145+ // Updating non-translatable field in eng-US language (allowed) and publishing it
146+ $ engContent = $ contentService ->createContentDraft ($ publishedContent ->contentInfo );
147+
148+ $ contentUpdateStruct = new ContentUpdateStruct ([
149+ 'initialLanguageCode ' => self ::ENG_US ,
150+ 'fields ' => $ contentDraft ->getFields (),
151+ ]);
152+
153+ $ expectedBodyValue = 'Non-translatable value ' ;
154+ $ contentUpdateStruct ->setField ('title ' , 'Title v2 ' , self ::ENG_US );
155+ $ contentUpdateStruct ->setField ('body ' , $ expectedBodyValue , self ::ENG_US );
156+
157+ $ engContent = $ contentService ->updateContent ($ engContent ->getVersionInfo (), $ contentUpdateStruct );
158+ $ contentService ->publishVersion ($ engContent ->getVersionInfo ());
159+
160+ // Loading content in ger-DE language
161+ $ mainPublishedContent = $ contentService ->loadContent ($ engContent ->id , ['ger-DE ' ]);
162+ $ bodyField = $ mainPublishedContent ->getField ('body ' );
163+ $ bodyFieldValue = $ bodyField !== null ? $ bodyField ->getValue () : null ;
164+
84165 self ::assertSame ($ expectedBodyValue , $ bodyFieldValue ->text );
85166 }
86167
168+ private function createEngDraft (): Content
169+ {
170+ $ contentService = self ::getContentService ();
171+ $ contentTypeService = self ::getContentTypeService ();
172+ $ locationService = self ::getLocationService ();
173+
174+ $ contentType = $ contentTypeService ->loadContentTypeByIdentifier (self ::CONTENT_TYPE_IDENTIFIER );
175+ $ mainLanguageCode = self ::ENG_US ;
176+ $ contentCreateStruct = $ contentService ->newContentCreateStruct ($ contentType , $ mainLanguageCode );
177+ $ contentCreateStruct ->setField ('title ' , 'Test title ' );
178+ $ contentCreateStruct ->setField ('body ' , 'Test body ' );
179+
180+ return $ contentService ->createContent (
181+ $ contentCreateStruct ,
182+ [
183+ $ locationService ->newLocationCreateStruct (2 ),
184+ ]
185+ );
186+ }
187+
87188 private function createNonTranslatableContentType (): void
88189 {
89190 $ permissionResolver = self ::getPermissionResolver ();
0 commit comments