Move validator methods
This commit is contained in:
@@ -90,53 +90,4 @@ class CommentTest extends Base
|
||||
$this->assertFalse($c->remove(1));
|
||||
$this->assertFalse($c->remove(1111));
|
||||
}
|
||||
|
||||
public function testValidateCreation()
|
||||
{
|
||||
$c = new Comment($this->container);
|
||||
|
||||
$result = $c->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => 'bla'));
|
||||
$this->assertTrue($result[0]);
|
||||
|
||||
$result = $c->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => ''));
|
||||
$this->assertFalse($result[0]);
|
||||
|
||||
$result = $c->validateCreation(array('user_id' => 1, 'task_id' => 'a', 'comment' => 'bla'));
|
||||
$this->assertFalse($result[0]);
|
||||
|
||||
$result = $c->validateCreation(array('user_id' => 'b', 'task_id' => 1, 'comment' => 'bla'));
|
||||
$this->assertFalse($result[0]);
|
||||
|
||||
$result = $c->validateCreation(array('user_id' => 1, 'comment' => 'bla'));
|
||||
$this->assertFalse($result[0]);
|
||||
|
||||
$result = $c->validateCreation(array('task_id' => 1, 'comment' => 'bla'));
|
||||
$this->assertTrue($result[0]);
|
||||
|
||||
$result = $c->validateCreation(array('comment' => 'bla'));
|
||||
$this->assertFalse($result[0]);
|
||||
|
||||
$result = $c->validateCreation(array());
|
||||
$this->assertFalse($result[0]);
|
||||
}
|
||||
|
||||
public function testValidateModification()
|
||||
{
|
||||
$c = new Comment($this->container);
|
||||
|
||||
$result = $c->validateModification(array('id' => 1, 'comment' => 'bla'));
|
||||
$this->assertTrue($result[0]);
|
||||
|
||||
$result = $c->validateModification(array('id' => 1, 'comment' => ''));
|
||||
$this->assertFalse($result[0]);
|
||||
|
||||
$result = $c->validateModification(array('comment' => 'bla'));
|
||||
$this->assertFalse($result[0]);
|
||||
|
||||
$result = $c->validateModification(array('id' => 'b', 'comment' => 'bla'));
|
||||
$this->assertFalse($result[0]);
|
||||
|
||||
$result = $c->validateModification(array());
|
||||
$this->assertFalse($result[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,34 +52,6 @@ class CustomFilterTest extends Base
|
||||
$this->assertEquals(1, $filter['is_shared']);
|
||||
}
|
||||
|
||||
public function testValidation()
|
||||
{
|
||||
$cf = new CustomFilter($this->container);
|
||||
|
||||
// Validate creation
|
||||
$r = $cf->validateCreation(array('filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $cf->validateCreation(array('filter' => str_repeat('a', 101), 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $cf->validateCreation(array('name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
// Validate modification
|
||||
$r = $cf->validateModification(array('id' => 1, 'filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $cf->validateModification(array('filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $cf->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 = $cf->validateModification(array('id' => 1, 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
|
||||
$this->assertFalse($r[0]);
|
||||
}
|
||||
|
||||
public function testGetAll()
|
||||
{
|
||||
$u = new User($this->container);
|
||||
|
||||
@@ -57,26 +57,4 @@ class GroupTest extends Base
|
||||
$this->assertTrue($groupModel->remove(1));
|
||||
$this->assertEmpty($groupModel->getById(1));
|
||||
}
|
||||
|
||||
public function testValidateCreation()
|
||||
{
|
||||
$groupModel = new Group($this->container);
|
||||
|
||||
$result = $groupModel->validateCreation(array('name' => 'Test'));
|
||||
$this->assertTrue($result[0]);
|
||||
|
||||
$result = $groupModel->validateCreation(array('name' => ''));
|
||||
$this->assertFalse($result[0]);
|
||||
}
|
||||
|
||||
public function testValidateModification()
|
||||
{
|
||||
$groupModel = new Group($this->container);
|
||||
|
||||
$result = $groupModel->validateModification(array('name' => 'Test', 'id' => 1));
|
||||
$this->assertTrue($result[0]);
|
||||
|
||||
$result = $groupModel->validateModification(array('name' => 'Test'));
|
||||
$this->assertFalse($result[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,50 +124,4 @@ class LinkTest extends Base
|
||||
$this->assertArrayNotHasKey(0, $links);
|
||||
$this->assertEquals('relates to', $links[1]);
|
||||
}
|
||||
|
||||
public function testValidateCreation()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
|
||||
$r = $l->validateCreation(array('label' => 'a'));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $l->validateCreation(array('label' => 'a', 'opposite_label' => 'b'));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $l->validateCreation(array('label' => 'relates to'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateCreation(array('label' => 'a', 'opposite_label' => 'a'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateCreation(array('label' => ''));
|
||||
$this->assertFalse($r[0]);
|
||||
}
|
||||
|
||||
public function testValidateModification()
|
||||
{
|
||||
$l = new Link($this->container);
|
||||
|
||||
$r = $l->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => 0));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => '1'));
|
||||
$this->assertTrue($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('id' => 20, 'label' => 'relates to', 'opposite_id' => '1'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('id' => 20, 'label' => '', 'opposite_id' => '1'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('label' => '', 'opposite_id' => '1'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('id' => 20, 'opposite_id' => '1'));
|
||||
$this->assertFalse($r[0]);
|
||||
|
||||
$r = $l->validateModification(array('label' => 'test'));
|
||||
$this->assertFalse($r[0]);
|
||||
}
|
||||
}
|
||||
|
||||
57
tests/units/Validator/CommentValidatorTest.php
Normal file
57
tests/units/Validator/CommentValidatorTest.php
Normal file
@@ -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]);
|
||||
}
|
||||
}
|
||||
40
tests/units/Validator/CustomFilterValidatorTest.php
Normal file
40
tests/units/Validator/CustomFilterValidatorTest.php
Normal file
@@ -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]);
|
||||
}
|
||||
}
|
||||
30
tests/units/Validator/GroupValidatorTest.php
Normal file
30
tests/units/Validator/GroupValidatorTest.php
Normal file
@@ -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]);
|
||||
}
|
||||
}
|
||||
54
tests/units/Validator/LinkValidatorTest.php
Normal file
54
tests/units/Validator/LinkValidatorTest.php
Normal file
@@ -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]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user