summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-01-30 20:38:20 -0500
committerFrederic Guillot <fred@kanboard.net>2016-01-30 20:38:20 -0500
commit5c92f467867b43034b9e66b46b3b465ba9db655c (patch)
treecb0855ea64d8bba3abe4dfe978c5dbabb745911d /tests
parentec66a779c9158830fe4bb0f96a44eadfe697ef00 (diff)
Add external links for tasks with plugin api
Diffstat (limited to 'tests')
-rw-r--r--tests/units/Core/ExternalLink/ExternalLinkManagerTest.php120
-rw-r--r--tests/units/ExternalLink/AttachmentLinkProviderTest.php64
-rw-r--r--tests/units/ExternalLink/AttachmentLinkTest.php18
-rw-r--r--tests/units/ExternalLink/WebLinkProviderTest.php52
-rw-r--r--tests/units/ExternalLink/WebLinkTest.php57
-rw-r--r--tests/units/Model/TaskExternalLinkTest.php167
-rw-r--r--tests/units/Validator/ExternalLinkValidatorTest.php63
7 files changed, 541 insertions, 0 deletions
diff --git a/tests/units/Core/ExternalLink/ExternalLinkManagerTest.php b/tests/units/Core/ExternalLink/ExternalLinkManagerTest.php
new file mode 100644
index 00000000..d284a80b
--- /dev/null
+++ b/tests/units/Core/ExternalLink/ExternalLinkManagerTest.php
@@ -0,0 +1,120 @@
+<?php
+
+require_once __DIR__.'/../../Base.php';
+
+use Kanboard\Core\ExternalLink\ExternalLinkManager;
+use Kanboard\ExternalLink\WebLinkProvider;
+use Kanboard\ExternalLink\AttachmentLinkProvider;
+
+class ExternalLinkManagerTest extends Base
+{
+ public function testRegister()
+ {
+ $externalLinkManager = new ExternalLinkManager($this->container);
+ $webLinkProvider = new WebLinkProvider($this->container);
+ $attachmentLinkProvider = new AttachmentLinkProvider($this->container);
+
+ $externalLinkManager->register($webLinkProvider);
+ $externalLinkManager->register($attachmentLinkProvider);
+
+ $this->assertInstanceOf(get_class($webLinkProvider), $externalLinkManager->getProvider($webLinkProvider->getType()));
+ $this->assertInstanceOf(get_class($attachmentLinkProvider), $externalLinkManager->getProvider($attachmentLinkProvider->getType()));
+ }
+
+ public function testGetProviderNotFound()
+ {
+ $externalLinkManager = new ExternalLinkManager($this->container);
+
+ $this->setExpectedException('\Kanboard\Core\ExternalLink\ExternalLinkProviderNotFound');
+ $externalLinkManager->getProvider('not found');
+ }
+
+ public function testGetTypes()
+ {
+ $externalLinkManager = new ExternalLinkManager($this->container);
+ $webLinkProvider = new WebLinkProvider($this->container);
+ $attachmentLinkProvider = new AttachmentLinkProvider($this->container);
+
+ $this->assertEquals(array(ExternalLinkManager::TYPE_AUTO => 'Auto'), $externalLinkManager->getTypes());
+
+ $externalLinkManager->register($webLinkProvider);
+ $externalLinkManager->register($attachmentLinkProvider);
+
+ $this->assertEquals(
+ array(ExternalLinkManager::TYPE_AUTO => 'Auto', 'attachment' => 'Attachment', 'weblink' => 'Web Link'),
+ $externalLinkManager->getTypes()
+ );
+ }
+
+ public function testGetDependencyLabel()
+ {
+ $externalLinkManager = new ExternalLinkManager($this->container);
+ $webLinkProvider = new WebLinkProvider($this->container);
+ $attachmentLinkProvider = new AttachmentLinkProvider($this->container);
+
+ $externalLinkManager->register($webLinkProvider);
+ $externalLinkManager->register($attachmentLinkProvider);
+
+ $this->assertSame('Related', $externalLinkManager->getDependencyLabel($webLinkProvider->getType(), 'related'));
+ $this->assertSame('custom', $externalLinkManager->getDependencyLabel($webLinkProvider->getType(), 'custom'));
+ }
+
+ public function testFindProviderNotFound()
+ {
+ $externalLinkManager = new ExternalLinkManager($this->container);
+ $webLinkProvider = new WebLinkProvider($this->container);
+ $attachmentLinkProvider = new AttachmentLinkProvider($this->container);
+
+ $externalLinkManager->register($webLinkProvider);
+ $externalLinkManager->register($attachmentLinkProvider);
+
+ $this->setExpectedException('\Kanboard\Core\ExternalLink\ExternalLinkProviderNotFound');
+ $externalLinkManager->find();
+ }
+
+ public function testFindProvider()
+ {
+ $externalLinkManager = new ExternalLinkManager($this->container);
+ $webLinkProvider = new WebLinkProvider($this->container);
+ $attachmentLinkProvider = new AttachmentLinkProvider($this->container);
+
+ $externalLinkManager->register($webLinkProvider);
+ $externalLinkManager->register($attachmentLinkProvider);
+
+ $externalLinkManager->setUserInput(array('text' => 'https://google.com/', 'type' => ExternalLinkManager::TYPE_AUTO));
+ $this->assertSame($webLinkProvider, $externalLinkManager->find());
+
+ $externalLinkManager->setUserInput(array('text' => 'https://google.com/file.pdf', 'type' => ExternalLinkManager::TYPE_AUTO));
+ $this->assertSame($attachmentLinkProvider, $externalLinkManager->find());
+ }
+
+ public function testFindProviderWithSelectedType()
+ {
+ $externalLinkManager = new ExternalLinkManager($this->container);
+ $webLinkProvider = new WebLinkProvider($this->container);
+ $attachmentLinkProvider = new AttachmentLinkProvider($this->container);
+
+ $externalLinkManager->register($webLinkProvider);
+ $externalLinkManager->register($attachmentLinkProvider);
+
+ $externalLinkManager->setUserInput(array('text' => 'https://google.com/', 'type' => $webLinkProvider->getType()));
+ $this->assertSame($webLinkProvider, $externalLinkManager->find());
+
+ $externalLinkManager->setUserInput(array('text' => 'https://google.com/file.pdf', 'type' => $attachmentLinkProvider->getType()));
+ $this->assertSame($attachmentLinkProvider, $externalLinkManager->find());
+ }
+
+ public function testFindProviderWithSelectedTypeNotFound()
+ {
+ $externalLinkManager = new ExternalLinkManager($this->container);
+ $webLinkProvider = new WebLinkProvider($this->container);
+ $attachmentLinkProvider = new AttachmentLinkProvider($this->container);
+
+ $externalLinkManager->register($webLinkProvider);
+ $externalLinkManager->register($attachmentLinkProvider);
+
+ $this->setExpectedException('\Kanboard\Core\ExternalLink\ExternalLinkProviderNotFound');
+ $externalLinkManager->setUserInput(array('text' => 'https://google.com/', 'type' => 'not found'));
+ $externalLinkManager->find();
+ }
+}
diff --git a/tests/units/ExternalLink/AttachmentLinkProviderTest.php b/tests/units/ExternalLink/AttachmentLinkProviderTest.php
new file mode 100644
index 00000000..fe374664
--- /dev/null
+++ b/tests/units/ExternalLink/AttachmentLinkProviderTest.php
@@ -0,0 +1,64 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\ExternalLink\AttachmentLinkProvider;
+
+class AttachmentLinkProviderTest extends Base
+{
+ public function testGetName()
+ {
+ $attachmentLinkProvider = new AttachmentLinkProvider($this->container);
+ $this->assertEquals('Attachment', $attachmentLinkProvider->getName());
+ }
+
+ public function testGetType()
+ {
+ $attachmentLinkProvider = new AttachmentLinkProvider($this->container);
+ $this->assertEquals('attachment', $attachmentLinkProvider->getType());
+ }
+
+ public function testGetDependencies()
+ {
+ $attachmentLinkProvider = new AttachmentLinkProvider($this->container);
+ $this->assertEquals(array('related' => 'Related'), $attachmentLinkProvider->getDependencies());
+ }
+
+ public function testMatch()
+ {
+ $attachmentLinkProvider = new AttachmentLinkProvider($this->container);
+
+ $attachmentLinkProvider->setUserTextInput('http://kanboard.net/FILE.DOC');
+ $this->assertTrue($attachmentLinkProvider->match());
+
+ $attachmentLinkProvider->setUserTextInput('http://kanboard.net/folder/document.PDF');
+ $this->assertTrue($attachmentLinkProvider->match());
+
+ $attachmentLinkProvider->setUserTextInput('http://kanboard.net/archive.zip');
+ $this->assertTrue($attachmentLinkProvider->match());
+
+ $attachmentLinkProvider->setUserTextInput(' https://kanboard.net/folder/archive.tar ');
+ $this->assertTrue($attachmentLinkProvider->match());
+
+ $attachmentLinkProvider->setUserTextInput('http:// invalid url');
+ $this->assertFalse($attachmentLinkProvider->match());
+
+ $attachmentLinkProvider->setUserTextInput('');
+ $this->assertFalse($attachmentLinkProvider->match());
+
+ $attachmentLinkProvider->setUserTextInput('http://kanboard.net/folder/document.html');
+ $this->assertFalse($attachmentLinkProvider->match());
+
+ $attachmentLinkProvider->setUserTextInput('http://kanboard.net/folder/DOC.HTML');
+ $this->assertFalse($attachmentLinkProvider->match());
+
+ $attachmentLinkProvider->setUserTextInput('http://kanboard.net/folder/document.do');
+ $this->assertFalse($attachmentLinkProvider->match());
+ }
+
+ public function testGetLink()
+ {
+ $attachmentLinkProvider = new AttachmentLinkProvider($this->container);
+ $this->assertInstanceOf('\Kanboard\ExternalLink\AttachmentLink', $attachmentLinkProvider->getLink());
+ }
+}
diff --git a/tests/units/ExternalLink/AttachmentLinkTest.php b/tests/units/ExternalLink/AttachmentLinkTest.php
new file mode 100644
index 00000000..0211869c
--- /dev/null
+++ b/tests/units/ExternalLink/AttachmentLinkTest.php
@@ -0,0 +1,18 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\ExternalLink\AttachmentLink;
+
+class AttachmentLinkTest extends Base
+{
+ public function testGetTitleFromUrl()
+ {
+ $url = 'https://kanboard.net/folder/document.pdf';
+
+ $link = new AttachmentLink($this->container);
+ $link->setUrl($url);
+ $this->assertEquals($url, $link->getUrl());
+ $this->assertEquals('document.pdf', $link->getTitle());
+ }
+}
diff --git a/tests/units/ExternalLink/WebLinkProviderTest.php b/tests/units/ExternalLink/WebLinkProviderTest.php
new file mode 100644
index 00000000..95110ed8
--- /dev/null
+++ b/tests/units/ExternalLink/WebLinkProviderTest.php
@@ -0,0 +1,52 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\ExternalLink\WebLinkProvider;
+
+class WebLinkProviderTest extends Base
+{
+ public function testGetName()
+ {
+ $webLinkProvider = new WebLinkProvider($this->container);
+ $this->assertEquals('Web Link', $webLinkProvider->getName());
+ }
+
+ public function testGetType()
+ {
+ $webLinkProvider = new WebLinkProvider($this->container);
+ $this->assertEquals('weblink', $webLinkProvider->getType());
+ }
+
+ public function testGetDependencies()
+ {
+ $webLinkProvider = new WebLinkProvider($this->container);
+ $this->assertEquals(array('related' => 'Related'), $webLinkProvider->getDependencies());
+ }
+
+ public function testMatch()
+ {
+ $webLinkProvider = new WebLinkProvider($this->container);
+
+ $webLinkProvider->setUserTextInput('http://kanboard.net/');
+ $this->assertTrue($webLinkProvider->match());
+
+ $webLinkProvider->setUserTextInput('http://kanboard.net/mypage');
+ $this->assertTrue($webLinkProvider->match());
+
+ $webLinkProvider->setUserTextInput(' https://kanboard.net/ ');
+ $this->assertTrue($webLinkProvider->match());
+
+ $webLinkProvider->setUserTextInput('http:// invalid url');
+ $this->assertFalse($webLinkProvider->match());
+
+ $webLinkProvider->setUserTextInput('');
+ $this->assertFalse($webLinkProvider->match());
+ }
+
+ public function testGetLink()
+ {
+ $webLinkProvider = new WebLinkProvider($this->container);
+ $this->assertInstanceOf('\Kanboard\ExternalLink\WebLink', $webLinkProvider->getLink());
+ }
+}
diff --git a/tests/units/ExternalLink/WebLinkTest.php b/tests/units/ExternalLink/WebLinkTest.php
new file mode 100644
index 00000000..0644620f
--- /dev/null
+++ b/tests/units/ExternalLink/WebLinkTest.php
@@ -0,0 +1,57 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\ExternalLink\WebLink;
+
+class WebLinkTest extends Base
+{
+ public function testGetTitleFromHtml()
+ {
+ $url = 'http://kanboard.net/something';
+ $title = 'My title';
+ $html = '<!DOCTYPE html><html><head><title> '.$title.' </title></head><body>Test</body></html>';
+
+ $this->container['httpClient'] = $this
+ ->getMockBuilder('\Kanboard\Core\Http\Client')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('get'))
+ ->getMock();
+
+ $webLink = new WebLink($this->container);
+ $webLink->setUrl($url);
+ $this->assertEquals($url, $webLink->getUrl());
+
+ $this->container['httpClient']
+ ->expects($this->once())
+ ->method('get')
+ ->with($url)
+ ->will($this->returnValue($html));
+
+ $this->assertEquals($title, $webLink->getTitle());
+ }
+
+ public function testGetTitleFromUrl()
+ {
+ $url = 'http://kanboard.net/something';
+ $html = '<!DOCTYPE html><html><head></head><body>Test</body></html>';
+
+ $this->container['httpClient'] = $this
+ ->getMockBuilder('\Kanboard\Core\Http\Client')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('get'))
+ ->getMock();
+
+ $webLink = new WebLink($this->container);
+ $webLink->setUrl($url);
+ $this->assertEquals($url, $webLink->getUrl());
+
+ $this->container['httpClient']
+ ->expects($this->once())
+ ->method('get')
+ ->with($url)
+ ->will($this->returnValue($html));
+
+ $this->assertEquals('kanboard.net/something', $webLink->getTitle());
+ }
+}
diff --git a/tests/units/Model/TaskExternalLinkTest.php b/tests/units/Model/TaskExternalLinkTest.php
new file mode 100644
index 00000000..b3f01759
--- /dev/null
+++ b/tests/units/Model/TaskExternalLinkTest.php
@@ -0,0 +1,167 @@
+<?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 testCreateWithNoType()
+ {
+ $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->assertFalse($taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'http://kanboard.net/', 'title' => 'My website', 'dependency' => 'related')));
+ }
+
+ public function testCreateWithNoDependency()
+ {
+ $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->assertFalse($taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'http://kanboard.net/', 'title' => 'My website', 'link_type' => 'test')));
+ }
+
+ public function testCreateWithNoTitle()
+ {
+ $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->assertFalse($taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'http://kanboard.net/', 'link_type' => 'test', 'dependency' => 'test')));
+ }
+
+ public function testCreateWithNoUrl()
+ {
+ $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->assertFalse($taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'title' => 'test', 'link_type' => 'test', 'dependency' => 'test')));
+ }
+
+ 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']);
+ }
+}
diff --git a/tests/units/Validator/ExternalLinkValidatorTest.php b/tests/units/Validator/ExternalLinkValidatorTest.php
new file mode 100644
index 00000000..b41b779a
--- /dev/null
+++ b/tests/units/Validator/ExternalLinkValidatorTest.php
@@ -0,0 +1,63 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Validator\ExternalLinkValidator;
+
+class ExternalLinkValidatorTest extends Base
+{
+ public function testValidateCreation()
+ {
+ $validator = new ExternalLinkValidator($this->container);
+
+ $result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
+ $this->assertTrue($result[0]);
+
+ $result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 'abc', 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'dependency' => 'related'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'link_type' => 'weblink', 'dependency' => 'related'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('url' => 'http://somewhere', 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
+ $this->assertFalse($result[0]);
+ }
+
+ public function testValidateModification()
+ {
+ $validator = new ExternalLinkValidator($this->container);
+
+ $result = $validator->validateModification(array('id' => 1, 'url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
+ $this->assertTrue($result[0]);
+
+ $result = $validator->validateModification(array('id' => 1, 'url' => 'http://somewhere', 'task_id' => 'abc', 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateModification(array('id' => 1, 'url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateModification(array('id' => 1, 'url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'dependency' => 'related'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateModification(array('id' => 1, 'url' => 'http://somewhere', 'task_id' => 1, 'link_type' => 'weblink', 'dependency' => 'related'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateModification(array('id' => 1, 'url' => 'http://somewhere', 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateModification(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
+ $this->assertFalse($result[0]);
+ }
+}