diff --git a/src/FileFetcher.php b/src/FileFetcher.php index 77ac6ff..d4c75ef 100644 --- a/src/FileFetcher.php +++ b/src/FileFetcher.php @@ -154,7 +154,7 @@ protected function getFilename($package_name, $drupal_version, $drupal_project_n else { $core_major_version = $this->coreMajorVersion; // Starting from 8.x, translations are in - // https://ftp.drupal.org/files/translations/8.x/ even for Drupal 9. + // https://ftp.drupal.org/files/translations/all/ even for Drupal 9. // And we make the assumption that only a few contrib projects have a 9.x // branch and will make a semver branch. if ($core_major_version >= 8) { @@ -186,12 +186,20 @@ protected function getFilename($package_name, $drupal_version, $drupal_project_n * The prepared URL. */ protected function getUrl($package_name, $drupal_project_name, $filename) { + $core_folder = 'all'; + // Starting from 8.x, translations are in + // https://ftp.drupal.org/files/translations/all/ even for Drupal 9. + // Otherwise it is https://ftp.drupal.org/files/translations/7.x/. + if ($this->coreMajorVersion < 8) { + $core_folder = $this->coreMajorVersion . '.x'; + } + // Special case for Drupal core. if (in_array($package_name, ['drupal/core', 'drupal/drupal'])) { - return 'https://ftp.drupal.org/files/translations/all/drupal/' . $filename; + return 'https://ftp.drupal.org/files/translations/' . $core_folder . '/drupal/' . $filename; } else { - return 'https://ftp.drupal.org/files/translations/all/' . $drupal_project_name . '/' . $filename; + return 'https://ftp.drupal.org/files/translations/' . $core_folder . '/' . $drupal_project_name . '/' . $filename; } } diff --git a/tests/PluginTest.php b/tests/PluginTest.php index 77e50eb..a9be052 100644 --- a/tests/PluginTest.php +++ b/tests/PluginTest.php @@ -173,7 +173,31 @@ public function testDrupal9() { } /** - * Writes the default composer json to the temp direcoty. + * Tests that on Drupal 7, core and contrib modules are handled. + */ + public function testDrupal7() { + $core_version = '7.78.0'; + $contrib_module = 'views'; + $contrib_composer_version = '3.24.0'; + $contrib_drupal_version = '7.x-3.24'; + $translations_directory = $this->tmpDir . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'translations' . DIRECTORY_SEPARATOR . 'contrib'; + $core_translation_file = $translations_directory . DIRECTORY_SEPARATOR . 'drupal-' . $core_version . '.fr.po'; + $fr_translation_file = $translations_directory . DIRECTORY_SEPARATOR . $contrib_module . '-' . $contrib_drupal_version . '.fr.po'; + + $this->assertFileNotExists($core_translation_file, 'French translations file should not exist.'); + $this->assertFileNotExists($fr_translation_file, 'French translations file should not exist.'); + $this->composer('install'); + $this->composer('remove drupal/core'); + // Set Drupal repository to target Drupal 7. + $this->composer('config repositories.drupal composer https://packages.drupal.org/7'); + $this->composer('require drupal/drupal:"' . $core_version . '"'); + $this->composer('require drupal/' . $contrib_module . ':"' . $contrib_composer_version . '"'); + $this->assertFileExists($core_translation_file, 'French translations file should exist.'); + $this->assertFileExists($fr_translation_file, 'French translations file should exist.'); + } + + /** + * Writes the default composer json to the temp directory. */ protected function writeComposerJson() { $json = json_encode($this->composerJsonDefaults(), JSON_PRETTY_PRINT); @@ -201,11 +225,11 @@ protected function writeTestReleaseTag() { protected function composerJsonDefaults() { return [ 'repositories' => [ - [ + 'this_package' => [ 'type' => 'vcs', 'url' => $this->rootDir, ], - [ + 'drupal' => [ 'type' => 'composer', 'url' => 'https://packages.drupal.org/8', ],