summaryrefslogtreecommitdiff
path: root/tests/units/Validator
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-01-11 22:07:39 -0500
committerFrederic Guillot <fred@kanboard.net>2016-01-11 22:07:39 -0500
commit3699073371acc66ccacb56a89e87147a9c90d8c4 (patch)
treec21c55936e472655aaa5aca3a976a2d02a0ed63a /tests/units/Validator
parente31185a2bd85d7d8e16a614cb21dfdbff10ce070 (diff)
Move project validator methods
Diffstat (limited to 'tests/units/Validator')
-rw-r--r--tests/units/Validator/ProjectValidatorTest.php67
1 files changed, 67 insertions, 0 deletions
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]);
+ }
+}