|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SourcesTests\Files\Volume; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use CommonTestClass; |
|
7
|
|
|
use kalanis\kw_auth\AuthException; |
|
8
|
|
|
use kalanis\kw_auth\Data\FileGroup; |
|
9
|
|
|
use kalanis\kw_auth\Sources\Files\Volume\Groups; |
|
10
|
|
|
use kalanis\kw_locks\LockException; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class GroupsTest extends CommonTestClass |
|
14
|
|
|
{ |
|
15
|
|
|
protected $sourcePath = ''; |
|
16
|
|
|
|
|
17
|
|
|
protected function setUp(): void |
|
18
|
|
|
{ |
|
19
|
|
|
$this->sourcePath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . '.groups'; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @throws AuthException |
|
24
|
|
|
* @throws LockException |
|
25
|
|
|
*/ |
|
26
|
|
|
public function testGroupManipulation(): void |
|
27
|
|
|
{ |
|
28
|
|
|
$lib = $this->groupSources(); |
|
29
|
|
|
$group = $this->wantedGroup(); |
|
30
|
|
|
|
|
31
|
|
|
// create |
|
32
|
|
|
$lib->createGroup($group); |
|
33
|
|
|
// check data |
|
34
|
|
|
$saved = $lib->getGroupDataOnly($group->getGroupId()); |
|
35
|
|
|
$this->assertEquals('another', $saved->getGroupName()); |
|
36
|
|
|
$this->assertEquals('Testing group', $saved->getGroupDesc()); |
|
37
|
|
|
$this->assertEquals(1001, $saved->getGroupAuthorId()); |
|
38
|
|
|
|
|
39
|
|
|
// update |
|
40
|
|
|
$group->setData( |
|
41
|
|
|
$group->getGroupId(), |
|
42
|
|
|
$group->getGroupName(), |
|
43
|
|
|
1002, |
|
44
|
|
|
'WheĐn yoĐu dđo nođt knđow' |
|
45
|
|
|
); |
|
46
|
|
|
$lib->updateGroup($group); |
|
47
|
|
|
|
|
48
|
|
|
// check data - again with new values |
|
49
|
|
|
$saved = $lib->getGroupDataOnly($group->getGroupId()); |
|
50
|
|
|
$this->assertEquals('When you do not know', $saved->getGroupDesc()); // overwrite this |
|
51
|
|
|
$this->assertEquals(1001, $saved->getGroupAuthorId()); // cannot overwrite this |
|
52
|
|
|
|
|
53
|
|
|
// remove |
|
54
|
|
|
$lib->deleteGroup($group->getGroupId()); |
|
55
|
|
|
// check for existence |
|
56
|
|
|
$this->assertEmpty($lib->getGroupDataOnly($group->getGroupId())); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @throws AuthException |
|
61
|
|
|
* @throws LockException |
|
62
|
|
|
*/ |
|
63
|
|
|
public function testCreateFail(): void |
|
64
|
|
|
{ |
|
65
|
|
|
$lib = $this->groupSources(); |
|
66
|
|
|
$group = $this->wantedGroup(''); |
|
67
|
|
|
$this->expectException(AuthException::class); |
|
68
|
|
|
$lib->createGroup($group); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @throws AuthException |
|
73
|
|
|
* @throws LockException |
|
74
|
|
|
*/ |
|
75
|
|
|
public function testAllGroups(): void |
|
76
|
|
|
{ |
|
77
|
|
|
$lib = $this->groupSources(); |
|
78
|
|
|
$data = $lib->readGroup(); |
|
79
|
|
|
$this->assertEquals('Maintainers', $data[0]->getGroupDesc()); |
|
80
|
|
|
$this->assertEquals(1000, $data[1]->getGroupAuthorId()); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Contains a full comedy/tragedy of work with locks |
|
85
|
|
|
* @throws LockException |
|
86
|
|
|
* @return Groups |
|
87
|
|
|
*/ |
|
88
|
|
|
protected function groupSources(): Groups |
|
89
|
|
|
{ |
|
90
|
|
|
return new Groups( |
|
91
|
|
|
$this->getLockPath(), |
|
92
|
|
|
$this->sourcePath |
|
93
|
|
|
); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
protected function wantedGroup($name = 'another'): FileGroup |
|
97
|
|
|
{ |
|
98
|
|
|
$user = new FileGroup(); |
|
99
|
|
|
$user->setData(3, $name, 1001, 'Testing group'); |
|
100
|
|
|
return $user; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|