summaryrefslogtreecommitdiff
path: root/tests/integration/ProjectPermissionTest.php
blob: 3ceda07df718dd5d7e50dd60ba83dddbd36ebeb3 (plain)
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
<?php

require_once __DIR__.'/BaseIntegrationTest.php';

class ProjectPermissionTest extends BaseIntegrationTest
{
    protected $projectName = 'Project with permission';
    protected $username = 'user-project-permission';
    protected $groupName1 = 'My group A for project permission';
    protected $groupName2 = 'My group B for project permission';

    public function testAll()
    {
        $this->assertCreateTeamProject();
        $this->assertCreateGroups();
        $this->assertCreateUser();

        $this->assertAddProjectUser();
        $this->assertGetProjectUsers();
        $this->assertGetAssignableUsers();
        $this->assertChangeProjectUserRole();
        $this->assertRemoveProjectUser();

        $this->assertAddProjectGroup();
        $this->assertGetProjectUsers();
        $this->assertGetAssignableUsers();
        $this->assertChangeProjectGroupRole();
        $this->assertRemoveProjectGroup();
    }

    public function assertAddProjectUser()
    {
        $this->assertTrue($this->app->addProjectUser($this->projectId, $this->userId));
    }

    public function assertGetProjectUsers()
    {
        $members = $this->app->getProjectUsers($this->projectId);
        $this->assertCount(1, $members);
        $this->assertArrayHasKey($this->userId, $members);
        $this->assertEquals($this->username, $members[$this->userId]);
    }

    public function assertGetAssignableUsers()
    {
        $members = $this->app->getAssignableUsers($this->projectId);
        $this->assertCount(1, $members);
        $this->assertArrayHasKey($this->userId, $members);
        $this->assertEquals($this->username, $members[$this->userId]);
    }

    public function assertChangeProjectUserRole()
    {
        $this->assertTrue($this->app->changeProjectUserRole($this->projectId, $this->userId, 'project-viewer'));

        $members = $this->app->getAssignableUsers($this->projectId);
        $this->assertCount(0, $members);
    }

    public function assertRemoveProjectUser()
    {
        $this->assertTrue($this->app->removeProjectUser($this->projectId, $this->userId));

        $members = $this->app->getProjectUsers($this->projectId);
        $this->assertCount(0, $members);
    }

    public function assertAddProjectGroup()
    {
        $this->assertTrue($this->app->addGroupMember($this->groupId1, $this->userId));
        $this->assertTrue($this->app->addProjectGroup($this->projectId, $this->groupId1));
    }

    public function assertChangeProjectGroupRole()
    {
        $this->assertTrue($this->app->changeProjectGroupRole($this->projectId, $this->groupId1, 'project-viewer'));

        $members = $this->app->getAssignableUsers($this->projectId);
        $this->assertCount(0, $members);
    }

    public function assertRemoveProjectGroup()
    {
        $this->assertTrue($this->app->removeProjectGroup($this->projectId, $this->groupId1));

        $members = $this->app->getProjectUsers($this->projectId);
        $this->assertCount(0, $members);
    }
}