[BUGFIX] Correct calculation of pageIsNotLockedForEditors 68/44568/4
authorSebastian Seidelmann <sebastian.seidelmann@wfp2.com>
Fri, 6 Nov 2015 09:35:52 +0000 (10:35 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 6 Nov 2015 19:55:54 +0000 (20:55 +0100)
Resolves the wrong calculation of binary operator result
that is used to check if the edit page button in page module
is displayed or not.

Resolves: #71363
Releases: master
Change-Id: I83f46e267d3716ef3954bd1470fa5fe01a9bc17f
Reviewed-on: https://review.typo3.org/44568
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Controller/PageLayoutController.php
typo3/sysext/backend/Tests/Unit/Controller/PageLayoutControllerTest.php [new file with mode: 0644]

index 7fda2ec..510517b 100755 (executable)
@@ -1347,7 +1347,7 @@ class PageLayoutController
      */
     public function pageIsNotLockedForEditors()
     {
-        return $this->getBackendUser()->isAdmin() || !($this->CALC_PERMS & Permission::PAGE_EDIT && $this->pageinfo['editlock']);
+        return $this->getBackendUser()->isAdmin() || ($this->CALC_PERMS & Permission::PAGE_EDIT) === Permission::PAGE_EDIT && !$this->pageinfo['editlock'];
     }
 
     /**
diff --git a/typo3/sysext/backend/Tests/Unit/Controller/PageLayoutControllerTest.php b/typo3/sysext/backend/Tests/Unit/Controller/PageLayoutControllerTest.php
new file mode 100644 (file)
index 0000000..528c6bf
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+namespace TYPO3\CMS\Backend\Tests\Unit\Controller;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Backend\Controller\PageLayoutController;
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Tests\UnitTestCase;
+use TYPO3\CMS\Core\Type\Bitmask\Permission;
+
+/**
+ * Class PageLayoutControllerTest
+ */
+class PageLayoutControllerTest extends UnitTestCase
+{
+
+    /**
+     * @test
+     * @dataProvider pageIsNotLockedForEditorsReturnsCorrectValueDataProvider
+     * @param bool $isAdmin
+     * @param int $permissions
+     * @param bool $editLock
+     * @param bool $expected
+     */
+    public function pageIsNotLockedForEditorsReturnsCorrectValue($isAdmin, $permissions, $editLock, $expected)
+    {
+        /** @var BackendUserAuthentication|\PHPUnit_Framework_MockObject_MockObject $beUserMock */
+        $beUserMock = $this->getMock(BackendUserAuthentication::class, ['isAdmin']);
+        $beUserMock->method('isAdmin')->will($this->returnValue($isAdmin));
+
+        /** @var PageLayoutController|\PHPUnit_Framework_MockObject_MockObject $pageController */
+        $pageController = $this->getMock(PageLayoutController::class, ['getBackendUser']);
+        $pageController->method('getBackendUser')->will($this->returnValue($beUserMock));
+
+        $pageController->CALC_PERMS = $permissions;
+        $pageController->pageinfo = ['editlock' => $editLock];
+
+        $this->assertTrue($pageController->pageIsNotLockedForEditors() === $expected);
+    }
+
+    /**
+     * @return array
+     */
+    public function pageIsNotLockedForEditorsReturnsCorrectValueDataProvider()
+    {
+        return [
+            'user is admin' => [ true, 0, false, true],
+            'user has permission' => [ false, Permission::PAGE_EDIT, false, true],
+            'page has permission, but editlock set' => [ false, Permission::PAGE_EDIT, true, false],
+            'user does not have permission' => [ false, 0, false, false],
+        ];
+    }
+
+}