summaryrefslogtreecommitdiff
path: root/tests/units/Core/ExternalLink/ExternalLinkManagerTest.php
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/units/Core/ExternalLink/ExternalLinkManagerTest.php
parentec66a779c9158830fe4bb0f96a44eadfe697ef00 (diff)
Add external links for tasks with plugin api
Diffstat (limited to 'tests/units/Core/ExternalLink/ExternalLinkManagerTest.php')
-rw-r--r--tests/units/Core/ExternalLink/ExternalLinkManagerTest.php120
1 files changed, 120 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();
+ }
+}