TYPO3 CMS  TYPO3_8-7
TranslateViewHelperTest.php
Go to the documentation of this file.
1 <?php
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 
20 
24 class TranslateViewHelperTest extends ViewHelperBaseTestcase
25 {
29  protected $viewHelper;
30 
35  {
36  $this->viewHelper = new TranslateViewHelper();
37  $this->injectDependenciesIntoViewHelper($this->viewHelper);
38 
39  $this->expectException(\TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException::class);
40  $this->expectExceptionCode(1351584844);
41 
42  $this->setArgumentsUnderTest(
43  $this->viewHelper,
44  []
45  );
46  $this->viewHelper->initializeArgumentsAndRender();
47  }
48 
53  {
54  $this->viewHelper = new TranslateViewHelperFixtureForEmptyString();
55  $this->injectDependenciesIntoViewHelper($this->viewHelper);
56 
57  $this->viewHelper->setRenderChildrenClosure(
58  function () {
59  return '<p>hello world</p>';
60  }
61  );
62  $this->setArgumentsUnderTest(
63  $this->viewHelper,
64  [
65  'key' => 'foo'
66  ]
67  );
68  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
69  $this->assertEquals('<p>hello world</p>', $actualResult);
70  }
71 
76  {
77  $this->viewHelper = new TranslateViewHelperFixtureForEmptyString();
78  $this->injectDependenciesIntoViewHelper($this->viewHelper);
79 
80  $this->viewHelper->setRenderChildrenClosure(
81  function () {
82  return '<p>hello world</p>';
83  }
84  );
85  $this->setArgumentsUnderTest(
86  $this->viewHelper,
87  [
88  'key' => null,
89  'id' => 'bar'
90  ]
91  );
92  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
93  $this->assertEquals('<p>hello world</p>', $actualResult);
94  }
95 
100  {
101  $this->viewHelper = new TranslateViewHelperFixtureForEmptyString();
102  $this->injectDependenciesIntoViewHelper($this->viewHelper);
103 
104  $this->viewHelper->setRenderChildrenClosure(
105  function () {
106  return 'default';
107  }
108  );
109  $this->setArgumentsUnderTest(
110  $this->viewHelper,
111  [
112  'key' => null,
113  'id' => 'bar',
114  'default' => 'default'
115  ]
116  );
117  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
118  $this->assertEquals('default', $actualResult);
119  }
120 }