3 namespace Drupal\Tests\locale\Functional;
5 use Drupal\Core\StreamWrapper\PublicStream;
6 use Drupal\language\Entity\ConfigurableLanguage;
7 use org\bovigo\vfs\vfsStream;
10 * Tests locale translation download.
14 class LocaleTranslationDownloadTest extends LocaleUpdateBase {
17 * The virtual file stream for storing translations.
19 * @var \org\bovigo\vfs\vfsStreamDirectory
21 protected $translationsStream;
26 protected function setUp() {
28 $moduleHandler = $this->container->get('module_handler');
29 $moduleHandler->loadInclude('locale', 'inc', 'locale.batch');
30 ConfigurableLanguage::createFromLangcode('de')->save();
32 // Let the translations:// stream wrapper point to a virtual file system to
33 // make it independent from the test environment.
34 $this->translationsStream = vfsStream::setup('translations');
35 \Drupal::configFactory()->getEditable('locale.settings')
36 ->set('translation.path', $this->translationsStream->url())
41 * Tests translation download from remote sources.
43 public function testUpdateImportSourceRemote() {
45 // Provide remote and 'previously' downloaded translation file.
46 $this->setTranslationFiles();
48 'contrib_module_one-8.x-1.1.de._po' => '__old_content__',
49 ], $this->translationsStream);
51 $url = \Drupal::service('url_generator')->generateFromRoute('<front>', [], ['absolute' => TRUE]);
52 $uri = $url . PublicStream::basePath() . '/remote/8.x/contrib_module_one/contrib_module_one-8.x-1.1.de._po';
53 $source_file = (object) [
57 $result = locale_translation_download_source($source_file, 'translations://');
59 $this->assertEquals('translations://contrib_module_one-8.x-1.1.de._po', $result->uri);
60 $this->assertFalse(file_exists('translations://contrib_module_one-8.x-1.1.de_0._po'));
61 $this->assertTrue(file_exists('translations://contrib_module_one-8.x-1.1.de._po'));
62 $this->assertNotContains('__old_content__', file_get_contents('translations://contrib_module_one-8.x-1.1.de._po'));