summaryrefslogtreecommitdiff
path: root/tests/units/Model/ColumnMoveRestrictionModelTest.php
blob: 9227012b2f25a9d6d3d4177808b5243dc12b87fc (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

use Kanboard\Model\ColumnMoveRestrictionModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\ProjectRoleModel;

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

class ColumnMoveRestrictionModelTest extends Base
{
    public function testCreation()
    {
        $projectModel = new ProjectModel($this->container);
        $projectRoleModel = new ProjectRoleModel($this->container);
        $columnMoveRestrictionModel = new ColumnMoveRestrictionModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
        $this->assertEquals(1, $projectRoleModel->create(1, 'Custom Role'));
        $this->assertEquals(1, $columnMoveRestrictionModel->create(1, 1, 2, 3));
        $this->assertFalse($columnMoveRestrictionModel->create(1, 1, 2, 3));
    }

    public function testRemove()
    {
        $projectModel = new ProjectModel($this->container);
        $projectRoleModel = new ProjectRoleModel($this->container);
        $columnMoveRestrictionModel = new ColumnMoveRestrictionModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
        $this->assertEquals(1, $projectRoleModel->create(1, 'Custom Role'));
        $this->assertEquals(1, $columnMoveRestrictionModel->create(1, 1, 2, 3));
        $this->assertTrue($columnMoveRestrictionModel->remove(1));
    }

    public function testGetAll()
    {
        $projectModel = new ProjectModel($this->container);
        $projectRoleModel = new ProjectRoleModel($this->container);
        $columnMoveRestrictionModel = new ColumnMoveRestrictionModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
        $this->assertEquals(2, $projectModel->create(array('name' => 'Test')));

        $this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
        $this->assertEquals(2, $projectRoleModel->create(1, 'Role B'));
        $this->assertEquals(3, $projectRoleModel->create(2, 'Role C'));

        $this->assertEquals(1, $columnMoveRestrictionModel->create(1, 1, 2, 3));
        $this->assertEquals(2, $columnMoveRestrictionModel->create(1, 2, 3, 4));

        $restrictions = $columnMoveRestrictionModel->getAll(1);
        $this->assertCount(2, $restrictions);

        $this->assertEquals(1, $restrictions[0]['restriction_id']);
        $this->assertEquals('Role A', $restrictions[0]['role']);
        $this->assertEquals('Ready', $restrictions[0]['src_column_title']);
        $this->assertEquals('Work in progress', $restrictions[0]['dst_column_title']);
        $this->assertEquals(2, $restrictions[0]['src_column_id']);
        $this->assertEquals(3, $restrictions[0]['dst_column_id']);

        $this->assertEquals(2, $restrictions[1]['restriction_id']);
        $this->assertEquals('Role B', $restrictions[1]['role']);
        $this->assertEquals('Work in progress', $restrictions[1]['src_column_title']);
        $this->assertEquals('Done', $restrictions[1]['dst_column_title']);
        $this->assertEquals(3, $restrictions[1]['src_column_id']);
        $this->assertEquals(4, $restrictions[1]['dst_column_id']);
    }

    public function testIsAllowed()
    {
        $projectModel = new ProjectModel($this->container);
        $projectRoleModel = new ProjectRoleModel($this->container);
        $columnMoveRestrictionModel = new ColumnMoveRestrictionModel($this->container);

        $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
        $this->assertEquals(2, $projectModel->create(array('name' => 'Test')));

        $this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
        $this->assertEquals(2, $projectRoleModel->create(1, 'Role B'));
        $this->assertEquals(3, $projectRoleModel->create(2, 'Role C'));

        $this->assertEquals(1, $columnMoveRestrictionModel->create(1, 1, 2, 3));
        $this->assertEquals(2, $columnMoveRestrictionModel->create(1, 2, 3, 4));

        $this->assertTrue($columnMoveRestrictionModel->isAllowed(1, 'Role D', 1, 2));
        $this->assertTrue($columnMoveRestrictionModel->isAllowed(1, 'Role A', 1, 2));
        $this->assertFalse($columnMoveRestrictionModel->isAllowed(1, 'Role A', 2, 3));
    }
}