function FieldUITest::testBooleanFilterHandler

Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Functional/Views/FieldUITest.php \Drupal\Tests\field\Functional\Views\FieldUITest::testBooleanFilterHandler()
  2. 8.9.x core/modules/field/tests/src/Functional/Views/FieldUITest.php \Drupal\Tests\field\Functional\Views\FieldUITest::testBooleanFilterHandler()
  3. 10 core/modules/field/tests/src/Functional/Views/FieldUITest.php \Drupal\Tests\field\Functional\Views\FieldUITest::testBooleanFilterHandler()

Tests adding a boolean field filter handler.

File

core/modules/field/tests/src/Functional/Views/FieldUITest.php, line 130

Class

FieldUITest
Tests the UI of the field handler.

Namespace

Drupal\Tests\field\Functional\Views

Code

public function testBooleanFilterHandler() : void {
  // Create a boolean field.
  $field_name = 'field_boolean';
  $field_storage = FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'node',
    'type' => 'boolean',
  ]);
  $field_storage->save();
  $field = FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => 'page',
  ]);
  $field->save();
  $url = "admin/structure/views/nojs/add-handler/test_view_fieldapi/default/filter";
  $this->drupalGet($url);
  $this->submitForm([
    'name[node__' . $field_name . '.' . $field_name . '_value]' => TRUE,
  ], 'Add and configure filter criteria');
  $this->assertSession()
    ->statusCodeEquals(200);
  // Verify that using a boolean field as a filter also results in using the
  // boolean plugin.
  $this->assertSession()
    ->elementTextEquals('xpath', '//label[@for="edit-options-value-1"]', 'True');
  $this->assertSession()
    ->elementTextEquals('xpath', '//label[@for="edit-options-value-0"]', 'False');
  // Expose the filter and see if the 'Any' option is added and if we can save
  // it.
  $this->submitForm([], 'Expose filter');
  $this->assertSession()
    ->elementTextEquals('xpath', '//label[@for="edit-options-value-all"]', '- Any -');
  $this->submitForm([
    'options[value]' => 'All',
    'options[expose][required]' => FALSE,
  ], 'Apply');
  $this->submitForm([], 'Save');
  $this->drupalGet('/admin/structure/views/nojs/handler/test_view_fieldapi/default/filter/field_boolean_value');
  $this->assertSession()
    ->checkboxChecked('edit-options-value-all');
}

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