[CLEANUP] Cleanup code in ext:backend/Configuration 21/33521/5
authorWouter Wolters <typo3@wouterwolters.nl>
Sat, 25 Oct 2014 13:47:03 +0000 (15:47 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Sun, 30 Nov 2014 15:38:27 +0000 (16:38 +0100)
Resolves: #63382
Releases: master
Change-Id: I1f940fefdde2801e8eced5be6ab44e3d9bf326d4
Reviewed-on: http://review.typo3.org/33521
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Frank Nägler <typo3@naegler.net>
Tested-by: Frank Nägler <typo3@naegler.net>
Reviewed-by: Frederic Gaus <gaus@flagbit.de>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/backend/Classes/Configuration/TranslationConfigurationProvider.php
typo3/sysext/backend/Classes/Configuration/TsConfigParser.php
typo3/sysext/backend/Classes/Configuration/TypoScript/ConditionMatching/ConditionMatcher.php
typo3/sysext/backend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php

index 48df5b6..316b3fb 100644 (file)
@@ -57,8 +57,8 @@ class TranslationConfigurationProvider {
                        'flagIcon' => 'flags-multiple'
                );
                // Find all system languages:
-               $sys_languages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_language', '');
-               foreach ($sys_languages as $row) {
+               $sysLanguages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_language', '');
+               foreach ($sysLanguages as $row) {
                        $languageIconTitles[$row['uid']] = $row;
                        if ($row['static_lang_isocode'] && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables')) {
                                $staticLangRow = BackendUtility::getRecord('static_languages', $row['static_lang_isocode'], 'lg_iso_2');
index b649410..0255ade 100644 (file)
@@ -96,12 +96,11 @@ class TsConfigParser extends \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
                $matchObj->setRootline($this->rootLine);
                $matchObj->setPageId($this->id);
                $this->parse($TSconfig, $matchObj);
-               $storeData = array(
+               return array(
                        'TSconfig' => $this->setup,
                        'sections' => $this->sections,
                        'match' => $this->sectionsMatch
                );
-               return $storeData;
        }
 
        /**
index 1d36fb2..f895d19 100644 (file)
@@ -14,7 +14,9 @@ namespace TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Controller\EditDocumentController;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -25,7 +27,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
  *
  * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  */
-class ConditionMatcher extends \TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher {
+class ConditionMatcher extends AbstractConditionMatcher {
 
        /**
         * Constructor for this class
@@ -50,15 +52,14 @@ class ConditionMatcher extends \TYPO3\CMS\Core\Configuration\TypoScript\Conditio
                                        $groupList = $this->getGroupList();
                                        $values = GeneralUtility::trimExplode(',', $value, TRUE);
                                        foreach ($values as $test) {
-                                               if ($test == '*' || GeneralUtility::inList($groupList, $test)) {
+                                               if ($test === '*' || GeneralUtility::inList($groupList, $test)) {
                                                        return TRUE;
                                                }
                                        }
                                        break;
                                case 'adminUser':
                                        if ($this->isUserLoggedIn()) {
-                                               $result = !((bool)$value xor $this->isAdminUser());
-                                               return $result;
+                                               return !((bool)$value xor $this->isAdminUser());
                                        }
                                        break;
                                case 'treeLevel':
@@ -75,7 +76,6 @@ class ConditionMatcher extends \TYPO3\CMS\Core\Configuration\TypoScript\Conditio
                                        }
                                        break;
                                case 'PIDupinRootline':
-
                                case 'PIDinRootline':
                                        $values = GeneralUtility::trimExplode(',', $value, TRUE);
                                        if ($key == 'PIDinRootline' || !in_array($this->pageId, $values) || $this->isNewPageWithPageId($this->pageId)) {
@@ -111,8 +111,7 @@ class ConditionMatcher extends \TYPO3\CMS\Core\Configuration\TypoScript\Conditio
         * @return string The usergroup list of the current user
         */
        protected function getGroupList() {
-               $groupList = $GLOBALS['BE_USER']->groupList;
-               return $groupList;
+               return $this->getBackendUserAuthentication()->groupList;
        }
 
        /**
@@ -187,11 +186,11 @@ class ConditionMatcher extends \TYPO3\CMS\Core\Configuration\TypoScript\Conditio
         * Determine if record of table 'pages' with the given $pid is currently created in TCEforms.
         * This information is required for conditions in BE for PIDupinRootline.
         *
-        * @param int $pid The pid the check for as parent page
+        * @param int $pageId The pid the check for as parent page
         * @return bool TRUE if the is currently a new page record being edited with $pid as uid of the parent page
         */
        protected function isNewPageWithPageId($pageId) {
-               if (isset($GLOBALS['SOBE']) && $GLOBALS['SOBE'] instanceof \TYPO3\CMS\Backend\Controller\EditDocumentController) {
+               if (isset($GLOBALS['SOBE']) && $GLOBALS['SOBE'] instanceof EditDocumentController) {
                        $pageId = (int)$pageId;
                        $elementsData = $GLOBALS['SOBE']->elementsData;
                        $data = $GLOBALS['SOBE']->data;
@@ -206,7 +205,7 @@ class ConditionMatcher extends \TYPO3\CMS\Core\Configuration\TypoScript\Conditio
                        // If editing a new page record (not saved yet):
                        if (is_array($elementsData)) {
                                foreach ($elementsData as $element) {
-                                       if ($element['cmd'] == 'new' && $element['table'] == 'pages') {
+                                       if ($element['cmd'] === 'new' && $element['table'] === 'pages') {
                                                if ($element['pid'] < 0) {
                                                        $pageRecord = BackendUtility::getRecord('pages', abs($element['pid']), 'pid');
                                                        $element['pid'] = $pageRecord['pid'];
@@ -228,8 +227,7 @@ class ConditionMatcher extends \TYPO3\CMS\Core\Configuration\TypoScript\Conditio
         */
        protected function determineRootline() {
                $pageId = isset($this->pageId) ? $this->pageId : $this->determinePageId();
-               $rootline = BackendUtility::BEgetRootLine($pageId, '', TRUE);
-               return $rootline;
+               return BackendUtility::BEgetRootLine($pageId, '', TRUE);
        }
 
        /**
@@ -238,8 +236,7 @@ class ConditionMatcher extends \TYPO3\CMS\Core\Configuration\TypoScript\Conditio
         * @return int The id of the current user
         */
        protected function getUserId() {
-               $userId = $GLOBALS['BE_USER']->user['uid'];
-               return $userId;
+               return $this->getBackendUserAuthentication()->user['uid'];
        }
 
        /**
@@ -248,11 +245,7 @@ class ConditionMatcher extends \TYPO3\CMS\Core\Configuration\TypoScript\Conditio
         * @return bool Determines if a user is logged in
         */
        protected function isUserLoggedIn() {
-               $userLoggedIn = FALSE;
-               if ($GLOBALS['BE_USER']->user['uid']) {
-                       $userLoggedIn = TRUE;
-               }
-               return $userLoggedIn;
+               return (bool)$this->getBackendUserAuthentication()->user['uid'];
        }
 
        /**
@@ -261,11 +254,7 @@ class ConditionMatcher extends \TYPO3\CMS\Core\Configuration\TypoScript\Conditio
         * @return bool Whether the current user is admin
         */
        protected function isAdminUser() {
-               $isAdminUser = FALSE;
-               if ($GLOBALS['BE_USER']->user['admin']) {
-                       $isAdminUser = TRUE;
-               }
-               return $isAdminUser;
+               return $this->getBackendUserAuthentication()->isAdmin();
        }
 
        /**
@@ -275,9 +264,16 @@ class ConditionMatcher extends \TYPO3\CMS\Core\Configuration\TypoScript\Conditio
         * @return void
         */
        protected function log($message) {
-               if (is_object($GLOBALS['BE_USER'])) {
-                       $GLOBALS['BE_USER']->writelog(3, 0, 1, 0, $message, array());
+               if (is_object($this->getBackendUserAuthentication())) {
+                       $this->getBackendUserAuthentication()->writelog(3, 0, 1, 0, $message, array());
                }
        }
 
+       /**
+        * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
+        */
+       protected function getBackendUserAuthentication() {
+               return $GLOBALS['BE_USER'];
+       }
+
 }
index 9fb1587..944d413 100644 (file)
@@ -13,6 +13,8 @@ namespace TYPO3\CMS\Backend\Tests\Unit\Configuration\TypoScript\ConditionMatchin
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Testcase for class \TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher.
@@ -34,8 +36,16 @@ class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @var string
         */
+       protected $testGlobalNamespace;
+
+       /**
+        * @var string
+        */
        protected $testTableName;
 
+       /**
+        * Set up tests
+        */
        public function setUp() {
                $this->testTableName = 'conditionMatcherTestTable';
                $this->testGlobalNamespace = uniqid('TEST');
@@ -45,15 +55,21 @@ class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->matchCondition = $this->getMock('TYPO3\\CMS\\Backend\\Configuration\\TypoScript\\ConditionMatching\\ConditionMatcher', array('determineRootline'), array(), '', FALSE);
        }
 
+       /**
+        * Set up a backend
+        */
        private function setUpBackend() {
                $this->rootline = array(
                        2 => array('uid' => 121, 'pid' => 111),
                        1 => array('uid' => 111, 'pid' => 101),
                        0 => array('uid' => 101, 'pid' => 0)
                );
-               $GLOBALS['BE_USER'] = $this->getMock('beUserAuth', array(), array(), '', FALSE);
+               $GLOBALS['BE_USER'] = $this->getMock(BackendUserAuthentication::class, array('dummy'), array(), '', FALSE);
        }
 
+       /**
+        * Set up database mock
+        */
        private function setUpDatabaseMockForDeterminePageId() {
                $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result'));
                $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTquery')->will($this->returnCallback(array($this, 'determinePageIdByRecordDatabaseExecuteCallback')));
@@ -66,7 +82,6 @@ class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function simulateDisabledMatchAllConditionsFailsOnFaultyExpression() {
-               $this->matchCondition->matchAll = FALSE;
                $this->assertFalse($this->matchCondition->match('[nullCondition = This expression would return FALSE in general]'));
        }
 
@@ -825,7 +840,7 @@ class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function genericGetVariablesSucceedsWithNamespaceIENV() {
-               $_SERVER['HTTP_HOST'] = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY') . ':1234567';
+               $_SERVER['HTTP_HOST'] = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY') . ':1234567';
                $this->assertTrue($this->matchCondition->match('[globalString = IENV:TYPO3_PORT = 1234567]'));
        }