Skip to content
Snippets Groups Projects
Unverified Commit 3e3b6687 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2949825 by Sutharsan, andypost, alexpott: Downloaded translation file...

Issue #2949825 by Sutharsan, andypost, alexpott: Downloaded translation file should replace existing
parent a9cd69a4
No related branches found
No related tags found
No related merge requests found
...@@ -292,7 +292,7 @@ function locale_translation_http_check($uri) { ...@@ -292,7 +292,7 @@ function locale_translation_http_check($uri) {
* File object if download was successful. FALSE on failure. * File object if download was successful. FALSE on failure.
*/ */
function locale_translation_download_source($source_file, $directory = 'temporary://') { function locale_translation_download_source($source_file, $directory = 'temporary://') {
if ($uri = system_retrieve_file($source_file->uri, $directory)) { if ($uri = system_retrieve_file($source_file->uri, $directory, FALSE, FILE_EXISTS_REPLACE)) {
$file = clone($source_file); $file = clone($source_file);
$file->type = LOCALE_TRANSLATION_LOCAL; $file->type = LOCALE_TRANSLATION_LOCAL;
$file->uri = $uri; $file->uri = $uri;
......
<?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'));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment