[CLEANUP] Category related tests cleanup 88/29488/2
authorHelmut Hummel <helmut.hummel@typo3.org>
Tue, 15 Apr 2014 13:31:42 +0000 (15:31 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Tue, 15 Apr 2014 13:33:15 +0000 (15:33 +0200)
The category registry test and makeCategorizable
test of extension management utility are cleaned up
to use proper naming and actually test what
is in their scope.

Resolves: #57949
Releases: 6.2
Change-Id: I5dae812435d71b5188b4dc8ecf9dd2ce9d400658
Reviewed-on: https://review.typo3.org/29488
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/core/Tests/Unit/Category/CategoryRegistryTest.php
typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php

index 51dff1e..ab0f178 100644 (file)
@@ -35,7 +35,7 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @var \TYPO3\CMS\Core\Category\CategoryRegistry
         */
-       protected $fixture;
+       protected $subject;
 
        /**
         * @var array
@@ -46,7 +46,7 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * Sets up this test suite.
         */
        protected function setUp() {
-               $this->fixture = new \TYPO3\CMS\Core\Category\CategoryRegistry();
+               $this->subject = new \TYPO3\CMS\Core\Category\CategoryRegistry();
                $this->tables = array(
                        'first' => uniqid('first'),
                        'second' => uniqid('second')
@@ -66,7 +66,7 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function doesAddReturnTrueOnDefinedTable() {
-               $this->assertTrue($this->fixture->add('test_extension_a', $this->tables['first'], 'categories'));
+               $this->assertTrue($this->subject->add('test_extension_a', $this->tables['first'], 'categories'));
        }
 
        /**
@@ -75,16 +75,16 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @expectedExceptionCode 1369122038
         */
        public function doesAddThrowExceptionOnEmptyTablename() {
-               $this->fixture->add('test_extension_a', '', 'categories');
+               $this->subject->add('test_extension_a', '', 'categories');
        }
 
        /**
         * @test
         */
        public function areMultipleElementsOfSameExtensionRegistered() {
-               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->fixture->add('test_extension_a', $this->tables['second'], 'categories');
-               $this->fixture->applyTca();
+               $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->subject->add('test_extension_a', $this->tables['second'], 'categories');
+               $this->subject->applyTca();
 
                $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['first']]['columns']);
                $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['second']]['columns']);
@@ -94,9 +94,9 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function areElementsOfDifferentExtensionsRegistered() {
-               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
-               $this->fixture->applyTca();
+               $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
+               $this->subject->applyTca();
 
                $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['first']]['columns']);
                $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['second']]['columns']);
