You are here

public function MediaBrowserEmbedCodeWidgetTest::testErrorMessages in Lightning Media 8.3

Tests that an error message is displayed for malformed URLs.

File

tests/src/FunctionalJavascript/MediaBrowserEmbedCodeWidgetTest.php, line 29

Class

MediaBrowserEmbedCodeWidgetTest
Tests the embed code widget in the media browser.

Namespace

Drupal\Tests\lightning_media\FunctionalJavascript

Code

public function testErrorMessages() {
  $account = $this
    ->drupalCreateUser([
    'access media_browser entity browser pages',
    'create media',
  ]);
  $this
    ->drupalLogin($account);
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $this
    ->drupalGet('/entity-browser/modal/media_browser');

  // Error message is displayed for malformed URLs.
  $page
    ->clickLink('Create embed');
  $page
    ->fillField('input', 'Foo');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->fieldNotExists('Bundle');
  $page
    ->fillField('input', '');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->fieldNotExists('Bundle');
  $assert_session
    ->elementNotExists('css', '[role="alert"]');

  // No error message when URL is valid.
  $page
    ->fillField('input', 'https://www.youtube.com/watch?v=zQ1_IbFFbzA');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->fieldNotExists('Bundle');
  $assert_session
    ->elementNotExists('css', '[role="alert"]');

  // Rerender the form if URL is changed.
  $page
    ->fillField('input', 'Bar');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->fieldNotExists('Bundle');
  $assert_session
    ->elementTextContains('css', '[role="alert"]', "Input did not match any media types: 'Bar'");
}