‪TYPO3CMS  10.4
TranslateViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
22 
26 class ‪TranslateViewHelperTest extends ViewHelperBaseTestcase
27 {
31  protected ‪$viewHelper;
32 
37  {
38  $this->viewHelper = new ‪TranslateViewHelper();
39  $this->injectDependenciesIntoViewHelper($this->viewHelper);
40 
41  $this->expectException(Exception::class);
42  $this->expectExceptionCode(1351584844);
43 
44  $this->setArgumentsUnderTest(
45  $this->viewHelper,
46  []
47  );
48  $this->viewHelper->initializeArgumentsAndRender();
49  }
50 
54  public function ‪renderReturnsStringForGivenKey()
55  {
56  $this->viewHelper = new ‪TranslateViewHelperFixtureForEmptyString();
57  $this->injectDependenciesIntoViewHelper($this->viewHelper);
58 
59  $this->viewHelper->setRenderChildrenClosure(
60  function () {
61  return '<p>hello world</p>';
62  }
63  );
64  $this->setArgumentsUnderTest(
65  $this->viewHelper,
66  [
67  'key' => 'foo'
68  ]
69  );
70  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
71  self::assertEquals('<p>hello world</p>', $actualResult);
72  }
73 
77  public function ‪renderReturnsStringForGivenId()
78  {
79  $this->viewHelper = new ‪TranslateViewHelperFixtureForEmptyString();
80  $this->injectDependenciesIntoViewHelper($this->viewHelper);
81 
82  $this->viewHelper->setRenderChildrenClosure(
83  function () {
84  return '<p>hello world</p>';
85  }
86  );
87  $this->setArgumentsUnderTest(
88  $this->viewHelper,
89  [
90  'key' => null,
91  'id' => 'bar'
92  ]
93  );
94  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
95  self::assertEquals('<p>hello world</p>', $actualResult);
96  }
97 
102  {
103  $this->viewHelper = new ‪TranslateViewHelperFixtureForEmptyString();
104  $this->injectDependenciesIntoViewHelper($this->viewHelper);
105 
106  $this->viewHelper->setRenderChildrenClosure(
107  function () {
108  return 'default';
109  }
110  );
111  $this->setArgumentsUnderTest(
112  $this->viewHelper,
113  [
114  'key' => null,
115  'id' => 'bar',
116  'default' => 'default'
117  ]
118  );
119  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
120  self::assertEquals('default', $actualResult);
121  }
122 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fixtures\TranslateViewHelperFixtureForEmptyString
Definition: TranslateViewHelperFixtureForEmptyString.php:24
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\TranslateViewHelperTest\$viewHelper
‪TranslateViewHelper $viewHelper
Definition: TranslateViewHelperTest.php:30
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\TranslateViewHelperTest\renderReturnsStringForGivenKey
‪renderReturnsStringForGivenKey()
Definition: TranslateViewHelperTest.php:53
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\TranslateViewHelperTest\renderThrowsExceptionIfNoKeyOrIdParameterIsGiven
‪renderThrowsExceptionIfNoKeyOrIdParameterIsGiven()
Definition: TranslateViewHelperTest.php:35
‪TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper
Definition: TranslateViewHelper.php:99
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\TranslateViewHelperTest
Definition: TranslateViewHelperTest.php:27
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\TranslateViewHelperTest\renderReturnsDefaultIfNoTranslationIsFound
‪renderReturnsDefaultIfNoTranslationIsFound()
Definition: TranslateViewHelperTest.php:100
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\TranslateViewHelperTest\renderReturnsStringForGivenId
‪renderReturnsStringForGivenId()
Definition: TranslateViewHelperTest.php:76