‪TYPO3CMS  10.4
CaseViewHelperTest.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 
19 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
21 
25 class ‪CaseViewHelperTest extends ViewHelperBaseTestcase
26 {
30  protected ‪$viewHelper;
31 
32  protected function ‪setUp(): void
33  {
34  parent::setUp();
35  $this->viewHelper = new ‪CaseViewHelper();
36  $this->injectDependenciesIntoViewHelper($this->viewHelper);
37  }
38 
43  {
44  $this->setArgumentsUnderTest(
45  $this->viewHelper,
46  [
47  'value' => ''
48  ]
49  );
50  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
51  self::assertEquals('', $actualResult);
52  }
53 
58  {
59  $this->setArgumentsUnderTest(
60  $this->viewHelper,
61  [
62  'value' => 'Some string'
63  ]
64  );
65  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
66  self::assertEquals('SOME STRING', $actualResult);
67  }
68 
73  {
74  $this->expectException(Exception::class);
75  $this->expectExceptionCode(1358349150);
76  $this->setArgumentsUnderTest(
77  $this->viewHelper,
78  [
79  'value' => 'Foo',
80  'mode' => 'incorrectMode'
81  ]
82  );
83  $this->viewHelper->initializeArgumentsAndRender();
84  }
85 
90  {
91  $this->setArgumentsUnderTest(
92  $this->viewHelper,
93  [
94  'value' => 'FooB4r'
95  ]
96  );
97  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
98  self::assertSame('FOOB4R', $actualResult);
99  }
100 
104  public function ‪conversionTestingDataProvider()
105  {
106  return [
107  ['FooB4r', ‪CaseViewHelper::CASE_LOWER, 'foob4r'],
108  ['FooB4r', ‪CaseViewHelper::CASE_UPPER, 'FOOB4R'],
109  ['foo bar', ‪CaseViewHelper::CASE_CAPITAL, 'Foo bar'],
110  ['FOO Bar', ‪CaseViewHelper::CASE_UNCAPITAL, 'fOO Bar'],
111  ['smørrebrød', ‪CaseViewHelper::CASE_UPPER, 'SMØRREBRØD'],
112  ['smørrebrød', ‪CaseViewHelper::CASE_CAPITAL, 'Smørrebrød'],
113  ['römtömtömtöm', ‪CaseViewHelper::CASE_UPPER, 'RÖMTÖMTÖMTÖM'],
114  ['Ἕλλάς α ω', ‪CaseViewHelper::CASE_UPPER, 'ἝΛΛΆΣ Α Ω'],
115  ];
116  }
117 
122  public function ‪viewHelperConvertsCorrectly($input, $mode, $expected)
123  {
124  $this->setArgumentsUnderTest(
125  $this->viewHelper,
126  [
127  'value' => $input,
128  'mode' => $mode
129  ]
130  );
131  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
132  self::assertSame($expected, $actualResult, sprintf('The conversion with mode "%s" did not perform as expected.', $mode));
133  }
134 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CaseViewHelperTest\conversionTestingDataProvider
‪conversionTestingDataProvider()
Definition: CaseViewHelperTest.php:103
‪TYPO3\CMS\Fluid\ViewHelpers\Format\CaseViewHelper\CASE_LOWER
‪const CASE_LOWER
Definition: CaseViewHelper.php:80
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CaseViewHelperTest
Definition: CaseViewHelperTest.php:26
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CaseViewHelperTest\viewHelperConvertsCorrectly
‪viewHelperConvertsCorrectly($input, $mode, $expected)
Definition: CaseViewHelperTest.php:121
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CaseViewHelperTest\viewHelperThrowsExceptionIfIncorrectModeIsGiven
‪viewHelperThrowsExceptionIfIncorrectModeIsGiven()
Definition: CaseViewHelperTest.php:71
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format
Definition: ScriptViewHelperTest.php:18
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CaseViewHelperTest\viewHelperDoesNotRenderChildrenIfGivenValueIsNotNull
‪viewHelperDoesNotRenderChildrenIfGivenValueIsNotNull()
Definition: CaseViewHelperTest.php:56
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CaseViewHelperTest\viewHelperRendersChildrenIfGivenValueIsNull
‪viewHelperRendersChildrenIfGivenValueIsNull()
Definition: CaseViewHelperTest.php:41
‪TYPO3\CMS\Fluid\ViewHelpers\Format\CaseViewHelper\CASE_UPPER
‪const CASE_UPPER
Definition: CaseViewHelper.php:85
‪TYPO3\CMS\Fluid\ViewHelpers\Format\CaseViewHelper\CASE_UNCAPITAL
‪const CASE_UNCAPITAL
Definition: CaseViewHelper.php:95
‪TYPO3\CMS\Fluid\ViewHelpers\Format\CaseViewHelper
Definition: CaseViewHelper.php:75
‪TYPO3\CMS\Fluid\ViewHelpers\Format\CaseViewHelper\CASE_CAPITAL
‪const CASE_CAPITAL
Definition: CaseViewHelper.php:90
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CaseViewHelperTest\viewHelperConvertsUppercasePerDefault
‪viewHelperConvertsUppercasePerDefault()
Definition: CaseViewHelperTest.php:88
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CaseViewHelperTest\setUp
‪setUp()
Definition: CaseViewHelperTest.php:31
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\CaseViewHelperTest\$viewHelper
‪CaseViewHelper $viewHelper
Definition: CaseViewHelperTest.php:29