Skip to content

Commit 6433d1e

Browse files
Issue #31: Fix Download URL for D7.
1 parent 1dd5eab commit 6433d1e

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

src/FileFetcher.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ protected function getFilename($package_name, $drupal_version, $drupal_project_n
154154
else {
155155
$core_major_version = $this->coreMajorVersion;
156156
// Starting from 8.x, translations are in
157-
// https://ftp.drupal.org/files/translations/8.x/ even for Drupal 9.
157+
// https://ftp.drupal.org/files/translations/all/ even for Drupal 9.
158158
// And we make the assumption that only a few contrib projects have a 9.x
159159
// branch and will make a semver branch.
160160
if ($core_major_version >= 8) {
@@ -186,12 +186,20 @@ protected function getFilename($package_name, $drupal_version, $drupal_project_n
186186
* The prepared URL.
187187
*/
188188
protected function getUrl($package_name, $drupal_project_name, $filename) {
189+
$core_folder = 'all';
190+
// Starting from 8.x, translations are in
191+
// https://ftp.drupal.org/files/translations/all/ even for Drupal 9.
192+
// Otherwise it is https://ftp.drupal.org/files/translations/7.x/.
193+
if ($this->coreMajorVersion < 8) {
194+
$core_folder = $this->coreMajorVersion . '.x';
195+
}
196+
189197
// Special case for Drupal core.
190198
if (in_array($package_name, ['drupal/core', 'drupal/drupal'])) {
191-
return 'https://ftp.drupal.org/files/translations/all/drupal/' . $filename;
199+
return 'https://ftp.drupal.org/files/translations/' . $core_folder . '/drupal/' . $filename;
192200
}
193201
else {
194-
return 'https://ftp.drupal.org/files/translations/all/' . $drupal_project_name . '/' . $filename;
202+
return 'https://ftp.drupal.org/files/translations/' . $core_folder . '/' . $drupal_project_name . '/' . $filename;
195203
}
196204
}
197205

tests/PluginTest.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,31 @@ public function testDrupal9() {
173173
}
174174

175175
/**
176-
* Writes the default composer json to the temp direcoty.
176+
* Tests that on Drupal 7, core and contrib modules are handled.
177+
*/
178+
public function testDrupal7() {
179+
$core_version = '7.78.0';
180+
$contrib_module = 'views';
181+
$contrib_composer_version = '3.24.0';
182+
$contrib_drupal_version = '7.x-3.24';
183+
$translations_directory = $this->tmpDir . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'translations' . DIRECTORY_SEPARATOR . 'contrib';
184+
$core_translation_file = $translations_directory . DIRECTORY_SEPARATOR . 'drupal-' . $core_version . '.fr.po';
185+
$fr_translation_file = $translations_directory . DIRECTORY_SEPARATOR . $contrib_module . '-' . $contrib_drupal_version . '.fr.po';
186+
187+
$this->assertFileNotExists($core_translation_file, 'French translations file should not exist.');
188+
$this->assertFileNotExists($fr_translation_file, 'French translations file should not exist.');
189+
$this->composer('install');
190+
$this->composer('remove drupal/core');
191+
// Set Drupal repository to target Drupal 7.
192+
$this->composer('config repositories.drupal composer https://packages.drupal.org/7');
193+
$this->composer('require drupal/drupal:"' . $core_version . '"');
194+
$this->composer('require drupal/' . $contrib_module . ':"' . $contrib_composer_version . '"');
195+
$this->assertFileExists($core_translation_file, 'French translations file should exist.');
196+
$this->assertFileExists($fr_translation_file, 'French translations file should exist.');
197+
}
198+
199+
/**
200+
* Writes the default composer json to the temp directory.
177201
*/
178202
protected function writeComposerJson() {
179203
$json = json_encode($this->composerJsonDefaults(), JSON_PRETTY_PRINT);
@@ -201,11 +225,11 @@ protected function writeTestReleaseTag() {
201225
protected function composerJsonDefaults() {
202226
return [
203227
'repositories' => [
204-
[
228+
'this_package' => [
205229
'type' => 'vcs',
206230
'url' => $this->rootDir,
207231
],
208-
[
232+
'drupal' => [
209233
'type' => 'composer',
210234
'url' => 'https://packages.drupal.org/8',
211235
],

0 commit comments

Comments
 (0)