You are here

public function EntityEmbedTest::testContextualBundle in Entity Browser 8

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

Tests the ContextualBundle filter plugin.

File

tests/src/FunctionalJavascript/EntityEmbedTest.php, line 106

Class

EntityEmbedTest
Tests entity browser within entity embed.

Namespace

Drupal\Tests\entity_browser\FunctionalJavascript

Code

public function testContextualBundle() {
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->createNode([
    'type' => 'shark',
    'title' => 'Luke',
  ]);
  $this
    ->createNode([
    'type' => 'jet',
    'title' => 'Leia',
  ]);
  $this
    ->createNode([
    'type' => 'article',
    'title' => 'Darth',
  ]);
  $this
    ->drupalGet('/node/add/test_entity_embed');
  $this
    ->assertSession()
    ->waitForElement('css', 'a.cke_button__bundle_filter_test')
    ->click();
  $this
    ->assertSession()
    ->waitForId('views-exposed-form-bundle-filter-entity-browser-1');
  $this
    ->getSession()
    ->switchToIFrame('entity_browser_iframe_bundle_filter');

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

  // Change the allowed bundles on the entity embed.
  $embed_button = $this->container
    ->get('entity_type.manager')
    ->getStorage('embed_button')
    ->load('bundle_filter_test');
  $type_settings = $embed_button
    ->getTypeSettings();
  $type_settings['bundles'] = [
    'article' => 'article',
  ];
  $embed_button
    ->set('type_settings', $type_settings);
  $embed_button
    ->save();

  // Test the new bundle settings are affecting what is visible in the view.
  $this
    ->drupalGet('/node/add/test_entity_embed');
  $this
    ->assertSession()
    ->waitForElement('css', 'a.cke_button__bundle_filter_test')
    ->click();
  $this
    ->assertSession()
    ->waitForId('views-exposed-form-bundle-filter-entity-browser-1');
  $this
    ->getSession()
    ->switchToIFrame('entity_browser_iframe_bundle_filter');

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