[TASK] Cleanup for ClassNamingUtility 89/18189/2
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Sun, 10 Feb 2013 14:17:46 +0000 (15:17 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 12 Apr 2013 12:03:08 +0000 (14:03 +0200)
Small cleanups for the new feature
which just got merged.

Releases: 6.1
Fixes: #43052
Change-Id: I9c7df202f7e63c148f35fefe30e134b0a299b124
Reviewed-on: https://review.typo3.org/18189
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/core/Classes/Utility/ClassNamingUtility.php
typo3/sysext/core/Tests/Unit/Utility/ClassNamingUtilityTest.php

index 8743a4d..c0dac66 100644 (file)
@@ -45,8 +45,8 @@ class ClassNamingUtility {
         */
        static public function translateModelNameToRepositoryName($modelName) {
                return str_replace(
-                       array('\\Domain\\Model', 'Domain_Model'),
-                       array('\\Domain\\Repository', 'Domain_Repository'),
+                       array('\\Domain\\Model', '_Domain_Model_'),
+                       array('\\Domain\\Repository', '_Domain_Repository_'),
                        $modelName
                ) . 'Repository';
        }
@@ -57,7 +57,6 @@ class ClassNamingUtility {
         * or \TYPO3\CMS\Extbase\Domain\Model\Foo to \TYPO3\CMS\Extbase\Domain\Validator\FooValidator
         *
         * @param string $modelName Name of the model to translate
-        *
         * @return string Name of the repository
         */
        static public function translateModelNameToValidatorName($modelName) {
@@ -78,8 +77,8 @@ class ClassNamingUtility {
         */
        static public function translateRepositoryNameToModelName($repositoryName) {
                return preg_replace(
-                       array('/\\\Domain\\\Repository/', '/Domain_Repository/', '/Repository$/'),
-                       array('\\Domain\\Model', 'Domain_Model', ''),
+                       array('/\\\\Domain\\\\Repository/', '/_Domain_Repository_/', '/Repository$/'),
+                       array('\\Domain\\Model', '_Domain_Model_', ''),
                        $repositoryName
                );
        }
@@ -97,14 +96,14 @@ class ClassNamingUtility {
                $matches = array();
 
                if (strpos($controllerObjectName, '\\') !== FALSE) {
-                       if (substr($controllerObjectName, 0, 9) === 'TYPO3\CMS') {
-                               $extensionName = '^(?P<vendorName>[^\\\]+\\\[^\\\]+)\\\(?P<extensionName>[^\\\]+)';
+                       if (substr($controllerObjectName, 0, 9) === 'TYPO3\\CMS') {
+                               $extensionName = '^(?P<vendorName>[^\\\\]+\\\[^\\\\]+)\\\(?P<extensionName>[^\\\\]+)';
                        } else {
-                               $extensionName = '^(?P<vendorName>[^\\\]+)\\\(?P<extensionName>[^\\\]+)';
+                               $extensionName = '^(?P<vendorName>[^\\\\]+)\\\\(?P<extensionName>[^\\\\]+)';
                        }
 
                        preg_match(
-                               '/' . $extensionName . '\\\(Controller|Command|(?P<subpackageKey>.+)\\\Controller)\\\(?P<controllerName>[a-z\\\]+)Controller$/ix',
+                               '/' . $extensionName . '\\\\(Controller|Command|(?P<subpackageKey>.+)\\\\Controller)\\\\(?P<controllerName>[a-z\\\\]+)Controller$/ix',
                                $controllerObjectName,
                                $matches
                        );
@@ -120,4 +119,4 @@ class ClassNamingUtility {
        }
 }
 
-?>
\ No newline at end of file
+?>
index 971be89..de3ac5a 100644 (file)
@@ -24,13 +24,14 @@ namespace TYPO3\CMS\Core\Tests\Unit\Utility;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 /**
- * Testcase for class \TYPO3\CMS\Extbase\Utility\NamingUtilityTest
+ * Testcase for class \TYPO3\CMS\Core\Utility\ClassNamingUtility
  */
 class ClassNamingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
         * DataProvider for translateModelNameToRepositoryName
         * and translateRepositoryNameToModelName
+        * and translateModelNameToValidatorName
         *
         * @return array
         */
@@ -113,9 +114,10 @@ class ClassNamingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @dataProvider repositoryAndModelClassNames
         * @param string $expectedRepositoryName
         * @param string $modelName
+        * @param string $dummyValidatorName not needed here - just a dummy to be able to cleanly use the same dataprovider
         * @test
         */
-       public function translateModelNameToRepositoryName($expectedRepositoryName, $modelName) {
+       public function translateModelNameToRepositoryName($expectedRepositoryName, $modelName, $dummyValidatorName) {
                $translatedRepositoryName = \TYPO3\CMS\Core\Utility\ClassNamingUtility::translateModelNameToRepositoryName($modelName);
                $this->assertSame($expectedRepositoryName, $translatedRepositoryName);
        }
@@ -124,9 +126,10 @@ class ClassNamingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @dataProvider repositoryAndModelClassNames
         * @param string $repositoryName
         * @param string $expectedModelName
+        * @param string $dummyValidatorName not needed here - just a dummy to be able to use the same dataprovider
         * @test
         */
-       public function translateRepositoryNameToModelName($repositoryName, $expectedModelName) {
+       public function translateRepositoryNameToModelName($repositoryName, $expectedModelName, $dummyValidatorName) {
                $translatedModelName = \TYPO3\CMS\Core\Utility\ClassNamingUtility::translateRepositoryNameToModelName($repositoryName);
                $this->assertSame($expectedModelName, $translatedModelName);
        }
@@ -256,4 +259,4 @@ class ClassNamingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        }
 }
 
-?>
\ No newline at end of file
+?>