You are here

public function InlineEntityFormTest::testContextualBundleExposed in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 tests/src/FunctionalJavascript/InlineEntityFormTest.php \Drupal\Tests\entity_browser\FunctionalJavascript\InlineEntityFormTest::testContextualBundleExposed()

Tests the ContextualBundle filter plugin with exposed option.

File

tests/src/FunctionalJavascript/InlineEntityFormTest.php, line 285

Class

InlineEntityFormTest
Test for integration of entity browser and inline entity form.

Namespace

Drupal\Tests\entity_browser\FunctionalJavascript

Code

public function testContextualBundleExposed() {
  $this
    ->config('core.entity_form_display.node.ief_content.default')
    ->set('content.field_nodes.third_party_settings.entity_browser_entity_form.entity_browser_id', 'bundle_filter')
    ->save();
  $this
    ->config('entity_browser.browser.bundle_filter')
    ->set('widgets.b882a89d-9ce4-4dfe-9802-62df93af232a.settings.view', 'bundle_filter_exposed')
    ->save();
  $this
    ->createNode([
    'type' => 'shark',
    'title' => 'Luke',
  ]);
  $this
    ->createNode([
    'type' => 'jet',
    'title' => 'Leia',
  ]);
  $this
    ->createNode([
    'type' => 'ief_content',
    'title' => 'Darth',
  ]);
  $this
    ->drupalGet('node/add/ief_content');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->fillField('Title', 'Test IEF Title');
  $page
    ->pressButton('Add existing node');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->getSession()
    ->switchToIFrame('entity_browser_iframe_bundle_filter');

  // Check that only nodes of an allowed type are listed.
  $this
    ->assertSession()
    ->pageTextContains('Luke');
  $this
    ->assertSession()
    ->pageTextContains('Leia');
  $this
    ->assertSession()
    ->pageTextNotContains('Darth');

  // Test exposed form type filter.
  $this
    ->assertSession()
    ->selectExists('Type')
    ->selectOption('jet');
  $this
    ->assertSession()
    ->buttonExists('Apply')
    ->press();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Check that only nodes of the type selected in the exposed filter display.
  $this
    ->assertSession()
    ->pageTextNotContains('Luke');
  $this
    ->assertSession()
    ->pageTextContains('Leia');
  $this
    ->assertSession()
    ->pageTextNotContains('Darth');
  $this
    ->assertSession()
    ->selectExists('Type')
    ->selectOption('shark');
  $this
    ->assertSession()
    ->buttonExists('Apply')
    ->press();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Check that only nodes of the type selected in the exposed filter display.
  $this
    ->assertSession()
    ->pageTextContains('Luke');
  $this
    ->assertSession()
    ->pageTextNotContains('Leia');
  $this
    ->assertSession()
    ->pageTextNotContains('Darth');
  $this
    ->assertSession()
    ->selectExists('Type')
    ->selectOption('All');
  $this
    ->assertSession()
    ->buttonExists('Apply')
    ->press();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Check that only nodes of the type selected in the exposed filter display.
  $this
    ->assertSession()
    ->pageTextContains('Luke');
  $this
    ->assertSession()
    ->pageTextContains('Leia');
  $this
    ->assertSession()
    ->pageTextNotContains('Darth');

  /** @var \Drupal\Core\Field\FieldConfigInterface $field_config */
  $field_config = $this->container
    ->get('entity_type.manager')
    ->getStorage('field_config')
    ->load('node.ief_content.field_nodes');
  $handler_settings = $field_config
    ->getSetting('handler_settings');
  $handler_settings['target_bundles'] = [
    'ief_content' => 'ief_content',
  ];
  $field_config
    ->setSetting('handler_settings', $handler_settings);
  $field_config
    ->save();
  $this
    ->drupalGet('node/add/ief_content');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->fillField('Title', 'Test IEF Title');
  $page
    ->pressButton('Add existing node');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->getSession()
    ->switchToIFrame('entity_browser_iframe_bundle_filter');

  // Check that only nodes of an allowed type are listed.
  $this
    ->assertSession()
    ->pageTextNotContains('Luke');
  $this
    ->assertSession()
    ->pageTextNotContains('Leia');
  $this
    ->assertSession()
    ->pageTextContains('Darth');

  // If there is just one target_bundle, the contextual filter
  // should not be visible.
  $this
    ->assertSession()
    ->fieldNotExists('Type');
}