‪TYPO3CMS  ‪main
RecordAccessVoterTest.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 
20 use Psr\EventDispatcher\EventDispatcherInterface;
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 final class ‪RecordAccessVoterTest extends FunctionalTestCase
28 {
30 
31  protected function ‪setUp(): void
32  {
33  parent::setUp();
34 
35  $this->subject = new ‪RecordAccessVoter(
36  $this->get(EventDispatcherInterface::class)
37  );
38  }
39 
40  public static function ‪accessGrantedTestDataProvider(): \Generator
41  {
42  yield 'No access permissions set' => [
43  'pages',
44  [
45  'uid' => 1,
46  ],
47  true,
48  ];
49  yield 'Record disabled' => [
50  'pages',
51  [
52  'uid' => 1,
53  'hidden' => 1,
54  ],
55  false,
56  ];
57  yield 'Starttime set' => [
58  'pages',
59  [
60  'uid' => 1,
61  'starttime' => 43,
62  ],
63  false,
64  ];
65  yield 'Endtime set' => [
66  'pages',
67  [
68  'uid' => 1,
69  'endtime' => 41,
70  ],
71  false,
72  ];
73  yield 'Invalid endtime' => [
74  'pages',
75  [
76  'uid' => 1,
77  'endtime' => 0,
78  ],
79  true,
80  ];
81  yield 'group access set' => [
82  'pages',
83  [
84  'uid' => 1,
85  'fe_group' => '1,2',
86  ],
87  false,
88  ];
89  yield 'all enable fields set - valid' => [
90  'pages',
91  [
92  'uid' => 1,
93  'hidden' => 0,
94  'starttime' => 41,
95  'endtime' => 43,
96  'fe_group' => '3,4',
97  ],
98  true,
99  ];
100  }
101 
106  public function ‪accessGrantedTest(string $table, array ‪$record, bool $access): void
107  {
108  ‪$GLOBALS['SIM_ACCESS_TIME'] = 42;
109  $context = new ‪Context();
110  $context->setAspect('frontend.user', new ‪UserAspect(null, [3, 4]));
111  self::assertEquals($access, $this->subject->accessGranted($table, ‪$record, $context));
112  }
113 
118  {
119  // Page is available even if the "disabled" flag is set
120  $context = new ‪Context();
121  $context->setAspect('visibility', new ‪VisibilityAspect(includeHiddenPages: true));
122  self::assertTrue($this->subject->accessGranted(
123  'pages',
124  ['uid' => 1, 'hidden' => 1],
125  $context
126  ));
127 
128  // Content is available even if the "disabled" flag is set
129  $context = new ‪Context();
130  $context->setAspect('visibility', new ‪VisibilityAspect(includeHiddenContent: true));
131  self::assertTrue($this->subject->accessGranted(
132  'tt_content',
133  ['uid' => 1, 'hidden' => 1],
134  $context
135  ));
136  }
137 
138  public static function ‪groupAccessGrantedTestDataProvider(): \Generator
139  {
140  yield 'No enable field' => [
141  'aTable',
142  [
143  'uid' => 1,
144  ],
145  true,
146  ];
147  yield 'No group access defined' => [
148  'pages',
149  [
150  'uid' => 1,
151  'fe_group' => '',
152  ],
153  true,
154  ];
155  yield 'Insufficient permissions' => [
156  'pages',
157  [
158  'uid' => 1,
159  'fe_group' => '1,2',
160  ],
161  false,
162  ];
163  yield 'Sufficient permissions' => [
164  'pages',
165  [
166  'uid' => 1,
167  'fe_group' => '3,4',
168  ],
169  true,
170  ];
171  }
172 
177  public function ‪groupAccessGrantedTest(string $table, array ‪$record, bool $access): void
178  {
179  $context = new ‪Context();
180  $context->setAspect('frontend.user', new ‪UserAspect(null, [3, 4]));
181  self::assertEquals($access, $this->subject->groupAccessGranted($table, ‪$record, $context));
182  }
183 
188  {
189  self::assertTrue($this->subject->accessGrantedForPageInRootLine(['uid ' => 1, 'hidden' => 1], new ‪Context()));
190  }
191 }
‪TYPO3\CMS\Core\Context\VisibilityAspect
Definition: VisibilityAspect.php:31
‪TYPO3\CMS\Core\Tests\Functional\Domain\Access\RecordAccessVoterTest\accessGrantedForPageInRootLineReturnsTrueForDisabledExtendToSubpages
‪accessGrantedForPageInRootLineReturnsTrueForDisabledExtendToSubpages()
Definition: RecordAccessVoterTest.php:187
‪TYPO3\CMS\Core\Tests\Functional\Domain\Access\RecordAccessVoterTest\accessGrantedTestDataProvider
‪static accessGrantedTestDataProvider()
Definition: RecordAccessVoterTest.php:40
‪TYPO3\CMS\Core\Tests\Functional\Domain\Access\RecordAccessVoterTest\groupAccessGrantedTestDataProvider
‪static groupAccessGrantedTestDataProvider()
Definition: RecordAccessVoterTest.php:138
‪TYPO3\CMS\Core\Tests\Functional\Domain\Access\RecordAccessVoterTest\groupAccessGrantedTest
‪groupAccessGrantedTest(string $table, array $record, bool $access)
Definition: RecordAccessVoterTest.php:177
‪TYPO3\CMS\Core\Tests\Functional\Domain\Access\RecordAccessVoterTest\accessGrantedTest
‪accessGrantedTest(string $table, array $record, bool $access)
Definition: RecordAccessVoterTest.php:106
‪TYPO3\CMS\Core\Tests\Functional\Domain\Access\RecordAccessVoterTest\$subject
‪RecordAccessVoter $subject
Definition: RecordAccessVoterTest.php:29
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:54
‪TYPO3\CMS\Core\Tests\Functional\Domain\Access\RecordAccessVoterTest
Definition: RecordAccessVoterTest.php:28
‪TYPO3\CMS\Core\Tests\Functional\Domain\Access\RecordAccessVoterTest\accessGrantedRespectsVisibilityAspect
‪accessGrantedRespectsVisibilityAspect()
Definition: RecordAccessVoterTest.php:117
‪TYPO3\CMS\Core\Tests\Functional\Domain\Access\RecordAccessVoterTest\setUp
‪setUp()
Definition: RecordAccessVoterTest.php:31
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Core\Tests\Functional\Domain\Access
Definition: RecordAccessVoterTest.php:18
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Domain\Access\RecordAccessVoter
Definition: RecordAccessVoter.php:29
‪TYPO3\CMS\Core\Context\UserAspect
Definition: UserAspect.php:37