‪TYPO3CMS  ‪main
AbstractRestrictionContainerTest.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 PHPUnit\Framework\Attributes\Test;
26 
28 {
29  #[Test]
31  {
32  $restriction = $this->createMock(MockEnforceableQueryRestriction::class);
33  $restriction->expects(self::atLeastOnce())->method('buildExpression')->with(['aTable' => 'aTable'], $this->expressionBuilder)
34  ->willReturn(‪CompositeExpression::and('"aTable"."pid" = 0'));
35  $restriction->method('isEnforced')->willReturn(true);
36 
38  $subject->add($restriction);
39  $subject->removeAll();
40 
41  $expression = $subject->buildExpression(['aTable' => 'aTable'], $this->expressionBuilder);
42  self::assertSame('"aTable"."pid" = 0', (string)$expression);
43  }
44 
45  #[Test]
47  {
48  $restriction = $this->createMock(MockEnforceableQueryRestriction::class);
49  $restriction->expects(self::never())->method('buildExpression');
50  $restriction->method('isEnforced')->willReturn(true);
51 
53  $subject->add($restriction);
54  $subject->removeByType(get_class($restriction));
55 
56  $expression = $subject->buildExpression(['aTable' => 'aTable'], $this->expressionBuilder);
57  self::assertSame('', (string)$expression);
58  }
59 
60  #[Test]
62  {
63  $restriction = new class () extends ‪HiddenRestriction {};
64 
66  $subject->add($restriction);
67  $subject->removeByType(HiddenRestriction::class);
68 
69  ‪$GLOBALS['TCA']['aTable']['ctrl']['enablecolumns']['disabled'] = 'hidden';
70  $expression = $subject->buildExpression(['aTable' => 'aTable'], $this->expressionBuilder);
71  self::assertSame('', (string)$expression);
72  }
73 
74  #[Test]
76  {
77  $restriction = $this->createMock(MockEnforceableQueryRestriction::class);
78  $restriction->expects(self::never())->method('buildExpression');
79  $restriction->method('isEnforced')->willReturn(true);
80 
82  $subject->add($restriction);
83  $subject->removeByType(get_class($restriction));
84  $subject->removeAll();
85 
86  $expression = $subject->buildExpression(['aTable' => 'aTable'], $this->expressionBuilder);
87  self::assertSame('', (string)$expression);
88  }
89 
90  #[Test]
92  {
93  $restriction = $this->createMock(MockQueryRestriction::class);
94  $restriction->expects(self::never())->method('buildExpression');
95 
97  $subject->add($restriction);
98  $subject->removeAll();
99 
100  $expression = $subject->buildExpression(['aTable' => 'aTable'], $this->expressionBuilder);
101  self::assertSame('', (string)$expression);
102  }
103 
104  #[Test]
106  {
107  $restriction = $this->createMock(MockEnforceableQueryRestriction::class);
108  $restriction->expects(self::never())->method('buildExpression');
109  $restriction->method('isEnforced')->willReturn(false);
110 
112  $subject->add($restriction);
113  $subject->removeAll();
114 
115  $expression = $subject->buildExpression(['aTable' => 'aTable'], $this->expressionBuilder);
116  self::assertSame('', (string)$expression);
117  }
118 }
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\AbstractRestrictionContainerTest
Definition: AbstractRestrictionContainerTest.php:28
‪TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction
Definition: HiddenRestriction.php:27
‪TYPO3\CMS\Core\Tests\Unit\Database\Mocks\MockEnforceableQueryRestriction
Definition: MockEnforceableQueryRestriction.php:23
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\AbstractRestrictionContainerTest\enforceableRestrictionsThatDeclareThemselvesNonStickyAreRemovedWhenRemoveAllIsCalled
‪enforceableRestrictionsThatDeclareThemselvesNonStickyAreRemovedWhenRemoveAllIsCalled()
Definition: AbstractRestrictionContainerTest.php:105
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\AbstractRestrictionContainerTest\notEnforceableRestrictionsAreRemovedWhenRemoveAllIsCalled
‪notEnforceableRestrictionsAreRemovedWhenRemoveAllIsCalled()
Definition: AbstractRestrictionContainerTest.php:91
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\AbstractRestrictionContainerTest\enforceableRestrictionsAreKeptWhenRemoveAllIsCalled
‪enforceableRestrictionsAreKeptWhenRemoveAllIsCalled()
Definition: AbstractRestrictionContainerTest.php:30
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression\and
‪static and($part=null,... $parts)
Definition: CompositeExpression.php:85
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction
Definition: AbstractRestrictionContainerTest.php:18
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:27
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\AbstractRestrictionContainerTest\enforceableRestrictionsWillBeRemovedWhenRemovedByType
‪enforceableRestrictionsWillBeRemovedWhenRemovedByType()
Definition: AbstractRestrictionContainerTest.php:46
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\AbstractRestrictionTestCase
Definition: AbstractRestrictionTestCase.php:27
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\AbstractRestrictionContainerTest\enforceableRestrictionsWillBeRemovedWhenRemovedByTypeAndRemovedAllIsAdditionallyCalled
‪enforceableRestrictionsWillBeRemovedWhenRemovedByTypeAndRemovedAllIsAdditionallyCalled()
Definition: AbstractRestrictionContainerTest.php:75
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\AbstractRestrictionContainerTest\crossClassWillBeRemovedWhenRemovedByType
‪crossClassWillBeRemovedWhenRemovedByType()
Definition: AbstractRestrictionContainerTest.php:61
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Unit\Database\Mocks\InstantiatableAbstractRestrictionContainer
Definition: InstantiatableAbstractRestrictionContainer.php:22
‪TYPO3\CMS\Core\Tests\Unit\Database\Mocks\MockQueryRestriction
Definition: MockQueryRestriction.php:25