[BUGFIX] Change order of tablename and alias in restriction container 49/53649/2
authorSebastian Fischer <typo3@evoweb.de>
Fri, 4 Aug 2017 13:28:13 +0000 (15:28 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Mon, 7 Aug 2017 08:53:24 +0000 (10:53 +0200)
Changing the order of tablename and alias in method call properties
makes if possible to get correct values from registered restrictions

Resolves: #82046
Releases: master, 8.7
Change-Id: I17151c47c29fb48829ce0d3256ca99a4feadbf4a
Reviewed-on: https://review.typo3.org/53649
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/core/Classes/Database/Query/Restriction/FrontendRestrictionContainer.php
typo3/sysext/core/Tests/Unit/Database/Query/Restriction/FrontendRestrictionContainerTest.php

index dda3df0..784f19f 100644 (file)
@@ -69,7 +69,7 @@ class FrontendRestrictionContainer extends AbstractRestrictionContainer
                     $disableRestriction = $tableName === 'pages' ? $typoScriptFrontendController->showHiddenPage : $typoScriptFrontendController->showHiddenRecords;
                 }
                 if (!$disableRestriction) {
-                    $constraints[] = $restriction->buildExpression([$tableName => $tableAlias], $expressionBuilder);
+                    $constraints[] = $restriction->buildExpression([$tableAlias => $tableName], $expressionBuilder);
                 }
             }
         }
index 82d8842..a796c28 100644 (file)
@@ -32,6 +32,7 @@ class FrontendRestrictionContainerTest extends AbstractRestrictionTestCase
         return [
             'Live, no preview' => [
                 'tableName' => 'aTable',
+                'tableAlias' => 'aTable',
                 'workspaceId' => 0,
                 'workspacePreview' => false,
                 'hiddenPagePreview' => false,
@@ -41,6 +42,7 @@ class FrontendRestrictionContainerTest extends AbstractRestrictionTestCase
             ],
             'Live, with hidden record preview' => [
                 'tableName' => 'aTable',
+                'tableAlias' => 'aTable',
                 'workspaceId' => 0,
                 'workspacePreview' => false,
                 'hiddenPagePreview' => true,
@@ -50,6 +52,7 @@ class FrontendRestrictionContainerTest extends AbstractRestrictionTestCase
             ],
             'Workspace, with WS preview' => [
                 'tableName' => 'aTable',
+                'tableAlias' => 'aTable',
                 'workspaceId' => 1,
                 'workspacePreview' => true,
                 'hiddenPagePreview' => false,
@@ -59,6 +62,7 @@ class FrontendRestrictionContainerTest extends AbstractRestrictionTestCase
             ],
             'Workspace, with WS preview and hidden record preview' => [
                 'tableName' => 'aTable',
+                'tableAlias' => 'aTable',
                 'workspaceId' => 1,
                 'workspacePreview' => true,
                 'hiddenPagePreview' => true,
@@ -68,6 +72,7 @@ class FrontendRestrictionContainerTest extends AbstractRestrictionTestCase
             ],
             'Live page, no preview' => [
                 'tableName' => 'pages',
+                'tableAlias' => 'pages',
                 'workspaceId' => 0,
                 'workspacePreview' => false,
                 'hiddenPagePreview' => false,
@@ -77,6 +82,7 @@ class FrontendRestrictionContainerTest extends AbstractRestrictionTestCase
             ],
             'Live page, with hidden page preview' => [
                 'tableName' => 'pages',
+                'tableAlias' => 'pages',
                 'workspaceId' => 0,
                 'workspacePreview' => false,
                 'hiddenPagePreview' => true,
@@ -86,6 +92,7 @@ class FrontendRestrictionContainerTest extends AbstractRestrictionTestCase
             ],
             'Workspace page, with WS preview' => [
                 'tableName' => 'pages',
+                'tableAlias' => 'pages',
                 'workspaceId' => 1,
                 'workspacePreview' => true,
                 'hiddenPagePreview' => false,
@@ -95,6 +102,7 @@ class FrontendRestrictionContainerTest extends AbstractRestrictionTestCase
             ],
             'Workspace page, with WS preview and hidden pages preview' => [
                 'tableName' => 'pages',
+                'tableAlias' => 'pages',
                 'workspaceId' => 1,
                 'workspacePreview' => true,
                 'hiddenPagePreview' => true,
@@ -102,11 +110,22 @@ class FrontendRestrictionContainerTest extends AbstractRestrictionTestCase
                 'feGroupList' => '0,-1',
                 'expectedSQL' => '("pages"."deleted" = 0) AND ("pages"."pid" <> -1) AND ("pages"."starttime" <= 42) AND (("pages"."endtime" = 0) OR ("pages"."endtime" > 42)) AND (("pages"."fe_group" IS NULL) OR ("pages"."fe_group" = \'\') OR ("pages"."fe_group" = \'0\') OR (FIND_IN_SET(\'0\', "pages"."fe_group")) OR (FIND_IN_SET(\'-1\', "pages"."fe_group")))'
             ],
+            'Live, no preview with alias' => [
+                'tableName' => 'aTable',
+                'tableAlias' => 'a',
+                'workspaceId' => 0,
+                'workspacePreview' => false,
+                'hiddenPagePreview' => false,
+                'hiddenRecordPreview' => false,
+                'feGroupList' => '0,-1',
+                'expectedSQL' => '("a"."deleted" = 0) AND (("a"."t3ver_state" <= 0) AND ("a"."pid" <> -1)) AND ("a"."myHiddenField" = 0) AND ("a"."myStartTimeField" <= 42) AND (("a"."myEndTimeField" = 0) OR ("a"."myEndTimeField" > 42)) AND (("a"."myGroupField" IS NULL) OR ("a"."myGroupField" = \'\') OR ("a"."myGroupField" = \'0\') OR (FIND_IN_SET(\'0\', "a"."myGroupField")) OR (FIND_IN_SET(\'-1\', "a"."myGroupField")))'
+            ],
         ];
     }
 
     /**
      * @param string $tableName
+     * @param string $tableAlias
      * @param int $workspaceId
      * @param bool $workspacePreview
      * @param bool $hiddenPagePreview
@@ -119,6 +138,7 @@ class FrontendRestrictionContainerTest extends AbstractRestrictionTestCase
      */
     public function buildExpressionAddsCorrectClause(
         string $tableName,
+        string $tableAlias,
         int $workspaceId,
         bool $workspacePreview,
         bool $hiddenPagePreview,
@@ -173,7 +193,7 @@ class FrontendRestrictionContainerTest extends AbstractRestrictionTestCase
         $GLOBALS['SIM_ACCESS_TIME'] = 42;
 
         $subject = new FrontendRestrictionContainer();
-        $expression = $subject->buildExpression([$tableName => $tableName], $this->expressionBuilder);
+        $expression = $subject->buildExpression([$tableAlias => $tableName], $this->expressionBuilder);
         $this->assertSame($expectedSQL, (string)$expression);
     }
 }