Mercurial > hg > isophonics-drupal-site
diff core/modules/locale/tests/src/Functional/LocaleTranslationDownloadTest.php @ 16:c2387f117808
Routine composer update
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 15:07:59 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/locale/tests/src/Functional/LocaleTranslationDownloadTest.php Tue Jul 10 15:07:59 2018 +0100 @@ -0,0 +1,65 @@ +<?php + +namespace Drupal\Tests\locale\Functional; + +use Drupal\Core\StreamWrapper\PublicStream; +use Drupal\language\Entity\ConfigurableLanguage; +use org\bovigo\vfs\vfsStream; + +/** + * Tests locale translation download. + * + * @group locale + */ +class LocaleTranslationDownloadTest extends LocaleUpdateBase { + + /** + * The virtual file stream for storing translations. + * + * @var \org\bovigo\vfs\vfsStreamDirectory + */ + protected $translationsStream; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $moduleHandler = $this->container->get('module_handler'); + $moduleHandler->loadInclude('locale', 'inc', 'locale.batch'); + ConfigurableLanguage::createFromLangcode('de')->save(); + + // Let the translations:// stream wrapper point to a virtual file system to + // make it independent from the test environment. + $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('<front>', [], ['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('translations://contrib_module_one-8.x-1.1.de._po')); + } + +}