‪TYPO3CMS  10.4
PagePermissionRestrictionTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 
25 {
26 
36  protected function ‪getPreparedUserAspect(bool $isLoggedIn, bool $isAdmin, int $userId, array $groupIds): ‪UserAspect
37  {
38  return new class($isLoggedIn, $isAdmin, $userId, $groupIds) extends ‪UserAspect {
39  private $isAdmin;
40  private $isLoggedIn;
41  private $userId;
42  private $groupIds;
43  public function __construct(bool $isLoggedIn, bool $isAdmin, int $userId, array $groupIds)
44  {
45  $this->isLoggedIn = $isLoggedIn;
46  $this->isAdmin = $isAdmin;
47  $this->userId = $userId;
48  $this->groupIds = $groupIds;
49  }
50  public function isAdmin(): bool
51  {
52  return $this->isAdmin;
53  }
54  public function isLoggedIn(): bool
55  {
56  return $this->isLoggedIn;
57  }
58  public function get($name)
59  {
60  if ($name === 'id') {
61  return $this->userId;
62  }
63  return parent::get($name);
64  }
65  public function getGroupIds(): array
66  {
67  return $this->groupIds;
68  }
69  };
70  }
71 
76  {
77  $aspect = $this->‪getPreparedUserAspect(true, false, 2, [13]);
79  $expression = $subject->buildExpression(['pages' => 'pages'], $this->expressionBuilder);
80  self::assertNotEmpty((string)$expression);
81  $expression = $subject->buildExpression(['anotherTable' => 'anotherTable'], $this->expressionBuilder);
82  self::assertEmpty((string)$expression);
83  }
84 
89  {
90  $aspect = $this->‪getPreparedUserAspect(false, false, 2, [13]);
92  $expression = $subject->buildExpression(['pages' => 'pages'], $this->expressionBuilder);
93  self::assertSame('1 = 0', (string)$expression);
94  }
95 
100  {
101  $aspect = $this->‪getPreparedUserAspect(true, true, 2, [13]);
103  $expression = $subject->buildExpression(['pages' => 'pages'], $this->expressionBuilder);
104  self::assertEmpty((string)$expression);
105  }
106 
111  {
112  $aspect = $this->‪getPreparedUserAspect(true, false, 2, [13, 14, 15, 16]);
114  $expression = $subject->buildExpression(['pages' => 'pages'], $this->expressionBuilder);
115  self::assertEquals('("pages"."perms_everybody" & 1 = 1) OR (("pages"."perms_userid" = 2) AND ("pages"."perms_user" & 1 = 1)) OR (("pages"."perms_groupid" IN (13, 14, 15, 16)) AND ("pages"."perms_group" & 1 = 1))', (string)$expression);
116  }
117 
122  {
123  $aspect = $this->‪getPreparedUserAspect(true, false, 42, [13, 14, 15, 16]);
125  $expression = $subject->buildExpression(['pages' => 'pages'], $this->expressionBuilder);
126  self::assertEquals('("pages"."perms_everybody" & 4 = 4) OR (("pages"."perms_userid" = 42) AND ("pages"."perms_user" & 4 = 4)) OR (("pages"."perms_groupid" IN (13, 14, 15, 16)) AND ("pages"."perms_group" & 4 = 4))', (string)$expression);
127  }
128 }
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\buildRestrictionsOnlyWorksOnPagesTable
‪buildRestrictionsOnlyWorksOnPagesTable()
Definition: PagePermissionRestrictionTest.php:75
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\buildRestrictionsReturnsAZeroReturnSetWhenNotLoggedIn
‪buildRestrictionsReturnsAZeroReturnSetWhenNotLoggedIn()
Definition: PagePermissionRestrictionTest.php:88
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:24
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest
Definition: PagePermissionRestrictionTest.php:25
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction
Definition: AbstractRestrictionContainerTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\AbstractRestrictionTestCase
Definition: AbstractRestrictionTestCase.php:28
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\buildRestrictionsContainsNonAdminUserIdAsOwnerAndGroupIdsAsOwnerGroup
‪buildRestrictionsContainsNonAdminUserIdAsOwnerAndGroupIdsAsOwnerGroup()
Definition: PagePermissionRestrictionTest.php:110
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\buildRestrictionsChecksForDeletionPermission
‪buildRestrictionsChecksForDeletionPermission()
Definition: PagePermissionRestrictionTest.php:121
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:33
‪TYPO3\CMS\Core\Database\Query\Restriction\PagePermissionRestriction
Definition: PagePermissionRestriction.php:42
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\buildRestrictionsIsSkippedForAdmins
‪buildRestrictionsIsSkippedForAdmins()
Definition: PagePermissionRestrictionTest.php:99
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_DELETE
‪const PAGE_DELETE
Definition: Permission.php:43
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\getPreparedUserAspect
‪UserAspect getPreparedUserAspect(bool $isLoggedIn, bool $isAdmin, int $userId, array $groupIds)
Definition: PagePermissionRestrictionTest.php:36
‪TYPO3\CMS\Core\Context\UserAspect
Definition: UserAspect.php:38