@@ -106,9 +106,9 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function areElementsOfDifferentExtensionsOnSameTableRegistered() {
-               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories1');
-               $this->fixture->add('test_extension_b', $this->tables['first'], 'categories2');
-               $this->fixture->applyTca();
+               $this->subject->add('test_extension_a', $this->tables['first'], 'categories1');
+               $this->subject->add('test_extension_b', $this->tables['first'], 'categories2');
+               $this->subject->applyTca();
 
                $this->assertArrayHasKey('categories1', $GLOBALS['TCA'][$this->tables['first']]['columns']);
                $this->assertArrayHasKey('categories2', $GLOBALS['TCA'][$this->tables['first']]['columns']);
@@ -118,9 +118,9 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function areElementsOfSameExtensionOnSameTableRegistered() {
-               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories1');
-               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories2');
-               $this->fixture->applyTca();
+               $this->subject->add('test_extension_a', $this->tables['first'], 'categories1');
+               $this->subject->add('test_extension_a', $this->tables['first'], 'categories2');
+               $this->subject->applyTca();
 
                $this->assertArrayHasKey('categories1', $GLOBALS['TCA'][$this->tables['first']]['columns']);
                $this->assertArrayHasKey('categories2', $GLOBALS['TCA'][$this->tables['first']]['columns']);
@@ -130,10 +130,10 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function areDatabaseDefinitionsOfAllElementsAvailable() {
-               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
-               $this->fixture->add('test_extension_c', $this->tables['first'], 'categories');
-               $definitions = $this->fixture->getDatabaseTableDefinitions();
+               $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
+               $this->subject->add('test_extension_c', $this->tables['first'], 'categories');
+               $definitions = $this->subject->getDatabaseTableDefinitions();
                $matches = array();
                preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
                $this->assertEquals(2, count($matches[0]));
@@ -147,9 +147,9 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function areDatabaseDefinitionsOfParticularExtensionAvailable() {
-               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
-               $definitions = $this->fixture->getDatabaseTableDefinition('test_extension_a');
+               $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
+               $definitions = $this->subject->getDatabaseTableDefinition('test_extension_a');
                $matches = array();
                preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
                $this->assertEquals(1, count($matches[0]));
@@ -162,7 +162,7 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         */
        public function areDefaultCategorizedTablesLoaded() {
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables'] = $this->tables['first'] . ',' . $this->tables['second'];
-               $this->fixture->applyTca();
+               $this->subject->applyTca();
 
                $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['first']]['columns']);
                $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['second']]['columns']);
@@ -172,9 +172,9 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function canApplyTca() {
-               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
-               $this->fixture->applyTca();
+               $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
+               $this->subject->applyTca();
 
                $this->assertNotEmpty($GLOBALS['TCA'][$this->tables['first']]['columns']['categories']);
                $this->assertNotEmpty($GLOBALS['TCA'][$this->tables['second']]['columns']['categories']);
@@ -184,25 +184,25 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function isRegisteredReturnsTrueIfElementIsAlreadyRegistered() {
-               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->assertTrue($this->fixture->isRegistered($this->tables['first'], 'categories'));
+               $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->assertTrue($this->subject->isRegistered($this->tables['first'], 'categories'));
        }
 
        /**
         * @test
         */
        public function isRegisteredReturnsFalseIfElementIsNotRegistered() {
-               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->assertFalse($this->fixture->isRegistered($this->tables['first'], '_not_registered'));
-               $this->assertFalse($this->fixture->isRegistered($this->tables['second'], 'categories'));
+               $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->assertFalse($this->subject->isRegistered($this->tables['first'], '_not_registered'));
+               $this->assertFalse($this->subject->isRegistered($this->tables['second'], 'categories'));
        }
 
        /**
         * @test
         */
        public function tabIsAddedForElement() {
-               $this->fixture->add('text_extension_a', $this->tables['first']);
-               $this->fixture->applyTca();
+               $this->subject->add('text_extension_a', $this->tables['first']);
+               $this->subject->applyTca();
 
                foreach($GLOBALS['TCA'][$this->tables['first']]['types'] as $typeConfig) {
                        $this->assertContains('--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category', $typeConfig['showitem']);
@@ -213,8 +213,8 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function tabIsNotAddedForElementIfFieldListIsSpecified() {
-               $this->fixture->add('text_extension_a', $this->tables['first'], 'categories', array('fieldList' => 'categories'));
-               $this->fixture->applyTca();
+               $this->subject->add('text_extension_a', $this->tables['first'], 'categories', array('fieldList' => 'categories'));
+               $this->subject->applyTca();
 
                foreach($GLOBALS['TCA'][$this->tables['first']]['types'] as $typeConfig) {
                        $this->assertNotContains('--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category', $typeConfig['showitem']);
@@ -225,9 +225,9 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function tabIsAddedOnlyOncePerTable() {
-               $this->fixture->add('text_extension_a', $this->tables['first'], 'categories1');
-               $this->fixture->add('text_extension_a', $this->tables['first'], 'categories2');
-               $this->fixture->applyTca();
+               $this->subject->add('text_extension_a', $this->tables['first'], 'categories1');
+               $this->subject->add('text_extension_a', $this->tables['first'], 'categories2');
+               $this->subject->applyTca();
 
                foreach($GLOBALS['TCA'][$this->tables['first']]['types'] as $typeConfig) {
                        $this->assertSame(
index 08b9d38..23fdd15 100644 (file)
@@ -1337,36 +1337,28 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
        /**
         * @test
         */
-       public function isMakeCategorizableAvailableInRegistryWithDefaultField() {
+       public function doesMakeCategorizableCallsTheCategoryRegistryWithDefaultFieldName() {
                $extensionKey = uniqid('extension');
                $tableName = uniqid('table');
-               $GLOBALS['TCA'][$tableName] = array(
-                       'ctrl' => array(),
-                       'columns' => array()
-               );
-               $registryMock = $this->getMock('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', array('dummy'));
+
+               $registryMock = $this->getMock('TYPO3\\CMS\\Core\\Category\\CategoryRegistry');
+               $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, 'categories', array());
                \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', $registryMock);
                ExtensionManagementUtility::makeCategorizable($extensionKey, $tableName);
-               $registryMock->applyTca();
-               $this->assertNotEmpty($GLOBALS['TCA'][$tableName]['columns']['categories']);
        }
 
        /**
         * @test
         */
-       public function isMakeCategorizableAvailableInRegistryWithSpecifictField() {
+       public function doesMakeCategorizableCallsTheCategoryRegistryWithFieldName() {
                $extensionKey = uniqid('extension');
                $tableName = uniqid('table');
                $fieldName = uniqid('field');
-               $GLOBALS['TCA'][$tableName] = array(
-                       'ctrl' => array(),
-                       'columns' => array()
-               );
-               $registryMock = $this->getMock('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', array('dummy'));
+
+               $registryMock = $this->getMock('TYPO3\\CMS\\Core\\Category\\CategoryRegistry');
+               $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, $fieldName, array());
                \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', $registryMock);
                ExtensionManagementUtility::makeCategorizable($extensionKey, $tableName, $fieldName);
-               $registryMock->applyTca();
-               $this->assertNotEmpty($GLOBALS['TCA'][$tableName]['columns'][$fieldName]);
        }
 
 }