Skip to content

Commit

Permalink
Issue #31: Fix Download URL for D7.
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentTorregrosa committed Feb 21, 2021
1 parent 1dd5eab commit 6433d1e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/FileFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}

Expand Down
30 changes: 27 additions & 3 deletions tests/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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',
],
Expand Down

0 comments on commit 6433d1e

Please sign in to comment.