[TASK] Move arguments to initializeArguments() in TranslateVH in ext:fluid
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / TranslateViewHelperTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers;
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 use TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper;
17
18 /**
19 * Test class for TranslateViewHelper
20 */
21 class TranslateViewHelperTest extends ViewHelperBaseTestcase
22 {
23 /**
24 * @var TranslateViewHelper
25 */
26 protected $viewHelper;
27
28 protected function setUp()
29 {
30 parent::setUp();
31 $this->viewHelper = new TranslateViewHelper();
32 $this->injectDependenciesIntoViewHelper($this->viewHelper);
33 }
34
35 /**
36 * @test
37 */
38 public function renderThrowsExceptionIfNoKeyOrIdParameterIsGiven()
39 {
40 $this->expectException(\TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException::class);
41 $this->expectExceptionCode(1351584844);
42
43 $this->setArgumentsUnderTest(
44 $this->viewHelper,
45 []
46 );
47 $this->viewHelper->initializeArgumentsAndRender();
48 }
49
50 /**
51 * @test
52 */
53 public function renderReturnsStringForGivenKey()
54 {
55 $this->viewHelper->setRenderChildrenClosure(
56 function () {
57 return '<p>hello world</p>';
58 }
59 );
60 $this->setArgumentsUnderTest(
61 $this->viewHelper,
62 [
63 'key' => 'foo'
64 ]
65 );
66 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
67 $this->assertEquals('<p>hello world</p>', $actualResult);
68 }
69
70 /**
71 * @test
72 */
73 public function renderReturnsStringForGivenId()
74 {
75 $this->viewHelper->setRenderChildrenClosure(
76 function () {
77 return '<p>hello world</p>';
78 }
79 );
80 $this->setArgumentsUnderTest(
81 $this->viewHelper,
82 [
83 'key' => null,
84 'id' => 'bar'
85 ]
86 );
87 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
88 $this->assertEquals('<p>hello world</p>', $actualResult);
89 }
90
91 /**
92 * @test
93 */
94 public function renderReturnsDefaultIfNoTranslationIsFound()
95 {
96 $this->viewHelper->setRenderChildrenClosure(
97 function () {
98 return 'default';
99 }
100 );
101 $this->setArgumentsUnderTest(
102 $this->viewHelper,
103 [
104 'key' => null,
105 'id' => 'bar',
106 'default' => 'default'
107 ]
108 );
109 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
110 $this->assertEquals('default', $actualResult);
111 }
112 }