Chris@16
|
1 <?php
|
Chris@16
|
2
|
Chris@16
|
3 namespace Drupal\Tests\locale\Functional;
|
Chris@16
|
4
|
Chris@16
|
5 use Drupal\Core\StreamWrapper\PublicStream;
|
Chris@16
|
6 use Drupal\language\Entity\ConfigurableLanguage;
|
Chris@16
|
7 use org\bovigo\vfs\vfsStream;
|
Chris@16
|
8
|
Chris@16
|
9 /**
|
Chris@16
|
10 * Tests locale translation download.
|
Chris@16
|
11 *
|
Chris@16
|
12 * @group locale
|
Chris@16
|
13 */
|
Chris@16
|
14 class LocaleTranslationDownloadTest extends LocaleUpdateBase {
|
Chris@16
|
15
|
Chris@16
|
16 /**
|
Chris@16
|
17 * The virtual file stream for storing translations.
|
Chris@16
|
18 *
|
Chris@16
|
19 * @var \org\bovigo\vfs\vfsStreamDirectory
|
Chris@16
|
20 */
|
Chris@16
|
21 protected $translationsStream;
|
Chris@16
|
22
|
Chris@16
|
23 /**
|
Chris@16
|
24 * {@inheritdoc}
|
Chris@16
|
25 */
|
Chris@16
|
26 protected function setUp() {
|
Chris@16
|
27 parent::setUp();
|
Chris@16
|
28 $moduleHandler = $this->container->get('module_handler');
|
Chris@16
|
29 $moduleHandler->loadInclude('locale', 'inc', 'locale.batch');
|
Chris@16
|
30 ConfigurableLanguage::createFromLangcode('de')->save();
|
Chris@16
|
31
|
Chris@16
|
32 // Let the translations:// stream wrapper point to a virtual file system to
|
Chris@16
|
33 // make it independent from the test environment.
|
Chris@16
|
34 $this->translationsStream = vfsStream::setup('translations');
|
Chris@16
|
35 \Drupal::configFactory()->getEditable('locale.settings')
|
Chris@16
|
36 ->set('translation.path', $this->translationsStream->url())
|
Chris@16
|
37 ->save();
|
Chris@16
|
38 }
|
Chris@16
|
39
|
Chris@16
|
40 /**
|
Chris@16
|
41 * Tests translation download from remote sources.
|
Chris@16
|
42 */
|
Chris@16
|
43 public function testUpdateImportSourceRemote() {
|
Chris@16
|
44
|
Chris@16
|
45 // Provide remote and 'previously' downloaded translation file.
|
Chris@16
|
46 $this->setTranslationFiles();
|
Chris@16
|
47 vfsStream::create([
|
Chris@16
|
48 'contrib_module_one-8.x-1.1.de._po' => '__old_content__',
|
Chris@16
|
49 ], $this->translationsStream);
|
Chris@16
|
50
|
Chris@16
|
51 $url = \Drupal::service('url_generator')->generateFromRoute('<front>', [], ['absolute' => TRUE]);
|
Chris@16
|
52 $uri = $url . PublicStream::basePath() . '/remote/8.x/contrib_module_one/contrib_module_one-8.x-1.1.de._po';
|
Chris@16
|
53 $source_file = (object) [
|
Chris@16
|
54 'uri' => $uri,
|
Chris@16
|
55 ];
|
Chris@16
|
56
|
Chris@16
|
57 $result = locale_translation_download_source($source_file, 'translations://');
|
Chris@16
|
58
|
Chris@16
|
59 $this->assertEquals('translations://contrib_module_one-8.x-1.1.de._po', $result->uri);
|
Chris@16
|
60 $this->assertFalse(file_exists('translations://contrib_module_one-8.x-1.1.de_0._po'));
|
Chris@16
|
61 $this->assertTrue(file_exists('translations://contrib_module_one-8.x-1.1.de._po'));
|
Chris@16
|
62 $this->assertNotContains('__old_content__', file_get_contents('translations://contrib_module_one-8.x-1.1.de._po'));
|
Chris@16
|
63 }
|
Chris@16
|
64
|
Chris@16
|
65 }
|