@@ -171,6 +171,38 @@ public function testCoreOnlyOption() {
171171 $ this ->assertFileDoesNotExist ($ contrib_translation_file , 'Contrib translation should not exist after --core-only command. ' );
172172 }
173173
174+ /**
175+ * Tests that core-only option from composer.json skips contrib translations.
176+ */
177+ public function testCoreOnlyOptionFromComposerJson () {
178+ $ composer_json = $ this ->composerJsonDefaults ();
179+ $ composer_json ['extra ' ]['drupal-l10n ' ]['core-only ' ] = TRUE ;
180+ $ this ->writeComposerJson ($ composer_json );
181+
182+ $ core_version = '9.5.3 ' ;
183+ $ contrib_module = 'entity_share ' ;
184+ $ contrib_composer_version = '3.0.0-rc4 ' ;
185+ $ contrib_drupal_version = '8.x-3.0-rc4 ' ;
186+ $ translations_directory = $ this ->tmpDir . DIRECTORY_SEPARATOR . 'translations ' . DIRECTORY_SEPARATOR . 'contrib ' ;
187+ $ core_translation_file = $ translations_directory . DIRECTORY_SEPARATOR . 'drupal- ' . $ core_version . '.fr.po ' ;
188+ $ contrib_translation_file = $ translations_directory . DIRECTORY_SEPARATOR . $ contrib_module . '- ' . $ contrib_drupal_version . '.fr.po ' ;
189+
190+ $ this ->composer ('install ' );
191+ $ this ->composer ('require --update-with-dependencies drupal/core:" ' . $ core_version . '" ' );
192+ $ this ->composer ('require drupal/ ' . $ contrib_module . ':" ' . $ contrib_composer_version . '" ' );
193+ $ this ->assertFileExists ($ core_translation_file , 'Drupal core translation should exist after install. ' );
194+ $ this ->assertFileExists ($ contrib_translation_file , 'Contrib translation should exist after install. ' );
195+
196+ $ this ->fs ->remove ($ core_translation_file );
197+ $ this ->fs ->remove ($ contrib_translation_file );
198+ $ this ->assertFileDoesNotExist ($ core_translation_file , 'Drupal core translation should not exist after removal. ' );
199+ $ this ->assertFileDoesNotExist ($ contrib_translation_file , 'Contrib translation should not exist after removal. ' );
200+
201+ $ this ->composer ('drupal:l10n ' );
202+ $ this ->assertFileExists ($ core_translation_file , 'Drupal core translation should exist after composer.json core-only mode. ' );
203+ $ this ->assertFileDoesNotExist ($ contrib_translation_file , 'Contrib translation should not exist after composer.json core-only mode. ' );
204+ }
205+
174206 /**
175207 * Tests that on Drupal 7, core and contrib modules are handled.
176208 */
@@ -219,8 +251,11 @@ public function testDrupal10() {
219251 /**
220252 * Writes the default composer json to the temp directory.
221253 */
222- protected function writeComposerJson () {
223- $ json = json_encode ($ this ->composerJsonDefaults (), JSON_PRETTY_PRINT );
254+ protected function writeComposerJson (array $ composer_json = NULL ) {
255+ if (is_null ($ composer_json )) {
256+ $ composer_json = $ this ->composerJsonDefaults ();
257+ }
258+ $ json = json_encode ($ composer_json , JSON_PRETTY_PRINT );
224259 // Write composer.json.
225260 file_put_contents ($ this ->tmpDir . '/composer.json ' , $ json );
226261 }
0 commit comments