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