View source
<?php
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewKernelTestBase;
use Drupal\views\Views;
class FilterCombineTest extends ViewKernelTestBase {
public static $testViews = array(
'test_view',
);
protected $columnMap = array(
'views_test_data_name' => 'name',
'views_test_data_job' => 'job',
);
public function testFilterCombineContains() {
$view = Views::getView('test_view');
$view
->setDisplay();
$fields = $view->displayHandlers
->get('default')
->getOption('fields');
$view->displayHandlers
->get('default')
->overrideOption('fields', $fields + array(
'job' => array(
'id' => 'job',
'table' => 'views_test_data',
'field' => 'job',
'relationship' => 'none',
),
));
$view->displayHandlers
->get('default')
->overrideOption('filters', array(
'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->columnMap);
}
public function testFilterCombineContainsFieldsOverwritten() {
$view = Views::getView('test_view');
$view
->setDisplay();
$fields = $view->displayHandlers
->get('default')
->getOption('fields');
$view->displayHandlers
->get('default')
->overrideOption('fields', $fields + array(
'job' => array(
'id' => 'job',
'table' => 'views_test_data',
'field' => 'job',
'relationship' => 'none',
),
));
$view->displayHandlers
->get('default')
->overrideOption('filters', array(
'age' => array(
'id' => 'combine',
'table' => 'views',
'field' => 'combine',
'relationship' => 'none',
'operator' => 'contains',
'fields' => array(
'name',
'job',
'dummy',
),
'value' => 'ing',
),
));
$this
->executeView($view);
$this
->assertTrue($view->build_info['fail'], "View build has been marked as failed.");
$errors = $view
->validate();
$this
->assertEqual(reset($errors['default']), t('Field %field set in %filter is not set in this display.', array(
'%field' => 'dummy',
'%filter' => 'Global: Combine fields filter',
)));
}
protected function dataSet() {
$data_set = parent::dataSet();
$data_set[] = array(
'name' => 'Ginger',
'age' => 25,
'job' => NULL,
'created' => gmmktime(0, 0, 0, 1, 2, 2000),
'status' => 1,
);
return $data_set;
}
protected function schemaDefinition() {
$schema = parent::schemaDefinition();
unset($schema['views_test_data']['fields']['job']['not null']);
return $schema;
}
}