View source
<?php
namespace Drupal\locale\Tests;
use Drupal\Core\Language\Language;
use Drupal\language\Entity\ConfigurableLanguage;
class LocaleConfigSubscriberForeignTest extends LocaleConfigSubscriberTest {
protected function defaultLanguageData() {
$data = Language::$defaultValues;
$data['id'] = 'hu';
$data['name'] = 'Hungarian';
return $data;
}
protected function setUpLanguages() {
parent::setUpLanguages();
ConfigurableLanguage::createFromLangcode('hu')
->save();
}
protected function setUpLocale() {
parent::setUpLocale();
$this
->setUpTranslation('locale_test.translation', 'test', 'English test', 'Hungarian test', 'hu', TRUE);
}
public function testDefaultConfigLanguage() {
$this
->assertEqual('hu', $this->configFactory
->getEditable('locale_test.no_translation')
->get('langcode'));
$this
->assertEqual('hu', $this->configFactory
->getEditable('locale_test.translation')
->get('langcode'));
$this
->assertEqual($this->configFactory
->getEditable('locale_test.translation')
->get('test'), 'Hungarian test');
}
public function testCreateActiveTranslation() {
$config_name = 'locale_test.no_translation';
$this
->saveLanguageActive($config_name, 'test', 'Test (Hungarian)', 'hu');
$this
->assertTranslation($config_name, 'Test (Hungarian)', 'hu');
}
public function testLocaleCreateActiveTranslation() {
$config_name = 'locale_test.no_translation';
$this
->saveLocaleTranslationData($config_name, 'test', 'Test', 'Test (Hungarian)', 'hu', TRUE);
$this
->assertTranslation($config_name, 'Test (Hungarian)', 'hu', FALSE);
}
public function testUpdateActiveTranslation() {
$config_name = 'locale_test.translation';
$this
->saveLanguageActive($config_name, 'test', 'Updated Hungarian test', 'hu');
$this
->assertTranslation($config_name, 'Updated Hungarian test', 'hu');
}
public function testLocaleUpdateActiveTranslation() {
$config_name = 'locale_test.translation';
$this
->saveLocaleTranslationData($config_name, 'test', 'English test', 'Updated Hungarian test', 'hu', TRUE);
$this
->assertTranslation($config_name, 'Updated Hungarian test', 'hu', FALSE);
}
public function testDeleteTranslation() {
$config_name = 'locale_test.translation';
$this
->deleteLanguageOverride($config_name, 'test', 'English test', 'de');
$this
->assertTranslation($config_name, 'Hungarian test', 'de');
}
public function testDeleteActiveTranslation() {
$config_name = 'locale_test.translation';
$this->configFactory
->getEditable($config_name)
->delete();
$this
->assertTranslation($config_name, 'Hungarian test', 'hu', FALSE);
}
public function testLocaleDeleteActiveTranslation() {
$config_name = 'locale_test.translation';
$this
->deleteLocaleTranslationData($config_name, 'test', 'English test', 'hu');
$this
->assertEqual($this->configFactory
->getEditable($config_name)
->get('test'), 'Hungarian test');
}
public function testEnglish() {
$config_name = 'locale_test.translation';
ConfigurableLanguage::createFromLangcode('en')
->save();
$this->localeConfigManager
->updateConfigTranslations(array(
$config_name,
), array(
'en',
));
$this
->assertConfigOverride($config_name, 'test', 'English test', 'en');
$this->configFactory
->getEditable('locale.settings')
->set('translate_english', TRUE)
->save();
$this
->saveLocaleTranslationData($config_name, 'test', 'English test', 'Updated English test', 'en');
$this
->assertTranslation($config_name, 'Updated English test', 'en', FALSE);
$this
->saveLanguageOverride($config_name, 'test', 'Updated English', 'en');
$this
->assertTranslation($config_name, 'Updated English', 'en');
$this
->deleteLocaleTranslationData($config_name, 'test', 'English test', 'en');
$this
->assertNoConfigOverride($config_name, 'en');
}
protected function saveLanguageActive($config_name, $key, $value, $langcode) {
$this->configFactory
->getEditable($config_name)
->set($key, $value)
->save();
$this
->assertActiveConfig($config_name, $key, $value, $langcode);
}
}