-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Expand file tree
/
Copy pathShareReviewAccessCheckEventTest.php
More file actions
96 lines (72 loc) · 2.55 KB
/
Copy pathShareReviewAccessCheckEventTest.php
File metadata and controls
96 lines (72 loc) · 2.55 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
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace lib\Share20\Events;
use OCP\Share\Events\ShareReviewAccessCheckEvent;
use PHPUnit\Framework\TestCase;
final class ShareReviewAccessCheckEventTest extends TestCase {
private function makeEvent(): ShareReviewAccessCheckEvent {
return new ShareReviewAccessCheckEvent('MyApp', '42');
}
public function testInitialState(): void {
$event = $this->makeEvent();
$this->assertFalse($event->isHandled());
$this->assertFalse($event->isGranted());
$this->assertNull($event->getReason());
}
public function testConstructorPayload(): void {
$event = new ShareReviewAccessCheckEvent('Deck', '99');
$this->assertSame('Deck', $event->getSourceName());
$this->assertSame('99', $event->getShareId());
}
public function testGrantAccess(): void {
$event = $this->makeEvent();
$event->grantAccess();
$this->assertTrue($event->isHandled());
$this->assertTrue($event->isGranted());
$this->assertNull($event->getReason());
$this->assertFalse($event->isPropagationStopped());
}
public function testDenyAccess(): void {
$event = $this->makeEvent();
$event->denyAccess('not in group');
$this->assertTrue($event->isHandled());
$this->assertFalse($event->isGranted());
$this->assertSame('not in group', $event->getReason());
}
public function testDenyStopsPropagation(): void {
$event = $this->makeEvent();
$event->denyAccess('no access');
$this->assertTrue($event->isPropagationStopped());
}
public function testGrantDoesNotStopPropagation(): void {
$event = $this->makeEvent();
$event->grantAccess();
$this->assertFalse($event->isPropagationStopped());
}
public function testGrantThenDenyIsDenied(): void {
$event = $this->makeEvent();
$event->grantAccess();
$event->denyAccess('revoked');
$this->assertFalse($event->isGranted());
$this->assertSame('revoked', $event->getReason());
$this->assertTrue($event->isPropagationStopped());
}
public function testDenyThenGrantRemainesDenied(): void {
$event = $this->makeEvent();
$event->denyAccess('not allowed');
$event->grantAccess(); // must be ignored — deny wins
$this->assertFalse($event->isGranted());
$this->assertSame('not allowed', $event->getReason());
}
public function testMultipleGrantsAreIdempotent(): void {
$event = $this->makeEvent();
$event->grantAccess();
$event->grantAccess();
$this->assertTrue($event->isGranted());
$this->assertFalse($event->isPropagationStopped());
}
}