You are here

public function FilterCombineTest::testFilterCombineContainsFieldsOverwritten in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/Handler/FilterCombineTest.php \Drupal\views\Tests\Handler\FilterCombineTest::testFilterCombineContainsFieldsOverwritten()

Tests if the filter can handle removed fields.

Tests the combined filter handler when a field overwrite is done and fields set in the combine filter are removed from the display but not from the combined filter settings.

File

core/modules/views/src/Tests/Handler/FilterCombineTest.php, line 96
Contains \Drupal\views\Tests\Handler\FilterCombineTest.

Class

FilterCombineTest
Tests the combine filter handler.

Namespace

Drupal\views\Tests\Handler

Code

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',
    ),
  ));

  // Change the filtering.
  $view->displayHandlers
    ->get('default')
    ->overrideOption('filters', array(
    'age' => array(
      'id' => 'combine',
      'table' => 'views',
      'field' => 'combine',
      'relationship' => 'none',
      'operator' => 'contains',
      'fields' => array(
        'name',
        'job',
        // Add a dummy field to the combined fields to simulate
        // a removed or deleted field.
        'dummy',
      ),
      'value' => 'ing',
    ),
  ));
  $this
    ->executeView($view);

  // Make sure this view will not get displayed.
  $this
    ->assertTrue($view->build_info['fail'], "View build has been marked as failed.");

  // Make sure this view does not pass validation with the right error.
  $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',
  )));
}