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