‪TYPO3CMS  9.5
PagePermissionRestrictionTest.php
Go to the documentation of this file.
1 <?php
2 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 
21 
23 {
24 
34  protected function ‪getPreparedUserAspect(bool $isLoggedIn, bool $isAdmin, int $userId, array $groupIds): ‪UserAspect
35  {
36  return new class($isLoggedIn, $isAdmin, $userId, $groupIds) extends ‪UserAspect {
37  private $isAdmin;
38  private $isLoggedIn;
39  private $userId;
40  private $groupIds;
41  public function __construct(bool $isLoggedIn, bool $isAdmin, int $userId, array $groupIds)
42  {
43  $this->isLoggedIn = $isLoggedIn;
44  $this->isAdmin = $isAdmin;
45  $this->userId = $userId;
46  $this->groupIds = $groupIds;
47  }
48  public function isAdmin(): bool
49  {
50  return $this->isAdmin;
51  }
52  public function isLoggedIn(): bool
53  {
54  return $this->isLoggedIn;
55  }
56  public function get($name)
57  {
58  if ($name === 'id') {
59  return $this->userId;
60  }
61  return parent::get($name);
62  }
63  public function getGroupIds(): array
64  {
65  return $this->groupIds;
66  }
67  };
68  }
69 
74  {
75  $aspect = $this->‪getPreparedUserAspect(true, false, 2, [13]);
77  $expression = $subject->buildExpression(['pages' => 'pages'], $this->expressionBuilder);
78  self::assertNotEmpty((string)$expression);
79  $expression = $subject->buildExpression(['anotherTable' => 'anotherTable'], $this->expressionBuilder);
80  self::assertEmpty((string)$expression);
81  }
82 
87  {
88  $aspect = $this->‪getPreparedUserAspect(false, false, 2, [13]);
90  $expression = $subject->buildExpression(['pages' => 'pages'], $this->expressionBuilder);
91  self::assertSame('1 = 0', (string)$expression);
92  }
93 
98  {
99  $aspect = $this->‪getPreparedUserAspect(true, true, 2, [13]);
101  $expression = $subject->buildExpression(['pages' => 'pages'], $this->expressionBuilder);
102  self::assertEmpty((string)$expression);
103  }
104 
109  {
110  $aspect = $this->‪getPreparedUserAspect(true, false, 2, [13, 14, 15, 16]);
112  $expression = $subject->buildExpression(['pages' => 'pages'], $this->expressionBuilder);
113  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);
114  }
115 
120  {
121  $aspect = $this->‪getPreparedUserAspect(true, false, 42, [13, 14, 15, 16]);
123  $expression = $subject->buildExpression(['pages' => 'pages'], $this->expressionBuilder);
124  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);
125  }
126 }
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\buildRestrictionsOnlyWorksOnPagesTable
‪buildRestrictionsOnlyWorksOnPagesTable()
Definition: PagePermissionRestrictionTest.php:73
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\buildRestrictionsReturnsAZeroReturnSetWhenNotLoggedIn
‪buildRestrictionsReturnsAZeroReturnSetWhenNotLoggedIn()
Definition: PagePermissionRestrictionTest.php:86
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:23
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest
Definition: PagePermissionRestrictionTest.php:23
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction
Definition: AbstractRestrictionContainerTest.php:3
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\AbstractRestrictionTestCase
Definition: AbstractRestrictionTestCase.php:26
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\buildRestrictionsContainsNonAdminUserIdAsOwnerAndGroupIdsAsOwnerGroup
‪buildRestrictionsContainsNonAdminUserIdAsOwnerAndGroupIdsAsOwnerGroup()
Definition: PagePermissionRestrictionTest.php:108
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\buildRestrictionsChecksForDeletionPermission
‪buildRestrictionsChecksForDeletionPermission()
Definition: PagePermissionRestrictionTest.php:119
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:32
‪TYPO3\CMS\Core\Database\Query\Restriction\PagePermissionRestriction
Definition: PagePermissionRestriction.php:40
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\buildRestrictionsIsSkippedForAdmins
‪buildRestrictionsIsSkippedForAdmins()
Definition: PagePermissionRestrictionTest.php:97
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_DELETE
‪const PAGE_DELETE
Definition: Permission.php:42
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\PagePermissionRestrictionTest\getPreparedUserAspect
‪UserAspect getPreparedUserAspect(bool $isLoggedIn, bool $isAdmin, int $userId, array $groupIds)
Definition: PagePermissionRestrictionTest.php:34
‪TYPO3\CMS\Core\Context\UserAspect
Definition: UserAspect.php:36