FilterInOperatorTest.php 2.24 KB
Newer Older
merlinofchaos's avatar
merlinofchaos committed
1 2 3 4
<?php

/**
 * @file
5
 * Definition of Drupal\views\Tests\Handler\FilterInOperatorTest.
merlinofchaos's avatar
merlinofchaos committed
6 7
 */

8 9
namespace Drupal\views\Tests\Handler;

10
use Drupal\views\Tests\ViewsSqlTest;
11

merlinofchaos's avatar
merlinofchaos committed
12
/**
aspilicious's avatar
aspilicious committed
13
 * Tests the core Drupal\views\Plugin\views\filter\InOperator handler.
merlinofchaos's avatar
merlinofchaos committed
14
 */
15
class FilterInOperatorTest extends ViewsSqlTest {
merlinofchaos's avatar
merlinofchaos committed
16 17 18
  public static function getInfo() {
    return array(
      'name' => 'Filter: in_operator',
aspilicious's avatar
aspilicious committed
19
      'description' => 'Test the core Drupal\views\Plugin\views\filter\InOperator handler.',
merlinofchaos's avatar
merlinofchaos committed
20 21 22 23 24 25
      'group' => 'Views Handlers',
    );
  }

  function viewsData() {
    $data = parent::viewsData();
aspilicious's avatar
aspilicious committed
26
    $data['views_test']['age']['filter']['id'] = 'in_operator';
merlinofchaos's avatar
merlinofchaos committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

    return $data;
  }

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

    // Add a in_operator ordering.
    $view->display['default']->handler->override_option('filters', array(
      'age' => array(
        'id' => 'age',
        'field' => 'age',
        'table' => 'views_test',
        '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, array(
      'views_test_name' => 'name',
      'views_test_age' => 'age',
    ));

    $view->delete();
    $view = $this->getBasicView();

    // Add a in_operator ordering.
    $view->display['default']->handler->override_option('filters', array(
      'age' => array(
        'id' => 'age',
        'field' => 'age',
        'table' => 'views_test',
        '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, array(
      'views_test_name' => 'name',
      'views_test_age' => 'age',
    ));
  }
}