diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-01-14 20:18:13 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-01-14 20:18:13 -0500 |
commit | 805be7d33155478ef32c4bd3643dcf4025d85a05 (patch) | |
tree | 4ee858d96f3e3bf2b630471db148446c3c56b693 /tests/units/Validator | |
parent | dc35a78374e9b091505cfc56eefcd0c631c56e3a (diff) |
Move validator methods
Diffstat (limited to 'tests/units/Validator')
-rw-r--r-- | tests/units/Validator/CommentValidatorTest.php | 57 | ||||
-rw-r--r-- | tests/units/Validator/CustomFilterValidatorTest.php | 40 | ||||
-rw-r--r-- | tests/units/Validator/GroupValidatorTest.php | 30 | ||||
-rw-r--r-- | tests/units/Validator/LinkValidatorTest.php | 54 |
4 files changed, 181 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/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/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]); + } +} |