function InstallerTranslationDownloadTest::testCustomProfileTranslationsAreDownloaded

Same name and namespace in other branches
  1. main core/tests/Drupal/KernelTests/Core/Installer/InstallerTranslationDownloadTest.php \Drupal\KernelTests\Core\Installer\InstallerTranslationDownloadTest::testCustomProfileTranslationsAreDownloaded()

Tests that the translations are downloaded for a custom profile.

Attributes

#[TestWith([ '1.2.3', ], 'Semantic version')] #[TestWith([ '2.x-dev', ], 'Dev branch with -dev suffix')] #[TestWith([ '2.x', ], 'Dev branch without -dev suffix')] #[TestWith([ '8.x-1.3', ], 'Legacy tagged version')] #[TestWith([ '2.1.0-alpha2', ], 'Pre-release semantic version')] #[TestWith([ '8.x-1.x-dev', ], 'Legacy dev branch with -dev suffix')] #[TestWith([ '8.x-1.x', ], 'Legacy dev branch without -dev suffix')]

Parameters

string $version: The version of the custom profile.

File

core/tests/Drupal/KernelTests/Core/Installer/InstallerTranslationDownloadTest.php, line 107

Class

InstallerTranslationDownloadTest
Tests that profile translations are downloaded by the installer.

Namespace

Drupal\KernelTests\Core\Installer

Code

public function testCustomProfileTranslationsAreDownloaded(string $version) : void {
  // In kernel tests, the site directory is a VFS URI. We need to make it real
  // so the Extension class can access it.
  $pathname = parse_url($this->siteDirectory, PHP_URL_PATH);
  $pathname = trim($pathname, '/');
  $pathname .= '/profiles/foo';
  mkdir($pathname, recursive: TRUE);
  // Make a fake, non-core profile and explicitly expose it to the profile
  // discovery.
  $pathname .= '/foo.info.yml';
  $info = <<<EOF
  name: Test
  type: profile
  version: {<span class="php-variable">$version</span>}
  core_version_requirement: '*'
  EOF;
  file_put_contents($pathname, $info);
  // We just created a new profile, but extensions have already been scanned.
  // Therefore, clear the extension discovery cache so the installer can
  // find the new profile.
  (new \ReflectionProperty(ExtensionDiscovery::class, 'files'))->setValue(NULL, []);
  // Expose our fake profile directly to the installer.
  $this->installParameters['profiles']['foo'] = new Extension($this->root, 'profile', $pathname);
  $this->installParameters['parameters']['profile'] = 'foo';
  install_drupal($this->classLoader, $this->installParameters);
  // Four requests should have been made: a HEAD and a GET request for each
  // of two files.
  $core_version = \Drupal::VERSION;
  $expected_requests = [
    "HEAD drupal-{$core_version}.de.po",
    "GET drupal-{$core_version}.de.po",
    "HEAD foo-{$version}.de.po",
    "GET foo-{$version}.de.po",
  ];
  $this->assertSame($expected_requests, $this->requests);
  // Confirm that the files were actually downloaded.
  $destination = dirname($pathname, 3) . '/files/translations';
  $this->assertFileExists($destination . "/drupal-{$core_version}.de.po");
  $this->assertFileExists($destination . "/foo-{$version}.de.po");
  // Put another unrelated translation file into the directory to ensure that
  // FileTranslation doesn't see it.
  touch($destination . "/unrelated-{$version}.de.po");
  // Confirm that the FileTranslation service used during the early installer
  // finds the downloaded files.
  $translation = new FileTranslation($destination, \Drupal::service(FileSystemInterface::class), 'foo');
  $found_translations = array_column($translation->findTranslationFiles(), 'filename');
  sort($found_translations);
  $expected_translations = [
    "drupal-{$core_version}.de.po",
    "foo-{$version}.de.po",
  ];
  $this->assertSame($expected_translations, $found_translations);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.