‪TYPO3CMS  11.5
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 {
35  protected function ‪getPreparedUserAspect(bool $isLoggedIn, bool $isAdmin, int $userId, array $groupIds): ‪UserAspect
36  {
37  return new class ($isLoggedIn, $isAdmin, $userId, $groupIds) extends ‪UserAspect {
38  private $isAdmin;
39  private $isLoggedIn;
40  private $userId;
41  private $groupIds;
42  public function __construct(bool $isLoggedIn, bool $isAdmin, int $userId, array $groupIds)
43  {
44  $this->isLoggedIn = $isLoggedIn;
45  $this->isAdmin = $isAdmin;
46  $this->userId = $userId;
47  $this->groupIds = $groupIds;
48  }
49  public function isAdmin(): bool
50  {
51  return $this->isAdmin;
52  }
53  public function isLoggedIn(): bool
54  {
55  return $this->isLoggedIn;
56  }
57  public function get($name): int
58  {
59  if ($name === 'id') {
60  return $this->userId;
61  }
62  return parent::get($name);
63  }
64  public function getGroupIds(): array
65  {
66  return $this->groupIds;
67  }
68  };
69  }
70 
75  {
76  $aspect = $this->‪getPreparedUserAspect(true, false, 2, [13]);
78  $expression = $subject->buildExpression(['pages' => 'pages'], $this->expressionBuilder);
79  self::assertNotEmpty((string)$expression);
80  $expression = $subject->buildExpression(['anotherTable' => 'anotherTable'], $this->expressionBuilder);
81  self::assertEmpty((string)$expression);
82  }
83 
88  {
89  $aspect = $this->‪getPreparedUserAspect(false, false, 2, [13]);
91  $expression = $subject->buildExpression(['pages' => 'pages'], $this->expressionBuilder);
92  self::assertSame('1 = 0', (string)$expression);
93  }
94 
99  {
100  $aspect = $this->‪getPreparedUserAspect(true, true, 2, [13]);
102  $expression = $subject->buildExpression(['pages' => 'pages'], $this->expressionBuilder);
103  self::assertEmpty((string)$expression);
104  }
105 
110  {
111  $aspect = $this->‪getPreparedUserAspect(true, false, 2, [13, 14, 15, 16]);
113  $expression = $subject->buildExpression(['pages' => 'pages'], $this->expressionBuilder);
114  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);
115  }
116 
121  {
122  $aspect = $this->‪getPreparedUserAspect(true, false, 42, [13, 14, 15, 16]);
124  $expression = $subject->buildExpression(['pages' => 'pages'], $this->expressionBuilder);
125  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);
126  }
127 }
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\buildRestrictionsOnlyWorksOnPagesTable
‪buildRestrictionsOnlyWorksOnPagesTable()
Definition: PagePermissionRestrictionTest.php:74
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\buildRestrictionsReturnsAZeroReturnSetWhenNotLoggedIn
‪buildRestrictionsReturnsAZeroReturnSetWhenNotLoggedIn()
Definition: PagePermissionRestrictionTest.php:87
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪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:29
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\buildRestrictionsContainsNonAdminUserIdAsOwnerAndGroupIdsAsOwnerGroup
‪buildRestrictionsContainsNonAdminUserIdAsOwnerAndGroupIdsAsOwnerGroup()
Definition: PagePermissionRestrictionTest.php:109
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\buildRestrictionsChecksForDeletionPermission
‪buildRestrictionsChecksForDeletionPermission()
Definition: PagePermissionRestrictionTest.php:120
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:35
‪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:98
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_DELETE
‪const PAGE_DELETE
Definition: Permission.php:45
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\getPreparedUserAspect
‪UserAspect getPreparedUserAspect(bool $isLoggedIn, bool $isAdmin, int $userId, array $groupIds)
Definition: PagePermissionRestrictionTest.php:35
‪TYPO3\CMS\Core\Context\UserAspect
Definition: UserAspect.php:37