function PagerTest::testPagerConfigTranslation

Same name in other branches
  1. 9 core/modules/views/tests/src/Functional/Plugin/PagerTest.php \Drupal\Tests\views\Functional\Plugin\PagerTest::testPagerConfigTranslation()
  2. 8.9.x core/modules/views/tests/src/Functional/Plugin/PagerTest.php \Drupal\Tests\views\Functional\Plugin\PagerTest::testPagerConfigTranslation()
  3. 10 core/modules/views/tests/src/Functional/Plugin/PagerTest.php \Drupal\Tests\views\Functional\Plugin\PagerTest::testPagerConfigTranslation()

Tests translating the pager using config_translation.

File

core/modules/views/tests/src/Functional/Plugin/PagerTest.php, line 492

Class

PagerTest
Tests the pluggable pager system.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testPagerConfigTranslation() : void {
    $view = Views::getView('content');
    $display =& $view->storage
        ->getDisplay('default');
    $display['display_options']['pager']['options']['items_per_page'] = 5;
    $view->save();
    // Enable locale, config_translation and language module.
    $this->container
        ->get('module_installer')
        ->install([
        'locale',
        'language',
        'config_translation',
    ]);
    $this->resetAll();
    $admin_user = $this->drupalCreateUser([
        'access content overview',
        'administer nodes',
        'bypass node access',
        'translate configuration',
    ]);
    $this->drupalLogin($admin_user);
    $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();
    $edit = [
        'translation[config_names][views.view.content][display][default][display_options][pager][options][tags][first]' => '« Eerste',
        'translation[config_names][views.view.content][display][default][display_options][pager][options][tags][previous]' => '‹ Vorige',
        'translation[config_names][views.view.content][display][default][display_options][pager][options][tags][next]' => 'Volgende ›',
        'translation[config_names][views.view.content][display][default][display_options][pager][options][tags][last]' => 'Laatste »',
    ];
    $this->drupalGet('admin/structure/views/view/content/translate/nl/edit');
    $this->submitForm($edit, 'Save translation');
    // 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/admin/content', [
        'query' => [
            'page' => 1,
        ],
    ]);
    // Translation mapping..
    $labels = [
        '« First' => '« Eerste',
        '‹ Previous' => '‹ Vorige',
        'Next ›' => 'Volgende ›',
        'Last »' => 'Laatste »',
    ];
    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.