99namespace Ibexa \Tests \Integration \Core \Repository \ContentService ;
1010
1111use DateTime ;
12+ use eZ \Publish \API \Repository \Values \Content \Content ;
1213use eZ \Publish \API \Repository \Values \ContentType \FieldDefinitionCreateStruct ;
1314use eZ \Publish \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'
@@ -84,6 +73,116 @@ public function testCopyNonTranslatableFieldsFromPublishedVersionToDraft(): void
8473 self ::assertSame ($ expectedBodyValue , $ bodyFieldValue ->text );
8574 }
8675
76+ /**
77+ * @throws \eZ\Publish\API\Repository\Exceptions\Exception
78+ */
79+ public function testCopyNonTranslatableFieldsTwoParallelDrafts (): void
80+ {
81+ $ this ->createNonTranslatableContentType ();
82+
83+ $ contentService = self ::getContentService ();
84+
85+ // Creating start content in eng-US language
86+ $ contentDraft = $ this ->createEngDraft ();
87+ $ publishedContent = $ contentService ->publishVersion ($ contentDraft ->getVersionInfo ());
88+
89+ // Creating two drafts at the same time
90+ $ usDraft = $ contentService ->createContentDraft ($ publishedContent ->contentInfo );
91+ $ gerDraft = $ contentService ->createContentDraft ($ publishedContent ->contentInfo );
92+
93+ // Publishing the draft in eng-US language
94+ $ contentUpdateStruct = new ContentUpdateStruct ([
95+ 'initialLanguageCode ' => self ::ENG_US ,
96+ 'fields ' => $ usDraft ->getFields (),
97+ ]);
98+ $ contentUpdateStruct ->setField ('title ' , 'Title v2 ' , self ::ENG_US );
99+ $ contentUpdateStruct ->setField ('body ' , 'Nontranslatable body v2 ' , self ::ENG_US );
100+ $ usContent = $ contentService ->updateContent ($ usDraft ->getVersionInfo (), $ contentUpdateStruct );
101+ $ contentService ->publishVersion ($ usContent ->getVersionInfo ());
102+
103+ // Publishing the draft in ger-DE language
104+ $ contentUpdateStruct = new ContentUpdateStruct ([
105+ 'initialLanguageCode ' => self ::GER_DE ,
106+ 'fields ' => $ gerDraft ->getFields (),
107+ ]);
108+ $ contentUpdateStruct ->setField ('title ' , 'Title ger ' , self ::GER_DE );
109+ $ gerContent = $ contentService ->updateContent ($ gerDraft ->getVersionInfo (), $ contentUpdateStruct );
110+ $ contentService ->publishVersion ($ gerContent ->getVersionInfo ());
111+
112+ // Loading main content
113+ $ mainPublishedContent = $ contentService ->loadContent ($ gerContent ->id );
114+ $ bodyFieldValue = $ mainPublishedContent ->getField ('body ' )->getValue ();
115+
116+ self ::assertSame ('Nontranslatable body v2 ' , $ bodyFieldValue ->text );
117+ }
118+
119+ /**
120+ * @throws \eZ\Publish\API\Repository\Exceptions\Exception
121+ */
122+ public function testCopyNonTranslatableFieldsOverridesNonMainLanguageDrafts (): void
123+ {
124+ $ this ->createNonTranslatableContentType ();
125+
126+ $ contentService = self ::getContentService ();
127+
128+ // Creating start content in eng-US language
129+ $ contentDraft = $ this ->createEngDraft ();
130+ $ publishedContent = $ contentService ->publishVersion ($ contentDraft ->getVersionInfo ());
131+
132+ // Creating a draft in ger-DE language with the only field updated being 'title'
133+ $ gerDraft = $ contentService ->createContentDraft ($ publishedContent ->contentInfo );
134+
135+ $ contentUpdateStruct = new ContentUpdateStruct ([
136+ 'initialLanguageCode ' => self ::GER_DE ,
137+ 'fields ' => $ contentDraft ->getFields (),
138+ ]);
139+
140+ $ contentUpdateStruct ->setField ('title ' , 'Folder GER ' , self ::GER_DE );
141+ $ gerContent = $ contentService ->updateContent ($ gerDraft ->getVersionInfo (), $ contentUpdateStruct );
142+ $ publishedContent = $ contentService ->publishVersion ($ gerContent ->getVersionInfo ());
143+
144+ // Updating non-translatable field in eng-US language (allowed) and publishing it
145+ $ engContent = $ contentService ->createContentDraft ($ publishedContent ->contentInfo );
146+
147+ $ contentUpdateStruct = new ContentUpdateStruct ([
148+ 'initialLanguageCode ' => self ::ENG_US ,
149+ 'fields ' => $ contentDraft ->getFields (),
150+ ]);
151+
152+ $ expectedBodyValue = 'Non-translatable value ' ;
153+ $ contentUpdateStruct ->setField ('title ' , 'Title v2 ' , self ::ENG_US );
154+ $ contentUpdateStruct ->setField ('body ' , $ expectedBodyValue , self ::ENG_US );
155+
156+ $ engContent = $ contentService ->updateContent ($ engContent ->getVersionInfo (), $ contentUpdateStruct );
157+ $ contentService ->publishVersion ($ engContent ->getVersionInfo ());
158+
159+ // Loading content in ger-DE language
160+ $ mainPublishedContent = $ contentService ->loadContent ($ engContent ->id , ['ger-DE ' ]);
161+ $ bodyFieldValue = $ mainPublishedContent ->getField ('body ' )->getValue ();
162+
163+ self ::assertSame ($ expectedBodyValue , $ bodyFieldValue ->text );
164+ }
165+
166+ private function createEngDraft (): Content
167+ {
168+ $ contentService = self ::getContentService ();
169+ $ contentTypeService = self ::getContentTypeService ();
170+ $ locationService = self ::getLocationService ();
171+
172+ $ contentType = $ contentTypeService ->loadContentTypeByIdentifier (self ::CONTENT_TYPE_IDENTIFIER );
173+ $ mainLanguageCode = self ::ENG_US ;
174+ $ contentCreateStruct = $ contentService ->newContentCreateStruct ($ contentType , $ mainLanguageCode );
175+ $ contentCreateStruct ->setField ('title ' , 'Test title ' );
176+ $ contentCreateStruct ->setField ('body ' , 'Test body ' );
177+
178+ return $ contentService ->createContent (
179+ $ contentCreateStruct ,
180+ [
181+ $ locationService ->newLocationCreateStruct (2 ),
182+ ]
183+ );
184+ }
185+
87186 private function createNonTranslatableContentType (): void
88187 {
89188 $ permissionResolver = self ::getPermissionResolver ();
0 commit comments