summaryrefslogtreecommitdiff
path: root/tests/units/Model/LinkTest.php
blob: 600c09f349d87117c8265af7b6edf80cde4c536c (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php

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

use Kanboard\Model\LinkModel;

class LinkTest extends Base
{
    public function testCreateLink()
    {
        $l = new LinkModel($this->container);

        $this->assertNotFalse($l->create('Link A'));
        $this->assertFalse($l->create('Link A'));
        $this->assertNotFalse($l->create('Link B', 'Link C'));

        $links = $l->getAll();
        $this->assertNotEmpty($links);
        $this->assertCount(14, $links);

        $link = $l->getByLabel('Link A');
        $this->assertNotEmpty($link);
        $this->assertEquals('Link A', $link['label']);
        $this->assertEquals(0, $link['opposite_id']);

        $link1 = $l->getByLabel('Link B');
        $this->assertNotEmpty($link1);
        $this->assertEquals('Link B', $link1['label']);
        $this->assertNotEmpty($link1['opposite_id']);

        $link2 = $l->getByLabel('Link C');
        $this->assertNotEmpty($link2);
        $this->assertEquals('Link C', $link2['label']);
        $this->assertNotEmpty($link2['opposite_id']);

        $this->assertNotEquals($link1['opposite_id'], $link2['opposite_id']);
    }

    public function testGetOppositeLinkId()
    {
        $l = new LinkModel($this->container);

        $this->assertNotFalse($l->create('Link A'));
        $this->assertNotFalse($l->create('Link B', 'Link C'));

        $this->assertEquals(1, $l->getOppositeLinkId(1));
        $this->assertEquals(3, $l->getOppositeLinkId(2));
        $this->assertEquals(2, $l->getOppositeLinkId(3));
    }

    public function testUpdate()
    {
        $l = new LinkModel($this->container);

        $this->assertTrue($l->update(array('id' => 2, 'label' => 'test', 'opposite_id' => 0)));

        $link = $l->getById(2);
        $this->assertNotEmpty($link);
        $this->assertEquals('test', $link['label']);
        $this->assertEquals(0, $link['opposite_id']);
    }

    public function testRemove()
    {
        $l = new LinkModel($this->container);

        $link = $l->getById(3);
        $this->assertNotEmpty($link);
        $this->assertEquals('is blocked by', $link['label']);
        $this->assertEquals(2, $link['opposite_id']);

        $this->assertTrue($l->remove(2));

        $link = $l->getById(2);
        $this->assertEmpty($link);

        $link = $l->getById(3);
        $this->assertNotEmpty($link);
        $this->assertEquals('is blocked by', $link['label']);
        $this->assertEquals(0, $link['opposite_id']);
    }

    public function testGetMergedList()
    {
        $l = new LinkModel($this->container);
        $links = $l->getMergedList();

        $this->assertNotEmpty($links);
        $this->assertCount(11, $links);
        $this->assertEquals('blocks', $links[1]['label']);
        $this->assertEquals('is blocked by', $links[1]['opposite_label']);
    }

    public function testGetList()
    {
        $l = new LinkModel($this->container);
        $links = $l->getList();

        $this->assertNotEmpty($links);
        $this->assertCount(12, $links);
        $this->assertEquals('', $links[0]);
        $this->assertEquals('relates to', $links[1]);

        $links = $l->getList(1);

        $this->assertNotEmpty($links);
        $this->assertCount(11, $links);
        $this->assertEquals('', $links[0]);
        $this->assertArrayNotHasKey(1, $links);
        $this->assertEquals('blocks', $links[2]);

        $links = $l->getList(1, false);

        $this->assertNotEmpty($links);
        $this->assertCount(10, $links);
        $this->assertArrayNotHasKey(0, $links);
        $this->assertArrayNotHasKey(1, $links);
        $this->assertEquals('blocks', $links[2]);

        $links = $l->getList(0, false);

        $this->assertNotEmpty($links);
        $this->assertCount(11, $links);
        $this->assertArrayNotHasKey(0, $links);
        $this->assertEquals('relates to', $links[1]);
    }
}