77 lines
2.9 KiB
PHP
77 lines
2.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Contains \Drupal\locale\Tests\LocaleConfigManagerTest.
|
|
*/
|
|
|
|
namespace Drupal\locale\Tests;
|
|
|
|
use Drupal\language\Entity\ConfigurableLanguage;
|
|
use Drupal\simpletest\KernelTestBase;
|
|
|
|
/**
|
|
* Tests that the locale config manager operates correctly.
|
|
*
|
|
* @group locale
|
|
*/
|
|
class LocaleConfigManagerTest extends KernelTestBase {
|
|
|
|
/**
|
|
* A list of modules to install for this test.
|
|
*
|
|
* @var array
|
|
*/
|
|
public static $modules = array('language', 'locale', 'locale_test');
|
|
|
|
/**
|
|
* Tests hasTranslation().
|
|
*/
|
|
public function testHasTranslation() {
|
|
$this->installSchema('locale', array('locales_location', 'locales_source', 'locales_target'));
|
|
$this->installConfig(array('locale_test'));
|
|
$locale_config_manager = \Drupal::service('locale.config_manager');
|
|
|
|
$language = ConfigurableLanguage::createFromLangcode('de');
|
|
$language->save();
|
|
$result = $locale_config_manager->hasTranslation('locale_test.no_translation', $language->getId());
|
|
$this->assertFalse($result, 'There is no translation for locale_test.no_translation configuration.');
|
|
|
|
$result = $locale_config_manager->hasTranslation('locale_test.translation', $language->getId());
|
|
$this->assertTrue($result, 'There is a translation for locale_test.translation configuration.');
|
|
}
|
|
|
|
/**
|
|
* Tests getStringTranslation().
|
|
*/
|
|
public function testGetStringTranslation() {
|
|
$this->installSchema('locale', array('locales_location', 'locales_source', 'locales_target'));
|
|
$this->installConfig(array('locale_test'));
|
|
|
|
$locale_config_manager = \Drupal::service('locale.config_manager');
|
|
|
|
$language = ConfigurableLanguage::createFromLangcode('de');
|
|
$language->save();
|
|
|
|
$translation_before = $locale_config_manager->getStringTranslation('locale_test.no_translation', $language->getId(), 'Test', '');
|
|
$this->assertTrue($translation_before->isNew());
|
|
$translation_before->setString('translation')->save();
|
|
|
|
$translation_after = $locale_config_manager->getStringTranslation('locale_test.no_translation', $language->getId(), 'Test', '');
|
|
$this->assertFalse($translation_after->isNew());
|
|
$translation_after->setString('updated_translation')->save();
|
|
}
|
|
|
|
/**
|
|
* Tests getDefaultConfigLangcode().
|
|
*/
|
|
public function testGetDefaultConfigLangcode() {
|
|
// Install the Language module's configuration so we can use the
|
|
// module_installer service.
|
|
$this->installConfig(['language']);
|
|
$this->assertNull(\Drupal::service('locale.config_manager')->getDefaultConfigLangcode('locale_test_translate.settings'), 'Before installing a module the locale config manager can not access the shipped configuration.');
|
|
\Drupal::service('module_installer')->install(['locale_test_translate']);
|
|
$this->assertEqual('en', \Drupal::service('locale.config_manager')->getDefaultConfigLangcode('locale_test_translate.settings'), 'After installing a module the locale config manager can get the shipped configuration langcode.');
|
|
}
|
|
|
|
}
|