summaryrefslogtreecommitdiff
path: root/tests/units/Validator/CommentValidatorTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/Validator/CommentValidatorTest.php')
-rw-r--r--tests/units/Validator/CommentValidatorTest.php57
1 files changed, 57 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]);
+ }
+}