‪TYPO3CMS  11.5
ClassNamingUtilityTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪ClassNamingUtilityTest extends UnitTestCase
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(string $expectedRepositoryName, string $modelName): void
75  {
76  $translatedRepositoryName = ‪ClassNamingUtility::translateModelNameToRepositoryName($modelName);
77  self::assertSame($expectedRepositoryName, $translatedRepositoryName);
78  }
79 
86  public function ‪translateRepositoryNameToModelName(string $repositoryName, string $expectedModelName): void
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  'VENDOR\\Ext\\Controller\\FooController',
120  [
121  'vendorName' => 'VENDOR',
122  'extensionName' => 'Ext',
123  'subpackageKey' => '',
124  'controllerName' => 'Foo',
125  ],
126  ],
127  [
128  'VENDOR\\Ext\\Command\\FooCommandController',
129  [
130  'vendorName' => 'VENDOR',
131  'extensionName' => 'Ext',
132  'subpackageKey' => '',
133  'controllerName' => 'FooCommand',
134  ],
135  ],
136  [
137  'VENDOR\\Ext\\ViewHelpers\\Widget\\Controller\\FooController',
138  [
139  'vendorName' => 'VENDOR',
140  'extensionName' => 'Ext',
141  'subpackageKey' => 'ViewHelpers\\Widget',
142  'controllerName' => 'Foo',
143  ],
144  ],
145  ];
146  }
147 
155  public function ‪explodeObjectControllerName(string $controllerObjectName, array $expectedMatches): void
156  {
157  $actualMatches = ‪ClassNamingUtility::explodeObjectControllerName($controllerObjectName);
158  self::assertSame($expectedMatches, $actualMatches);
159  }
160 }
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest
Definition: ClassNamingUtilityTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest\controllerObjectNamesAndMatches
‪array controllerObjectNamesAndMatches()
Definition: ClassNamingUtilityTest.php:97
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\translateRepositoryNameToModelName
‪static class string translateRepositoryNameToModelName($repositoryName)
Definition: ClassNamingUtility.php:53
‪TYPO3\CMS\Core\Tests\Unit\Utility
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\translateModelNameToRepositoryName
‪static string translateModelNameToRepositoryName($modelName)
Definition: ClassNamingUtility.php:35
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest\translateRepositoryNameToModelName
‪translateRepositoryNameToModelName(string $repositoryName, string $expectedModelName)
Definition: ClassNamingUtilityTest.php:86
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest\translateModelNameToRepositoryName
‪translateModelNameToRepositoryName(string $expectedRepositoryName, string $modelName)
Definition: ClassNamingUtilityTest.php:74
‪TYPO3\CMS\Core\Utility\ClassNamingUtility\explodeObjectControllerName
‪static array explodeObjectControllerName($controllerObjectName)
Definition: ClassNamingUtility.php:69
‪TYPO3\CMS\Core\Utility\ClassNamingUtility
Definition: ClassNamingUtility.php:26
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest\explodeObjectControllerName
‪explodeObjectControllerName(string $controllerObjectName, array $expectedMatches)
Definition: ClassNamingUtilityTest.php:155
‪TYPO3\CMS\Core\Tests\Unit\Utility\ClassNamingUtilityTest\repositoryAndModelClassNames
‪array repositoryAndModelClassNames()
Definition: ClassNamingUtilityTest.php:34