Skip to content
ArgumentStringTest.php 1.44 KiB
Newer Older
Earl Miles's avatar
Earl Miles committed
<?php
Earl Miles's avatar
Earl Miles committed
/**
 * @file
 * Definition of Drupal\views\Tests\Handler\ArgumentStringTest.
Earl Miles's avatar
Earl Miles committed
/**
 * Tests the core Drupal\views\Plugin\views\argument\String handler.
class ArgumentStringTest extends HandlerTestBase {
  /**
   * Views used by this test.
   *
   * @var array
   */
  public static $testViews = array('test_glossary');

Earl Miles's avatar
Earl Miles committed
  public static function getInfo() {
    return array(
      'name' => 'Argument: String',
      'description' => 'Test the core Drupal\views\Plugin\views\argument\String handler.',
Earl Miles's avatar
Earl Miles committed
      'group' => 'Views Handlers',
    );
  }

  /**
   * Tests the glossary feature.
   */
  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->randomName(),
        );
        $this->drupalCreateNode($edit);
      }
    }

Earl Miles's avatar
Earl Miles committed
    $this->executeView($view);

    $count_field = 'nid';
    foreach ($view->result as &$row) {
      if (strpos($row->node_title, 'a') === 0) {
        $this->assertEqual(1, $row->{$count_field});
      }
      if (strpos($row->node_title, 'b') === 0) {
        $this->assertEqual(2, $row->{$count_field});
      }
      if (strpos($row->node_title, 'c') === 0) {
        $this->assertEqual(3, $row->{$count_field});
      }
    }
  }

}