You are here

public function PagerTest::testPagerConfigTranslation in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/views/src/Tests/Plugin/PagerTest.php \Drupal\views\Tests\Plugin\PagerTest::testPagerConfigTranslation()

Tests translating the pager using config_translation.

File

core/modules/views/src/Tests/Plugin/PagerTest.php, line 346
Contains \Drupal\views\Tests\Plugin\PagerTest.

Class

PagerTest
Tests the pluggable pager system.

Namespace

Drupal\views\Tests\Plugin

Code

public function testPagerConfigTranslation() {
  $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(array(
    'locale',
    'language',
    'config_translation',
  ));
  $this
    ->resetAll();
  $admin_user = $this
    ->drupalCreateUser(array(
    '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 = array(
    '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
    ->drupalPostForm('admin/structure/views/view/content/translate/nl/edit', $edit, t('Save translation'));

  // We create 11 nodes, this will give us 3 pages.
  $this
    ->drupalCreateContentType(array(
    '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', array(
    'query' => array(
      'page' => 1,
    ),
  ));

  // Translation mapping..
  $labels = array(
    '« First' => '« Eerste',
    '‹ Previous' => '‹ Vorige',
    'Next ›' => 'Volgende ›',
    'Last »' => 'Laatste »',
  );
  foreach ($labels as $label => $translation) {

    // Check if we can find the translation.
    $this
      ->assertRaw($translation);
  }
}