View source
<?php
namespace Drupal\Tests\locale\Functional;
use Drupal\Component\Gettext\PoItem;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
class LocaleLocaleLookupTest extends BrowserTestBase {
protected static $modules = [
'locale',
'locale_test',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
ConfigurableLanguage::createFromLangcode('fr')
->save();
$this
->config('system.site')
->set('default_langcode', 'fr')
->save();
$this
->drupalLogin($this->rootUser);
}
public function testCircularDependency() {
$this
->drupalGet('admin/modules');
$this
->submitForm([
'modules[early_translation_test][enable]' => TRUE,
], 'Install');
$this
->assertSession()
->statusCodeEquals(200);
}
public function testLanguageFallbackDefaults() {
$this
->drupalGet('');
$this
->assertEquals([], \Drupal::state()
->get('locale.test_language_fallback_candidates_locale_lookup_alter_candidates'));
$context = \Drupal::state()
->get('locale.test_language_fallback_candidates_locale_lookup_alter_context');
$this
->assertEquals('fr', $context['langcode']);
$this
->assertEquals('locale_lookup', $context['operation']);
}
public function testFixOldPluralStyle($translation_value, $expected) {
$string_storage = \Drupal::service('locale.storage');
$string = $string_storage
->findString([
'source' => 'Member for',
'context' => '',
]);
$lid = $string
->getId();
$string_storage
->createTranslation([
'lid' => $lid,
'language' => 'fr',
'translation' => $translation_value,
])
->save();
_locale_refresh_translations([
'fr',
], [
$lid,
]);
$this
->drupalGet('');
$this
->assertSession()
->pageTextContains($expected);
$translation = $string_storage
->findTranslation([
'language' => 'fr',
'lid' => $lid,
])->translation;
$this
->assertSame($translation_value, $translation, 'Source value not changed');
$this
->assertStringContainsString('@count[2]', $translation, 'Source value contains @count[2]');
}
public function providerTestFixOldPluralStyle() {
return [
'non-plural translation' => [
'@count[2] non-plural test',
'@count[2] non-plural test',
],
'plural translation' => [
'@count[2] plural test' . PoItem::DELIMITER,
'@count plural test',
],
];
}
}