You are here

public function EntityEmbedDialogTest::testEntityEmbedDialog in Entity Embed 8

Tests the entity embed dialog.

File

tests/src/Functional/EntityEmbedDialogTest.php, line 24

Class

EntityEmbedDialogTest
Tests the entity_embed dialog controller and route.

Namespace

Drupal\Tests\entity_embed\Functional

Code

public function testEntityEmbedDialog() {

  // Ensure that the route is not accessible without specifying all the
  // parameters.
  $this
    ->drupalGet('/entity-embed/dialog');

  // Verify embed dialog is not accessible without specifying filter format
  // and embed button.
  $this
    ->assertSession()
    ->statusCodeEquals(404);
  $this
    ->drupalGet('/entity-embed/dialog/custom_format');

  // Verify embed dialog is not accessible without specifying embed button.
  $this
    ->assertSession()
    ->statusCodeEquals(404);

  // Ensure that the route is not accessible with an invalid embed button.
  $this
    ->drupalGet('/entity-embed/dialog/custom_format/invalid_button');

  // Verify embed dialog is not accessible without specifying filter format
  // and embed button.
  $this
    ->assertSession()
    ->statusCodeEquals(404);

  // Ensure that the route is not accessible with text format without the
  // button configured.
  $this
    ->drupalGet('/entity-embed/dialog/plain_text/node');

  // Verify embed dialog is not accessible with a filter that does not have
  // an editor configuration.
  $this
    ->assertSession()
    ->statusCodeEquals(404);

  // Add an empty configuration for the plain_text editor configuration.
  $editor = Editor::create([
    'format' => 'plain_text',
    'editor' => 'ckeditor',
  ]);
  $editor
    ->save();
  $this
    ->drupalGet('/entity-embed/dialog/plain_text/node');

  // Verify embed dialog is not accessible with a filter that does not have
  // the embed button assigned to it.
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // 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');

  // Verify embed dialog is accessible with correct filter format
  // and embed button.
  $this
    ->assertSession()
    ->statusCodeEquals(200);

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