summaryrefslogtreecommitdiff
path: root/tests/units/Core/User/GroupSyncTest.php
blob: decb2fdcba5b2a440bca6a50201c2ad1a7143c72 (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__.'/../../Base.php';

use Kanboard\Core\User\GroupSync;
use Kanboard\Model\Group;
use Kanboard\Model\GroupMember;

class GroupSyncTest extends Base
{
    public function testAddGroups()
    {
        $group = new Group($this->container);
        $groupMember = new GroupMember($this->container);
        $groupSync = new GroupSync($this->container);

        $this->assertEquals(1, $group->create('My Group 1', 'externalId1'));
        $this->assertEquals(2, $group->create('My Group 2', 'externalId2'));

        $this->assertTrue($groupMember->addUser(1, 1));

        $this->assertTrue($groupMember->isMember(1, 1));
        $this->assertFalse($groupMember->isMember(2, 1));

        $groupSync->synchronize(1, array('externalId1', 'externalId2', 'externalId3'));

        $this->assertTrue($groupMember->isMember(1, 1));
        $this->assertTrue($groupMember->isMember(2, 1));
    }

    public function testRemoveGroups()
    {
        $group = new Group($this->container);
        $groupMember = new GroupMember($this->container);
        $groupSync = new GroupSync($this->container);

        $this->assertEquals(1, $group->create('My Group 1', 'externalId1'));
        $this->assertEquals(2, $group->create('My Group 2', 'externalId2'));

        $this->assertTrue($groupMember->addUser(1, 1));

        $this->assertTrue($groupMember->isMember(1, 1));
        $this->assertFalse($groupMember->isMember(2, 1));

        $groupSync->synchronize(1, array('externalId3'));

        $this->assertFalse($groupMember->isMember(1, 1));
        $this->assertFalse($groupMember->isMember(2, 1));
    }

    public function testBoth()
    {
        $group = new Group($this->container);
        $groupMember = new GroupMember($this->container);
        $groupSync = new GroupSync($this->container);

        $this->assertEquals(1, $group->create('My Group 1', 'externalId1'));
        $this->assertEquals(2, $group->create('My Group 2', 'externalId2'));
        $this->assertEquals(3, $group->create('My Group 3', 'externalId3'));

        $this->assertTrue($groupMember->addUser(1, 1));
        $this->assertTrue($groupMember->addUser(2, 1));

        $this->assertTrue($groupMember->isMember(1, 1));
        $this->assertTrue($groupMember->isMember(2, 1));
        $this->assertFalse($groupMember->isMember(3, 1));

        $groupSync->synchronize(1, array('externalId1', 'externalId3'));

        $this->assertTrue($groupMember->isMember(1, 1));
        $this->assertFalse($groupMember->isMember(2, 1));
        $this->assertTrue($groupMember->isMember(3, 1));
    }

    public function testThatInternalGroupsAreNotTouched()
    {
        $group = new Group($this->container);
        $groupMember = new GroupMember($this->container);
        $groupSync = new GroupSync($this->container);

        $this->assertEquals(1, $group->create('My Group 1'));
        $this->assertTrue($groupMember->addUser(1, 1));
        $this->assertTrue($groupMember->isMember(1, 1));

        $groupSync->synchronize(1, array('externalId3'));

        $this->assertTrue($groupMember->isMember(1, 1));
    }
}