You are here

function ArgumentStringTest::testGlossary in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/Handler/ArgumentStringTest.php \Drupal\views\Tests\Handler\ArgumentStringTest::testGlossary()

Tests the glossary feature.

File

core/modules/views/src/Tests/Handler/ArgumentStringTest.php, line 36
Contains \Drupal\views\Tests\Handler\ArgumentStringTest.

Class

ArgumentStringTest
Tests the core Drupal\views\Plugin\views\argument\StringArgument handler.

Namespace

Drupal\views\Tests\Handler

Code

function testGlossary() {

  // Setup some nodes, one with a, two with b and three with c.
  $counter = 1;
  foreach (array(
    'a',
    'b',
    'c',
  ) as $char) {
    for ($i = 0; $i < $counter; $i++) {
      $edit = array(
        'title' => $char . $this
          ->randomMachineName(),
      );
      $this
        ->drupalCreateNode($edit);
    }
  }
  $view = Views::getView('test_glossary');
  $this
    ->executeView($view);
  $count_field = 'nid';
  foreach ($view->result as &$row) {
    if (strpos($view->field['title']
      ->getValue($row), 'a') === 0) {
      $this
        ->assertEqual(1, $row->{$count_field});
    }
    if (strpos($view->field['title']
      ->getValue($row), 'b') === 0) {
      $this
        ->assertEqual(2, $row->{$count_field});
    }
    if (strpos($view->field['title']
      ->getValue($row), 'c') === 0) {
      $this
        ->assertEqual(3, $row->{$count_field});
    }
  }
}