‪TYPO3CMS  ‪main
VideoTagRendererTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 final class ‪VideoTagRendererTest extends UnitTestCase
30 {
31  #[Test]
32  public function ‪getPriorityReturnsCorrectValue(): void
33  {
34  $VideoTagRenderer = new ‪VideoTagRenderer();
35 
36  self::assertSame(1, $VideoTagRenderer->getPriority());
37  }
38 
39  #[Test]
40  public function ‪canRenderReturnsTrueOnCorrectFile(): void
41  {
42  $VideoTagRenderer = new ‪VideoTagRenderer();
43 
44  $fileResourceMock1 = $this->createMock(File::class);
45  $fileResourceMock1->method('getMimeType')->willReturn('video/mp4');
46  $fileResourceMock2 = $this->createMock(File::class);
47  $fileResourceMock2->method('getMimeType')->willReturn('video/webm');
48  $fileResourceMock3 = $this->createMock(File::class);
49  $fileResourceMock3->method('getMimeType')->willReturn('video/ogg');
50  $fileResourceMock4 = $this->createMock(File::class);
51  $fileResourceMock4->method('getMimeType')->willReturn('application/ogg');
52 
53  self::assertTrue($VideoTagRenderer->canRender($fileResourceMock1));
54  self::assertTrue($VideoTagRenderer->canRender($fileResourceMock2));
55  self::assertTrue($VideoTagRenderer->canRender($fileResourceMock3));
56  self::assertTrue($VideoTagRenderer->canRender($fileResourceMock4));
57  }
58 
59  #[Test]
60  public function ‪canRenderReturnsFalseOnCorrectFile(): void
61  {
62  $VideoTagRenderer = new ‪VideoTagRenderer();
63 
64  $fileResourceMock = $this->createMock(File::class);
65  $fileResourceMock->method('getMimeType')->willReturn('audio/mpeg');
66 
67  self::assertFalse($VideoTagRenderer->canRender($fileResourceMock));
68  }
69 
73  public static function ‪renderArgumentsDataProvider(): array
74  {
75  return [
76  [
77  '//:path/myVideoFile?foo=bar&baz=true',
78  [],
79  '<video width="300" height="200" controls><source src="//:path/myVideoFile?foo=bar&amp;baz=true" type="video/mp4"></video>',
80  ],
81  [
82  '//:path/myVideoFile',
83  ['loop' => 1],
84  '<video width="300" height="200" controls loop><source src="//:path/myVideoFile" type="video/mp4"></video>',
85  ],
86  [
87  '//:path/myVideoFile',
88  ['autoplay' => 1],
89  '<video width="300" height="200" controls autoplay muted><source src="//:path/myVideoFile" type="video/mp4"></video>',
90  ],
91  [
92  '//:path/myVideoFile',
93  ['controls' => 0, 'autoplay' => 1],
94  '<video width="300" height="200" autoplay muted><source src="//:path/myVideoFile" type="video/mp4"></video>',
95  ],
96  [
97  '//:path/myVideoFile',
98  ['controls' => 1, 'controlsList' => 'nodownload'],
99  '<video width="300" height="200" controls controlsList="nodownload"><source src="//:path/myVideoFile" type="video/mp4"></video>',
100  ],
101  [
102  '//:path/myVideoFile',
103  ['additionalAttributes' => ['muted' => 'muted', 'foo' => 'bar']],
104  '<video muted="muted" foo="bar" width="300" height="200" controls><source src="//:path/myVideoFile" type="video/mp4"></video>',
105  ],
106  [
107  '//:path/myVideoFile',
108  ['data' => ['js-required' => 'yes', 'custom-id' => 'video-123']],
109  '<video data-js-required="yes" data-custom-id="video-123" width="300" height="200" controls><source src="//:path/myVideoFile" type="video/mp4"></video>',
110  ],
111  [
112  '//:path/myVideoFile',
113  [
114  'data' => [
115  'js-required' => 'yes',
116  'custom-id' => 'video-123',
117  ],
118  'additionalAttributes' => [
119  'muted' => 'muted',
120  'foo' => 'bar',
121  ],
122  'additionalConfig' => [
123  'playsinline' => '1',
124  'controls' => '1',
125  ],
126  ],
127  '<video muted="muted" foo="bar" data-js-required="yes" data-custom-id="video-123" width="300" height="200" controls playsinline><source src="//:path/myVideoFile" type="video/mp4"></video>',
128  ],
129  [
130  '//:path/myVideoFile',
131  ['preload' => 'auto'],
132  '<video width="300" height="200" controls preload="auto"><source src="//:path/myVideoFile" type="video/mp4"></video>',
133  ],
134  [
135  '//:path/myVideoFile',
136  [
137  'data' => [
138  'js-required' => 'yes',
139  'custom-id' => 'video-123',
140  ],
141  'additionalAttributes' => [
142  'muted' => 'muted',
143  'foo' => 'bar',
144  ],
145  'controlsList' => 'nodownload',
146  ],
147  '<video muted="muted" foo="bar" data-js-required="yes" data-custom-id="video-123" width="300" height="200" controls controlsList="nodownload"><source src="//:path/myVideoFile" type="video/mp4"></video>',
148  ],
149  ];
150  }
151 
152  #[DataProvider('renderArgumentsDataProvider')]
153  #[Test]
154  public function ‪renderOutputIsCorrect(string ‪$url, array $arguments, string $expected): void
155  {
156  $VideoTagRenderer = new ‪VideoTagRenderer();
157 
158  $fileResourceMock = $this->createMock(File::class);
159  $fileResourceMock->method('getMimeType')->willReturn('video/mp4');
160  $fileResourceMock->method('getPublicUrl')->willReturn(‪$url);
161 
162  self::assertSame(
163  $expected,
164  $VideoTagRenderer->render($fileResourceMock, '300m', '200', $arguments)
165  );
166  }
167 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VideoTagRendererTest\canRenderReturnsTrueOnCorrectFile
‪canRenderReturnsTrueOnCorrectFile()
Definition: VideoTagRendererTest.php:40
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VideoTagRendererTest\renderOutputIsCorrect
‪renderOutputIsCorrect(string $url, array $arguments, string $expected)
Definition: VideoTagRendererTest.php:154
‪TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer
Definition: VideoTagRenderer.php:26
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VideoTagRendererTest\canRenderReturnsFalseOnCorrectFile
‪canRenderReturnsFalseOnCorrectFile()
Definition: VideoTagRendererTest.php:60
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering
Definition: AudioTagRendererTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VideoTagRendererTest\getPriorityReturnsCorrectValue
‪getPriorityReturnsCorrectValue()
Definition: VideoTagRendererTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VideoTagRendererTest\renderArgumentsDataProvider
‪static renderArgumentsDataProvider()
Definition: VideoTagRendererTest.php:73
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:26
‪TYPO3\CMS\Webhooks\Message\$url
‪identifier readonly UriInterface $url
Definition: LoginErrorOccurredMessage.php:36
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VideoTagRendererTest
Definition: VideoTagRendererTest.php:30