Move validator methods
This commit is contained in:
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