summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/CommentProcedureTest.php3
-rw-r--r--tests/integration/TaskTagProcedureTest.php27
-rw-r--r--tests/units.postgres.xml2
-rw-r--r--tests/units/Base.php1
-rw-r--r--tests/units/Core/DateParserTest.php9
-rw-r--r--tests/units/Core/ExternalTask/ExternalTaskManagerTest.php6
-rw-r--r--tests/units/Core/Http/RequestTest.php3
-rw-r--r--tests/units/Core/Plugin/VersionTest.php29
-rw-r--r--tests/units/Helper/FileHelperTest.php (renamed from tests/units/Helper/FileHelperText.php)9
-rw-r--r--tests/units/Helper/TaskHelperTest.php6
-rw-r--r--tests/units/Model/CommentModelTest.php3
-rw-r--r--tests/units/Model/InviteModelTest.php27
-rw-r--r--tests/units/ServiceProvider/ClassProviderTest.php21
-rw-r--r--tests/units/ServiceProvider/FormatterProviderTest.php21
14 files changed, 156 insertions, 11 deletions
diff --git a/tests/integration/CommentProcedureTest.php b/tests/integration/CommentProcedureTest.php
index 881d938c..0a969420 100644
--- a/tests/integration/CommentProcedureTest.php
+++ b/tests/integration/CommentProcedureTest.php
@@ -35,10 +35,12 @@ class CommentProcedureTest extends BaseProcedureTest
$this->assertNotEmpty($comment);
$this->assertEquals(1, $comment['user_id']);
$this->assertEquals('foobar', $comment['comment']);
+ $this->assertEquals($comment['date_creation'], $comment['date_modification']);
}
public function assertUpdateComment()
{
+ sleep(1); // Integration test fails because its too fast
$this->assertTrue($this->app->execute('updateComment', array(
'id' => $this->commentId,
'content' => 'test',
@@ -46,6 +48,7 @@ class CommentProcedureTest extends BaseProcedureTest
$comment = $this->app->getComment($this->commentId);
$this->assertEquals('test', $comment['comment']);
+ $this->assertNotEquals($comment['date_creation'], $comment['date_modification']);
}
public function assertGetAllComments()
diff --git a/tests/integration/TaskTagProcedureTest.php b/tests/integration/TaskTagProcedureTest.php
index ae6139d3..4b820c9a 100644
--- a/tests/integration/TaskTagProcedureTest.php
+++ b/tests/integration/TaskTagProcedureTest.php
@@ -12,6 +12,8 @@ class TaskTagProcedureTest extends BaseProcedureTest
$this->assertCreateTask();
$this->assertSetTaskTags();
$this->assertGetTaskTags();
+ $this->assertCreateTaskWithTags();
+ $this->assertUpdateTaskWithTags();
}
public function assertSetTaskTags()
@@ -24,4 +26,29 @@ class TaskTagProcedureTest extends BaseProcedureTest
$tags = $this->app->getTaskTags($this->taskId);
$this->assertEquals(array('tag1', 'tag2'), array_values($tags));
}
+
+ public function assertCreateTaskWithTags()
+ {
+ $this->taskId = $this->app->createTask(array(
+ 'title' => $this->taskTitle,
+ 'project_id' => $this->projectId,
+ 'tags' => array('tag A', 'tag B'),
+ ));
+
+ $this->assertNotFalse($this->taskId);
+
+ $tags = $this->app->getTaskTags($this->taskId);
+ $this->assertEquals(array('tag A', 'tag B'), array_values($tags));
+ }
+
+ public function assertUpdateTaskWithTags()
+ {
+ $this->assertTrue($this->app->updateTask(array(
+ 'id' => $this->taskId,
+ 'tags' => array('tag C'),
+ )));
+
+ $tags = $this->app->getTaskTags($this->taskId);
+ $this->assertEquals(array('tag C'), array_values($tags));
+ }
}
diff --git a/tests/units.postgres.xml b/tests/units.postgres.xml
index 3442db1c..cf538a82 100644
--- a/tests/units.postgres.xml
+++ b/tests/units.postgres.xml
@@ -10,4 +10,4 @@
<const name="DB_PASSWORD" value="" />
<const name="DB_NAME" value="kanboard_unit_test" />
</php>
-</phpunit> \ No newline at end of file
+</phpunit>
diff --git a/tests/units/Base.php b/tests/units/Base.php
index 1b986fcb..1c93e9b8 100644
--- a/tests/units/Base.php
+++ b/tests/units/Base.php
@@ -47,6 +47,7 @@ abstract class Base extends PHPUnit_Framework_TestCase
$this->container->register(new Kanboard\ServiceProvider\RouteProvider());
$this->container->register(new Kanboard\ServiceProvider\AvatarProvider());
$this->container->register(new Kanboard\ServiceProvider\FilterProvider());
+ $this->container->register(new Kanboard\ServiceProvider\FormatterProvider());
$this->container->register(new Kanboard\ServiceProvider\JobProvider());
$this->container->register(new Kanboard\ServiceProvider\QueueProvider());
$this->container->register(new Kanboard\ServiceProvider\ExternalTaskProvider());
diff --git a/tests/units/Core/DateParserTest.php b/tests/units/Core/DateParserTest.php
index 1cf98bd3..e0dfb4c1 100644
--- a/tests/units/Core/DateParserTest.php
+++ b/tests/units/Core/DateParserTest.php
@@ -64,7 +64,7 @@ class DateParserTest extends Base
$dates = $dateParser->getDateTimeFormats(true);
$this->assertEquals('m/d/Y H:i', $dates[0]);
- $this->container['configModel']->save(array('application_datetime_format' => 'd/m/Y g:i a'));
+ $this->container['configModel']->save(array('application_date_format' => 'd/m/Y', 'application_time_format' => 'g:i a'));
$this->container['memoryCache']->flush();
$dates = $dateParser->getDateTimeFormats();
@@ -121,7 +121,7 @@ class DateParserTest extends Base
{
$this->container['configModel']->save(array(
'application_date_format' => 'd/m/Y',
- 'application_datetime_format' => 'd/m/Y g:i a',
+ 'application_time_format' => 'g:i a',
));
$dateParser = new DateParser($this->container);
@@ -138,7 +138,7 @@ class DateParserTest extends Base
{
$this->container['configModel']->save(array(
'application_date_format' => 'd.m.Y',
- 'application_datetime_format' => 'd.m.Y H:i',
+ 'application_time_format' => 'H:i',
));
$dateParser = new DateParser($this->container);
@@ -204,9 +204,6 @@ class DateParserTest extends Base
$this->assertEquals(array('date' => '06/02/2016'), $dateParser->format($values, array('date'), 'd/m/Y'));
$this->assertEquals(array('date' => '02/06/2016 7:30 pm'), $dateParser->format($values, array('date'), 'm/d/Y g:i a'));
-
- $values['date'] = '2016-02-06';
- $this->assertEquals(array('date' => '06/02/2016'), $dateParser->format($values, array('date'), 'd/m/Y'));
}
public function testConvert()
diff --git a/tests/units/Core/ExternalTask/ExternalTaskManagerTest.php b/tests/units/Core/ExternalTask/ExternalTaskManagerTest.php
index e6f4e069..8eec64de 100644
--- a/tests/units/Core/ExternalTask/ExternalTaskManagerTest.php
+++ b/tests/units/Core/ExternalTask/ExternalTaskManagerTest.php
@@ -41,4 +41,10 @@ class ExternalTaskManagerTest extends Base
$expected = array('MyProvider1' => 'MyProvider1', 'MyProvider2' => 'MyProvider2');
$this->assertEquals($expected, $providers);
}
+
+ public function testGetProviderListWithNoProviders()
+ {
+ $manager = new ExternalTaskManager();
+ $this->assertSame(array(), $manager->getProvidersList());
+ }
}
diff --git a/tests/units/Core/Http/RequestTest.php b/tests/units/Core/Http/RequestTest.php
index 1db0100c..697c3c0f 100644
--- a/tests/units/Core/Http/RequestTest.php
+++ b/tests/units/Core/Http/RequestTest.php
@@ -43,6 +43,9 @@ class RequestTest extends Base
$request = new Request($this->container, array(), array(), array('myvar' => 'myvalue', 'csrf_token' => $this->container['token']->getCSRFToken()), array(), array());
$this->assertEquals(array('myvar' => 'myvalue'), $request->getValues());
+
+ $request = new Request($this->container, array(), array(), array('myvar' => 'myvalue', '-----------------------------7e1c32510025c--' => '', 'csrf_token' => $this->container['token']->getCSRFToken()), array(), array());
+ $this->assertEquals(array('myvar' => 'myvalue'), $request->getValues());
}
public function testGetFileContent()
diff --git a/tests/units/Core/Plugin/VersionTest.php b/tests/units/Core/Plugin/VersionTest.php
new file mode 100644
index 00000000..78f10d95
--- /dev/null
+++ b/tests/units/Core/Plugin/VersionTest.php
@@ -0,0 +1,29 @@
+<?php
+
+use Kanboard\Core\Plugin\Version;
+
+require_once __DIR__.'/../../Base.php';
+
+class VersionTest extends Base
+{
+ public function testIsCompatible()
+ {
+ $this->assertFalse(Version::isCompatible('1.0.29', '1.0.28'));
+ $this->assertTrue(Version::isCompatible('1.0.28', '1.0.28'));
+ $this->assertTrue(Version::isCompatible('1.0.28', 'master.1234'));
+ $this->assertTrue(Version::isCompatible('>=1.0.32', 'master'));
+ $this->assertTrue(Version::isCompatible('>=1.0.32', '1.0.32'));
+ $this->assertTrue(Version::isCompatible('>=1.0.32', '1.0.33'));
+ $this->assertTrue(Version::isCompatible('>1.0.32', '1.0.33'));
+ $this->assertFalse(Version::isCompatible('>1.0.32', '1.0.32'));
+ $this->assertTrue(Version::isCompatible('1.0.32', 'v1.0.32'));
+ $this->assertTrue(Version::isCompatible('>=v1.0.32', 'v1.0.32'));
+ $this->assertTrue(Version::isCompatible('<=v1.0.36', 'v1.0.36'));
+ $this->assertFalse(Version::isCompatible('<1.0.36', 'v1.0.36'));
+ $this->assertTrue(Version::isCompatible('<1.0.40', '1.0.36'));
+ $this->assertTrue(Version::isCompatible('<=1.0.40', '1.0.36'));
+ $this->assertFalse(Version::isCompatible('<1.0.40', '1.0.40'));
+ $this->assertFalse(Version::isCompatible('1.0.40', 'v1.0.36'));
+ $this->assertTrue(Version::isCompatible('<1.1.0', 'v1.0.36'));
+ }
+}
diff --git a/tests/units/Helper/FileHelperText.php b/tests/units/Helper/FileHelperTest.php
index 215b024b..7db43460 100644
--- a/tests/units/Helper/FileHelperText.php
+++ b/tests/units/Helper/FileHelperTest.php
@@ -30,7 +30,14 @@ class FileHelperTest extends Base
$helper = new FileHelper($this->container);
$this->assertEquals('text', $helper->getPreviewType('test.txt'));
$this->assertEquals('markdown', $helper->getPreviewType('test.markdown'));
- $this->assertEquals('md', $helper->getPreviewType('test.md'));
+ $this->assertEquals('markdown', $helper->getPreviewType('test.md'));
$this->assertEquals(null, $helper->getPreviewType('test.doc'));
}
+
+ public function testGetBrowserViewType()
+ {
+ $fileHelper = new FileHelper($this->container);
+ $this->assertSame('application/pdf', $fileHelper->getBrowserViewType('SomeFile.PDF'));
+ $this->assertSame(null, $fileHelper->getBrowserViewType('SomeFile.doc'));
+ }
}
diff --git a/tests/units/Helper/TaskHelperTest.php b/tests/units/Helper/TaskHelperTest.php
index 2e2da6ee..8609983e 100644
--- a/tests/units/Helper/TaskHelperTest.php
+++ b/tests/units/Helper/TaskHelperTest.php
@@ -9,9 +9,9 @@ class TaskHelperTest extends Base
public function testSelectPriority()
{
$helper = new TaskHelper($this->container);
- $this->assertNotEmpty($helper->selectPriority(array('priority_end' => '1', 'priority_start' => '5', 'priority_default' => '2'), array()));
- $this->assertNotEmpty($helper->selectPriority(array('priority_end' => '3', 'priority_start' => '1', 'priority_default' => '2'), array()));
- $this->assertEmpty($helper->selectPriority(array('priority_end' => '3', 'priority_start' => '3', 'priority_default' => '2'), array()));
+ $this->assertNotEmpty($helper->renderPriorityField(array('priority_end' => '1', 'priority_start' => '5', 'priority_default' => '2'), array()));
+ $this->assertNotEmpty($helper->renderPriorityField(array('priority_end' => '3', 'priority_start' => '1', 'priority_default' => '2'), array()));
+ $this->assertEmpty($helper->renderPriorityField(array('priority_end' => '3', 'priority_start' => '3', 'priority_default' => '2'), array()));
}
public function testFormatPriority()
diff --git a/tests/units/Model/CommentModelTest.php b/tests/units/Model/CommentModelTest.php
index 4178a839..c75401cc 100644
--- a/tests/units/Model/CommentModelTest.php
+++ b/tests/units/Model/CommentModelTest.php
@@ -26,6 +26,7 @@ class CommentModelTest extends Base
$this->assertEquals(1, $comment['user_id']);
$this->assertEquals('admin', $comment['username']);
$this->assertEquals(time(), $comment['date_creation'], '', 3);
+ $this->assertEquals(time(), $comment['date_modification'], '', 3);
$comment = $commentModel->getById(2);
$this->assertNotEmpty($comment);
@@ -34,6 +35,7 @@ class CommentModelTest extends Base
$this->assertEquals(0, $comment['user_id']);
$this->assertEquals('', $comment['username']);
$this->assertEquals(time(), $comment['date_creation'], '', 3);
+ $this->assertEquals(time(), $comment['date_modification'], '', 3);
}
public function testGetAll()
@@ -73,6 +75,7 @@ class CommentModelTest extends Base
$comment = $commentModel->getById(1);
$this->assertNotEmpty($comment);
$this->assertEquals('bla', $comment['comment']);
+ $this->assertEquals(time(), $comment['date_modification'], '', 3);
}
public function testRemove()
diff --git a/tests/units/Model/InviteModelTest.php b/tests/units/Model/InviteModelTest.php
new file mode 100644
index 00000000..3a0519fb
--- /dev/null
+++ b/tests/units/Model/InviteModelTest.php
@@ -0,0 +1,27 @@
+<?php
+
+use Kanboard\Model\InviteModel;
+
+require_once __DIR__.'/../Base.php';
+
+class InviteModelTest extends Base
+{
+ public function testCreation()
+ {
+ $inviteModel = new InviteModel($this->container);
+
+ $this->container['emailClient']
+ ->expects($this->exactly(2))
+ ->method('send');
+
+ $inviteModel->createInvites(array('user@domain1.tld', '', 'user@domain2.tld'), 1);
+ }
+
+ public function testRemove()
+ {
+ $inviteModel = new InviteModel($this->container);
+ $inviteModel->createInvites(array('user@domain1.tld', 'user@domain2.tld'), 0);
+ $this->assertTrue($inviteModel->remove('user@domain1.tld'));
+ $this->assertFalse($inviteModel->remove('foobar'));
+ }
+}
diff --git a/tests/units/ServiceProvider/ClassProviderTest.php b/tests/units/ServiceProvider/ClassProviderTest.php
new file mode 100644
index 00000000..f6528918
--- /dev/null
+++ b/tests/units/ServiceProvider/ClassProviderTest.php
@@ -0,0 +1,21 @@
+<?php
+
+use Kanboard\ServiceProvider\ClassProvider;
+use Pimple\Container;
+
+require_once __DIR__.'/../Base.php';
+
+class ModelProviderTest extends Base
+{
+ public function testServiceInstance()
+ {
+ $container = new Container();
+ $serviceProvider = new ClassProvider($container);
+ $serviceProvider->register($container);
+
+ $instance1 = $container['userModel'];
+ $instance2 = $container['userModel'];
+
+ $this->assertSame($instance1, $instance2);
+ }
+}
diff --git a/tests/units/ServiceProvider/FormatterProviderTest.php b/tests/units/ServiceProvider/FormatterProviderTest.php
new file mode 100644
index 00000000..7984a12b
--- /dev/null
+++ b/tests/units/ServiceProvider/FormatterProviderTest.php
@@ -0,0 +1,21 @@
+<?php
+
+use Kanboard\ServiceProvider\FormatterProvider;
+use Pimple\Container;
+
+require_once __DIR__.'/../Base.php';
+
+class FormatterProviderTest extends Base
+{
+ public function testServiceInstance()
+ {
+ $container = new Container();
+ $serviceProvider = new FormatterProvider($container);
+ $serviceProvider->register($container);
+
+ $instance1 = $container['userAutoCompleteFormatter'];
+ $instance2 = $container['userAutoCompleteFormatter'];
+
+ $this->assertNotSame($instance1, $instance2);
+ }
+}