You are here

public function PagerTest::testPagerLocale in Zircon Profile 8

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

Tests translating the pager using locale.

File

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

Class

PagerTest
Tests the pluggable pager system.

Namespace

Drupal\views\Tests\Plugin

Code

public function testPagerLocale() {

  // Enable locale and language module.
  $this->container
    ->get('module_installer')
    ->install(array(
    '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 = array(
    '« First' => '« Eerste',
    '‹ Previous' => '‹ Vorige',
    'Next ›' => 'Volgende ›',
    'Last »' => 'Laatste »',
  );
  foreach ($labels as $label => $translation) {

    // Create source string.
    $source = $this->localeStorage
      ->createString(array(
      'source' => $label,
    ));
    $source
      ->save();
    $this
      ->createTranslation($source, $translation, $langcode);
  }

  // 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/test_pager_full', array(
    'query' => array(
      'page' => 1,
    ),
  ));
  foreach ($labels as $label => $translation) {

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