3 namespace Drupal\Tests\locale\Functional;
5 use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
6 use Drupal\language\Entity\ConfigurableLanguage;
7 use Drupal\Tests\BrowserTestBase;
14 class LocaleLocaleLookupTest extends BrowserTestBase {
21 public static $modules = ['locale', 'locale_test'];
26 protected function setUp() {
29 // Change the language default object to different values.
30 ConfigurableLanguage::createFromLangcode('fr')->save();
31 $this->config('system.site')->set('default_langcode', 'fr')->save();
33 $this->drupalLogin($this->rootUser);
37 * Tests that there are no circular dependencies.
39 public function testCircularDependency() {
40 // Ensure that we can enable early_translation_test on a non-english site.
41 $this->drupalPostForm('admin/modules', ['modules[early_translation_test][enable]' => TRUE], t('Install'));
42 $this->assertResponse(200);
46 * Test language fallback defaults.
48 public function testLanguageFallbackDefaults() {
50 // Ensure state of fallback languages persisted by
51 // locale_test_language_fallback_candidates_locale_lookup_alter() is empty.
52 $this->assertEqual(\Drupal::state()->get('locale.test_language_fallback_candidates_locale_lookup_alter_candidates'), []);
53 // Make sure there is enough information provided for alter hooks.
54 $context = \Drupal::state()->get('locale.test_language_fallback_candidates_locale_lookup_alter_context');
55 $this->assertEqual($context['langcode'], 'fr');
56 $this->assertEqual($context['operation'], 'locale_lookup');
60 * Test old plural style @count[number] fix.
62 * @dataProvider providerTestFixOldPluralStyle
64 public function testFixOldPluralStyle($translation_value, $expected) {
65 $string_storage = \Drupal::service('locale.storage');
66 $string = $string_storage->findString(['source' => 'Member for', 'context' => '']);
67 $lid = $string->getId();
68 $string_storage->createTranslation([
71 'translation' => $translation_value,
73 _locale_refresh_translations(['fr'], [$lid]);
75 // Check that 'count[2]' was fixed for render value.
77 $this->assertSession()->pageTextContains($expected);
79 // Check that 'count[2]' was saved for source value.
80 $translation = $string_storage->findTranslation(['language' => 'fr', 'lid' => $lid])->translation;
81 $this->assertSame($translation_value, $translation, 'Source value not changed');
82 $this->assertNotFalse(strpos($translation, '@count[2]'), 'Source value contains @count[2]');
86 * Provides data for testFixOldPluralStyle().
89 * An array of test data:
93 public function providerTestFixOldPluralStyle() {
95 'non-plural translation' => ['@count[2] non-plural test', '@count[2] non-plural test'],
96 'plural translation' => ['@count[2] plural test' . PluralTranslatableMarkup::DELIMITER, '@count plural test'],