You are here

public function EntityEmbedDialogTest::testEntityEmbedButtonMarkup in Entity Embed 8

Same name in this branch
  1. 8 tests/src/Functional/EntityEmbedDialogTest.php \Drupal\Tests\entity_embed\Functional\EntityEmbedDialogTest::testEntityEmbedButtonMarkup()
  2. 8 tests/src/FunctionalJavascript/EntityEmbedDialogTest.php \Drupal\Tests\entity_embed\FunctionalJavascript\EntityEmbedDialogTest::testEntityEmbedButtonMarkup()

Tests the entity embed button markup.

File

tests/src/FunctionalJavascript/EntityEmbedDialogTest.php, line 97

Class

EntityEmbedDialogTest
Tests the entity_embed dialog controller and route.

Namespace

Drupal\Tests\entity_embed\FunctionalJavascript

Code

public function testEntityEmbedButtonMarkup() {

  // Ensure that the route is accessible with a valid embed button.
  // 'Node' embed button is provided by default by the module and hence the
  // request must be successful.
  $this
    ->drupalGet('/entity-embed/dialog/custom_format/node');

  // Ensure form structure of the 'select' step and submit form.
  $this
    ->assertSession()
    ->fieldExists('entity_id');

  // Check that 'Next' is a primary button.
  $this
    ->assertSession()
    ->elementExists('xpath', '//input[contains(@class, "button--primary")]');
  $title = $this->node
    ->getTitle() . ' (' . $this->node
    ->id() . ')';
  $this
    ->assertSession()
    ->fieldExists('entity_id')
    ->setValue($title);
  $this
    ->assertSession()
    ->buttonExists('Next')
    ->press();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $plugins = [
    'entity_reference:entity_reference_label',
    'entity_reference:entity_reference_entity_id',
    'view_mode:node.full',
    'view_mode:node.rss',
    'view_mode:node.search_index',
    'view_mode:node.search_result',
    'view_mode:node.teaser',
  ];
  foreach ($plugins as $plugin) {
    $this
      ->assertSession()
      ->optionExists('Display as', $plugin);
  }
  $this->container
    ->get('config.factory')
    ->getEditable('entity_embed.settings')
    ->set('rendered_entity_mode', TRUE)
    ->save();
  $this->container
    ->get('plugin.manager.entity_embed.display')
    ->clearCachedDefinitions();
  $this
    ->drupalGet('/entity-embed/dialog/custom_format/node');
  $title = $this->node
    ->getTitle() . ' (' . $this->node
    ->id() . ')';
  $this
    ->assertSession()
    ->fieldExists('entity_id')
    ->setValue($title);
  $this
    ->assertSession()
    ->buttonExists('Next')
    ->press();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $plugins = [
    'entity_reference:entity_reference_label',
    'entity_reference:entity_reference_entity_id',
    'entity_reference:entity_reference_entity_view',
  ];
  foreach ($plugins as $plugin) {
    $this
      ->assertSession()
      ->optionExists('Display as', $plugin);
  }
}