summaryrefslogtreecommitdiff
path: root/tests/units/Validator
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/Validator')
-rw-r--r--tests/units/Validator/CommentValidatorTest.php57
-rw-r--r--tests/units/Validator/CurrencyValidatorTest.php27
-rw-r--r--tests/units/Validator/CustomFilterValidatorTest.php40
-rw-r--r--tests/units/Validator/ExternalLinkValidatorTest.php63
-rw-r--r--tests/units/Validator/GroupValidatorTest.php30
-rw-r--r--tests/units/Validator/LinkValidatorTest.php54
-rw-r--r--tests/units/Validator/PasswordResetValidatorTest.php64
-rw-r--r--tests/units/Validator/ProjectValidatorTest.php67
-rw-r--r--tests/units/Validator/TaskLinkValidatorTest.php72
-rw-r--r--tests/units/Validator/UserValidatorTest.php41
10 files changed, 515 insertions, 0 deletions
diff --git a/tests/units/Validator/CommentValidatorTest.php b/tests/units/Validator/CommentValidatorTest.php
new file mode 100644
index 00000000..378fe924
--- /dev/null
+++ b/tests/units/Validator/CommentValidatorTest.php
@@ -0,0 +1,57 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Validator\CommentValidator;
+
+class CommentValidatorTest extends Base
+{
+ public function testValidateCreation()
+ {
+ $validator = new CommentValidator($this->container);
+
+ $result = $validator->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => 'bla'));
+ $this->assertTrue($result[0]);
+
+ $result = $validator->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => ''));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('user_id' => 1, 'task_id' => 'a', 'comment' => 'bla'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('user_id' => 'b', 'task_id' => 1, 'comment' => 'bla'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('user_id' => 1, 'comment' => 'bla'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('task_id' => 1, 'comment' => 'bla'));
+ $this->assertTrue($result[0]);
+
+ $result = $validator->validateCreation(array('comment' => 'bla'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array());
+ $this->assertFalse($result[0]);
+ }
+
+ public function testValidateModification()
+ {
+ $validator = new CommentValidator($this->container);
+
+ $result = $validator->validateModification(array('id' => 1, 'comment' => 'bla'));
+ $this->assertTrue($result[0]);
+
+ $result = $validator->validateModification(array('id' => 1, 'comment' => ''));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateModification(array('comment' => 'bla'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateModification(array('id' => 'b', 'comment' => 'bla'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateModification(array());
+ $this->assertFalse($result[0]);
+ }
+}
diff --git a/tests/units/Validator/CurrencyValidatorTest.php b/tests/units/Validator/CurrencyValidatorTest.php
new file mode 100644
index 00000000..39c06d44
--- /dev/null
+++ b/tests/units/Validator/CurrencyValidatorTest.php
@@ -0,0 +1,27 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Validator\CurrencyValidator;
+
+class CurrencyValidatorTest extends Base
+{
+ public function testValidation()
+ {
+ $validator = new CurrencyValidator($this->container);
+ $result = $validator->validateCreation(array());
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('currency' => 'EUR'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('rate' => 1.9));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('currency' => 'EUR', 'rate' => 'foobar'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validateCreation(array('currency' => 'EUR', 'rate' => 1.25));
+ $this->assertTrue($result[0]);
+ }
+}
diff --git a/tests/units/Validator/CustomFilterValidatorTest.php b/tests/units/Validator/CustomFilterValidatorTest.php
new file mode 100644
index 00000000..3b70e42c
--- /dev/null
+++ b/tests/units/Validator/CustomFilterValidatorTest.php
@@ -0,0 +1,40 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Validator\CustomFilterValidator;
+
+class CustomFilterValidatorTest extends Base
+{
+ public function testValidateCreation()
+ {
+ $validator = new CustomFilterValidator($this->container);
+
+ // Validate creation
+ $r = $validator->validateCreation(array('filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
+ $this->assertTrue($r[0]);
+
+ $r = $validator->validateCreation(array('filter' => str_repeat('a', 101), 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateCreation(array('name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
+ $this->assertFalse($r[0]);
+ }
+
+ public function testValidateModification()
+ {
+ $validator = new CustomFilterValidator($this->container);
+
+ $r = $validator->validateModification(array('id' => 1, 'filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
+ $this->assertTrue($r[0]);
+
+ $r = $validator->validateModification(array('filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateModification(array('id' => 1, 'filter' => str_repeat('a', 101), 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
+ $this->assertFalse($r[0]);
+ }
+}
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]);
+ }
+}
diff --git a/tests/units/Validator/GroupValidatorTest.php b/tests/units/Validator/GroupValidatorTest.php
new file mode 100644
index 00000000..879f99ce
--- /dev/null
+++ b/tests/units/Validator/GroupValidatorTest.php
@@ -0,0 +1,30 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Validator\GroupValidator;
+
+class GroupValidatorTest extends Base
+{
+ public function testValidateCreation()
+ {
+ $validator = new GroupValidator($this->container);
+
+ $result = $validator->validateCreation(array('name' => 'Test'));
+ $this->assertTrue($result[0]);
+
+ $result = $validator->validateCreation(array('name' => ''));
+ $this->assertFalse($result[0]);
+ }
+
+ public function testValidateModification()
+ {
+ $validator = new GroupValidator($this->container);
+
+ $result = $validator->validateModification(array('name' => 'Test', 'id' => 1));
+ $this->assertTrue($result[0]);
+
+ $result = $validator->validateModification(array('name' => 'Test'));
+ $this->assertFalse($result[0]);
+ }
+}
diff --git a/tests/units/Validator/LinkValidatorTest.php b/tests/units/Validator/LinkValidatorTest.php
new file mode 100644
index 00000000..8b7b182c
--- /dev/null
+++ b/tests/units/Validator/LinkValidatorTest.php
@@ -0,0 +1,54 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Validator\LinkValidator;
+
+class LinkValidatorTest extends Base
+{
+ public function testValidateCreation()
+ {
+ $validator = new LinkValidator($this->container);
+
+ $r = $validator->validateCreation(array('label' => 'a'));
+ $this->assertTrue($r[0]);
+
+ $r = $validator->validateCreation(array('label' => 'a', 'opposite_label' => 'b'));
+ $this->assertTrue($r[0]);
+
+ $r = $validator->validateCreation(array('label' => 'relates to'));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateCreation(array('label' => 'a', 'opposite_label' => 'a'));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateCreation(array('label' => ''));
+ $this->assertFalse($r[0]);
+ }
+
+ public function testValidateModification()
+ {
+ $validator = new LinkValidator($this->container);
+
+ $r = $validator->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => 0));
+ $this->assertTrue($r[0]);
+
+ $r = $validator->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => '1'));
+ $this->assertTrue($r[0]);
+
+ $r = $validator->validateModification(array('id' => 20, 'label' => 'relates to', 'opposite_id' => '1'));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateModification(array('id' => 20, 'label' => '', 'opposite_id' => '1'));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateModification(array('label' => '', 'opposite_id' => '1'));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateModification(array('id' => 20, 'opposite_id' => '1'));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateModification(array('label' => 'test'));
+ $this->assertFalse($r[0]);
+ }
+}
diff --git a/tests/units/Validator/PasswordResetValidatorTest.php b/tests/units/Validator/PasswordResetValidatorTest.php
new file mode 100644
index 00000000..4af6c75e
--- /dev/null
+++ b/tests/units/Validator/PasswordResetValidatorTest.php
@@ -0,0 +1,64 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\User;
+use Kanboard\Validator\PasswordResetValidator;
+
+class PasswordResetValidatorTest extends Base
+{
+ public function testValidateModification()
+ {
+ $validator = new PasswordResetValidator($this->container);
+ list($valid, ) = $validator->validateModification(array('password' => 'test123', 'confirmation' => 'test123'));
+ $this->assertTrue($valid);
+ }
+
+ public function testValidateModificationWithWrongPasswords()
+ {
+ $validator = new PasswordResetValidator($this->container);
+ list($valid, ) = $validator->validateModification(array('password' => 'test123', 'confirmation' => 'test456'));
+ $this->assertFalse($valid);
+ }
+
+ public function testValidateModificationWithPasswordTooShort()
+ {
+ $validator = new PasswordResetValidator($this->container);
+ list($valid, ) = $validator->validateModification(array('password' => 'test', 'confirmation' => 'test'));
+ $this->assertFalse($valid);
+ }
+
+ public function testValidateCreation()
+ {
+ $this->container['sessionStorage']->captcha = 'test';
+
+ $validator = new PasswordResetValidator($this->container);
+ list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
+ $this->assertTrue($valid);
+ }
+
+ public function testValidateCreationWithNoUsername()
+ {
+ $this->container['sessionStorage']->captcha = 'test';
+
+ $validator = new PasswordResetValidator($this->container);
+ list($valid,) = $validator->validateCreation(array('captcha' => 'test'));
+ $this->assertFalse($valid);
+ }
+
+ public function testValidateCreationWithWrongCaptcha()
+ {
+ $this->container['sessionStorage']->captcha = 'test123';
+
+ $validator = new PasswordResetValidator($this->container);
+ list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
+ $this->assertFalse($valid);
+ }
+
+ public function testValidateCreationWithMissingCaptcha()
+ {
+ $validator = new PasswordResetValidator($this->container);
+ list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
+ $this->assertFalse($valid);
+ }
+}
diff --git a/tests/units/Validator/ProjectValidatorTest.php b/tests/units/Validator/ProjectValidatorTest.php
new file mode 100644
index 00000000..a73e8247
--- /dev/null
+++ b/tests/units/Validator/ProjectValidatorTest.php
@@ -0,0 +1,67 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Validator\ProjectValidator;
+use Kanboard\Model\Project;
+
+class ProjectValidatorTest extends Base
+{
+ public function testValidateCreation()
+ {
+ $validator = new ProjectValidator($this->container);
+ $p = new Project($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
+
+ $project = $p->getById(1);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('TEST1', $project['identifier']);
+
+ $project = $p->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('', $project['identifier']);
+
+ $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'TEST1'));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'test1'));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'a-b-c'));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'test 123'));
+ $this->assertFalse($r[0]);
+ }
+
+ public function testValidateModification()
+ {
+ $validator = new ProjectValidator($this->container);
+ $p = new Project($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'UnitTest2', 'identifier' => 'TEST2')));
+
+ $project = $p->getById(1);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('TEST1', $project['identifier']);
+
+ $project = $p->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('TEST2', $project['identifier']);
+
+ $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1'));
+ $this->assertTrue($r[0]);
+
+ $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'test3'));
+ $this->assertTrue($r[0]);
+
+ $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => ''));
+ $this->assertTrue($r[0]);
+
+ $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST2'));
+ $this->assertFalse($r[0]);
+ }
+}
diff --git a/tests/units/Validator/TaskLinkValidatorTest.php b/tests/units/Validator/TaskLinkValidatorTest.php
new file mode 100644
index 00000000..5ac4588e
--- /dev/null
+++ b/tests/units/Validator/TaskLinkValidatorTest.php
@@ -0,0 +1,72 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Validator\TaskLinkValidator;
+use Kanboard\Model\TaskLink;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\Project;
+
+class TaskLinkValidatorTest extends Base
+{
+ public function testValidateCreation()
+ {
+ $validator = new TaskLinkValidator($this->container);
+ $tl = new TaskLink($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
+
+ $links = $tl->getAll(1);
+ $this->assertEmpty($links);
+
+ $links = $tl->getAll(2);
+ $this->assertEmpty($links);
+
+ // Check creation
+ $r = $validator->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2));
+ $this->assertTrue($r[0]);
+
+ $r = $validator->validateCreation(array('task_id' => 1, 'link_id' => 1));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1));
+ $this->assertFalse($r[0]);
+ }
+
+ public function testValidateModification()
+ {
+ $validator = new TaskLinkValidator($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
+
+ // Check modification
+ $r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2));
+ $this->assertTrue($r[0]);
+
+ $r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1));
+ $this->assertFalse($r[0]);
+ }
+}
diff --git a/tests/units/Validator/UserValidatorTest.php b/tests/units/Validator/UserValidatorTest.php
new file mode 100644
index 00000000..6d904ade
--- /dev/null
+++ b/tests/units/Validator/UserValidatorTest.php
@@ -0,0 +1,41 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Validator\UserValidator;
+use Kanboard\Core\Security\Role;
+
+class UserValidatorTest extends Base
+{
+ public function testValidatePasswordModification()
+ {
+ $validator = new UserValidator($this->container);
+
+ $this->container['sessionStorage']->user = array(
+ 'id' => 1,
+ 'role' => Role::APP_ADMIN,
+ 'username' => 'admin',
+ );
+
+ $result = $validator->validatePasswordModification(array());
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validatePasswordModification(array('id' => 1));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => 'wrong'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'wrong'));
+ $this->assertFalse($result[0]);
+
+ $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'admin'));
+ $this->assertTrue($result[0]);
+ }
+}