TYPO3 CMS  TYPO3_8-7
CaseViewHelperTest.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 
19 
23 class CaseViewHelperTest extends ViewHelperBaseTestcase
24 {
28  protected $viewHelper;
29 
30  protected function setUp()
31  {
32  parent::setUp();
33  $this->viewHelper = new CaseViewHelper();
34  $this->injectDependenciesIntoViewHelper($this->viewHelper);
35  }
36 
41  {
42  $this->setArgumentsUnderTest(
43  $this->viewHelper,
44  [
45  'value' => ''
46  ]
47  );
48  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
49  $this->assertEquals('', $actualResult);
50  }
51 
56  {
57  $this->setArgumentsUnderTest(
58  $this->viewHelper,
59  [
60  'value' => 'Some string'
61  ]
62  );
63  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
64  $this->assertEquals('SOME STRING', $actualResult);
65  }
66 
71  {
72  $this->expectException(\TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException::class);
73  $this->expectExceptionCode(1358349150);
74  $this->setArgumentsUnderTest(
75  $this->viewHelper,
76  [
77  'value' => 'Foo',
78  'mode' => 'incorrectMode'
79  ]
80  );
81  $this->viewHelper->initializeArgumentsAndRender();
82  }
83 
88  {
89  $this->setArgumentsUnderTest(
90  $this->viewHelper,
91  [
92  'value' => 'FooB4r'
93  ]
94  );
95  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
96  $this->assertSame('FOOB4R', $actualResult);
97  }
98 
103  {
104  return [
105  ['FooB4r', CaseViewHelper::CASE_LOWER, 'foob4r'],
106  ['FooB4r', CaseViewHelper::CASE_UPPER, 'FOOB4R'],
107  ['foo bar', CaseViewHelper::CASE_CAPITAL, 'Foo bar'],
108  ['FOO Bar', CaseViewHelper::CASE_UNCAPITAL, 'fOO Bar'],
109  ['smørrebrød', CaseViewHelper::CASE_UPPER, 'SMØRREBRØD'],
110  ['smørrebrød', CaseViewHelper::CASE_CAPITAL, 'Smørrebrød'],
111  ['römtömtömtöm', CaseViewHelper::CASE_UPPER, 'RÖMTÖMTÖMTÖM'],
112  ['Ἕλλάς α ω', CaseViewHelper::CASE_UPPER, 'ἝΛΛΆΣ Α Ω'],
113  ];
114  }
115 
120  public function viewHelperConvertsCorrectly($input, $mode, $expected)
121  {
122  $this->setArgumentsUnderTest(
123  $this->viewHelper,
124  [
125  'value' => $input,
126  'mode' => $mode
127  ]
128  );
129  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
130  $this->assertSame($expected, $actualResult, sprintf('The conversion with mode "%s" did not perform as expected.', $mode));
131  }
132 }