TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
CaseViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format;
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  */
18 
23 {
27  protected $viewHelper;
28 
29  protected function setUp()
30  {
31  parent::setUp();
32  $this->viewHelper = new CaseViewHelper();
33  $this->injectDependenciesIntoViewHelper($this->viewHelper);
34  }
35 
40  {
41  $this->setArgumentsUnderTest(
42  $this->viewHelper,
43  [
44  'value' => ''
45  ]
46  );
47  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
48  $this->assertEquals('', $actualResult);
49  }
50 
55  {
56  $this->setArgumentsUnderTest(
57  $this->viewHelper,
58  [
59  'value' => 'Some string'
60  ]
61  );
62  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
63  $this->assertEquals('SOME STRING', $actualResult);
64  }
65 
70  {
71  $this->expectException(\TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException::class);
72  $this->expectExceptionCode(1358349150);
73  $this->setArgumentsUnderTest(
74  $this->viewHelper,
75  [
76  'value' => 'Foo',
77  'mode' => 'incorrectMode'
78  ]
79  );
80  $this->viewHelper->initializeArgumentsAndRender();
81  }
82 
87  {
88  $this->setArgumentsUnderTest(
89  $this->viewHelper,
90  [
91  'value' => 'FooB4r'
92  ]
93  );
94  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
95  $this->assertSame('FOOB4R', $actualResult);
96  }
97 
102  {
103  return [
104  ['FooB4r', CaseViewHelper::CASE_LOWER, 'foob4r'],
105  ['FooB4r', CaseViewHelper::CASE_UPPER, 'FOOB4R'],
106  ['foo bar', CaseViewHelper::CASE_CAPITAL, 'Foo bar'],
107  ['FOO Bar', CaseViewHelper::CASE_UNCAPITAL, 'fOO Bar'],
108  ['smørrebrød', CaseViewHelper::CASE_UPPER, 'SMØRREBRØD'],
109  ['smørrebrød', CaseViewHelper::CASE_CAPITAL, 'Smørrebrød'],
110  ['römtömtömtöm', CaseViewHelper::CASE_UPPER, 'RÖMTÖMTÖMTÖM'],
111  ['Ἕλλάς α ω', CaseViewHelper::CASE_UPPER, 'ἝΛΛΆΣ Α Ω'],
112  ];
113  }
114 
119  public function viewHelperConvertsCorrectly($input, $mode, $expected)
120  {
121  $this->setArgumentsUnderTest(
122  $this->viewHelper,
123  [
124  'value' => $input,
125  'mode' => $mode
126  ]
127  );
128  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
129  $this->assertSame($expected, $actualResult, sprintf('The conversion with mode "%s" did not perform as expected.', $mode));
130  }
131 }
setArgumentsUnderTest(ViewHelperInterface $viewHelper, array $arguments=[])