Version 1
[yaffs-website] / web / modules / contrib / video_embed_field / tests / src / Functional / AutoplayPermissionTest.php
1 <?php
2
3 namespace Drupal\Tests\video_embed_field\Functional;
4 use Drupal\Tests\BrowserTestBase;
5
6 /**
7  * Test the autoplay permission works.
8  *
9  * @group video_embed_field
10  */
11 class AutoplayPermissionTest extends BrowserTestBase {
12
13   use EntityDisplaySetupTrait;
14
15   public static $modules = [
16     'video_embed_field',
17     'node',
18   ];
19
20   /**
21    * Test the autoplay permission works.
22    */
23   public function testAutoplay() {
24     $this->setupEntityDisplays();
25     $node = $this->createVideoNode('https://vimeo.com/80896303');
26     $this->setDisplayComponentSettings('video_embed_field_video', [
27       'autoplay' => TRUE,
28     ]);
29     $bypass_autoplay_user = $this->drupalCreateUser(['never autoplay videos']);
30     // Assert a user with the permission doesn't get autoplay.
31     $this->drupalLogin($bypass_autoplay_user);
32     $this->drupalGet('node/' . $node->id());
33     $this->assertSession()->elementAttributeContains('css', 'iframe', 'src', 'autoplay=0');
34     // Ensure an anonymous user gets autoplay.
35     $this->drupalLogout();
36     $this->drupalGet('node/' . $node->id());
37     $this->assertSession()->elementAttributeContains('css', 'iframe', 'src', 'autoplay=1');
38   }
39
40 }