You are here

public function InlineEntityFormTest::testContextualFilter 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::testContextualFilter()

Tests the EntityBrowserWidgetContext argument_default views plugin.

File

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

Class

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

Namespace

Drupal\Tests\entity_browser\FunctionalJavascript

Code

public function testContextualFilter() {
  $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_widget_context_default_value');

  // Check that only nodes of an allowed type are listed.
  $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_widget_context_default_value');

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