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