[TASK] UnitTests for TranslateViewHelper
[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
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\TranslateViewHelperFixtureForEmptyString;
19 use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\TranslateViewHelperFixtureForTranslatedString;
20 use TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper;
21
22 /**
23 * Test class for TranslateViewHelper
24 */
25 class TranslateViewHelperTest extends ViewHelperBaseTestcase {
26
27 /**
28 * @var TranslateViewHelper
29 */
30 protected $subject;
31
32 /**
33 * @test
34 * @expectedException \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException
35 * @expectedExceptionCode 1351584844
36 */
37 public function renderThrowsExceptionIfNoKeyOrIdParameterIsGiven() {
38 $this->subject = GeneralUtility::makeInstance(TranslateViewHelper::class);
39 $this->injectDependenciesIntoViewHelper($this->subject);
40 $this->subject->render();
41 }
42
43 /**
44 * @test
45 */
46 public function renderReturnsStringForGivenKey() {
47 $this->subject = GeneralUtility::makeInstance(TranslateViewHelperFixtureForTranslatedString::class);
48 $this->injectDependenciesIntoViewHelper($this->subject);
49 $this->assertEquals('<p>hello world</p>', $this->subject->render('foo'));
50 }
51
52 /**
53 * @test
54 */
55 public function renderReturnsStringForGivenId() {
56 $this->subject = GeneralUtility::makeInstance(TranslateViewHelperFixtureForTranslatedString::class);
57 $this->injectDependenciesIntoViewHelper($this->subject);
58 $this->assertEquals('<p>hello world</p>', $this->subject->render(NULL, 'bar'));
59 }
60
61 /**
62 * @test
63 */
64 public function renderReturnsDefaultIfNoTranslationIsFound() {
65 $this->subject = GeneralUtility::makeInstance(TranslateViewHelperFixtureForEmptyString::class);
66 $this->injectDependenciesIntoViewHelper($this->subject);
67 $this->assertEquals('default', $this->subject->render(NULL, 'bar', 'default'));
68 }
69
70 /**
71 * @test
72 */
73 public function resultIsNotHtmlEscapedIfSoRequested() {
74 $this->subject = GeneralUtility::makeInstance(TranslateViewHelperFixtureForTranslatedString::class);
75 $this->injectDependenciesIntoViewHelper($this->subject);
76 $this->assertEquals('&lt;p&gt;hello world&lt;/p&gt;', $this->subject->render('foo', NULL, NULL, TRUE));
77 }
78
79 }