TYPO3 CMS  TYPO3_7-6
AudioTagRendererTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
26  {
27  $audioTagRenderer = new \TYPO3\CMS\Core\Resource\Rendering\AudioTagRenderer();
28 
29  $this->assertSame(1, $audioTagRenderer->getPriority());
30  }
31 
36  {
37  $audioTagRenderer = new \TYPO3\CMS\Core\Resource\Rendering\AudioTagRenderer();
38 
39  $fileResourceMock1 = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, [], [], '', false);
40  $fileResourceMock1->expects($this->any())->method('getMimeType')->will($this->returnValue('audio/mpeg'));
41  $fileResourceMock2 = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, [], [], '', false);
42  $fileResourceMock2->expects($this->any())->method('getMimeType')->will($this->returnValue('audio/wav'));
43  $fileResourceMock3 = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, [], [], '', false);
44  $fileResourceMock3->expects($this->any())->method('getMimeType')->will($this->returnValue('audio/ogg'));
45 
46  $this->assertTrue($audioTagRenderer->canRender($fileResourceMock1));
47  $this->assertTrue($audioTagRenderer->canRender($fileResourceMock2));
48  $this->assertTrue($audioTagRenderer->canRender($fileResourceMock3));
49  }
50 
55  {
56  $audioTagRenderer = new \TYPO3\CMS\Core\Resource\Rendering\AudioTagRenderer();
57 
58  $fileResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, [], [], '', false);
59  $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('video/mp4'));
60 
61  $this->assertFalse($audioTagRenderer->canRender($fileResourceMock));
62  }
63 
67  public function renderArgumentsDataProvider()
68  {
69  return [
70  [
71  '//:path/myAudioFile?foo=bar&baz=true',
72  [],
73  '<audio controls><source src="//:path/myAudioFile?foo=bar&amp;baz=true" type="audio/mpeg"></audio>',
74  ],
75  [
76  '//:path/myAudioFile',
77  ['loop' => 1],
78  '<audio controls loop><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
79  ],
80  [
81  '//:path/myAudioFile',
82  ['autoplay' => 1],
83  '<audio controls autoplay><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
84  ],
85  [
86  '//:path/myAudioFile',
87  ['controls' => 0, 'autoplay' => 1],
88  '<audio autoplay><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
89  ],
90  [
91  '//:path/myAudioFile',
92  ['controls' => 1, 'controlsList' => 'nodownload'],
93  '<audio controls controlsList="nodownload"><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
94  ]
95  ];
96  }
97 
105  public function renderOutputIsCorrect($url, $arguments, $expected)
106  {
107  $audioTagRenderer = new \TYPO3\CMS\Core\Resource\Rendering\AudioTagRenderer();
108 
109  $fileResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, [], [], '', false);
110  $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('audio/mpeg'));
111  $fileResourceMock->expects($this->any())->method('getPublicUrl')->will($this->returnValue($url));
112 
113  $this->assertSame(
114  $expected,
115  $audioTagRenderer->render($fileResourceMock, '300m', '200', $arguments)
116  );
117  }
118 }