public function FilterInOperatorTest::testFilterInOperatorSimple

File

drupal/core/modules/views/lib/Drupal/views/Tests/Handler/FilterInOperatorTest.php, line 51
Definition of Drupal\views\Tests\Handler\FilterInOperatorTest.

Class

FilterInOperatorTest
Tests the core Drupal\views\Plugin\views\filter\InOperator handler.

Namespace

Drupal\views\Tests\Handler

Code

public function testFilterInOperatorSimple() {
  $view = views_get_view('test_view');
  $view
    ->setDisplay();

  // Add a in_operator ordering.
  $view->displayHandlers
    ->get('default')
    ->overrideOption('filters', array(
    'age' => array(
      'id' => 'age',
      'field' => 'age',
      'table' => 'views_test_data',
      'value' => array(
        26,
        30,
      ),
      'operator' => 'in',
    ),
  ));
  $this
    ->executeView($view);
  $expected_result = array(
    array(
      'name' => 'Paul',
      'age' => 26,
    ),
    array(
      'name' => 'Meredith',
      'age' => 30,
    ),
  );
  $this
    ->assertEqual(2, count($view->result));
  $this
    ->assertIdenticalResultset($view, $expected_result, $this->column_map);
  $view
    ->destroy();
  $view
    ->setDisplay();

  // Add a in_operator ordering.
  $view->displayHandlers
    ->get('default')
    ->overrideOption('filters', array(
    'age' => array(
      'id' => 'age',
      'field' => 'age',
      'table' => 'views_test_data',
      'value' => array(
        26,
        30,
      ),
      'operator' => 'not in',
    ),
  ));
  $this
    ->executeView($view);
  $expected_result = array(
    array(
      'name' => 'John',
      'age' => 25,
    ),
    array(
      'name' => 'George',
      'age' => 27,
    ),
    array(
      'name' => 'Ringo',
      'age' => 28,
    ),
  );
  $this
    ->assertEqual(3, count($view->result));
  $this
    ->assertIdenticalResultset($view, $expected_result, $this->column_map);
}