You are here

public function AutoplayPermissionTest::testAutoplay in Video Embed Field 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/AutoplayPermissionTest.php \Drupal\Tests\video_embed_field\Functional\AutoplayPermissionTest::testAutoplay()

Test the autoplay permission works.

File

tests/src/Functional/AutoplayPermissionTest.php, line 23

Class

AutoplayPermissionTest
Test the autoplay permission works.

Namespace

Drupal\Tests\video_embed_field\Functional

Code

public function testAutoplay() {
  $this
    ->setupEntityDisplays();
  $node = $this
    ->createVideoNode('https://vimeo.com/80896303');
  $this
    ->setDisplayComponentSettings('video_embed_field_video', [
    'autoplay' => TRUE,
  ]);
  $bypass_autoplay_user = $this
    ->drupalCreateUser([
    'never autoplay videos',
  ]);

  // Assert a user with the permission doesn't get autoplay.
  $this
    ->drupalLogin($bypass_autoplay_user);
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertSession()
    ->elementAttributeContains('css', 'iframe', 'src', 'autoplay=0');

  // Ensure an anonymous user gets autoplay.
  $this
    ->drupalLogout();
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertSession()
    ->elementAttributeContains('css', 'iframe', 'src', 'autoplay=1');
}