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
|
<?php
require_once __DIR__.'/../Base.php';
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskExternalLinkModel;
use Kanboard\Core\ExternalLink\ExternalLinkManager;
use Kanboard\ExternalLink\WebLinkProvider;
class TaskExternalLinkTest extends Base
{
public function testCreate()
{
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskExternalLinkModel = new TaskExternalLinkModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1)));
$this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'https://kanboard.org/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related')));
$link = $taskExternalLinkModel->getById(1);
$this->assertNotEmpty($link);
$this->assertEquals('My website', $link['title']);
$this->assertEquals('https://kanboard.org/', $link['url']);
$this->assertEquals('related', $link['dependency']);
$this->assertEquals('weblink', $link['link_type']);
$this->assertEquals(0, $link['creator_id']);
$this->assertEquals(time(), $link['date_modification'], '', 2);
$this->assertEquals(time(), $link['date_creation'], '', 2);
}
public function testCreateWithUserSession()
{
$_SESSION['user'] = array('id' => 1);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskExternalLinkModel = new TaskExternalLinkModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1)));
$this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'https://kanboard.org/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related')));
$link = $taskExternalLinkModel->getById(1);
$this->assertNotEmpty($link);
$this->assertEquals('My website', $link['title']);
$this->assertEquals('https://kanboard.org/', $link['url']);
$this->assertEquals('related', $link['dependency']);
$this->assertEquals('weblink', $link['link_type']);
$this->assertEquals(1, $link['creator_id']);
$this->assertEquals(time(), $link['date_modification'], '', 2);
$this->assertEquals(time(), $link['date_creation'], '', 2);
}
public function testModification()
{
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskExternalLinkModel = new TaskExternalLinkModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1)));
$this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'https://kanboard.org/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related')));
sleep(1);
$this->assertTrue($taskExternalLinkModel->update(array('id' => 1, 'url' => 'https://kanboard.org/')));
$link = $taskExternalLinkModel->getById(1);
$this->assertNotEmpty($link);
$this->assertEquals('https://kanboard.org/', $link['url']);
$this->assertEquals(time(), $link['date_modification'], '', 2);
}
public function testRemove()
{
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskExternalLinkModel = new TaskExternalLinkModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1)));
$this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'https://kanboard.org/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related')));
$this->assertTrue($taskExternalLinkModel->remove(1));
$this->assertFalse($taskExternalLinkModel->remove(1));
$this->assertEmpty($taskExternalLinkModel->getById(1));
}
public function testGetAll()
{
$_SESSION['user'] = array('id' => 1);
$this->container['externalLinkManager'] = new ExternalLinkManager($this->container);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskExternalLinkModel = new TaskExternalLinkModel($this->container);
$webLinkProvider = new WebLinkProvider($this->container);
$this->container['externalLinkManager']->register($webLinkProvider);
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1)));
$this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'url' => 'https://miniflux.net/', 'title' => 'MX', 'link_type' => 'weblink', 'dependency' => 'related')));
$this->assertEquals(2, $taskExternalLinkModel->create(array('task_id' => 1, 'url' => 'https://kanboard.org/', 'title' => 'KB', 'link_type' => 'weblink', 'dependency' => 'related')));
$links = $taskExternalLinkModel->getAll(1);
$this->assertCount(2, $links);
$this->assertEquals('KB', $links[0]['title']);
$this->assertEquals('MX', $links[1]['title']);
$this->assertEquals('Web Link', $links[0]['type']);
$this->assertEquals('Web Link', $links[1]['type']);
$this->assertEquals('Related', $links[0]['dependency_label']);
$this->assertEquals('Related', $links[1]['dependency_label']);
$this->assertEquals('admin', $links[0]['creator_username']);
$this->assertEquals('admin', $links[1]['creator_username']);
$this->assertEquals('', $links[0]['creator_name']);
$this->assertEquals('', $links[1]['creator_name']);
}
}
|