‪TYPO3CMS  10.4
AudioTagRendererTest.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 ‪AudioTagRendererTest extends UnitTestCase
28 {
33  {
34  $audioTagRenderer = new ‪AudioTagRenderer();
35 
36  self::assertSame(1, $audioTagRenderer->getPriority());
37  }
38 
43  {
44  $audioTagRenderer = new ‪AudioTagRenderer();
45 
46  $fileResourceMock1 = $this->createMock(File::class);
47  $fileResourceMock1->expects(self::any())->method('getMimeType')->willReturn('audio/mpeg');
48  $fileResourceMock2 = $this->createMock(File::class);
49  $fileResourceMock2->expects(self::any())->method('getMimeType')->willReturn('audio/wav');
50  $fileResourceMock3 = $this->createMock(File::class);
51  $fileResourceMock3->expects(self::any())->method('getMimeType')->willReturn('audio/ogg');
52 
53  self::assertTrue($audioTagRenderer->canRender($fileResourceMock1));
54  self::assertTrue($audioTagRenderer->canRender($fileResourceMock2));
55  self::assertTrue($audioTagRenderer->canRender($fileResourceMock3));
56  }
57 
62  {
63  $audioTagRenderer = new ‪AudioTagRenderer();
64 
65  $fileResourceMock = $this->createMock(File::class);
66  $fileResourceMock->expects(self::any())->method('getMimeType')->willReturn('video/mp4');
67 
68  self::assertFalse($audioTagRenderer->canRender($fileResourceMock));
69  }
70 
75  {
76  return [
77  [
78  '//:path/myAudioFile?foo=bar&baz=true',
79  [],
80  '<audio controls><source src="//:path/myAudioFile?foo=bar&amp;baz=true" type="audio/mpeg"></audio>',
81  ],
82  [
83  '//:path/myAudioFile',
84  ['loop' => 1],
85  '<audio controls loop><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
86  ],
87  [
88  '//:path/myAudioFile',
89  ['autoplay' => 1],
90  '<audio controls autoplay><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
91  ],
92  [
93  '//:path/myAudioFile',
94  ['controls' => 0, 'autoplay' => 1],
95  '<audio autoplay><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
96  ],
97  [
98  '//:path/myAudioFile',
99  ['controls' => 1, 'controlsList' => 'nodownload'],
100  '<audio controls controlsList="nodownload"><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
101  ],
102  [
103  '//:path/myAudioFile',
104  ['additionalAttributes' => ['muted' => 'muted', 'foo' => 'bar']],
105  '<audio muted="muted" foo="bar" controls><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
106  ],
107  [
108  '//:path/myAudioFile',
109  ['data' => ['js-required' => 'yes', 'custom-id' => 'audio-123']],
110  '<audio data-js-required="yes" data-custom-id="audio-123" controls><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
111  ]
112  ,
113  [
114  '//:path/myAudioFile',
115  ['data' => ['js-required' => 'yes', 'custom-id' => 'audio-123'], 'additionalAttributes' => ['muted' => 'muted', 'foo' => 'bar']],
116  '<audio muted="muted" foo="bar" data-js-required="yes" data-custom-id="audio-123" controls><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
117  ]
118  ];
119  }
120 
128  public function ‪renderOutputIsCorrect($url, $arguments, $expected)
129  {
130  $audioTagRenderer = new ‪AudioTagRenderer();
131 
132  $fileResourceMock = $this->createMock(File::class);
133  $fileResourceMock->expects(self::any())->method('getMimeType')->willReturn('audio/mpeg');
134  $fileResourceMock->expects(self::any())->method('getPublicUrl')->willReturn($url);
135 
136  self::assertSame(
137  $expected,
138  $audioTagRenderer->render($fileResourceMock, '300m', '200', $arguments)
139  );
140  }
141 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\AudioTagRendererTest\getPriorityReturnsCorrectValue
‪getPriorityReturnsCorrectValue()
Definition: AudioTagRendererTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\AudioTagRendererTest\canRenderReturnsFalseOnCorrectFile
‪canRenderReturnsFalseOnCorrectFile()
Definition: AudioTagRendererTest.php:61
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\AudioTagRendererTest\canRenderReturnsTrueOnCorrectFile
‪canRenderReturnsTrueOnCorrectFile()
Definition: AudioTagRendererTest.php:42
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering
Definition: AudioTagRendererTest.php:18
‪TYPO3\CMS\Core\Resource\Rendering\AudioTagRenderer
Definition: AudioTagRenderer.php:26
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\AudioTagRendererTest\renderOutputIsCorrect
‪renderOutputIsCorrect($url, $arguments, $expected)
Definition: AudioTagRendererTest.php:128
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\AudioTagRendererTest\renderArgumentsDataProvider
‪renderArgumentsDataProvider()
Definition: AudioTagRendererTest.php:74
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\AudioTagRendererTest
Definition: AudioTagRendererTest.php:28