diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/units/Model/ProjectTest.php | 25 | ||||
-rw-r--r-- | tests/units/Model/TaskLinkTest.php | 49 | ||||
-rw-r--r-- | tests/units/Model/UserTest.php | 32 | ||||
-rw-r--r-- | tests/units/Validator/ProjectValidatorTest.php | 67 | ||||
-rw-r--r-- | tests/units/Validator/TaskLinkValidatorTest.php | 72 | ||||
-rw-r--r-- | tests/units/Validator/UserValidatorTest.php | 41 |
6 files changed, 180 insertions, 106 deletions
diff --git a/tests/units/Model/ProjectTest.php b/tests/units/Model/ProjectTest.php index 4d8e6fc7..990cee5a 100644 --- a/tests/units/Model/ProjectTest.php +++ b/tests/units/Model/ProjectTest.php @@ -277,30 +277,5 @@ class ProjectTest extends Base $project = $p->getByIdentifier(''); $this->assertFalse($project); - - // Validation rules - $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'TEST1')); - $this->assertFalse($r[0]); - - $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'test1')); - $this->assertFalse($r[0]); - - $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1')); - $this->assertTrue($r[0]); - - $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'test3')); - $this->assertTrue($r[0]); - - $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => '')); - $this->assertTrue($r[0]); - - $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST2')); - $this->assertFalse($r[0]); - - $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'a-b-c')); - $this->assertFalse($r[0]); - - $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'test 123')); - $this->assertFalse($r[0]); } } diff --git a/tests/units/Model/TaskLinkTest.php b/tests/units/Model/TaskLinkTest.php index 4db42d99..192a4298 100644 --- a/tests/units/Model/TaskLinkTest.php +++ b/tests/units/Model/TaskLinkTest.php @@ -194,53 +194,4 @@ class TaskLinkTest extends Base $links = $tl->getAll(2); $this->assertEmpty($links); } - - public function testValidation() - { - $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 = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2)); - $this->assertTrue($r[0]); - - $r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1)); - $this->assertFalse($r[0]); - - $r = $tl->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2)); - $this->assertFalse($r[0]); - - $r = $tl->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2)); - $this->assertFalse($r[0]); - - $r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1)); - $this->assertFalse($r[0]); - - // Check modification - $r = $tl->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2)); - $this->assertTrue($r[0]); - - $r = $tl->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1)); - $this->assertFalse($r[0]); - - $r = $tl->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2)); - $this->assertFalse($r[0]); - - $r = $tl->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2)); - $this->assertFalse($r[0]); - - $r = $tl->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1)); - $this->assertFalse($r[0]); - } } diff --git a/tests/units/Model/UserTest.php b/tests/units/Model/UserTest.php index 1d381006..0987fa56 100644 --- a/tests/units/Model/UserTest.php +++ b/tests/units/Model/UserTest.php @@ -391,36 +391,4 @@ class UserTest extends Base $this->assertEquals('toto', $user['username']); $this->assertEmpty($user['token']); } - - public function testValidatePasswordModification() - { - $u = new User($this->container); - - $this->container['sessionStorage']->user = array( - 'id' => 1, - 'role' => Role::APP_ADMIN, - 'username' => 'admin', - ); - - $result = $u->validatePasswordModification(array()); - $this->assertFalse($result[0]); - - $result = $u->validatePasswordModification(array('id' => 1)); - $this->assertFalse($result[0]); - - $result = $u->validatePasswordModification(array('id' => 1, 'password' => '123456')); - $this->assertFalse($result[0]); - - $result = $u->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => 'wrong')); - $this->assertFalse($result[0]); - - $result = $u->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456')); - $this->assertFalse($result[0]); - - $result = $u->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'wrong')); - $this->assertFalse($result[0]); - - $result = $u->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'admin')); - $this->assertTrue($result[0]); - } } 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]); + } +} |