View source
<?php
namespace Drupal\FunctionalTests\Installer;
use Drupal\Component\Serialization\Yaml;
class InstallerExistingConfigSyncDirectoryMultilingualTest extends InstallerExistingConfigTestBase {
protected $defaultTheme = 'stark';
protected $profile = 'testing_config_install_multilingual';
protected $existingSyncDirectory = TRUE;
protected function setUpProfile() {
$this
->assertSession()
->pageTextContains('Install Multilingual using existing configuration.');
return parent::setUpProfile();
}
protected function getConfigTarball() {
return __DIR__ . '/../../../fixtures/config_install/multilingual.tar.gz';
}
protected function prepareEnvironment() {
parent::prepareEnvironment();
mkdir($this->publicFilesDirectory . '/translations', 0777, TRUE);
file_put_contents($this->publicFilesDirectory . '/translations/drupal-8.0.0.es.po', $this
->getPo('es'));
$locale_settings = Yaml::decode(file_get_contents($this->siteDirectory . '/config/sync/locale.settings.yml'));
$locale_settings['translation']['use_source'] = 'local';
$locale_settings['translation']['path'] = $this->publicFilesDirectory . '/translations';
file_put_contents($this->siteDirectory . '/config/sync/locale.settings.yml', Yaml::encode($locale_settings));
}
public function testConfigSync() {
$comparer = $this
->configImporter()
->getStorageComparer();
$expected_changelist_default_collection = [
'create' => [],
'update' => [
'system.mail',
],
'delete' => [],
'rename' => [],
];
$this
->assertEquals($expected_changelist_default_collection, $comparer
->getChangelist());
$expected_changelist_spanish_collection = [
'create' => [],
'update' => [
'views.view.who_s_new',
],
'delete' => [],
'rename' => [],
];
$this
->assertEquals($expected_changelist_spanish_collection, $comparer
->getChangelist(NULL, 'language.es'));
$this
->assertSession()
->responseNotContains('This block is broken or missing.');
$this
->assertSession()
->linkExists('Add content');
$this
->assertSame('Anónimo', \Drupal::languageManager()
->getLanguageConfigOverride('es', 'user.settings')
->get('anonymous'));
$locale_storage = \Drupal::service('locale.storage');
$translation = $locale_storage
->findTranslation([
'source' => 'Anonymous',
'language' => 'es',
]);
$this
->assertSame('Anónimo', $translation
->getString());
$this
->assertTrue((bool) $translation->customized, "A customized translation has been created for Anonymous");
$translation = $locale_storage
->findTranslation([
'source' => 'Apply',
'language' => 'es',
]);
$this
->assertSame('Aplicar', $translation
->getString());
$this
->assertFalse((bool) $translation->customized, "A non-customized translation has been created for Apply");
$view_config = \Drupal::languageManager()
->getLanguageConfigOverride('es', 'views.view.who_s_new');
$this
->assertSame('Aplicar', $view_config
->get('display.default.display_options.exposed_form.options.submit_button'));
$view_config = \Drupal::languageManager()
->getLanguageConfigOverride('es', 'views.view.archive');
$this
->assertSame('Aplicar', $view_config
->get('display.default.display_options.exposed_form.options.submit_button'));
$status = locale_translation_get_status();
$status['drupal']['es']->type = 'local';
$status['drupal']['es']->files['local']->timestamp = time();
\Drupal::keyValue('locale.translation_status')
->set('drupal', $status['drupal']);
$this
->drupalGet('admin/reports/translations');
$this
->submitForm([], 'Update translations');
$comparer = $this
->configImporter()
->getStorageComparer();
$expected_changelist_spanish_collection = [
'create' => [],
'update' => [
'views.view.who_s_new',
],
'delete' => [],
'rename' => [],
];
$this
->assertEquals($expected_changelist_spanish_collection, $comparer
->getChangelist(NULL, 'language.es'));
$po = <<<ENDPO
msgid ""
msgstr ""
msgid "Anonymous"
msgstr "Anonymous es"
msgid "Apply"
msgstr "Aplicar New"
ENDPO;
file_put_contents($this->publicFilesDirectory . '/translations/drupal-8.0.0.es.po', $po);
$status = locale_translation_get_status();
$status['drupal']['es']->type = 'local';
$status['drupal']['es']->files['local']->timestamp = time();
\Drupal::keyValue('locale.translation_status')
->set('drupal', $status['drupal']);
$this
->drupalGet('admin/reports/translations');
$this
->submitForm([], 'Update translations');
$translation = \Drupal::service('locale.storage')
->findTranslation([
'source' => 'Apply',
'language' => 'es',
]);
$this
->assertSame('Aplicar New', $translation
->getString());
$this
->assertFalse((bool) $translation->customized, "A non-customized translation has been created for Apply");
$comparer = $this
->configImporter()
->getStorageComparer();
$expected_changelist_spanish_collection = [
'create' => [],
'update' => [
'views.view.archive',
'views.view.content_recent',
'views.view.frontpage',
'views.view.glossary',
'views.view.who_s_new',
'views.view.who_s_online',
],
'delete' => [],
'rename' => [],
];
$this
->assertEquals($expected_changelist_spanish_collection, $comparer
->getChangelist(NULL, 'language.es'));
}
protected function getPo($langcode) {
return <<<ENDPO
msgid ""
msgstr ""
msgid "Anonymous"
msgstr "Anonymous {<span class="php-variable">$langcode</span>}"
msgid "Apply"
msgstr "Aplicar"
ENDPO;
}
}