diff --git a/core/modules/locale/tests/src/Functional/LocaleTranslationDownloadTest.php b/core/modules/locale/tests/src/Functional/LocaleTranslationDownloadTest.php new file mode 100644 index 0000000000..af044f238a --- /dev/null +++ b/core/modules/locale/tests/src/Functional/LocaleTranslationDownloadTest.php @@ -0,0 +1,70 @@ +container->get('module_handler'); + $moduleHandler->loadInclude('locale', 'inc', 'locale.batch'); + $admin_user = $this->drupalCreateUser([ + 'administer modules', + 'administer site configuration', + 'administer languages', + 'access administration pages', + 'translate interface', + ]); + $this->drupalLogin($admin_user); + $this->addLanguage('de'); + + $this->translationsStream = vfsStream::setup('translations'); + \Drupal::configFactory()->getEditable('locale.settings') + ->set('translation.path', $this->translationsStream->url()) + ->save(); + } + + /** + * Tests translation download from remote sources. + */ + public function testUpdateImportSourceRemote() { + + // Provide remote and 'previously' downloaded translation file. + $this->setTranslationFiles(); + vfsStream::create([ + 'contrib_module_one-8.x-1.1.de._po' => '__old_content__', + ], $this->translationsStream); + + $url = \Drupal::service('url_generator')->generateFromRoute('', [], ['absolute' => TRUE]); + $uri = $url . PublicStream::basePath() . '/remote/8.x/contrib_module_one/contrib_module_one-8.x-1.1.de._po'; + $source_file = (object) [ + 'uri' => $uri, + ]; + + $result = locale_translation_download_source($source_file, 'translations://'); + + $this->assertEquals('translations://contrib_module_one-8.x-1.1.de._po', $result->uri); + $this->assertFalse(file_exists('translations://contrib_module_one-8.x-1.1.de_0._po')); + $this->assertTrue(file_exists('translations://contrib_module_one-8.x-1.1.de._po')); + $this->assertNotContains('__old_content__', file_get_contents($this->translationsStream->url() . '/contrib_module_one-8.x-1.1.de._po')); + } + +}