Skip to content

Commit a21d881

Browse files
Issue #22: Drupal 9 support.
1 parent ec462e1 commit a21d881

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
php:
4-
- 7.2
54
- 7.3
65
- 7.4
76

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"require-dev": {
1111
"composer/composer": "~2.0",
12-
"phpunit/phpunit": "^6"
12+
"phpunit/phpunit": "<10"
1313
},
1414
"extra": {
1515
"class": "DrupalComposer\\DrupalL10n\\Plugin"

src/FileFetcher.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,18 @@ protected function getFilename($package_name, $drupal_version, $drupal_project_n
152152
return 'drupal-' . $drupal_version . '.' . $langcode . '.po';
153153
}
154154
else {
155+
$core_major_version = $this->coreMajorVersion;
156+
// Starting from 8.x, translations are in
157+
// https://ftp.drupal.org/files/translations/8.x/ even for Drupal 9.
158+
// And we make the assumption that only a few contrib projects have a 9.x
159+
// branch and will make a semver branch.
160+
if ($core_major_version >= 8) {
161+
$core_major_version = 8;
162+
}
163+
155164
// Old Drupal format.
156165
if ($version_format == 'drupal_format') {
157-
return $drupal_project_name . '-' . $this->coreMajorVersion . '.x-' . $drupal_version . '.' . $langcode . '.po';
166+
return $drupal_project_name . '-' . $core_major_version . '.x-' . $drupal_version . '.' . $langcode . '.po';
158167
}
159168
// Semver format.
160169
else {
@@ -179,10 +188,10 @@ protected function getFilename($package_name, $drupal_version, $drupal_project_n
179188
protected function getUrl($package_name, $drupal_project_name, $filename) {
180189
// Special case for Drupal core.
181190
if (in_array($package_name, ['drupal/core', 'drupal/drupal'])) {
182-
return 'https://ftp.drupal.org/files/translations/' . $this->coreMajorVersion . '.x/drupal/' . $filename;
191+
return 'https://ftp.drupal.org/files/translations/all/drupal/' . $filename;
183192
}
184193
else {
185-
return 'https://ftp.drupal.org/files/translations/' . $this->coreMajorVersion . '.x/' . $drupal_project_name . '/' . $filename;
194+
return 'https://ftp.drupal.org/files/translations/all/' . $drupal_project_name . '/' . $filename;
186195
}
187196
}
188197

tests/PluginTest.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class PluginTest extends TestCase {
4141
/**
4242
* SetUp test.
4343
*/
44-
public function setUp() {
44+
public function setUp() : void {
4545
$this->rootDir = realpath(realpath(__DIR__ . '/..'));
4646

4747
// Prepare temp directory.
@@ -58,7 +58,7 @@ public function setUp() {
5858
/**
5959
* Method tearDown.
6060
*/
61-
public function tearDown() {
61+
public function tearDown() : void {
6262
$this->fs->removeDirectory($this->tmpDir);
6363
$this->git(sprintf('tag -d "%s"', $this->tmpReleaseTag));
6464
}
@@ -143,6 +143,35 @@ public function testContribmodules() {
143143
$this->assertFileExists($fr_translation_file, "French translations file for version: $contrib_drupal_version should exist.");
144144
}
145145

146+
/**
147+
* Tests that on Drupal 9, core and contrib modules are handled.
148+
*
149+
* Either if using semver or not.
150+
*/
151+
public function testDrupal9() {
152+
$core_version = '9.1.3';
153+
$contrib_module = 'entity_share';
154+
$contrib_composer_version = '3.0.0-beta2';
155+
$contrib_drupal_version = '8.x-3.0-beta2';
156+
$semver_contrib_module = 'entity_share_cron';
157+
$semver_contrib_composer_version = '3.0.0-beta1';
158+
$semver_contrib_drupal_version = '3.0.0-beta1';
159+
$translations_directory = $this->tmpDir . DIRECTORY_SEPARATOR . 'translations' . DIRECTORY_SEPARATOR . 'contrib';
160+
$core_translation_file = $translations_directory . DIRECTORY_SEPARATOR . 'drupal-' . $core_version . '.fr.po';
161+
$fr_translation_file = $translations_directory . DIRECTORY_SEPARATOR . $contrib_module . '-' . $contrib_drupal_version . '.fr.po';
162+
$semver_fr_translation_file = $translations_directory . DIRECTORY_SEPARATOR . $semver_contrib_module . '-' . $semver_contrib_drupal_version . '.fr.po';
163+
164+
$this->assertFileNotExists($core_translation_file, 'French translations file should not exist.');
165+
$this->assertFileNotExists($fr_translation_file, 'French translations file should not exist.');
166+
$this->assertFileNotExists($semver_fr_translation_file, 'French translations file should not exist.');
167+
$this->composer('install');
168+
$this->composer('require --update-with-dependencies drupal/core:"' . $core_version . '"');
169+
$this->composer('require drupal/' . $contrib_module . ':"' . $contrib_composer_version . '" drupal/' . $semver_contrib_module . ':"' . $semver_contrib_composer_version . '"');
170+
$this->assertFileExists($core_translation_file, 'French translations file should exist.');
171+
$this->assertFileExists($fr_translation_file, 'French translations file should exist.');
172+
$this->assertFileExists($semver_fr_translation_file, 'French translations file should exist.');
173+
}
174+
146175
/**
147176
* Writes the default composer json to the temp direcoty.
148177
*/

0 commit comments

Comments
 (0)