[BUGFIX] Dont respect pid for static & rootlevel tables
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Sat, 17 Mar 2012 12:40:57 +0000 (13:40 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Wed, 7 Nov 2012 14:54:34 +0000 (15:54 +0100)
If TCA defines a table to be static or on root level
setRespectStoragePage should be set to false as pid
is either 0 or even not set at all.

Releases: 6.0
Fixes: #42519
Change-Id: Ia18f9258da68f228a13cf8d1ed7656e939ba52b8
Reviewed-on: http://review.typo3.org/16049
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMap.php
typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php
typo3/sysext/extbase/Classes/Persistence/Generic/QueryFactory.php
typo3/sysext/extbase/Tests/Unit/Persistence/QueryFactoryTest.php [new file with mode: 0644]

index 8ea8e4e..cf84995 100644 (file)
@@ -124,6 +124,16 @@ class DataMap {
        protected $recordTypeColumnName;
 
        /**
+        * @var bool
+        */
+       protected $isStatic = FALSE;
+
+       /**
+        * @var bool
+        */
+       protected $rootLevel = FALSE;
+
+       /**
         * Constructs this DataMap
         *
         * @param string $className The class name
@@ -472,6 +482,33 @@ class DataMap {
                return $this->recordTypeColumnName;
        }
 
+       /**
+        * @param boolean $isStatic
+        */
+       public function setIsStatic($isStatic) {
+               $this->isStatic = $isStatic;
+       }
+
+       /**
+        * @return boolean
+        */
+       public function getIsStatic() {
+               return $this->isStatic;
+       }
+
+       /**
+        * @param boolean $rootLevel
+        */
+       public function setRootLevel($rootLevel) {
+               $this->rootLevel = $rootLevel;
+       }
+
+       /**
+        * @return boolean
+        */
+       public function getRootLevel() {
+               return $this->rootLevel;
+       }
 }
 
 
index 7563573..c992e49 100644 (file)
@@ -283,6 +283,12 @@ class DataMapFactory implements \TYPO3\CMS\Core\SingletonInterface {
                if (isset($controlSection['type'])) {
                        $dataMap->setRecordTypeColumnName($controlSection['type']);
                }
+               if (isset($controlSection['rootLevel'])) {
+                       $dataMap->setRootLevel($controlSection['rootLevel']);
+               }
+               if (isset($controlSection['is_static'])) {
+                       $dataMap->setIsStatic($controlSection['is_static']);
+               }
                if (isset($controlSection['enablecolumns']['disabled'])) {
                        $dataMap->setDisabledFlagColumnName($controlSection['enablecolumns']['disabled']);
                }
index 6d9fdb7..420b4df 100644 (file)
@@ -39,6 +39,11 @@ class QueryFactory implements \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactor
        protected $configurationManager;
 
        /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper
+        */
+       protected $dataMapper;
+
+       /**
         * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
         * @return void
         * @author Sebastian Kurf├╝rst <sebastian@typo3.org>
@@ -56,14 +61,28 @@ class QueryFactory implements \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactor
        }
 
        /**
+        * @param \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper $dataMapper
+        */
+       public function injectDataMapper(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper $dataMapper) {
+               $this->dataMapper = $dataMapper;
+       }
+
+       /**
         * Creates a query object working on the given class name
         *
         * @param string $className The class name
         * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
+        * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception
         */
        public function create($className) {
                $query = $this->objectManager->create('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface', $className);
                $querySettings = $this->objectManager->create('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface');
+
+               $dataMap = $this->dataMapper->getDataMap($className);
+               if ($dataMap->getIsStatic() || $dataMap->getRootLevel()) {
+                       $querySettings->setRespectStoragePage(FALSE);
+               }
+
                $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
                $querySettings->setStoragePageIds(\TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $frameworkConfiguration['persistence']['storagePid']));
                $query->setQuerySettings($querySettings);
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/QueryFactoryTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/QueryFactoryTest.php
new file mode 100644 (file)
index 0000000..1dde490
--- /dev/null
@@ -0,0 +1,121 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Alexander Schnitzler <alex.schnitzler@typovision.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Testcase for \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory
+ *
+ * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
+ * @author Oliver Klee <typo3-coding@oliverklee.de>
+ */
+class QueryFactoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @var string
+        */
+       protected $className = 'Vendor\\Ext\\Domain\\Model\\ClubMate';
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory
+        */
+       protected $queryFactory = NULL;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $objectManager = NULL;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $dataMapper = NULL;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $dataMap;
+
+       protected function setUp() {
+               $this->dataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('getIsStatic', 'getRootLevel'), array('Vendor\\Ext\\Domain\\Model\\ClubMate', 'tx_ext_domain_model_clubmate'));
+
+               $this->queryFactory = new \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory();
+               $this->queryFactory->injectConfigurationManager(
+                       $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface')
+               );
+
+               $this->objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
+               $this->queryFactory->injectObjectManager($this->objectManager);
+
+               $this->dataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap', 'convertClassNameToTableName'));
+               $this->dataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($this->dataMap));
+               $this->queryFactory->injectDataMapper($this->dataMapper);
+       }
+
+       protected function tearDown() {
+               unset($this->objectManager, $this->dataMapper, $this->queryFactory);
+       }
+
+       public function getStaticAndRootLevelAndExpectedResult() {
+               return array(
+                       'Respect storage page is set when entity is neither marked as static nor as rootLevel.' => array(FALSE, FALSE, TRUE),
+                       'Respect storage page is set when entity is marked as static and rootLevel.' => array(TRUE, TRUE, FALSE),
+                       'Respect storage page is set when entity is marked as static but not rootLevel.' => array(TRUE, FALSE, FALSE),
+                       'Respect storage page is set when entity is not marked as static but as rootLevel.' => array(FALSE, TRUE, FALSE),
+               );
+       }
+
+       /**
+        * @param boolean $static
+        * @param boolean $rootLevel
+        * @param boolean $expectedResult
+        *
+        * @dataProvider getStaticAndRootLevelAndExpectedResult
+        * @test
+        */
+       public function createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue($static, $rootLevel, $expectedResult) {
+               $this->dataMap->expects($this->any())->method('getIsStatic')->will($this->returnValue($static));
+               $this->dataMap->expects($this->any())->method('getRootLevel')->will($this->returnValue($rootLevel));
+
+               $query = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface');
+               $this->objectManager->expects($this->at(0))->method('create')
+                       ->with('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface')
+                       ->will($this->returnValue($query));
+
+               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
+               $this->objectManager->expects($this->at(1))->method('create')
+                       ->with('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface')
+                       ->will($this->returnValue($querySettings));
+               $query->expects($this->once())->method('setQuerySettings')->with($querySettings);
+               $this->queryFactory->create($this->className);
+
+               $this->assertSame(
+                       $expectedResult,
+                       $querySettings->getRespectStoragePage()
+               );
+       }
+
+}
+
+?>
\ No newline at end of file