function LocaleTranslationDownloadTest::testUpdateImportSourceRemote

Same name and namespace in other branches
  1. 10 core/modules/locale/tests/src/Functional/LocaleTranslationDownloadTest.php \Drupal\Tests\locale\Functional\LocaleTranslationDownloadTest::testUpdateImportSourceRemote()
  2. 11.x core/modules/locale/tests/src/Functional/LocaleTranslationDownloadTest.php \Drupal\Tests\locale\Functional\LocaleTranslationDownloadTest::testUpdateImportSourceRemote()
  3. 9 core/modules/locale/tests/src/Functional/LocaleTranslationDownloadTest.php \Drupal\Tests\locale\Functional\LocaleTranslationDownloadTest::testUpdateImportSourceRemote()
  4. 8.9.x core/modules/locale/tests/src/Functional/LocaleTranslationDownloadTest.php \Drupal\Tests\locale\Functional\LocaleTranslationDownloadTest::testUpdateImportSourceRemote()

Tests translation download from remote sources.

File

core/modules/locale/tests/src/Functional/LocaleTranslationDownloadTest.php, line 57

Class

LocaleTranslationDownloadTest
Tests locale translation download.

Namespace

Drupal\Tests\locale\Functional

Code

public function testUpdateImportSourceRemote() : void {
  // Provide remote and 'previously' downloaded translation file.
  $this->setTranslationFiles();
  vfsStream::create([
    'contrib_module_one-8.x-1.1.de._po' => '__old_content__',
  ], $this->translationsStream);
  $filepath = PublicStream::basePath() . '/remote/all/contrib_module_one/contrib_module_one-8.x-1.1.de._po';
  $filename = basename($filepath);
  $url = \Drupal::service('url_generator')->generateFromRoute('<front>', [], [
    'absolute' => TRUE,
  ]);
  $uri = $url . $filepath;
  $hash = hash_file(LocaleSource::LOCAL_FILE_HASH_ALGO, $uri);
  $source_file = new LocaleFile($filename, $uri, $hash);
  $result = \Drupal::service(LocaleFileManager::class)->downloadTranslationSource($source_file, 'translations://');
  $this->assertEquals('translations://contrib_module_one-8.x-1.1.de._po', $result->uri);
  $this->assertFileDoesNotExist('translations://contrib_module_one-8.x-1.1.de_0._po');
  $this->assertFileExists('translations://contrib_module_one-8.x-1.1.de._po');
  $this->assertStringNotContainsString('__old_content__', file_get_contents('translations://contrib_module_one-8.x-1.1.de._po'));
}

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