[BUGFIX] Fix flexform inline record editing with empty uc 40/48540/3
authorJörg Bösche <typo3@joergboesche.de>
Thu, 9 Jun 2016 14:50:30 +0000 (16:50 +0200)
committerFrank Naegler <frank.naegler@typo3.org>
Fri, 10 Jun 2016 07:35:14 +0000 (09:35 +0200)
When the uc of a backend user is empty a unserialize error
will be shown. Fix this by checking the uc['inlineView']
correctly.

Resolves: #76561
Releases: master, 7.6
Change-Id: Ic7ad77333312b570bb29f46a908838085f020f50
Reviewed-on: https://review.typo3.org/48540
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/backend/Classes/Controller/FormInlineAjaxController.php
typo3/sysext/backend/Tests/Unit/Controller/FormInlineAjaxControllerTest.php

index 1d69322..ac69943 100644 (file)
@@ -799,14 +799,30 @@ class FormInlineAjaxController
     protected function getInlineExpandCollapseStateArray()
     {
         $backendUser = $this->getBackendUserAuthentication();
+        if (!$this->backendUserHasUcInlineView($backendUser)) {
+            return [];
+        }
+
         $inlineView = unserialize($backendUser->uc['inlineView']);
         if (!is_array($inlineView)) {
-            $inlineView = array();
+            $inlineView = [];
         }
+
         return $inlineView;
     }
 
     /**
+     * Method to check whether the backend user has the property inline view for the current IRRE item.
+     * In existing or old IRRE items the attribute may not exist, then the unserialize will fail.
+     *
+     * @param BackendUserAuthentication $backendUser
+     * @return bool
+     */
+    protected function backendUserHasUcInlineView(BackendUserAuthentication $backendUser) {
+        return !empty($backendUser->uc['inlineView']);
+    }
+
+    /**
      * Remove an element from an array.
      *
      * @param mixed $needle The element to be removed.
index 0433ea8..b40ebd0 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Backend\Tests\Unit\Controller;
  */
 
 use TYPO3\CMS\Backend\Controller\FormInlineAjaxController;
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Tests\UnitTestCase;
 
 /**
@@ -166,4 +167,55 @@ class FormInlineAjaxControllerTest extends UnitTestCase
             ],
         ];
     }
+
+    /**
+     * Fallback for IRRE items without inline view attribute
+     * @issue https://forge.typo3.org/issues/76561
+     *
+     * @test
+     */
+    public function getInlineExpandCollapseStateArraySwitchesToFallbackIfTheBackendUserDoesNotHaveAnUCInlineViewProperty()
+    {
+        $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
+        $backendUserProphecy->uc = [];
+        $backendUser = $backendUserProphecy->reveal();
+
+        $mockObject = $this->getAccessibleMock(
+            FormInlineAjaxController::class,
+            ['getBackendUserAuthentication'],
+            [],
+            '',
+            false
+        );
+        $mockObject->method('getBackendUserAuthentication')->willReturn($backendUser);
+        $result = $mockObject->_call('getInlineExpandCollapseStateArray');
+
+        $this->assertEmpty($result);
+    }
+
+
+    /**
+     * Unserialize uc inline view string for IRRE item
+     * @issue https://forge.typo3.org/issues/76561
+     *
+     * @test
+     */
+    public function getInlineExpandCollapseStateArrayWillUnserializeUCInlineViewPropertyAsAnArrayWithData()
+    {
+        $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
+        $backendUserProphecy->uc = ['inlineView' => serialize(['foo' => 'bar'])];
+        $backendUser = $backendUserProphecy->reveal();
+
+        $mockObject = $this->getAccessibleMock(
+            FormInlineAjaxController::class,
+            ['getBackendUserAuthentication'],
+            [],
+            '',
+            false
+        );
+        $mockObject->method('getBackendUserAuthentication')->willReturn($backendUser);
+        $result = $mockObject->_call('getInlineExpandCollapseStateArray');
+
+        $this->assertNotEmpty($result);
+    }
 }