-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractDetectorTest.php
More file actions
118 lines (97 loc) · 3.56 KB
/
Copy pathAbstractDetectorTest.php
File metadata and controls
118 lines (97 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
declare(strict_types=1);
/*
* This file is part of the "typo3_login_warning" TYPO3 CMS extension.
*
* (c) 2025-2026 Konrad Michalik <km@move-elevator.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MoveElevator\Typo3LoginWarning\Tests\Unit\Detector;
use KonradMichalik\Ttt\Attribute\WithTypo3ConfVars;
use MoveElevator\Typo3LoginWarning\Detector\AbstractDetector;
use PHPUnit\Framework\TestCase;
/**
* AbstractDetectorTest.
*
* @author Konrad Michalik <km@move-elevator.de>
* @license GPL-2.0-or-later
*/
final class AbstractDetectorTest extends TestCase
{
private AbstractDetectorTestDouble $subject;
protected function setUp(): void
{
$this->subject = new AbstractDetectorTestDouble();
}
public function testShouldDetectForUserReturnsTrueWithoutRestrictions(): void
{
$userArray = $this->createUserArray();
self::assertTrue($this->subject->exposeShouldDetectForUser($userArray, []));
}
public function testShouldDetectForUserReturnsTrueForAdminWhenAffectedUsersIsAdmins(): void
{
$userArray = $this->createUserArray(isAdmin: true);
self::assertTrue($this->subject->exposeShouldDetectForUser($userArray, ['affectedUsers' => 'admins']));
}
public function testShouldDetectForUserReturnsFalseForNonAdminWhenAffectedUsersIsAdmins(): void
{
$userArray = $this->createUserArray(isAdmin: false);
self::assertFalse($this->subject->exposeShouldDetectForUser($userArray, ['affectedUsers' => 'admins']));
}
#[WithTypo3ConfVars(['SYS' => ['systemMaintainers' => [1, 2]]])]
public function testShouldDetectForUserReturnsTrueForSystemMaintainerWhenAffectedUsersIsMaintainers(): void
{
$userArray = $this->createUserArray(uid: 1);
self::assertTrue($this->subject->exposeShouldDetectForUser($userArray, ['affectedUsers' => 'maintainers']));
}
#[WithTypo3ConfVars(['SYS' => ['systemMaintainers' => [2, 3]]])]
public function testShouldDetectForUserReturnsFalseForNonSystemMaintainerWhenAffectedUsersIsMaintainers(): void
{
$userArray = $this->createUserArray(uid: 1);
self::assertFalse($this->subject->exposeShouldDetectForUser($userArray, ['affectedUsers' => 'maintainers']));
}
public function testShouldDetectForUserReturnsTrueWhenAffectedUsersIsAll(): void
{
$userArray = $this->createUserArray(isAdmin: false);
self::assertTrue($this->subject->exposeShouldDetectForUser($userArray, [
'affectedUsers' => 'all',
]));
}
/**
* @return array<string, mixed>
*/
private function createUserArray(bool $isAdmin = false, int $uid = 1): array
{
return [
'uid' => $uid,
'admin' => $isAdmin,
];
}
}
/**
* AbstractDetectorTestDouble.
*
* @author Konrad Michalik <km@move-elevator.de>
* @license GPL-2.0-or-later
*/
class AbstractDetectorTestDouble extends AbstractDetector
{
/**
* @param array<string, mixed> $userArray
* @param array<string, mixed> $configuration
*/
public function detect(array $userArray, array $configuration = [], ?\Psr\Http\Message\ServerRequestInterface $request = null): bool
{
return true;
}
/**
* @param array<string, mixed> $userArray
* @param array<string, mixed> $configuration
*/
public function exposeShouldDetectForUser(array $userArray, array $configuration): bool
{
return $this->shouldDetectForUser($userArray, $configuration);
}
}