‪TYPO3CMS  10.4
ClassNamingUtilityTest.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 
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
25 class ‪ClassNamingUtilityTest extends UnitTestCase
26 {
27 
34  public function ‪repositoryAndModelClassNames(): array
35  {
36  return [
37  [
38  'VENDOR\\EXT\\Domain\\Repository\\BlogRepository',
39  'VENDOR\\EXT\\Domain\\Model\\Blog',
40  ],
41  [
42  'VENDOR\\EXT\\Domain\\Repository\\_PageRepository',
43  'VENDOR\\EXT\\Domain\\Model\\_Page',
44  ],
45  [
46  'VENDOR\\Repository\\Domain\\Repository\\SomeModelRepository',
47  'VENDOR\\Repository\\Domain\\Model\\SomeModel',
48  ],
49  [
50  'VENDOR\\EXT\\Domain\\Repository\\RepositoryRepository',
51  'VENDOR\\EXT\\Domain\\Model\\Repository',
52  ],
53  [
54  'VENDOR\\Repository\\Domain\\Repository\\RepositoryRepository',
55  'VENDOR\\Repository\\Domain\\Model\\Repository',
56  ],
57  [
58  'VENDOR\\ModelCollection\\Domain\\Repository\\ModelRepository',
59  'VENDOR\\ModelCollection\\Domain\\Model\\Model',
60  ],
61  [
62  'VENDOR\\Model\\Domain\\Repository\\ModelRepository',
63  'VENDOR\\Model\\Domain\\Model\\Model',
64  ],
65  ];
66  }
67 
74  public function ‪translateModelNameToRepositoryName($expectedRepositoryName, $modelName)
75  {
76  $translatedRepositoryName = ‪ClassNamingUtility::translateModelNameToRepositoryName($modelName);
77  self::assertSame($expectedRepositoryName, $translatedRepositoryName);
78  }
79 
86  public function ‪translateRepositoryNameToModelName($repositoryName, $expectedModelName)
87  {
88  $translatedModelName = ‪ClassNamingUtility::translateRepositoryNameToModelName($repositoryName);
89  self::assertSame($expectedModelName, $translatedModelName);
90  }
91 
97  public function ‪controllerObjectNamesAndMatches(): array
98  {
99  return [
100  [
101  'TYPO3\\CMS\\Ext\\Controller\\FooController',
102  [
103  'vendorName' => 'TYPO3\\CMS',
104  'extensionName' => 'Ext',
105  'subpackageKey' => '',
106  'controllerName' => 'Foo',
107  ]
108  ],
109  [
110  'TYPO3\\CMS\\Ext\\Command\\FooCommandController',
111  [
112  'vendorName' => 'TYPO3\\CMS',
113  'extensionName' => 'Ext',
114  'subpackageKey' => '',
115  'controllerName' => 'FooCommand',
116  ]
117  ],
118  [
119  PaginateController::class,
120  [
121  'vendorName' => 'TYPO3\\CMS',
122  'extensionName' => 'Fluid',
123  'subpackageKey' => 'ViewHelpers\\Widget',
124  'controllerName' => 'Paginate',
125  ]
126  ],
127  [
128  'VENDOR\\Ext\\Controller\\FooController',
129  [
130  'vendorName' => 'VENDOR',
131  'extensionName' => 'Ext',
132  'subpackageKey' => '',
133  'controllerName' => 'Foo',
134  ]
135  ],
136  [
137  'VENDOR\\Ext\\Command\\FooCommandController',
138  [
139  'vendorName' => 'VENDOR',
140  'extensionName' => 'Ext',
141  'subpackageKey' => '',
142  'controllerName' => 'FooCommand',
143  ]
144  ],
145  [
146  'VENDOR\\Ext\\ViewHelpers\\Widget\\Controller\\FooController',
147  [
148  'vendorName' => 'VENDOR',
149  'extensionName' => 'Ext',
150  'subpackageKey' => 'ViewHelpers\\Widget',
151  'controllerName' => 'Foo',
152  ]
153  ],
154  ];
155  }
156 
164  public function ‪explodeObjectControllerName($controllerObjectName, $expectedMatches)
165  {
166  $actualMatches = ‪ClassNamingUtility::explodeObjectControllerName($controllerObjectName);
167  self::assertSame($expectedMatches, $actualMatches);
168  }
169 }
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest
Definition: ClassNamingUtilityTest.php:26
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest\controllerObjectNamesAndMatches
‪array controllerObjectNamesAndMatches()
Definition: ClassNamingUtilityTest.php:97
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest\translateModelNameToRepositoryName
‪translateModelNameToRepositoryName($expectedRepositoryName, $modelName)
Definition: ClassNamingUtilityTest.php:74
‪TYPO3\CMS\Core\Tests\Unit\Utility
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest\explodeObjectControllerName
‪explodeObjectControllerName($controllerObjectName, $expectedMatches)
Definition: ClassNamingUtilityTest.php:164
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\translateModelNameToRepositoryName
‪static string translateModelNameToRepositoryName($modelName)
Definition: ClassNamingUtility.php:33
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\explodeObjectControllerName
‪static array explodeObjectControllerName($controllerObjectName)
Definition: ClassNamingUtility.php:66
‪TYPO3\CMS\Core\Utility\ClassNamingUtility
Definition: ClassNamingUtility.php:24
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\translateRepositoryNameToModelName
‪static string translateRepositoryNameToModelName($repositoryName)
Definition: ClassNamingUtility.php:50
‪TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller\PaginateController
Definition: PaginateController.php:27
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest\translateRepositoryNameToModelName
‪translateRepositoryNameToModelName($repositoryName, $expectedModelName)
Definition: ClassNamingUtilityTest.php:86
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest\repositoryAndModelClassNames
‪array repositoryAndModelClassNames()
Definition: ClassNamingUtilityTest.php:34