‪TYPO3CMS  9.5
ClassNamingUtilityTest.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 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪ClassNamingUtilityTest extends UnitTestCase
25 {
26 
34  public function ‪repositoryAndModelClassNames(): array
35  {
36  return [
37  [
38  'VENDOR\\EXT\\Domain\\Repository\\BlogRepository',
39  'VENDOR\\EXT\\Domain\\Model\\Blog',
40  'VENDOR\\EXT\\Domain\\Validator\\BlogValidator'
41  ],
42  [
43  'VENDOR\\EXT\\Domain\\Repository\\_PageRepository',
44  'VENDOR\\EXT\\Domain\\Model\\_Page',
45  'VENDOR\\EXT\\Domain\\Validator\\_PageValidator'
46  ],
47  [
48  'VENDOR\\Repository\\Domain\\Repository\\SomeModelRepository',
49  'VENDOR\\Repository\\Domain\\Model\\SomeModel',
50  'VENDOR\\Repository\\Domain\\Validator\\SomeModelValidator'
51  ],
52  [
53  'VENDOR\\EXT\\Domain\\Repository\\RepositoryRepository',
54  'VENDOR\\EXT\\Domain\\Model\\Repository',
55  'VENDOR\\EXT\\Domain\\Validator\\RepositoryValidator'
56  ],
57  [
58  'VENDOR\\Repository\\Domain\\Repository\\RepositoryRepository',
59  'VENDOR\\Repository\\Domain\\Model\\Repository',
60  'VENDOR\\Repository\\Domain\\Validator\\RepositoryValidator'
61  ],
62  [
63  'VENDOR\\ModelCollection\\Domain\\Repository\\ModelRepository',
64  'VENDOR\\ModelCollection\\Domain\\Model\\Model',
65  'VENDOR\\ModelCollection\\Domain\\Validator\\ModelValidator'
66  ],
67  [
68  'VENDOR\\Model\\Domain\\Repository\\ModelRepository',
69  'VENDOR\\Model\\Domain\\Model\\Model',
70  'VENDOR\\Model\\Domain\\Validator\\ModelValidator'
71  ],
72  ];
73  }
74 
82  public function ‪translateModelNameToRepositoryName($expectedRepositoryName, $modelName, $dummyValidatorName)
83  {
84  $translatedRepositoryName = ‪ClassNamingUtility::translateModelNameToRepositoryName($modelName);
85  $this->assertSame($expectedRepositoryName, $translatedRepositoryName);
86  }
87 
95  public function ‪translateRepositoryNameToModelName($repositoryName, $expectedModelName, $dummyValidatorName)
96  {
97  $translatedModelName = ‪ClassNamingUtility::translateRepositoryNameToModelName($repositoryName);
98  $this->assertSame($expectedModelName, $translatedModelName);
99  }
100 
108  public function ‪translateModelNameToValidatorName($repositoryName, $modelName, $expectedValidatorName)
109  {
110  $translatedModelName = ‪ClassNamingUtility::translateModelNameToValidatorName($modelName);
111  $this->assertSame($expectedValidatorName, $translatedModelName);
112  }
113 
119  public function ‪controllerObjectNamesAndMatches(): array
120  {
121  return [
122  [
123  'TYPO3\\CMS\\Ext\\Controller\\FooController',
124  [
125  'vendorName' => 'TYPO3\\CMS',
126  'extensionName' => 'Ext',
127  'subpackageKey' => '',
128  'controllerName' => 'Foo',
129  ]
130  ],
131  [
132  'TYPO3\\CMS\\Ext\\Command\\FooCommandController',
133  [
134  'vendorName' => 'TYPO3\\CMS',
135  'extensionName' => 'Ext',
136  'subpackageKey' => '',
137  'controllerName' => 'FooCommand',
138  ]
139  ],
140  [
141  PaginateController::class,
142  [
143  'vendorName' => 'TYPO3\\CMS',
144  'extensionName' => 'Fluid',
145  'subpackageKey' => 'ViewHelpers\\Widget',
146  'controllerName' => 'Paginate',
147  ]
148  ],
149  [
150  'VENDOR\\Ext\\Controller\\FooController',
151  [
152  'vendorName' => 'VENDOR',
153  'extensionName' => 'Ext',
154  'subpackageKey' => '',
155  'controllerName' => 'Foo',
156  ]
157  ],
158  [
159  'VENDOR\\Ext\\Command\\FooCommandController',
160  [
161  'vendorName' => 'VENDOR',
162  'extensionName' => 'Ext',
163  'subpackageKey' => '',
164  'controllerName' => 'FooCommand',
165  ]
166  ],
167  [
168  'VENDOR\\Ext\\ViewHelpers\\Widget\\Controller\\FooController',
169  [
170  'vendorName' => 'VENDOR',
171  'extensionName' => 'Ext',
172  'subpackageKey' => 'ViewHelpers\\Widget',
173  'controllerName' => 'Foo',
174  ]
175  ],
176  ];
177  }
178 
186  public function ‪explodeObjectControllerName($controllerObjectName, $expectedMatches)
187  {
188  $actualMatches = ‪ClassNamingUtility::explodeObjectControllerName($controllerObjectName);
189  $this->assertSame($expectedMatches, $actualMatches);
190  }
191 }
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest
Definition: ClassNamingUtilityTest.php:25
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest\controllerObjectNamesAndMatches
‪array controllerObjectNamesAndMatches()
Definition: ClassNamingUtilityTest.php:119
‪TYPO3\CMS\Core\Tests\Unit\Utility
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest\explodeObjectControllerName
‪explodeObjectControllerName($controllerObjectName, $expectedMatches)
Definition: ClassNamingUtilityTest.php:186
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest\translateModelNameToRepositoryName
‪translateModelNameToRepositoryName($expectedRepositoryName, $modelName, $dummyValidatorName)
Definition: ClassNamingUtilityTest.php:82
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\translateModelNameToRepositoryName
‪static string translateModelNameToRepositoryName($modelName)
Definition: ClassNamingUtility.php:32
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\explodeObjectControllerName
‪static array explodeObjectControllerName($controllerObjectName)
Definition: ClassNamingUtility.php:82
‪TYPO3\CMS\Core\Utility\ClassNamingUtility
Definition: ClassNamingUtility.php:23
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\translateRepositoryNameToModelName
‪static string translateRepositoryNameToModelName($repositoryName)
Definition: ClassNamingUtility.php:66
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller\PaginateController
Definition: PaginateController.php:25
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest\translateModelNameToValidatorName
‪translateModelNameToValidatorName($repositoryName, $modelName, $expectedValidatorName)
Definition: ClassNamingUtilityTest.php:108
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest\translateRepositoryNameToModelName
‪translateRepositoryNameToModelName($repositoryName, $expectedModelName, $dummyValidatorName)
Definition: ClassNamingUtilityTest.php:95
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest\repositoryAndModelClassNames
‪array repositoryAndModelClassNames()
Definition: ClassNamingUtilityTest.php:34
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\translateModelNameToValidatorName
‪static string translateModelNameToValidatorName($modelName)
Definition: ClassNamingUtility.php:49