summaryrefslogtreecommitdiff
path: root/tests/units/Model/GroupTest.php
blob: 2cbb254a36255d70ae98d29456061d94ca579bb4 (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
<?php

require_once __DIR__.'/../Base.php';

use Kanboard\Model\Group;

class GroupTest extends Base
{
    public function testCreation()
    {
        $groupModel = new Group($this->container);
        $this->assertEquals(1, $groupModel->create('Test'));
        $this->assertFalse($groupModel->create('Test'));
    }

    public function testGetById()
    {
        $groupModel = new Group($this->container);
        $this->assertEquals(1, $groupModel->create('Test'));

        $group = $groupModel->getById(1);
        $this->assertEquals('Test', $group['name']);
        $this->assertEquals('', $group['external_id']);

        $this->assertEmpty($groupModel->getById(2));
    }

    public function testGetAll()
    {
        $groupModel = new Group($this->container);
        $this->assertEquals(1, $groupModel->create('B'));
        $this->assertEquals(2, $groupModel->create('A', 'uuid'));

        $groups = $groupModel->getAll();
        $this->assertCount(2, $groups);
        $this->assertEquals('A', $groups[0]['name']);
        $this->assertEquals('uuid', $groups[0]['external_id']);
        $this->assertEquals('B', $groups[1]['name']);
        $this->assertEquals('', $groups[1]['external_id']);
    }

    public function testUpdate()
    {
        $groupModel = new Group($this->container);
        $this->assertEquals(1, $groupModel->create('Test'));
        $this->assertTrue($groupModel->update(array('id' => 1, 'name' => 'My group', 'external_id' => 'test')));

        $group = $groupModel->getById(1);
        $this->assertEquals('My group', $group['name']);
        $this->assertEquals('test', $group['external_id']);
    }

    public function testRemove()
    {
        $groupModel = new Group($this->container);
        $this->assertEquals(1, $groupModel->create('Test'));
        $this->assertTrue($groupModel->remove(1));
        $this->assertEmpty($groupModel->getById(1));
    }

    public function testValidateCreation()
    {
        $groupModel = new Group($this->container);

        $result = $groupModel->validateCreation(array('name' => 'Test'));
        $this->assertTrue($result[0]);

        $result = $groupModel->validateCreation(array('name' => ''));
        $this->assertFalse($result[0]);
    }

    public function testValidateModification()
    {
        $groupModel = new Group($this->container);

        $result = $groupModel->validateModification(array('name' => 'Test', 'id' => 1));
        $this->assertTrue($result[0]);

        $result = $groupModel->validateModification(array('name' => 'Test'));
        $this->assertFalse($result[0]);
    }
}