You are here

abstract class MediaJavascriptTestBase in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/media/tests/src/FunctionalJavascript/MediaJavascriptTestBase.php \Drupal\Tests\media\FunctionalJavascript\MediaJavascriptTestBase
  2. 9 core/modules/media/tests/src/FunctionalJavascript/MediaJavascriptTestBase.php \Drupal\Tests\media\FunctionalJavascript\MediaJavascriptTestBase

Base class for Media functional JavaScript tests.

Hierarchy

Expanded class hierarchy of MediaJavascriptTestBase

File

core/modules/media/tests/src/FunctionalJavascript/MediaJavascriptTestBase.php, line 12

Namespace

Drupal\Tests\media\FunctionalJavascript
View source
abstract class MediaJavascriptTestBase extends WebDriverTestBase {
  use MediaFunctionalTestTrait;
  use MediaTypeCreationTrait;

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = [
    'system',
    'node',
    'field_ui',
    'views_ui',
    'media',
    'media_test_source',
  ];

  /**
   * Waits and asserts that a given element is visible.
   *
   * @param string $selector
   *   The CSS selector.
   * @param int $timeout
   *   (Optional) Timeout in milliseconds, defaults to 1000.
   * @param string $message
   *   (Optional) Message to pass to assertJsCondition().
   */
  protected function waitUntilVisible($selector, $timeout = 1000, $message = '') {
    $condition = "jQuery('" . $selector . ":visible').length > 0";
    $this
      ->assertJsCondition($condition, $timeout, $message);
  }

  /**
   * Asserts that a link to a new media item is displayed in the messages area.
   *
   * @return string
   *   The link URL.
   */
  protected function assertLinkToCreatedMedia() {
    $assert_session = $this
      ->assertSession();
    $selector = 'div[aria-label="Status message"] a';

    // Get the canonical media entity URL from the creation message.
    $link = $assert_session
      ->elementExists('css', $selector);
    $assert_session
      ->elementAttributeExists('css', $selector, 'href');
    return $link
      ->getAttribute('href');
  }

}

Members