Add external links for tasks with plugin api

This commit is contained in:
Frederic Guillot
2016-01-30 20:38:20 -05:00
parent ec66a779c9
commit 5c92f46786
81 changed files with 2544 additions and 75 deletions

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}

View File

@@ -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());
}
}