function FilterEntityReferenceTest::testAddConfigEntityReferenceFieldWithDefaultSelectionHandler

Tests end to end creation of a Config Entity Reference filter.

File

core/modules/views_ui/tests/src/FunctionalJavascript/FilterEntityReferenceTest.php, line 185

Class

FilterEntityReferenceTest
Tests views creation wizard.

Namespace

Drupal\Tests\views_ui\FunctionalJavascript

Code

public function testAddConfigEntityReferenceFieldWithDefaultSelectionHandler() : void {
  $this->drupalGet('admin/structure/views/view/content');
  $assert = $this->assertSession();
  $page = $this->getSession()
    ->getPage();
  // Open the 'Add filter dialog'.
  $page->clickLink('views-add-filter');
  // Wait for the popup to open and the search field to be available.
  $assert->waitForField('override[controls][group]');
  // Test that the entity_reference option is visible.
  $this->assertTrue($page->findField('name[node__field_test_config.field_test_config_target_id]')
    ->isVisible());
  $page->findField('name[node__field_test_config.field_test_config_target_id]')
    ->click();
  $submitButton = $page->find('css', 'button.button.button--primary.form-submit.ui-button');
  $this->assertTrue($submitButton->isVisible());
  $submitButton->click();
  // Wait for the selection handler to show up.
  $assert->waitForField('options[sub_handler]');
  $page->selectFieldOption('options[sub_handler]', 'default:node_type');
  // Choose the default handler using the select widget with article type
  // checked.
  $page->selectFieldOption('options[widget]', 'select');
  $this->assertSame('select', $page->findField('options[widget]')
    ->getValue());
  $page->find('xpath', "//*[contains(text(), 'Apply and continue')]")
    ->press();
  // Test the exposed filter options show up correctly.
  $assert->waitForField('options[expose_button][checkbox][checkbox]');
  $page->findField('options[expose_button][checkbox][checkbox]')
    ->click();
  $this->assertSession()
    ->assertWaitOnAjaxRequest();
  $this->assertTrue($page->hasCheckedField('options[expose_button][checkbox][checkbox]'));
  // Check the exposed filters multiple option.
  $assert->waitForField('options[expose][multiple]');
  $page->findField('options[expose][multiple]')
    ->click();
  $this->assertTrue($page->hasCheckedField('options[expose][multiple]'));
  $page->find('css', '.ui-dialog .ui-dialog-buttonpane')
    ->pressButton('Apply');
  $assert->waitForElementRemoved('css', '.ui-dialog');
  // Wait for the Views Preview to show up with the reference field.
  $assert->waitForField('field_test_config_target_id[]');
  $this->assertTrue($page->findField('field_test_config_target_id[]')
    ->isVisible());
  $this->assertTrue($page->find('css', 'select[name="field_test_config_target_id[]"]')
    ->hasAttribute('multiple'));
  // Check references config options.
  $options = $page->findAll('css', 'select[name="field_test_config_target_id[]"] option');
  $this->assertCount(2, $options);
  $this->assertSame('article', $options[0]->getValue());
  $this->assertSame('page', $options[1]->getValue());
  $base_url = Url::fromRoute('entity.view.collection')->toString();
  $url = $base_url . '/nojs/handler-extra/content/page_1/filter/field_test_config_target_id';
  $extra_settings_selector = 'a[href="' . $url . '"]';
  // Change to an autocomplete filter.
  $page->find('css', $extra_settings_selector)
    ->click();
  $assert->waitForField('options[widget]');
  $page->selectFieldOption('options[widget]', 'autocomplete');
  $this->assertSame('autocomplete', $page->findField('options[widget]')
    ->getValue());
  $page->find('css', '.ui-dialog .ui-dialog-buttonpane')
    ->pressButton('Apply');
  $this->assertSession()
    ->assertWaitOnAjaxRequest();
  // Check that it is now an autocomplete input.
  $assert->waitForField('field_test_config_target_id');
  $this->assertTrue($page->findField('field_test_config_target_id')
    ->isVisible());
  $this->assertTrue($page->find('css', 'input[name="field_test_config_target_id"]')
    ->hasAttribute('data-autocomplete-path'));
}

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