function PagerTest::testPagerLocale

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Functional/Plugin/PagerTest.php \Drupal\Tests\views\Functional\Plugin\PagerTest::testPagerLocale()
  2. 10 core/modules/views/tests/src/Functional/Plugin/PagerTest.php \Drupal\Tests\views\Functional\Plugin\PagerTest::testPagerLocale()
  3. 11.x 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\Plugin

Code

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);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.