From 3caace1d211990375b9447e60776526b34dfc217 Mon Sep 17 00:00:00 2001 From: Florent Torregrosa Date: Sun, 31 Jan 2021 16:38:54 +0100 Subject: [PATCH] Issue #22: Drupal 9 support. --- .travis.yml | 1 - composer.json | 2 +- src/FileFetcher.php | 15 ++++++++++++--- tests/PluginTest.php | 33 +++++++++++++++++++++++++++++++-- 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index d2fbf0b..726ef97 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 7.2 - 7.3 - 7.4 diff --git a/composer.json b/composer.json index 8143d54..3328c2a 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,6 @@ }, "require-dev": { "composer/composer": "1.*", - "phpunit/phpunit": "^6" + "phpunit/phpunit": "<10" } } diff --git a/src/FileFetcher.php b/src/FileFetcher.php index 63600c5..77ac6ff 100644 --- a/src/FileFetcher.php +++ b/src/FileFetcher.php @@ -152,9 +152,18 @@ protected function getFilename($package_name, $drupal_version, $drupal_project_n return 'drupal-' . $drupal_version . '.' . $langcode . '.po'; } 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. + // 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) { + $core_major_version = 8; + } + // Old Drupal format. if ($version_format == 'drupal_format') { - return $drupal_project_name . '-' . $this->coreMajorVersion . '.x-' . $drupal_version . '.' . $langcode . '.po'; + return $drupal_project_name . '-' . $core_major_version . '.x-' . $drupal_version . '.' . $langcode . '.po'; } // Semver format. else { @@ -179,10 +188,10 @@ protected function getFilename($package_name, $drupal_version, $drupal_project_n protected function getUrl($package_name, $drupal_project_name, $filename) { // Special case for Drupal core. if (in_array($package_name, ['drupal/core', 'drupal/drupal'])) { - return 'http://ftp.drupal.org/files/translations/' . $this->coreMajorVersion . '.x/drupal/' . $filename; + return 'https://ftp.drupal.org/files/translations/all/drupal/' . $filename; } else { - return 'http://ftp.drupal.org/files/translations/' . $this->coreMajorVersion . '.x/' . $drupal_project_name . '/' . $filename; + return 'https://ftp.drupal.org/files/translations/all/' . $drupal_project_name . '/' . $filename; } } diff --git a/tests/PluginTest.php b/tests/PluginTest.php index dd8c9b9..77e50eb 100644 --- a/tests/PluginTest.php +++ b/tests/PluginTest.php @@ -41,7 +41,7 @@ class PluginTest extends TestCase { /** * SetUp test. */ - public function setUp() { + public function setUp() : void { $this->rootDir = realpath(realpath(__DIR__ . '/..')); // Prepare temp directory. @@ -58,7 +58,7 @@ public function setUp() { /** * Method tearDown. */ - public function tearDown() { + public function tearDown() : void { $this->fs->removeDirectory($this->tmpDir); $this->git(sprintf('tag -d "%s"', $this->tmpReleaseTag)); } @@ -143,6 +143,35 @@ public function testContribmodules() { $this->assertFileExists($fr_translation_file, "French translations file for version: $contrib_drupal_version should exist."); } + /** + * Tests that on Drupal 9, core and contrib modules are handled. + * + * Either if using semver or not. + */ + public function testDrupal9() { + $core_version = '9.1.3'; + $contrib_module = 'entity_share'; + $contrib_composer_version = '3.0.0-beta2'; + $contrib_drupal_version = '8.x-3.0-beta2'; + $semver_contrib_module = 'entity_share_cron'; + $semver_contrib_composer_version = '3.0.0-beta1'; + $semver_contrib_drupal_version = '3.0.0-beta1'; + $translations_directory = $this->tmpDir . 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'; + $semver_fr_translation_file = $translations_directory . DIRECTORY_SEPARATOR . $semver_contrib_module . '-' . $semver_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->assertFileNotExists($semver_fr_translation_file, 'French translations file should not exist.'); + $this->composer('install'); + $this->composer('require --update-with-dependencies drupal/core:"' . $core_version . '"'); + $this->composer('require drupal/' . $contrib_module . ':"' . $contrib_composer_version . '" drupal/' . $semver_contrib_module . ':"' . $semver_contrib_composer_version . '"'); + $this->assertFileExists($core_translation_file, 'French translations file should exist.'); + $this->assertFileExists($fr_translation_file, 'French translations file should exist.'); + $this->assertFileExists($semver_fr_translation_file, 'French translations file should exist.'); + } + /** * Writes the default composer json to the temp direcoty. */