[FEATURE] Enable chaining of set* funtions 21/21121/5
authorDaniel Hürtgen <huertgen@rheinschafe.de>
Mon, 29 Apr 2013 08:05:11 +0000 (10:05 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 22 Jun 2013 22:10:52 +0000 (00:10 +0200)
Applies chaining possibility for set*
handling methods within querysettings api.

Make sure method chaining like
$query->getQuerySettings()->setRespectStoragePage(FALSE)
                          ->setRespectSysLanguage(FALSE)
                          ->setIgnoreEnableFields(TRUE)
                          ->setIncludeDeleted(TRUE);
is possible for all methods.

Releases: 6.2
Resolves: #47684
Change-Id: I3ce6eb3b100cf7762d885ad28f118a17f3268977
Reviewed-on: https://review.typo3.org/21121
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/extbase/Classes/Persistence/Generic/QuerySettingsInterface.php
typo3/sysext/extbase/Classes/Persistence/Generic/Typo3QuerySettings.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Typo3QuerySettingsTest.php [new file with mode: 0644]

index 14e428f..80e6b0d 100644 (file)
@@ -102,6 +102,7 @@ interface QuerySettingsInterface {
         * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
         *
         * @param boolean $ignoreEnableFields
+        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface instance of $this to allow method chaining
         * @see setEnableFieldsToBeIgnored()
         * @api
         */
@@ -124,7 +125,7 @@ interface QuerySettingsInterface {
         * by this column. This setting is only taken into account if $this->ignoreEnableFields = TRUE.
         *
         * @param array $enableFieldsToBeIgnored
-        * @return void
+        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface instance of $this to allow method chaining
         * @see setIgnoreEnableFields()
         * @api
         */
@@ -143,7 +144,7 @@ interface QuerySettingsInterface {
         * Sets the flag if the query should return objects that are deleted.
         *
         * @param boolean $includeDeleted
-        * @return void
+        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface instance of $this to allow method chaining
         * @api
         */
        public function setIncludeDeleted($includeDeleted);
index 5a7ab62..c5ef6a4 100644 (file)
@@ -27,6 +27,8 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic;
  *
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * Query settings. This class is NOT part of the FLOW3 API.
  * It reflects the settings unique to TYPO3 4.x.
@@ -100,7 +102,7 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         */
        public function initializeObject() {
                /** @var $objectManager \TYPO3\CMS\Extbase\Object\ObjectManager */
-               $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
+               $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
                /** @var $configurationManager \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface */
                $configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
                if (TYPO3_MODE === 'BE' && $configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
@@ -110,9 +112,9 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
                // Set correct language uid for frontend handling
                if (isset($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE'])) {
                        $this->setSysLanguageUid($GLOBALS['TSFE']->sys_language_content);
-               } elseif (intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('L'))) {
+               } elseif (intval(GeneralUtility::_GP('L'))) {
                        // Set language from 'L' parameter
-                       $this->setSysLanguageUid(intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('L')));
+                       $this->setSysLanguageUid(intval(GeneralUtility::_GP('L')));
                }
        }
 
@@ -120,7 +122,7 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         * Sets the flag if the storage page should be respected for the query.
         *
         * @param boolean $respectStoragePage If TRUE the storage page ID will be determined and the statement will be extended accordingly.
-        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface (fluent interface)
+        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
         * @api
         */
        public function setRespectStoragePage($respectStoragePage) {
@@ -140,12 +142,13 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
        /**
         * Sets the pid(s) of the storage page(s) that should be respected for the query.
         *
-        * @param array $storagePageIds If TRUE the storage page ID will be determined and the statement will be extended accordingly.
-        * @return void
+        * @param array $storagePageIds If given the storage page IDs will be determined and the statement will be extended accordingly.
+        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
         * @api
         */
        public function setStoragePageIds(array $storagePageIds) {
                $this->storagePageIds = $storagePageIds;
+               return $this;
        }
 
        /**
@@ -161,7 +164,7 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         * Sets the flag if a  and language overlay should be performed.
         *
         * @param boolean $respectSysLanguage TRUE if a  and language overlay should be performed.
-        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface (fluent interface)
+        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
         * @api
         */
        public function setRespectSysLanguage($respectSysLanguage) {
@@ -182,11 +185,12 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         * Sets the language uid for the language overlay.
         *
         * @param integer $sysLanguageUid language uid for the language overlay
-        * @return void
+        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
         * @api
         */
        public function setSysLanguageUid($sysLanguageUid) {
                $this->sysLanguageUid = $sysLanguageUid;
+               return $this;
        }
 
        /**
@@ -202,14 +206,14 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         * Sets the flag if the visibility in the frontend should be respected.
         *
         * @param boolean $respectEnableFields TRUE if the visibility in the frontend should be respected. If TRUE, the "enable fields" of TYPO3 will be added to the query statement.
-        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface (fluent interface)
-        * @deprecated since Extbase 6.0, will be removed in Extbase 6.2. Use setIgnoreEnableFields() and setEnableFieldsToBeIgnored() instead.
+        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
+        * @deprecated since Extbase 6.0, will be removed two versions later. Use setIgnoreEnableFields() and setEnableFieldsToBeIgnored() instead.
         * @see setIgnoreEnableFields()
         * @see setEnableFieldsToBeIgnored()
         * @api
         */
        public function setRespectEnableFields($respectEnableFields) {
-               \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
+               GeneralUtility::logDeprecatedFunction();
                $this->setIgnoreEnableFields(!$respectEnableFields);
                $this->setIncludeDeleted(!$respectEnableFields);
                return $this;
@@ -219,12 +223,12 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         * Returns the state, if the visibility settings for the frontend should be respected for the query.
         *
         * @return boolean TRUE, if the visibility settings for the frontend should should be respected; otherwise FALSE.
-        * @deprecated since Extbase 6.0, will be removed in Extbase 6.2. Use getIgnoreEnableFields() and getEnableFieldsToBeIgnored() instead.
+        * @deprecated since Extbase 6.0, will be removed two versions later. Use getIgnoreEnableFields() and getEnableFieldsToBeIgnored() instead.
         * @see getIgnoreEnableFields()
         * @see getEnableFieldsToBeIgnored()
         */
        public function getRespectEnableFields() {
-               \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
+               GeneralUtility::logDeprecatedFunction();
                return !($this->getIgnoreEnableFields() && $this->getIncludeDeleted());
        }
 
@@ -234,11 +238,13 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
         *
         * @param boolean $ignoreEnableFields
+        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
         * @see setEnableFieldsToBeIgnored()
         * @api
         */
        public function setIgnoreEnableFields($ignoreEnableFields) {
                $this->ignoreEnableFields = $ignoreEnableFields;
+               return $this;
        }
 
        /**
@@ -260,12 +266,13 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         * by this column. This setting is only taken into account if $this->ignoreEnableFields = TRUE.
         *
         * @param array $enableFieldsToBeIgnored
-        * @return void
+        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
         * @see setIgnoreEnableFields()
         * @api
         */
        public function setEnableFieldsToBeIgnored($enableFieldsToBeIgnored) {
                $this->enableFieldsToBeIgnored = $enableFieldsToBeIgnored;
+               return $this;
        }
 
        /**
@@ -283,11 +290,12 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         * Sets the flag if the query should return objects that are deleted.
         *
         * @param boolean $includeDeleted
-        * @return void
+        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
         * @api
         */
        public function setIncludeDeleted($includeDeleted) {
                $this->includeDeleted = $includeDeleted;
+               return $this;
        }
 
        /**
@@ -303,10 +311,11 @@ class Typo3QuerySettings implements \TYPO3\CMS\Extbase\Persistence\Generic\Query
         * Sets the state, if the QueryResult should be returned unmapped.
         *
         * @param boolean $returnRawQueryResult TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
-        * @return void
+        * @return \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
         */
        public function setReturnRawQueryResult($returnRawQueryResult) {
                $this->returnRawQueryResult = $returnRawQueryResult;
+               return $this;
        }
 
        /**
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Typo3QuerySettingsTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Typo3QuerySettingsTest.php
new file mode 100644 (file)
index 0000000..fc9a475
--- /dev/null
@@ -0,0 +1,229 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Anja Leichsenring <anja.leichsenring@typo3.org>
+ *  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\Typo3QuerySettings
+ *
+ * @author Anja Leichsenring <anja.leichsenring@typo3.org>
+ */
+class Typo3QuerySettingsTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings
+        */
+       protected $typo3QuerySettings;
+
+       /**
+        * setup test environment
+        */
+       public function setUp() {
+               $this->typo3QuerySettings = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings', array('dummy'));
+       }
+
+       /**
+        * @return array
+        */
+       public function booleanValueProvider() {
+               return array(
+                       'TRUE setting' => array(TRUE),
+                       'FALSE setting' => array(FALSE)
+               );
+       }
+
+       /**
+        * @return array
+        */
+       public function arrayValueProvider() {
+               return array(
+                       'empty array' => array(array()),
+                       'two elements associative' => array(
+                               array(
+                                       'one' => '42',
+                                       21 => 12
+                               )
+                       ),
+                       'three elements' => array(
+                               array(
+                                       1,
+                                       'dummy',
+                                       array()
+                               )
+                       )
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider booleanValueProvider
+        * @param boolean $input
+        */
+       public function setRespectStoragePageSetsRespectStoragePageCorrectly($input) {
+               $this->typo3QuerySettings->setRespectStoragePage($input);
+               $this->assertEquals($input, $this->typo3QuerySettings->getRespectStoragePage());
+       }
+
+       /**
+        * @test
+        */
+       public function setRespectStoragePageAllowsChaining() {
+               $this->assertTrue($this->typo3QuerySettings->setRespectStoragePage(TRUE) instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface);
+       }
+
+       /**
+        * @test
+        * @dataProvider arrayValueProvider
+        *
+        * @param array $input
+        */
+       public function setStoragePageIdsSetsStoragePageIdsCorrectly($input) {
+               $this->typo3QuerySettings->setStoragePageIds($input);
+               $this->assertEquals($input, $this->typo3QuerySettings->getStoragePageIds());
+       }
+
+       /**
+        * @test
+        */
+       public function setStoragePageIdsAllowsChaining() {
+               $this->assertTrue($this->typo3QuerySettings->setStoragePageIds(array(1,2,3)) instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface);
+       }
+
+       /**
+        * @test
+        * @dataProvider booleanValueProvider
+        *
+        * @param boolean $input
+        */
+       public function setRespectSysLanguageSetsRespectSysLanguageCorrectly($input) {
+               $this->typo3QuerySettings->setRespectSysLanguage($input);
+               $this->assertEquals($input, $this->typo3QuerySettings->getRespectSysLanguage());
+       }
+
+       /**
+        * @test
+        */
+       public function setRespectSysLanguageAllowsChaining() {
+               $this->assertTrue($this->typo3QuerySettings->setRespectSysLanguage(TRUE) instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface);
+       }
+
+       /**
+        * @test
+        */
+       public function setSysLanguageUidAllowsChaining() {
+               $this->assertTrue($this->typo3QuerySettings->setSysLanguageUid(42) instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface);
+       }
+
+       /**
+        * @test
+        * @dataProvider booleanValueProvider
+        *
+        * @param boolean $input
+        */
+       public function setRespectEnableFieldsSetsRespectEnableFieldsCorrectly($input) {
+               $this->typo3QuerySettings->setRespectEnableFields($input);
+               $this->assertEquals($input, $this->typo3QuerySettings->getRespectEnableFields());
+       }
+
+       /**
+        * @test
+        */
+       public function setRespectEnableFieldsAllowsChaining() {
+               $this->assertTrue($this->typo3QuerySettings->setRespectEnableFields(TRUE) instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface);
+       }
+
+       /**
+        * @test
+        * @dataProvider booleanValueProvider
+        *
+        * @param boolean $input
+        */
+       public function setIgnoreEnableFieldsSetsIgnoreEnableFieldsCorrectly($input) {
+               $this->typo3QuerySettings->setIgnoreEnableFields($input);
+               $this->assertEquals($input, $this->typo3QuerySettings->getIgnoreEnableFields());
+       }
+
+       /**
+        * @test
+        */
+       public function setIgnoreEnableFieldsAllowsChaining() {
+               $this->assertTrue($this->typo3QuerySettings->setIgnoreEnableFields(TRUE) instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface);
+       }
+
+       /**
+        * @test
+        * @dataProvider arrayValueProvider
+        *
+        * @param array $input
+        */
+       public function setEnableFieldsToBeIgnoredSetsEnableFieldsToBeIgnoredCorrectly($input) {
+               $this->typo3QuerySettings->setEnableFieldsToBeIgnored($input);
+               $this->assertEquals($input, $this->typo3QuerySettings->getEnableFieldsToBeIgnored());
+       }
+
+       /**
+        * @test
+        */
+       public function setEnableFieldsToBeIgnoredAllowsChaining() {
+               $this->assertTrue($this->typo3QuerySettings->setEnableFieldsToBeIgnored(array('starttime', 'endtime')) instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface);
+       }
+
+       /**
+        * @test
+        * @dataProvider booleanValueProvider
+        *
+        * @param boolean $input
+        */
+       public function setIncludeDeletedSetsIncludeDeletedCorrectly($input) {
+               $this->typo3QuerySettings->setIncludeDeleted($input);
+               $this->assertEquals($input, $this->typo3QuerySettings->getIncludeDeleted());
+       }
+
+       /**
+        * @test
+        */
+       public function setIncludeDeletedAllowsChaining() {
+               $this->assertTrue($this->typo3QuerySettings->setIncludeDeleted(TRUE) instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface);
+       }
+
+       /**
+        * @test
+        * @dataProvider booleanValueProvider
+        *
+        * @param boolean $input
+        */
+       public function setReturnRawQueryResultSetsReturnRawQueryResultCorrectly($input) {
+               $this->typo3QuerySettings->setReturnRawQueryResult($input);
+               $this->assertEquals($input, $this->typo3QuerySettings->getReturnRawQueryResult());
+       }
+
+       /**
+        * @test
+        */
+       public function setReturnRawQueryResultAllowsChaining() {
+               $this->assertTrue($this->typo3QuerySettings->setReturnRawQueryResult(TRUE) instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface);
+       }
+}
+
+?>
\ No newline at end of file