public function PagerTest::testPagerLocale in Drupal 9
Same name and namespace in other branches
- 8 core/modules/views/tests/src/Functional/Plugin/PagerTest.php \Drupal\Tests\views\Functional\Plugin\PagerTest::testPagerLocale()
- 10 core/modules/views/tests/src/Functional/Plugin/PagerTest.php \Drupal\Tests\views\Functional\Plugin\PagerTest::testPagerLocale()
Tests translating the pager using locale.
File
- core/
modules/ views/ tests/ src/ Functional/ Plugin/ PagerTest.php, line 494
Class
- PagerTest
- Tests the pluggable pager system.
Namespace
Drupal\Tests\views\Functional\PluginCode
public function testPagerLocale() {
// Enable locale and language module.
$this->container
->get('module_installer')
->install([
'locale',
'language',
]);
$this
->resetAll();
$langcode = 'nl';
// Add a default locale storage for this test.
$this->localeStorage = $this->container
->get('locale.storage');
// Add Dutch language programmatically.
ConfigurableLanguage::createFromLangcode($langcode)
->save();
// Labels that need translations.
$labels = [
'« First' => '« Eerste',
'‹ Previous' => '‹ Vorige',
'Next ›' => 'Volgende ›',
'Last »' => 'Laatste »',
];
foreach ($labels as $label => $translation) {
// Create source string.
$source = $this->localeStorage
->createString([
'source' => $label,
]);
$source
->save();
$this
->createTranslation($source, $translation, $langcode);
}
// We create 11 nodes, this will give us 3 pages.
$this
->drupalCreateContentType([
'type' => 'page',
]);
for ($i = 0; $i < 11; $i++) {
$this
->drupalCreateNode();
}
// Go to the second page so we see both previous and next buttons.
$this
->drupalGet('nl/test_pager_full', [
'query' => [
'page' => 1,
],
]);
foreach ($labels as $label => $translation) {
// Check if we can find the translation.
$this
->assertSession()
->pageTextContains($translation);
}
}