summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-10-08 09:58:11 -0400
committerFrederic Guillot <fred@kanboard.net>2016-10-08 09:58:11 -0400
commitc2f1cc8f7419fe4eb5e9bd5e6ce05d90e719be17 (patch)
tree93900cc242574a346f14e2002f050b5f2c7dc55e /tests
parent1466afb771f0291bc350441aede14c97459128e7 (diff)
Restrict task complexity to a specific range to avoid integer overflow
Diffstat (limited to 'tests')
-rw-r--r--tests/units/Validator/CommentValidatorTest.php30
-rw-r--r--tests/units/Validator/CurrencyValidatorTest.php12
-rw-r--r--tests/units/Validator/CustomFilterValidatorTest.php8
-rw-r--r--tests/units/Validator/ExternalLinkValidatorTest.php16
-rw-r--r--tests/units/Validator/GroupValidatorTest.php6
-rw-r--r--tests/units/Validator/LinkValidatorTest.php12
-rw-r--r--tests/units/Validator/PasswordResetValidatorTest.php28
-rw-r--r--tests/units/Validator/ProjectValidatorTest.php44
-rw-r--r--tests/units/Validator/TaskLinkValidatorTest.php50
-rw-r--r--tests/units/Validator/TaskValidatorTest.php42
-rw-r--r--tests/units/Validator/UserValidatorTest.php16
11 files changed, 153 insertions, 111 deletions
diff --git a/tests/units/Validator/CommentValidatorTest.php b/tests/units/Validator/CommentValidatorTest.php
index 378fe924..ce65e7a3 100644
--- a/tests/units/Validator/CommentValidatorTest.php
+++ b/tests/units/Validator/CommentValidatorTest.php
@@ -8,50 +8,50 @@ class CommentValidatorTest extends Base
{
public function testValidateCreation()
{
- $validator = new CommentValidator($this->container);
+ $commentValidator = new CommentValidator($this->container);
- $result = $validator->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => 'bla'));
+ $result = $commentValidator->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' => ''));
+ $result = $commentValidator->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'));
+ $result = $commentValidator->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'));
+ $result = $commentValidator->validateCreation(array('user_id' => 'b', 'task_id' => 1, 'comment' => 'bla'));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('user_id' => 1, 'comment' => 'bla'));
+ $result = $commentValidator->validateCreation(array('user_id' => 1, 'comment' => 'bla'));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('task_id' => 1, 'comment' => 'bla'));
+ $result = $commentValidator->validateCreation(array('task_id' => 1, 'comment' => 'bla'));
$this->assertTrue($result[0]);
- $result = $validator->validateCreation(array('comment' => 'bla'));
+ $result = $commentValidator->validateCreation(array('comment' => 'bla'));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array());
+ $result = $commentValidator->validateCreation(array());
$this->assertFalse($result[0]);
}
public function testValidateModification()
{
- $validator = new CommentValidator($this->container);
+ $commentValidator = new CommentValidator($this->container);
- $result = $validator->validateModification(array('id' => 1, 'comment' => 'bla'));
+ $result = $commentValidator->validateModification(array('id' => 1, 'comment' => 'bla'));
$this->assertTrue($result[0]);
- $result = $validator->validateModification(array('id' => 1, 'comment' => ''));
+ $result = $commentValidator->validateModification(array('id' => 1, 'comment' => ''));
$this->assertFalse($result[0]);
- $result = $validator->validateModification(array('comment' => 'bla'));
+ $result = $commentValidator->validateModification(array('comment' => 'bla'));
$this->assertFalse($result[0]);
- $result = $validator->validateModification(array('id' => 'b', 'comment' => 'bla'));
+ $result = $commentValidator->validateModification(array('id' => 'b', 'comment' => 'bla'));
$this->assertFalse($result[0]);
- $result = $validator->validateModification(array());
+ $result = $commentValidator->validateModification(array());
$this->assertFalse($result[0]);
}
}
diff --git a/tests/units/Validator/CurrencyValidatorTest.php b/tests/units/Validator/CurrencyValidatorTest.php
index 39c06d44..0b646732 100644
--- a/tests/units/Validator/CurrencyValidatorTest.php
+++ b/tests/units/Validator/CurrencyValidatorTest.php
@@ -8,20 +8,20 @@ class CurrencyValidatorTest extends Base
{
public function testValidation()
{
- $validator = new CurrencyValidator($this->container);
- $result = $validator->validateCreation(array());
+ $currencyValidator = new CurrencyValidator($this->container);
+ $result = $currencyValidator->validateCreation(array());
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('currency' => 'EUR'));
+ $result = $currencyValidator->validateCreation(array('currency' => 'EUR'));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('rate' => 1.9));
+ $result = $currencyValidator->validateCreation(array('rate' => 1.9));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('currency' => 'EUR', 'rate' => 'foobar'));
+ $result = $currencyValidator->validateCreation(array('currency' => 'EUR', 'rate' => 'foobar'));
$this->assertFalse($result[0]);
- $result = $validator->validateCreation(array('currency' => 'EUR', 'rate' => 1.25));
+ $result = $currencyValidator->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
index 3b70e42c..4e107f7f 100644
--- a/tests/units/Validator/CustomFilterValidatorTest.php
+++ b/tests/units/Validator/CustomFilterValidatorTest.php
@@ -8,16 +8,16 @@ class CustomFilterValidatorTest extends Base
{
public function testValidateCreation()
{
- $validator = new CustomFilterValidator($this->container);
+ $customFilterValidator = new CustomFilterValidator($this->container);
// Validate creation
- $r = $validator->validateCreation(array('filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
+ $r = $customFilterValidator->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));
+ $r = $customFilterValidator->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));
+ $r = $customFilterValidator->validateCreation(array('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
index b41b779a..c94c31db 100644
--- a/tests/units/Validator/ExternalLinkValidatorTest.php
+++ b/tests/units/Validator/ExternalLinkValidatorTest.php
@@ -8,27 +8,27 @@ class ExternalLinkValidatorTest extends Base
{
public function testValidateCreation()
{
- $validator = new ExternalLinkValidator($this->container);
+ $externalLinkValidator = new ExternalLinkValidator($this->container);
- $result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
+ $result = $externalLinkValidator->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'));
+ $result = $externalLinkValidator->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'));
+ $result = $externalLinkValidator->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'));
+ $result = $externalLinkValidator->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'));
+ $result = $externalLinkValidator->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'));
+ $result = $externalLinkValidator->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'));
+ $result = $externalLinkValidator->validateCreation(array('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
index 879f99ce..020a8bc6 100644
--- a/tests/units/Validator/GroupValidatorTest.php
+++ b/tests/units/Validator/GroupValidatorTest.php
@@ -8,12 +8,12 @@ class GroupValidatorTest extends Base
{
public function testValidateCreation()
{
- $validator = new GroupValidator($this->container);
+ $groupValidator = new GroupValidator($this->container);
- $result = $validator->validateCreation(array('name' => 'Test'));
+ $result = $groupValidator->validateCreation(array('name' => 'Test'));
$this->assertTrue($result[0]);
- $result = $validator->validateCreation(array('name' => ''));
+ $result = $groupValidator->validateCreation(array('name' => ''));
$this->assertFalse($result[0]);
}
diff --git a/tests/units/Validator/LinkValidatorTest.php b/tests/units/Validator/LinkValidatorTest.php
index 8b7b182c..a4ec170e 100644
--- a/tests/units/Validator/LinkValidatorTest.php
+++ b/tests/units/Validator/LinkValidatorTest.php
@@ -8,21 +8,21 @@ class LinkValidatorTest extends Base
{
public function testValidateCreation()
{
- $validator = new LinkValidator($this->container);
+ $linkValidator = new LinkValidator($this->container);
- $r = $validator->validateCreation(array('label' => 'a'));
+ $r = $linkValidator->validateCreation(array('label' => 'a'));
$this->assertTrue($r[0]);
- $r = $validator->validateCreation(array('label' => 'a', 'opposite_label' => 'b'));
+ $r = $linkValidator->validateCreation(array('label' => 'a', 'opposite_label' => 'b'));
$this->assertTrue($r[0]);
- $r = $validator->validateCreation(array('label' => 'relates to'));
+ $r = $linkValidator->validateCreation(array('label' => 'relates to'));
$this->assertFalse($r[0]);
- $r = $validator->validateCreation(array('label' => 'a', 'opposite_label' => 'a'));
+ $r = $linkValidator->validateCreation(array('label' => 'a', 'opposite_label' => 'a'));
$this->assertFalse($r[0]);
- $r = $validator->validateCreation(array('label' => ''));
+ $r = $linkValidator->validateCreation(array('label' => ''));
$this->assertFalse($r[0]);
}
diff --git a/tests/units/Validator/PasswordResetValidatorTest.php b/tests/units/Validator/PasswordResetValidatorTest.php
index d26ad422..eed77e42 100644
--- a/tests/units/Validator/PasswordResetValidatorTest.php
+++ b/tests/units/Validator/PasswordResetValidatorTest.php
@@ -8,22 +8,22 @@ class PasswordResetValidatorTest extends Base
{
public function testValidateModification()
{
- $validator = new PasswordResetValidator($this->container);
- list($valid, ) = $validator->validateModification(array('password' => 'test123', 'confirmation' => 'test123'));
+ $passwordResetValidator = new PasswordResetValidator($this->container);
+ list($valid, ) = $passwordResetValidator->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'));
+ $passwordResetValidator = new PasswordResetValidator($this->container);
+ list($valid, ) = $passwordResetValidator->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'));
+ $passwordResetValidator = new PasswordResetValidator($this->container);
+ list($valid, ) = $passwordResetValidator->validateModification(array('password' => 'test', 'confirmation' => 'test'));
$this->assertFalse($valid);
}
@@ -31,8 +31,8 @@ class PasswordResetValidatorTest extends Base
{
$this->container['sessionStorage']->captcha = 'test';
- $validator = new PasswordResetValidator($this->container);
- list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
+ $passwordResetValidator = new PasswordResetValidator($this->container);
+ list($valid,) = $passwordResetValidator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
$this->assertTrue($valid);
}
@@ -40,8 +40,8 @@ class PasswordResetValidatorTest extends Base
{
$this->container['sessionStorage']->captcha = 'test';
- $validator = new PasswordResetValidator($this->container);
- list($valid,) = $validator->validateCreation(array('captcha' => 'test'));
+ $passwordResetValidator = new PasswordResetValidator($this->container);
+ list($valid,) = $passwordResetValidator->validateCreation(array('captcha' => 'test'));
$this->assertFalse($valid);
}
@@ -49,15 +49,15 @@ class PasswordResetValidatorTest extends Base
{
$this->container['sessionStorage']->captcha = 'test123';
- $validator = new PasswordResetValidator($this->container);
- list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
+ $passwordResetValidator = new PasswordResetValidator($this->container);
+ list($valid,) = $passwordResetValidator->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'));
+ $passwordResetValidator = new PasswordResetValidator($this->container);
+ list($valid,) = $passwordResetValidator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
$this->assertFalse($valid);
}
}
diff --git a/tests/units/Validator/ProjectValidatorTest.php b/tests/units/Validator/ProjectValidatorTest.php
index e1e2f077..212c5317 100644
--- a/tests/units/Validator/ProjectValidatorTest.php
+++ b/tests/units/Validator/ProjectValidatorTest.php
@@ -9,65 +9,65 @@ class ProjectValidatorTest extends Base
{
public function testValidateCreation()
{
- $validator = new ProjectValidator($this->container);
- $p = new ProjectModel($this->container);
+ $projectValidator = new ProjectValidator($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
- $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2')));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals('TEST1', $project['identifier']);
- $project = $p->getById(2);
+ $project = $projectModel->getById(2);
$this->assertNotEmpty($project);
$this->assertEquals('', $project['identifier']);
- $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'TEST1'));
+ $r = $projectValidator->validateCreation(array('name' => 'test', 'identifier' => 'TEST1'));
$this->assertFalse($r[0]);
- $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'test1'));
+ $r = $projectValidator->validateCreation(array('name' => 'test', 'identifier' => 'test1'));
$this->assertFalse($r[0]);
- $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'a-b-c'));
+ $r = $projectValidator->validateCreation(array('name' => 'test', 'identifier' => 'a-b-c'));
$this->assertFalse($r[0]);
- $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'test 123'));
+ $r = $projectValidator->validateCreation(array('name' => 'test', 'identifier' => 'test 123'));
$this->assertFalse($r[0]);
}
public function testValidateModification()
{
- $validator = new ProjectValidator($this->container);
- $p = new ProjectModel($this->container);
+ $projectValidator = new ProjectValidator($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
- $this->assertEquals(2, $p->create(array('name' => 'UnitTest2', 'identifier' => 'TEST2')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2', 'identifier' => 'TEST2')));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals('TEST1', $project['identifier']);
- $project = $p->getById(2);
+ $project = $projectModel->getById(2);
$this->assertNotEmpty($project);
$this->assertEquals('TEST2', $project['identifier']);
- $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1'));
+ $r = $projectValidator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1'));
$this->assertTrue($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'identifier' => 'test3'));
+ $r = $projectValidator->validateModification(array('id' => 1, 'identifier' => 'test3'));
$this->assertTrue($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'identifier' => ''));
+ $r = $projectValidator->validateModification(array('id' => 1, 'identifier' => ''));
$this->assertTrue($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'identifier' => 'TEST2'));
+ $r = $projectValidator->validateModification(array('id' => 1, 'identifier' => 'TEST2'));
$this->assertFalse($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'name' => ''));
+ $r = $projectValidator->validateModification(array('id' => 1, 'name' => ''));
$this->assertFalse($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'name' => null));
+ $r = $projectValidator->validateModification(array('id' => 1, 'name' => null));
$this->assertFalse($r[0]);
}
}
diff --git a/tests/units/Validator/TaskLinkValidatorTest.php b/tests/units/Validator/TaskLinkValidatorTest.php
index 5fc50e3e..414cf696 100644
--- a/tests/units/Validator/TaskLinkValidatorTest.php
+++ b/tests/units/Validator/TaskLinkValidatorTest.php
@@ -11,62 +11,62 @@ class TaskLinkValidatorTest extends Base
{
public function testValidateCreation()
{
- $validator = new TaskLinkValidator($this->container);
- $tl = new TaskLinkModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
+ $taskLinkValidator = new TaskLinkValidator($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($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')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
- $links = $tl->getAll(1);
+ $links = $taskLinkModel->getAll(1);
$this->assertEmpty($links);
- $links = $tl->getAll(2);
+ $links = $taskLinkModel->getAll(2);
$this->assertEmpty($links);
// Check creation
- $r = $validator->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2));
+ $r = $taskLinkValidator->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));
+ $r = $taskLinkValidator->validateCreation(array('task_id' => 1, 'link_id' => 1));
$this->assertFalse($r[0]);
- $r = $validator->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2));
+ $r = $taskLinkValidator->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2));
$this->assertFalse($r[0]);
- $r = $validator->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2));
+ $r = $taskLinkValidator->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));
+ $r = $taskLinkValidator->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 ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
+ $taskLinkValidator = new TaskLinkValidator($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($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')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->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));
+ $r = $taskLinkValidator->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));
+ $r = $taskLinkValidator->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));
+ $r = $taskLinkValidator->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));
+ $r = $taskLinkValidator->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));
+ $r = $taskLinkValidator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1));
$this->assertFalse($r[0]);
}
}
diff --git a/tests/units/Validator/TaskValidatorTest.php b/tests/units/Validator/TaskValidatorTest.php
new file mode 100644
index 00000000..f6530027
--- /dev/null
+++ b/tests/units/Validator/TaskValidatorTest.php
@@ -0,0 +1,42 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Validator\TaskValidator;
+
+class TaskValidatorTest extends Base
+{
+ public function testRequiredFields()
+ {
+ $taskValidator = new TaskValidator($this->container);
+
+ $result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test'));
+ $this->assertTrue($result[0]);
+
+ $result = $taskValidator->validateCreation(array('project_id' => 1));
+ $this->assertFalse($result[0]);
+
+ $result = $taskValidator->validateCreation(array('title' => 'test'));
+ $this->assertFalse($result[0]);
+ }
+
+ public function testRangeFields()
+ {
+ $taskValidator = new TaskValidator($this->container);
+
+ $result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => 2147483647));
+ $this->assertTrue($result[0]);
+
+ $result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => -2147483647));
+ $this->assertTrue($result[0]);
+
+ $result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => 0));
+ $this->assertTrue($result[0]);
+
+ $result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => 2147483648));
+ $this->assertFalse($result[0]);
+
+ $result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => -2147483648));
+ $this->assertFalse($result[0]);
+ }
+}
diff --git a/tests/units/Validator/UserValidatorTest.php b/tests/units/Validator/UserValidatorTest.php
index 6d904ade..64c76175 100644
--- a/tests/units/Validator/UserValidatorTest.php
+++ b/tests/units/Validator/UserValidatorTest.php
@@ -9,7 +9,7 @@ class UserValidatorTest extends Base
{
public function testValidatePasswordModification()
{
- $validator = new UserValidator($this->container);
+ $userValidator = new UserValidator($this->container);
$this->container['sessionStorage']->user = array(
'id' => 1,
@@ -17,25 +17,25 @@ class UserValidatorTest extends Base
'username' => 'admin',
);
- $result = $validator->validatePasswordModification(array());
+ $result = $userValidator->validatePasswordModification(array());
$this->assertFalse($result[0]);
- $result = $validator->validatePasswordModification(array('id' => 1));
+ $result = $userValidator->validatePasswordModification(array('id' => 1));
$this->assertFalse($result[0]);
- $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456'));
+ $result = $userValidator->validatePasswordModification(array('id' => 1, 'password' => '123456'));
$this->assertFalse($result[0]);
- $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => 'wrong'));
+ $result = $userValidator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => 'wrong'));
$this->assertFalse($result[0]);
- $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456'));
+ $result = $userValidator->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'));
+ $result = $userValidator->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'));
+ $result = $userValidator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'admin'));
$this->assertTrue($result[0]);
}
}