You are here

trait EntityEmbedTrait in Lightning Media 8.3

Same name and namespace in other branches
  1. 8.4 tests/src/Traits/EntityEmbedTrait.php \Drupal\Tests\lightning_media\Traits\EntityEmbedTrait

Contains helper methods for interacting with Entity Embed.

Hierarchy

2 files declare their use of EntityEmbedTrait
CKEditorMediaBrowserTest.php in tests/src/FunctionalJavascript/CKEditorMediaBrowserTest.php
EmbeddedMediaTest.php in tests/src/FunctionalJavascript/EmbeddedMediaTest.php

File

tests/src/Traits/EntityEmbedTrait.php, line 10

Namespace

Drupal\Tests\lightning_media\Traits
View source
trait EntityEmbedTrait {

  /**
   * Waits for the entity embed form to appear.
   *
   * @return \Behat\Mink\Element\NodeElement
   *   The entity embed form.
   */
  private function waitForEmbedForm() {
    $embed_form = $this
      ->assertSession()
      ->waitForElement('css', 'form.entity-embed-dialog.entity-embed-dialog-step--embed');
    $this
      ->assertNotEmpty($embed_form);
    return $embed_form;
  }

  /**
   * Waits for an image-based entity embed form to appear.
   *
   * @return \Behat\Mink\Element\NodeElement
   *   The entity embed form.
   */
  private function waitForImageEmbedForm() {
    $assert_session = $this
      ->assertSession();
    $embed_form = $this
      ->waitForEmbedForm();
    $assert_session
      ->selectExists('Image style', $embed_form);
    $assert_session
      ->fieldExists('Alternate text', $embed_form);
    $assert_session
      ->fieldExists('Title', $embed_form);
    return $embed_form;
  }

  /**
   * Waits for a non-image based entity embed form to appear.
   *
   * @return \Behat\Mink\Element\NodeElement
   *   The entity embed form.
   */
  private function waitForStandardEmbedForm() {
    $assert_session = $this
      ->assertSession();
    $embed_form = $this
      ->waitForEmbedForm();
    $assert_session
      ->fieldNotExists('Image style', $embed_form);
    $assert_session
      ->fieldNotExists('Alternate text', $embed_form);
    $assert_session
      ->fieldNotExists('Title', $embed_form);
    return $embed_form;
  }

  /**
   * Presses the "Embed" button in the embed form, then waits for it to vanish.
   */
  private function submitEmbedForm() {
    $this
      ->waitForEmbedForm();

    // Don't click the Embed button *in* the form, because it is hidden by
    // Drupal's dialog system.
    $this
      ->assertSession()
      ->elementExists('css', '.ui-dialog-buttonpane')
      ->pressButton('Embed');
    $result = $this
      ->getSession()
      ->getPage()
      ->waitFor(10, function (DocumentElement $page) {
      return $page
        ->find('css', '.ui-dialog') == NULL;
    });
    $this
      ->assertTrue($result);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityEmbedTrait::submitEmbedForm private function Presses the "Embed" button in the embed form, then waits for it to vanish.
EntityEmbedTrait::waitForEmbedForm private function Waits for the entity embed form to appear.
EntityEmbedTrait::waitForImageEmbedForm private function Waits for an image-based entity embed form to appear.
EntityEmbedTrait::waitForStandardEmbedForm private function Waits for a non-image based entity embed form to appear.