function FilterNumericTest::testAllowEmpty

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Kernel/Handler/FilterNumericTest.php \Drupal\Tests\views\Kernel\Handler\FilterNumericTest::testAllowEmpty()
  2. 8.9.x core/modules/views/tests/src/Kernel/Handler/FilterNumericTest.php \Drupal\Tests\views\Kernel\Handler\FilterNumericTest::testAllowEmpty()
  3. 11.x core/modules/views/tests/src/Kernel/Handler/FilterNumericTest.php \Drupal\Tests\views\Kernel\Handler\FilterNumericTest::testAllowEmpty()

File

core/modules/views/tests/src/Kernel/Handler/FilterNumericTest.php, line 503

Class

FilterNumericTest
Tests the numeric filter handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testAllowEmpty() : void {
  $view = Views::getView('test_view');
  $view->setDisplay();
  $view->displayHandlers
    ->get('default')
    ->overrideOption('filters', [
    'id' => [
      'id' => 'id',
      'table' => 'views_test_data',
      'field' => 'id',
      'relationship' => 'none',
    ],
    'age' => [
      'id' => 'age',
      'table' => 'views_test_data',
      'field' => 'age',
      'relationship' => 'none',
    ],
  ]);
  $view->initHandlers();
  $id_operators = $view->filter['id']
    ->operators();
  $age_operators = $view->filter['age']
    ->operators();
  $this->assertFalse(isset($id_operators['empty']));
  $this->assertFalse(isset($id_operators['not empty']));
  $this->assertTrue(isset($age_operators['empty']));
  $this->assertTrue(isset($age_operators['not empty']));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.