/
ScriptViewHelperTest.php
57 lines (51 loc) · 1.86 KB
/
ScriptViewHelperTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\Asset;
use Prophecy\Argument;
use TYPO3\CMS\Core\Page\AssetCollector;
use TYPO3\CMS\Fluid\ViewHelpers\Asset\ScriptViewHelper;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
class ScriptViewHelperTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
public function valueDataProvider(): array
{
return [
'fileadmin reference' => ['fileadmin/JavaScript/foo.js'],
'EXT: reference' => ['EXT:core/Resources/Public/JavaScript/foo.js'],
'external reference' => ['https://typo3.com/foo.js'],
'external reference with 1 parameter' => ['https://typo3.com/foo.js?foo=bar'],
'external reference with 2 parameters' => ['https://typo3.com/foo.js?foo=bar&bar=baz'],
];
}
/**
* @test
* @dataProvider valueDataProvider
*/
public function render(string $src): void
{
$assetCollector = $this->prophesize(AssetCollector::class);
$assetCollector
->addJavaScript('test', $src, Argument::any(), Argument::any())
->shouldBeCalled();
$viewHelper = new ScriptViewHelper();
$viewHelper->injectAssetCollector($assetCollector->reveal());
$viewHelper->setArguments([
'identifier' => 'test',
'src' => $src,
]);
$viewHelper->initializeArgumentsAndRender();
}
}