summaryrefslogtreecommitdiff
path: root/tests/units/Model/TaskExternalLinkTest.php
diff options
context:
space:
mode:
author85pando <85pando@googlemail.com>2016-02-05 10:28:40 +0100
committer85pando <85pando@googlemail.com>2016-02-05 10:28:40 +0100
commit791d13c87bf510d913973b77a5f6d152311a1d87 (patch)
tree81412e8dbd3ac4fa0047030a6068afafd975687e /tests/units/Model/TaskExternalLinkTest.php
parent2074aaaa9a75455097e4e77ca09f4fba3e567052 (diff)
parent12aaec03b19a07635f59b00f532c92c37ac1df5f (diff)
Merge remote-tracking branch 'refs/remotes/upstream/master'
Conflicts: app/Locale/de_DE/translations.php
Diffstat (limited to 'tests/units/Model/TaskExternalLinkTest.php')
-rw-r--r--tests/units/Model/TaskExternalLinkTest.php123
1 files changed, 123 insertions, 0 deletions
diff --git a/tests/units/Model/TaskExternalLinkTest.php b/tests/units/Model/TaskExternalLinkTest.php
new file mode 100644
index 00000000..28ccab83
--- /dev/null
+++ b/tests/units/Model/TaskExternalLinkTest.php
@@ -0,0 +1,123 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\Project;
+use Kanboard\Model\TaskExternalLink;
+use Kanboard\Core\ExternalLink\ExternalLinkManager;
+use Kanboard\ExternalLink\WebLinkProvider;
+
+class TaskExternalLinkTest extends Base
+{
+ public function testCreate()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskExternalLinkModel = new TaskExternalLink($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' => 'http://kanboard.net/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related')));
+
+ $link = $taskExternalLinkModel->getById(1);
+ $this->assertNotEmpty($link);
+ $this->assertEquals('My website', $link['title']);
+ $this->assertEquals('http://kanboard.net/', $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()
+ {
+ $this->container['sessionStorage']->user = array('id' => 1);
+
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskExternalLinkModel = new TaskExternalLink($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' => 'http://kanboard.net/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related')));
+
+ $link = $taskExternalLinkModel->getById(1);
+ $this->assertNotEmpty($link);
+ $this->assertEquals('My website', $link['title']);
+ $this->assertEquals('http://kanboard.net/', $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 Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskExternalLinkModel = new TaskExternalLink($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' => 'http://kanboard.net/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related')));
+
+ sleep(1);
+
+ $this->assertTrue($taskExternalLinkModel->update(array('id' => 1, 'url' => 'https://kanboard.net/')));
+
+ $link = $taskExternalLinkModel->getById(1);
+ $this->assertNotEmpty($link);
+ $this->assertEquals('https://kanboard.net/', $link['url']);
+ $this->assertEquals(time(), $link['date_modification'], '', 2);
+ }
+
+ public function testRemove()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskExternalLinkModel = new TaskExternalLink($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' => 'http://kanboard.net/', '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()
+ {
+ $this->container['sessionStorage']->user = array('id' => 1);
+ $this->container['externalLinkManager'] = new ExternalLinkManager($this->container);
+
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskExternalLinkModel = new TaskExternalLink($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' => 'http://kanboard.net/', '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']);
+ }
+}