function FileVideoFormatterTest::testRender

Same name in other branches
  1. 9 core/modules/file/tests/src/Functional/Formatter/FileVideoFormatterTest.php \Drupal\Tests\file\Functional\Formatter\FileVideoFormatterTest::testRender()
  2. 10 core/modules/file/tests/src/Functional/Formatter/FileVideoFormatterTest.php \Drupal\Tests\file\Functional\Formatter\FileVideoFormatterTest::testRender()
  3. 11.x core/modules/file/tests/src/Functional/Formatter/FileVideoFormatterTest.php \Drupal\Tests\file\Functional\Formatter\FileVideoFormatterTest::testRender()

@covers ::viewElements

@dataProvider dataProvider

File

core/modules/file/tests/src/Functional/Formatter/FileVideoFormatterTest.php, line 24

Class

FileVideoFormatterTest
@coversDefaultClass \Drupal\file\Plugin\Field\FieldFormatter\FileVideoFormatter @group file

Namespace

Drupal\Tests\file\Functional\Formatter

Code

public function testRender($tag_count, $formatter_settings) {
    $field_config = $this->createMediaField('file_video', 'mp4', $formatter_settings);
    file_put_contents('public://file.mp4', str_repeat('t', 10));
    $file1 = File::create([
        'uri' => 'public://file.mp4',
        'filename' => 'file.mp4',
    ]);
    $file1->save();
    $file2 = File::create([
        'uri' => 'public://file.mp4',
        'filename' => 'file.mp4',
    ]);
    $file2->save();
    $entity = EntityTest::create([
        $field_config->getName() => [
            [
                'target_id' => $file1->id(),
            ],
            [
                'target_id' => $file2->id(),
            ],
        ],
    ]);
    $entity->save();
    $this->drupalGet($entity->toUrl());
    $file1_url = $file1->createFileUrl();
    $file2_url = $file2->createFileUrl();
    $assert_session = $this->assertSession();
    $assert_session->elementsCount('css', 'video[controls="controls"]', $tag_count);
    $assert_session->elementExists('css', "video > source[src='{$file1_url}'][type='video/mp4']");
    $assert_session->elementExists('css', "video > source[src='{$file2_url}'][type='video/mp4']");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.