Skip to content

Commit

Permalink
Issue #22: Drupal 9 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentTorregrosa committed Feb 1, 2021
1 parent 5d59a82 commit 3caace1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 7.2
- 7.3
- 7.4

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
},
"require-dev": {
"composer/composer": "1.*",
"phpunit/phpunit": "^6"
"phpunit/phpunit": "<10"
}
}
15 changes: 12 additions & 3 deletions src/FileFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
}

Expand Down
33 changes: 31 additions & 2 deletions tests/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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));
}
Expand Down Expand Up @@ -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.
*/
Expand Down

0 comments on commit 3caace1

Please sign in to comment.