[BUGFIX] Let FrontendGroupRestriction handle missing TSFE gr_list property 04/49704/2
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Thu, 1 Sep 2016 08:10:19 +0000 (10:10 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Thu, 1 Sep 2016 09:22:21 +0000 (11:22 +0200)
Check for an uninitialized frontend group list property in the
FrontendGroupRestriction and provide proper input to explode();

Change-Id: I807c0e1dc748ed1547a7dd937f0da69e69bb6e4c
Resolves: #77712
Releases: master
Reviewed-on: https://review.typo3.org/49704
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Julian Hofmann <info@julian-hofmann.net>
Tested-by: Julian Hofmann <info@julian-hofmann.net>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/core/Classes/Database/Query/Restriction/FrontendGroupRestriction.php
typo3/sysext/core/Tests/Unit/Database/Query/Restriction/FrontendGroupRestrictionTest.php

index b8db8ed..4487059 100644 (file)
@@ -33,7 +33,7 @@ class FrontendGroupRestriction implements QueryRestrictionInterface
      */
     public function __construct(array $frontendGroupIds = null)
     {
-        $this->frontendGroupIds = $frontendGroupIds === null ? explode(',', $GLOBALS['TSFE']->gr_list) : $frontendGroupIds;
+        $this->frontendGroupIds = $frontendGroupIds === null ? explode(',', $GLOBALS['TSFE']->gr_list ?? '') : $frontendGroupIds;
     }
 
     /**
index 05718e8..66d4572 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction;
  */
 
 use TYPO3\CMS\Core\Database\Query\Restriction\FrontendGroupRestriction;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 
 class FrontendGroupRestrictionTest extends AbstractRestrictionTestCase
 {
@@ -56,4 +57,22 @@ class FrontendGroupRestrictionTest extends AbstractRestrictionTestCase
         $expression = $subject->buildExpression(['aTable' => ''], $this->expressionBuilder);
         $this->assertSame('("aTable"."myGroupField" IS NULL) OR ("aTable"."myGroupField" = \'\') OR ("aTable"."myGroupField" = \'0\') OR (FIND_IN_SET(\'2\', "aTable"."myGroupField")) OR (FIND_IN_SET(\'3\', "aTable"."myGroupField"))', (string)$expression);
     }
+
+    /**
+     * @test
+     */
+    public function handlesNullTypoScriptFrontendControllerGroupList()
+    {
+        $GLOBALS['TSFE'] = $this->prophesize(TypoScriptFrontendController::class);
+        $GLOBALS['TSFE']->gr_list = null;
+
+        $GLOBALS['TCA']['aTable']['ctrl'] = [
+            'enablecolumns' => [
+                'fe_group' => 'myGroupField',
+            ],
+        ];
+        $subject = new FrontendGroupRestriction();
+        $expression = $subject->buildExpression(['aTable' => ''], $this->expressionBuilder);
+        $this->assertSame('("aTable"."myGroupField" IS NULL) OR ("aTable"."myGroupField" = \'\') OR ("aTable"."myGroupField" = \'0\') OR (FIND_IN_SET(\'\', "aTable"."myGroupField"))', (string)$expression);
+    }
 }