You are here

public function EmbedDialogTest::testEmbedDialog in Video Embed Field 8

Same name and namespace in other branches
  1. 8.2 modules/video_embed_wysiwyg/tests/src/FunctionalJavascript/EmbedDialogTest.php \Drupal\Tests\video_embed_wysiwyg\FunctionalJavascript\EmbedDialogTest::testEmbedDialog()

Test the WYSIWYG embed modal.

File

modules/video_embed_wysiwyg/tests/src/FunctionalJavascript/EmbedDialogTest.php, line 72

Class

EmbedDialogTest
Test the dialog form.

Namespace

Drupal\Tests\video_embed_wysiwyg\FunctionalJavascript

Code

public function testEmbedDialog() {

  // Use the modal to embed into a page.
  $this
    ->drupalGet('node/add/page');
  $this
    ->find('.cke_button__video_embed')
    ->click();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Assert all the form fields appear on the modal.
  $this
    ->assertSession()
    ->pageTextContains('Autoplay');
  $this
    ->assertSession()
    ->pageTextContains('Responsive Video');
  $this
    ->assertSession()
    ->pageTextContains('Video URL');

  // Attempt to submit the modal with no values.
  $this
    ->find('input[name="video_url"]')
    ->setValue('');
  $this
    ->find('button.form-submit')
    ->click();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertSession()
    ->pageTextContains('Video URL field is required.');

  // Submit the form with an invalid video URL.
  $this
    ->find('input[name="video_url"]')
    ->setValue('http://example.com/');
  $this
    ->find('button.form-submit')
    ->click();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertSession()
    ->pageTextContains('Could not find a video provider to handle the given URL.');
  $this
    ->assertContains('http://example.com/', $this
    ->getSession()
    ->getPage()
    ->getHtml());

  // Submit a valid URL.
  $this
    ->find('input[name="video_url"]')
    ->setValue('https://www.youtube.com/watch?v=iaf3Sl2r3jE&t=1553s');
  $this
    ->find('button.form-submit')
    ->click();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // View the source of the ckeditor and find the output.
  $this
    ->find('.cke_button__source_label')
    ->click();
  $base_path = \Drupal::request()
    ->getBasePath();
  $this
    ->assertEquals('<p>{"preview_thumbnail":"' . rtrim($base_path, '/') . '/' . $this->publicFilesDirectory . '/styles/video_embed_wysiwyg_preview/public/video_thumbnails/iaf3Sl2r3jE.jpg","video_url":"https://www.youtube.com/watch?v=iaf3Sl2r3jE&amp;t=1553s","settings":{"responsive":1,"width":"854","height":"480","autoplay":1},"settings_summary":["Embedded Video (Responsive, autoplaying)."]}</p>', trim($this
    ->getSession()
    ->getPage()
    ->find('css', '.cke_source')
    ->getValue()));
}