1 views_basic.test public ViewsBasicTest::testSimpleFiltering()

Tests filtering of the result set.

File

core/modules/views/tests/views_basic.test, line 34
Definition of ViewsBasicTest.

Class

ViewsBasicTest
Basic test class for Views query builder tests.

Code

public function testSimpleFiltering() {
  $view = $this->getBasicView();

  // Add a filter.
  $view->display['default']->handler->override_option('filters', array(
    'age' => array(
      'operator' => '<',
      'value' => array(
        'value' => '28',
        'min' => '',
        'max' => '',
      ),
      'group' => '0',
      'exposed' => FALSE,
      'expose' => array(
        'operator' => FALSE,
        'label' => '',
      ),
      'id' => 'age',
      'table' => 'views_test',
      'field' => 'age',
      'relationship' => 'none',
    ),
  ));

  // Execute the view.
  $this->executeView($view);

  // Build the expected result.
  $dataset = array(
    array(
      'id' => 1,
      'name' => 'John',
      'age' => 25,
    ),
    array(
      'id' => 2,
      'name' => 'George',
      'age' => 27,
    ),
    array(
      'id' => 4,
      'name' => 'Paul',
      'age' => 26,
    ),
  );

  // Verify the result.
  $this->assertEqual(3, count($view->result), t('The number of returned rows match.'));
  $this->assertIdenticalResultSet($view, $dataset, array(
    'views_test_name' => 'name',
    'views_test_age' => 'age',
  ));
}