summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php12
-rw-r--r--tests/units/Core/Ldap/LdapUserTest.php28
-rw-r--r--tests/units/ExternalLink/FileLinkProviderTest.php43
-rw-r--r--tests/units/ExternalLink/FileLinkTest.php28
-rw-r--r--tests/units/Model/ProjectDailyColumnStatsTest.php4
-rw-r--r--tests/units/Model/ProjectDailyStatsTest.php8
-rw-r--r--tests/units/User/Avatar/LetterAvatarProviderTest.php37
7 files changed, 147 insertions, 13 deletions
diff --git a/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php b/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php
index b8faec6c..b87e9573 100644
--- a/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php
+++ b/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php
@@ -23,6 +23,7 @@ class AverageLeadCycleTimeAnalyticTest extends Base
$this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$this->assertEquals(4, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(5, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
// LT=3600 CT=1800
$this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600, 'date_started' => $now + 1800));
@@ -36,21 +37,22 @@ class AverageLeadCycleTimeAnalyticTest extends Base
// LT=2*3600 CT=0
$this->container['db']->table(Task::TABLE)->eq('id', 4)->update(array('date_completed' => $now + 2 * 3600));
+ // CT=0
+ $this->container['db']->table(Task::TABLE)->eq('id', 5)->update(array('date_started' => $now + 900));
+
$stats = $averageLeadCycleTimeAnalytic->build(1);
- $this->assertEquals(4, $stats['count']);
+ $this->assertEquals(5, $stats['count']);
$this->assertEquals(3600 + 1800 + 3600 + 2*3600, $stats['total_lead_time'], '', 5);
$this->assertEquals(1800 + 900, $stats['total_cycle_time'], '', 5);
- $this->assertEquals((3600 + 1800 + 3600 + 2*3600) / 4, $stats['avg_lead_time'], '', 5);
- $this->assertEquals((1800 + 900) / 4, $stats['avg_cycle_time'], '', 5);
+ $this->assertEquals((3600 + 1800 + 3600 + 2*3600) / 5, $stats['avg_lead_time'], '', 5);
+ $this->assertEquals((1800 + 900) / 5, $stats['avg_cycle_time'], '', 5);
}
public function testBuildWithNoTasks()
{
- $taskCreationModel = new TaskCreation($this->container);
$projectModel = new Project($this->container);
$averageLeadCycleTimeAnalytic = new AverageLeadCycleTimeAnalytic($this->container);
- $now = time();
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test1')));
diff --git a/tests/units/Core/Ldap/LdapUserTest.php b/tests/units/Core/Ldap/LdapUserTest.php
index 2b3db1e5..b4b63053 100644
--- a/tests/units/Core/Ldap/LdapUserTest.php
+++ b/tests/units/Core/Ldap/LdapUserTest.php
@@ -321,8 +321,6 @@ class LdapUserTest extends Base
public function testGetUserNotFound()
{
- $entries = new Entries(array());
-
$this->client
->expects($this->any())
->method('getConnection')
@@ -376,4 +374,30 @@ class LdapUserTest extends Base
$user = new User($this->query);
$user->getBasDn();
}
+
+ public function testGetLdapUserPatternNotConfigured()
+ {
+ $this->setExpectedException('\LogicException');
+
+ $user = new User($this->query);
+ $user->getLdapUserPattern('test');
+ }
+
+ public function testGetLdapUserWithMultiplePlaceholders()
+ {
+ $filter = '(|(&(objectClass=user)(mail=%s))(&(objectClass=user)(sAMAccountName=%s)))';
+ $expected = '(|(&(objectClass=user)(mail=test))(&(objectClass=user)(sAMAccountName=test)))';
+
+ $user = new User($this->query);
+ $this->assertEquals($expected, $user->getLdapUserPattern('test', $filter));
+ }
+
+ public function testGetLdapUserWithOnePlaceholder()
+ {
+ $filter = '(sAMAccountName=%s)';
+ $expected = '(sAMAccountName=test)';
+
+ $user = new User($this->query);
+ $this->assertEquals($expected, $user->getLdapUserPattern('test', $filter));
+ }
}
diff --git a/tests/units/ExternalLink/FileLinkProviderTest.php b/tests/units/ExternalLink/FileLinkProviderTest.php
new file mode 100644
index 00000000..8cef82f8
--- /dev/null
+++ b/tests/units/ExternalLink/FileLinkProviderTest.php
@@ -0,0 +1,43 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\ExternalLink\FileLinkProvider;
+
+class FileLinkProviderTest extends Base
+{
+ public function testGetName()
+ {
+ $attachmentLinkProvider = new FileLinkProvider($this->container);
+ $this->assertEquals('Local File', $attachmentLinkProvider->getName());
+ }
+
+ public function testGetType()
+ {
+ $attachmentLinkProvider = new FileLinkProvider($this->container);
+ $this->assertEquals('file', $attachmentLinkProvider->getType());
+ }
+
+ public function testGetDependencies()
+ {
+ $attachmentLinkProvider = new FileLinkProvider($this->container);
+ $this->assertEquals(array('related' => 'Related'), $attachmentLinkProvider->getDependencies());
+ }
+
+ public function testMatch()
+ {
+ $attachmentLinkProvider = new FileLinkProvider($this->container);
+
+ $attachmentLinkProvider->setUserTextInput('file:///tmp/test.txt');
+ $this->assertTrue($attachmentLinkProvider->match());
+
+ $attachmentLinkProvider->setUserTextInput('');
+ $this->assertFalse($attachmentLinkProvider->match());
+ }
+
+ public function testGetLink()
+ {
+ $attachmentLinkProvider = new FileLinkProvider($this->container);
+ $this->assertInstanceOf('\Kanboard\ExternalLink\FileLink', $attachmentLinkProvider->getLink());
+ }
+}
diff --git a/tests/units/ExternalLink/FileLinkTest.php b/tests/units/ExternalLink/FileLinkTest.php
new file mode 100644
index 00000000..b83000cd
--- /dev/null
+++ b/tests/units/ExternalLink/FileLinkTest.php
@@ -0,0 +1,28 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\ExternalLink\FileLink;
+
+class FileLinkTest extends Base
+{
+ public function testGetTitleFromUrlWithUnixPath()
+ {
+ $url = 'file:///tmp/test.txt';
+
+ $link = new FileLink($this->container);
+ $link->setUrl($url);
+ $this->assertEquals($url, $link->getUrl());
+ $this->assertEquals('test.txt', $link->getTitle());
+ }
+
+ public function testGetTitleFromUrlWithWindowsPath()
+ {
+ $url = 'file:///c:\temp\test.txt';
+
+ $link = new FileLink($this->container);
+ $link->setUrl($url);
+ $this->assertEquals($url, $link->getUrl());
+ $this->assertEquals('test.txt', $link->getTitle());
+ }
+}
diff --git a/tests/units/Model/ProjectDailyColumnStatsTest.php b/tests/units/Model/ProjectDailyColumnStatsTest.php
index 1a0e826c..4f92ad2b 100644
--- a/tests/units/Model/ProjectDailyColumnStatsTest.php
+++ b/tests/units/Model/ProjectDailyColumnStatsTest.php
@@ -244,7 +244,7 @@ class ProjectDailyColumnStatsTest extends Base
array('2016-01-18', 4, 5, 3, 0),
);
- $this->assertEquals($expected, $projectDailyColumnStats->getAggregatedMetrics(1, '2016-01-16', '2016-01-18'));
+ $this->assertSame($expected, $projectDailyColumnStats->getAggregatedMetrics(1, '2016-01-16', '2016-01-18'));
$expected = array(
array('Date', 'Backlog', 'Ready', 'Work in progress', 'Done'),
@@ -253,7 +253,7 @@ class ProjectDailyColumnStatsTest extends Base
array('2016-01-18', 11, 14, 1, 0),
);
- $this->assertEquals($expected, $projectDailyColumnStats->getAggregatedMetrics(1, '2016-01-16', '2016-01-18', 'score'));
+ $this->assertSame($expected, $projectDailyColumnStats->getAggregatedMetrics(1, '2016-01-16', '2016-01-18', 'score'));
}
private function createTasks($column_id, $score, $is_active)
diff --git a/tests/units/Model/ProjectDailyStatsTest.php b/tests/units/Model/ProjectDailyStatsTest.php
index c3b20cb9..60afc4c3 100644
--- a/tests/units/Model/ProjectDailyStatsTest.php
+++ b/tests/units/Model/ProjectDailyStatsTest.php
@@ -45,10 +45,10 @@ class ProjectDailyStatsTest extends Base
$this->assertEquals($expected[0]['day'], $metrics[0]['day']);
$this->assertEquals($expected[1]['day'], $metrics[1]['day']);
- $this->assertEquals($expected[0]['avg_lead_time'], $metrics[0]['avg_lead_time'], '', 2);
- $this->assertEquals($expected[1]['avg_lead_time'], $metrics[1]['avg_lead_time'], '', 2);
+ $this->assertSame($expected[0]['avg_lead_time'], $metrics[0]['avg_lead_time'], '', 2);
+ $this->assertSame($expected[1]['avg_lead_time'], $metrics[1]['avg_lead_time'], '', 2);
- $this->assertEquals($expected[0]['avg_cycle_time'], $metrics[0]['avg_cycle_time'], '', 2);
- $this->assertEquals($expected[1]['avg_cycle_time'], $metrics[1]['avg_cycle_time'], '', 2);
+ $this->assertSame($expected[0]['avg_cycle_time'], $metrics[0]['avg_cycle_time'], '', 2);
+ $this->assertSame($expected[1]['avg_cycle_time'], $metrics[1]['avg_cycle_time'], '', 2);
}
}
diff --git a/tests/units/User/Avatar/LetterAvatarProviderTest.php b/tests/units/User/Avatar/LetterAvatarProviderTest.php
new file mode 100644
index 00000000..0c1bfc4b
--- /dev/null
+++ b/tests/units/User/Avatar/LetterAvatarProviderTest.php
@@ -0,0 +1,37 @@
+<?php
+
+require_once __DIR__.'/../../Base.php';
+
+use Kanboard\User\Avatar\LetterAvatarProvider;
+
+class LetterAvatarProviderTest extends Base
+{
+ public function testGetBackgroundColor()
+ {
+ $provider = new LetterAvatarProvider($this->container);
+ $rgb = $provider->getBackgroundColor('Test');
+ $this->assertEquals(array(107, 83, 172), $rgb);
+ }
+
+ public function testIsActive()
+ {
+ $provider = new LetterAvatarProvider($this->container);
+ $this->assertTrue($provider->isActive(array()));
+ }
+
+ public function testRenderWithFullName()
+ {
+ $provider = new LetterAvatarProvider($this->container);
+ $user = array('id' => 123, 'name' => 'Kanboard Admin', 'username' => 'bob', 'email' => '');
+ $expected = '<div class="avatar-letter" style="background-color: rgb(187, 224, 108)" title="Kanboard Admin">KA</div>';
+ $this->assertEquals($expected, $provider->render($user, 48));
+ }
+
+ public function testRenderWithUsername()
+ {
+ $provider = new LetterAvatarProvider($this->container);
+ $user = array('id' => 123, 'name' => '', 'username' => 'admin', 'email' => '');
+ $expected = '<div class="avatar-letter" style="background-color: rgb(210, 97, 45)" title="admin">A</div>';
+ $this->assertEquals($expected, $provider->render($user, 48));
+ }
+}