You are here

public function MediaSourceOEmbedVideoTest::testOEmbedSecurityWarning in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media/tests/src/FunctionalJavascript/MediaSourceOEmbedVideoTest.php \Drupal\Tests\media\FunctionalJavascript\MediaSourceOEmbedVideoTest::testOEmbedSecurityWarning()

Tests that a security warning appears if iFrame domain is not set.

File

core/modules/media/tests/src/FunctionalJavascript/MediaSourceOEmbedVideoTest.php, line 227

Class

MediaSourceOEmbedVideoTest
Tests the oembed:video media source.

Namespace

Drupal\Tests\media\FunctionalJavascript

Code

public function testOEmbedSecurityWarning() {
  $media_type_id = 'test_media_oembed_type';
  $source_id = 'oembed:video';
  $session = $this
    ->getSession();
  $page = $session
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $this
    ->drupalGet('admin/structure/media/add');
  $page
    ->fillField('label', $media_type_id);
  $this
    ->getSession()
    ->wait(5000, "jQuery('.machine-name-value').text() === '{$media_type_id}'");

  // Make sure the source is available.
  $assert_session
    ->fieldExists('Media source');
  $assert_session
    ->optionExists('Media source', $source_id);
  $page
    ->selectFieldOption('Media source', $source_id);
  $result = $assert_session
    ->waitForElementVisible('css', 'fieldset[data-drupal-selector="edit-source-configuration"]');
  $this
    ->assertNotEmpty($result);
  $assert_session
    ->pageTextContains('It is potentially insecure to display oEmbed content in a frame');
  $this
    ->config('media.settings')
    ->set('iframe_domain', 'http://example.com')
    ->save();
  $this
    ->drupalGet('admin/structure/media/add');
  $page
    ->fillField('label', $media_type_id);
  $this
    ->getSession()
    ->wait(5000, "jQuery('.machine-name-value').text() === '{$media_type_id}'");

  // Make sure the source is available.
  $assert_session
    ->fieldExists('Media source');
  $assert_session
    ->optionExists('Media source', $source_id);
  $page
    ->selectFieldOption('Media source', $source_id);
  $result = $assert_session
    ->waitForElementVisible('css', 'fieldset[data-drupal-selector="edit-source-configuration"]');
  $this
    ->assertNotEmpty($result);
  $assert_session
    ->pageTextNotContains('It is potentially insecure to display oEmbed content in a frame');
}