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

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

8 9
namespace Drupal\views\Tests\Handler;

10 11
use Drupal\views\Tests\ViewUnitTestBase;

merlinofchaos's avatar
merlinofchaos committed
12 13 14
/**
 * Tests the combine filter handler.
 */
15
class FilterCombineTest extends ViewUnitTestBase {
16

17 18 19 20 21 22 23
  /**
   * Views used by this test.
   *
   * @var array
   */
  public static $testViews = array('test_view');

24 25 26 27
  protected $column_map = array(
    'views_test_data_name' => 'name',
    'views_test_data_job' => 'job',
  );
merlinofchaos's avatar
merlinofchaos committed
28 29 30 31 32 33 34 35 36 37

  public static function getInfo() {
    return array(
      'name' => 'Filter: Combine',
      'description' => 'Tests the combine filter handler.',
      'group' => 'Views Handlers',
    );
  }

  public function testFilterCombineContains() {
38 39 40 41 42 43 44 45 46 47 48 49
    $view = views_get_view('test_view');
    $view->setDisplay();

    $fields = $view->displayHandlers['default']->getOption('fields');
    $view->displayHandlers['default']->overrideOption('fields', $fields + array(
      'job' => array(
        'id' => 'job',
        'table' => 'views_test_data',
        'field' => 'job',
        'relationship' => 'none',
      ),
    ));
merlinofchaos's avatar
merlinofchaos committed
50 51

    // Change the filtering.
52
    $view->displayHandlers['default']->overrideOption('filters', array(
merlinofchaos's avatar
merlinofchaos committed
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 102 103
      'age' => array(
        'id' => 'combine',
        'table' => 'views',
        'field' => 'combine',
        'relationship' => 'none',
        'operator' => 'contains',
        'fields' => array(
          'name',
          'job',
        ),
        'value' => 'ing',
      ),
    ));

    $this->executeView($view);
    $resultset = array(
      array(
        'name' => 'John',
        'job' => 'Singer',
      ),
      array(
        'name' => 'George',
        'job' => 'Singer',
      ),
      array(
        'name' => 'Ringo',
        'job' => 'Drummer',
      ),
      array(
        'name' => 'Ginger',
        'job' => NULL,
      ),
    );
    $this->assertIdenticalResultset($view, $resultset, $this->column_map);
  }

  /**
   * Additional data to test the NULL issue.
   */
  protected function dataSet() {
    $data_set = parent::dataSet();
    $data_set[] = array(
      'name' => 'Ginger',
      'age' => 25,
      'job' => NULL,
      'created' => gmmktime(0, 0, 0, 1, 2, 2000),
    );
    return $data_set;
  }

  /**
104
   * Allow {views_test_data}.job to be NULL.
merlinofchaos's avatar
merlinofchaos committed
105 106 107
   */
  protected function schemaDefinition() {
    $schema = parent::schemaDefinition();
108
    unset($schema['views_test_data']['fields']['job']['not null']);
merlinofchaos's avatar
merlinofchaos committed
109 110
    return $schema;
  }
111

merlinofchaos's avatar
merlinofchaos committed
112
}