You are here

public function UrlEmbedDialogTest::testUrlEmbedDialog in URL Embed 8

Tests the URL embed dialog.

File

tests/src/Functional/UrlEmbedDialogTest.php, line 17

Class

UrlEmbedDialogTest
Tests the url_embed dialog controller and route.

Namespace

Drupal\Tests\url_embed\Functional

Code

public function testUrlEmbedDialog() {

  // Ensure that the route is not accessible without specifying all the
  // parameters.
  $this
    ->getEmbedDialog();
  $this
    ->assertResponse(404, 'Embed dialog is not accessible without specifying filter format and embed button.');
  $this
    ->getEmbedDialog('custom_format');
  $this
    ->assertResponse(404, 'Embed dialog is not accessible without specifying embed button.');

  // Ensure that the route is not accessible with an invalid embed button.
  $this
    ->getEmbedDialog('custom_format', 'invalid_button');
  $this
    ->assertResponse(404, 'Embed dialog is not accessible without specifying filter format and embed button.');

  // Ensure that the route is not accessible with text format without the
  // button configured.
  $this
    ->getEmbedDialog('plain_text', 'url');
  $this
    ->assertResponse(404, 'Embed dialog is not accessible with a filter that does not have an editor configuration.');

  // Add an empty configuration for the plain_text editor configuration.
  $editor = Editor::create([
    'format' => 'plain_text',
    'editor' => 'ckeditor',
  ]);
  $editor
    ->save();
  $this
    ->getEmbedDialog('plain_text', 'url');
  $this
    ->assertResponse(403, 'Embed dialog is not accessible with a filter that does not have the embed button assigned to it.');

  // Ensure that the route is accessible with a valid embed button.
  // 'URL' embed button is provided by default by the module and hence the
  // request must be successful.
  $this
    ->getEmbedDialog('custom_format', 'url');
  $this
    ->assertResponse(200, 'Embed dialog is accessible with correct filter format and embed button.');
}