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

require_once __DIR__.'/Base.php';

class ProjectPermissionTest extends Base
{
    public function testGetProjectUsers()
    {
        $this->assertNotFalse($this->app->createProject('Test'));
        $this->assertNotFalse($this->app->createGroup('Test'));

        $projectId = $this->getProjectId();
        $groupId = $this->getGroupId();

        $this->assertTrue($this->app->addGroupMember($projectId, $groupId));
        $this->assertSame(array(), $this->app->getProjectUsers($projectId));
    }

    public function testProjectUser()
    {
        $projectId = $this->getProjectId();
        $this->assertTrue($this->app->addProjectUser($projectId, 1));

        $users = $this->app->getProjectUsers($projectId);
        $this->assertCount(1, $users);
        $this->assertEquals('admin', $users[1]);

        $users = $this->app->getAssignableUsers($projectId);
        $this->assertCount(1, $users);
        $this->assertEquals('admin', $users[1]);

        $this->assertTrue($this->app->changeProjectUserRole($projectId, 1, 'project-viewer'));

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

        $this->assertTrue($this->app->removeProjectUser($projectId, 1));
        $this->assertSame(array(), $this->app->getProjectUsers($projectId));
    }

    public function testProjectGroup()
    {
        $projectId = $this->getProjectId();
        $groupId = $this->getGroupId();

        $this->assertTrue($this->app->addProjectGroup($projectId, $groupId));

        $users = $this->app->getProjectUsers($projectId);
        $this->assertCount(1, $users);
        $this->assertEquals('admin', $users[1]);

        $users = $this->app->getAssignableUsers($projectId);
        $this->assertCount(1, $users);
        $this->assertEquals('admin', $users[1]);

        $this->assertTrue($this->app->changeProjectGroupRole($projectId, $groupId, 'project-viewer'));

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

        $this->assertTrue($this->app->removeProjectGroup($projectId, 1));
        $this->assertSame(array(), $this->app->getProjectUsers($projectId));
    }
}