‪TYPO3CMS  10.4
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 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪VideoTagRendererTest extends UnitTestCase
28 {
33  {
34  $VideoTagRenderer = new ‪VideoTagRenderer();
35 
36  self::assertSame(1, $VideoTagRenderer->getPriority());
37  }
38 
43  {
44  $VideoTagRenderer = new ‪VideoTagRenderer();
45 
46  $fileResourceMock1 = $this->createMock(File::class);
47  $fileResourceMock1->expects(self::any())->method('getMimeType')->willReturn('video/mp4');
48  $fileResourceMock2 = $this->createMock(File::class);
49  $fileResourceMock2->expects(self::any())->method('getMimeType')->willReturn('video/webm');
50  $fileResourceMock3 = $this->createMock(File::class);
51  $fileResourceMock3->expects(self::any())->method('getMimeType')->willReturn('video/ogg');
52  $fileResourceMock4 = $this->createMock(File::class);
53  $fileResourceMock4->expects(self::any())->method('getMimeType')->willReturn('application/ogg');
54 
55  self::assertTrue($VideoTagRenderer->canRender($fileResourceMock1));
56  self::assertTrue($VideoTagRenderer->canRender($fileResourceMock2));
57  self::assertTrue($VideoTagRenderer->canRender($fileResourceMock3));
58  self::assertTrue($VideoTagRenderer->canRender($fileResourceMock4));
59  }
60 
65  {
66  $VideoTagRenderer = new ‪VideoTagRenderer();
67 
68  $fileResourceMock = $this->createMock(File::class);
69  $fileResourceMock->expects(self::any())->method('getMimeType')->willReturn('audio/mpeg');
70 
71  self::assertFalse($VideoTagRenderer->canRender($fileResourceMock));
72  }
73 
78  {
79  return [
80  [
81  '//:path/myVideoFile?foo=bar&baz=true',
82  [],
83  '<video width="300" height="200" controls><source src="//:path/myVideoFile?foo=bar&amp;baz=true" type="video/mp4"></video>',
84  ],
85  [
86  '//:path/myVideoFile',
87  ['loop' => 1],
88  '<video width="300" height="200" controls loop><source src="//:path/myVideoFile" type="video/mp4"></video>',
89  ],
90  [
91  '//:path/myVideoFile',
92  ['autoplay' => 1],
93  '<video width="300" height="200" controls autoplay><source src="//:path/myVideoFile" type="video/mp4"></video>',
94  ],
95  [
96  '//:path/myVideoFile',
97  ['controls' => 0, 'autoplay' => 1],
98  '<video width="300" height="200" autoplay><source src="//:path/myVideoFile" type="video/mp4"></video>',
99  ],
100  [
101  '//:path/myVideoFile',
102  ['controls' => 1, 'controlsList' => 'nodownload'],
103  '<video width="300" height="200" controls controlsList="nodownload"><source src="//:path/myVideoFile" type="video/mp4"></video>',
104  ],
105  [
106  '//:path/myVideoFile',
107  ['additionalAttributes' => ['muted' => 'muted', 'foo' => 'bar']],
108  '<video muted="muted" foo="bar" width="300" height="200" controls><source src="//:path/myVideoFile" type="video/mp4"></video>',
109  ],
110  [
111  '//:path/myVideoFile',
112  ['data' => ['js-required' => 'yes', 'custom-id' => 'video-123']],
113  '<video data-js-required="yes" data-custom-id="video-123" width="300" height="200" controls><source src="//:path/myVideoFile" type="video/mp4"></video>',
114  ],
115  [
116  '//:path/myVideoFile',
117  [
118  'data' => [
119  'js-required' => 'yes',
120  'custom-id' => 'video-123'
121  ],
122  'additionalAttributes' => [
123  'muted' => 'muted',
124  'foo' => 'bar'
125  ],
126  'additionalConfig' => [
127  'playsinline' => '1',
128  'controls' => '1'
129  ]
130  ],
131  '<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>',
132  ],
133  [
134  '//:path/myVideoFile',
135  ['preload' => 'auto'],
136  '<video width="300" height="200" controls preload="auto"><source src="//:path/myVideoFile" type="video/mp4"></video>',
137  ],
138  ];
139  }
140 
148  public function ‪renderOutputIsCorrect($url, $arguments, $expected)
149  {
150  $VideoTagRenderer = new ‪VideoTagRenderer();
151 
152  $fileResourceMock = $this->createMock(File::class);
153  $fileResourceMock->expects(self::any())->method('getMimeType')->willReturn('video/mp4');
154  $fileResourceMock->expects(self::any())->method('getPublicUrl')->willReturn($url);
155 
156  self::assertSame(
157  $expected,
158  $VideoTagRenderer->render($fileResourceMock, '300m', '200', $arguments)
159  );
160  }
161 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VideoTagRendererTest\canRenderReturnsTrueOnCorrectFile
‪canRenderReturnsTrueOnCorrectFile()
Definition: VideoTagRendererTest.php:42
‪TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer
Definition: VideoTagRenderer.php:26
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VideoTagRendererTest\canRenderReturnsFalseOnCorrectFile
‪canRenderReturnsFalseOnCorrectFile()
Definition: VideoTagRendererTest.php:64
‪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
‪renderArgumentsDataProvider()
Definition: VideoTagRendererTest.php:77
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VideoTagRendererTest\renderOutputIsCorrect
‪renderOutputIsCorrect($url, $arguments, $expected)
Definition: VideoTagRendererTest.php:148
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VideoTagRendererTest
Definition: VideoTagRendererTest.php:28