Move validator methods
This commit is contained in:
parent
dc35a78374
commit
805be7d331
|
|
@ -32,7 +32,7 @@ class Category extends \Kanboard\Core\Base
|
|||
'name' => $name,
|
||||
);
|
||||
|
||||
list($valid, ) = $this->category->validateCreation($values);
|
||||
list($valid, ) = $this->categoryValidator->validateCreation($values);
|
||||
return $valid ? $this->category->create($values) : false;
|
||||
}
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ class Category extends \Kanboard\Core\Base
|
|||
'name' => $name,
|
||||
);
|
||||
|
||||
list($valid, ) = $this->category->validateModification($values);
|
||||
list($valid, ) = $this->categoryValidator->validateModification($values);
|
||||
return $valid && $this->category->update($values);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Comment extends \Kanboard\Core\Base
|
|||
'reference' => $reference,
|
||||
);
|
||||
|
||||
list($valid, ) = $this->comment->validateCreation($values);
|
||||
list($valid, ) = $this->commentValidator->validateCreation($values);
|
||||
|
||||
return $valid ? $this->comment->create($values) : false;
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ class Comment extends \Kanboard\Core\Base
|
|||
'comment' => $content,
|
||||
);
|
||||
|
||||
list($valid, ) = $this->comment->validateModification($values);
|
||||
list($valid, ) = $this->commentValidator->validateModification($values);
|
||||
return $valid && $this->comment->update($values);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ class Link extends \Kanboard\Core\Base
|
|||
'opposite_label' => $opposite_label,
|
||||
);
|
||||
|
||||
list($valid, ) = $this->link->validateCreation($values);
|
||||
list($valid, ) = $this->linkValidator->validateCreation($values);
|
||||
return $valid ? $this->link->create($label, $opposite_label) : false;
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ class Link extends \Kanboard\Core\Base
|
|||
'label' => $label,
|
||||
);
|
||||
|
||||
list($valid, ) = $this->link->validateModification($values);
|
||||
list($valid, ) = $this->linkValidator->validateModification($values);
|
||||
return $valid && $this->link->update($values);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class Auth extends Base
|
|||
{
|
||||
$values = $this->request->getValues();
|
||||
$this->sessionStorage->hasRememberMe = ! empty($values['remember_me']);
|
||||
list($valid, $errors) = $this->authentication->validateForm($values);
|
||||
list($valid, $errors) = $this->authValidator->validateForm($values);
|
||||
|
||||
if ($valid) {
|
||||
$this->redirectAfterLogin();
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class Category extends Base
|
|||
$project = $this->getProject();
|
||||
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->category->validateCreation($values);
|
||||
list($valid, $errors) = $this->categoryValidator->validateCreation($values);
|
||||
|
||||
if ($valid) {
|
||||
if ($this->category->create($values)) {
|
||||
|
|
@ -99,7 +99,7 @@ class Category extends Base
|
|||
$project = $this->getProject();
|
||||
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->category->validateModification($values);
|
||||
list($valid, $errors) = $this->categoryValidator->validateModification($values);
|
||||
|
||||
if ($valid) {
|
||||
if ($this->category->update($values)) {
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class Comment extends Base
|
|||
$values = $this->request->getValues();
|
||||
$ajax = $this->request->isAjax() || $this->request->getIntegerParam('ajax');
|
||||
|
||||
list($valid, $errors) = $this->comment->validateCreation($values);
|
||||
list($valid, $errors) = $this->commentValidator->validateCreation($values);
|
||||
|
||||
if ($valid) {
|
||||
if ($this->comment->create($values)) {
|
||||
|
|
@ -127,7 +127,7 @@ class Comment extends Base
|
|||
$comment = $this->getComment();
|
||||
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->comment->validateModification($values);
|
||||
list($valid, $errors) = $this->commentValidator->validateModification($values);
|
||||
|
||||
if ($valid) {
|
||||
if ($this->comment->update($values)) {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class Currency extends Base
|
|||
public function create()
|
||||
{
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->currency->validate($values);
|
||||
list($valid, $errors) = $this->currencyValidator->validateCreation($values);
|
||||
|
||||
if ($valid) {
|
||||
if ($this->currency->create($values['currency'], $values['rate'])) {
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class Customfilter extends Base
|
|||
$values = $this->request->getValues();
|
||||
$values['user_id'] = $this->userSession->getId();
|
||||
|
||||
list($valid, $errors) = $this->customFilter->validateCreation($values);
|
||||
list($valid, $errors) = $this->customFilterValidator->validateCreation($values);
|
||||
|
||||
if ($valid) {
|
||||
if ($this->customFilter->create($values)) {
|
||||
|
|
@ -121,7 +121,7 @@ class Customfilter extends Base
|
|||
$values += array('append' => 0);
|
||||
}
|
||||
|
||||
list($valid, $errors) = $this->customFilter->validateModification($values);
|
||||
list($valid, $errors) = $this->customFilterValidator->validateModification($values);
|
||||
|
||||
if ($valid) {
|
||||
if ($this->customFilter->update($values)) {
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class Group extends Base
|
|||
public function save()
|
||||
{
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->group->validateCreation($values);
|
||||
list($valid, $errors) = $this->groupValidator->validateCreation($values);
|
||||
|
||||
if ($valid) {
|
||||
if ($this->group->create($values['name']) !== false) {
|
||||
|
|
@ -120,7 +120,7 @@ class Group extends Base
|
|||
public function update()
|
||||
{
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->group->validateModification($values);
|
||||
list($valid, $errors) = $this->groupValidator->validateModification($values);
|
||||
|
||||
if ($valid) {
|
||||
if ($this->group->update($values) !== false) {
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ class Link extends Base
|
|||
public function save()
|
||||
{
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->link->validateCreation($values);
|
||||
list($valid, $errors) = $this->linkValidator->validateCreation($values);
|
||||
|
||||
if ($valid) {
|
||||
if ($this->link->create($values['label'], $values['opposite_label']) !== false) {
|
||||
|
|
@ -108,7 +108,7 @@ class Link extends Base
|
|||
public function update()
|
||||
{
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->link->validateModification($values);
|
||||
list($valid, $errors) = $this->linkValidator->validateModification($values);
|
||||
|
||||
if ($valid) {
|
||||
if ($this->link->update($values)) {
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ use Pimple\Container;
|
|||
* @property \Kanboard\Formatter\GroupAutoCompleteFormatter $groupAutoCompleteFormatter
|
||||
* @property \Kanboard\Model\Action $action
|
||||
* @property \Kanboard\Model\ActionParameter $actionParameter
|
||||
* @property \Kanboard\Model\Authentication $authentication
|
||||
* @property \Kanboard\Model\Board $board
|
||||
* @property \Kanboard\Model\Category $category
|
||||
* @property \Kanboard\Model\Color $color
|
||||
|
|
@ -114,7 +113,15 @@ use Pimple\Container;
|
|||
* @property \Kanboard\Model\UserMetadata $userMetadata
|
||||
* @property \Kanboard\Model\Webhook $webhook
|
||||
* @property \Kanboard\Validator\ActionValidator $actionValidator
|
||||
* @property \Kanboard\Validator\AuthValidator $authValidator
|
||||
* @property \Kanboard\Validator\ColumnValidator $columnValidator
|
||||
* @property \Kanboard\Validator\CategoryValidator $categoryValidator
|
||||
* @property \Kanboard\Validator\ColumnValidator $columnValidator
|
||||
* @property \Kanboard\Validator\CommentValidator $commentValidator
|
||||
* @property \Kanboard\Validator\CurrencyValidator $currencyValidator
|
||||
* @property \Kanboard\Validator\CustomFilterValidator $customFilterValidator
|
||||
* @property \Kanboard\Validator\GroupValidator $groupValidator
|
||||
* @property \Kanboard\Validator\LinkValidator $linkValidator
|
||||
* @property \Kanboard\Validator\PasswordResetValidator $passwordResetValidator
|
||||
* @property \Kanboard\Validator\ProjectValidator $projectValidator
|
||||
* @property \Kanboard\Validator\SubtaskValidator $subtaskValidator
|
||||
|
|
|
|||
|
|
@ -2,9 +2,6 @@
|
|||
|
||||
namespace Kanboard\Model;
|
||||
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
|
||||
/**
|
||||
* Category model
|
||||
*
|
||||
|
|
@ -212,63 +209,4 @@ class Category extends Base
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate category creation
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateCreation(array $values)
|
||||
{
|
||||
$rules = array(
|
||||
new Validators\Required('project_id', t('The project id is required')),
|
||||
new Validators\Required('name', t('The name is required')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate category modification
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateModification(array $values)
|
||||
{
|
||||
$rules = array(
|
||||
new Validators\Required('id', t('The id is required')),
|
||||
new Validators\Required('name', t('The name is required')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common validation rules
|
||||
*
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
private function commonValidationRules()
|
||||
{
|
||||
return array(
|
||||
new Validators\Integer('id', t('The id must be an integer')),
|
||||
new Validators\Integer('project_id', t('The project id must be an integer')),
|
||||
new Validators\MaxLength('name', t('The maximum length is %d characters', 50), 50)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
namespace Kanboard\Model;
|
||||
|
||||
use Kanboard\Event\CommentEvent;
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
|
||||
/**
|
||||
* Comment model
|
||||
|
|
@ -152,63 +150,4 @@ class Comment extends Base
|
|||
{
|
||||
return $this->db->table(self::TABLE)->eq('id', $comment_id)->remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate comment creation
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Required parameters to save an action
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateCreation(array $values)
|
||||
{
|
||||
$rules = array(
|
||||
new Validators\Required('task_id', t('This value is required')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate comment modification
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Required parameters to save an action
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateModification(array $values)
|
||||
{
|
||||
$rules = array(
|
||||
new Validators\Required('id', t('This value is required')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common validation rules
|
||||
*
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
private function commonValidationRules()
|
||||
{
|
||||
return array(
|
||||
new Validators\Integer('id', t('This value must be an integer')),
|
||||
new Validators\Integer('task_id', t('This value must be an integer')),
|
||||
new Validators\Integer('user_id', t('This value must be an integer')),
|
||||
new Validators\MaxLength('reference', t('The maximum length is %d characters', 50), 50),
|
||||
new Validators\Required('comment', t('Comment is required'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,6 @@
|
|||
|
||||
namespace Kanboard\Model;
|
||||
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
|
||||
/**
|
||||
* Currency
|
||||
*
|
||||
|
|
@ -83,24 +80,4 @@ class Currency extends Base
|
|||
{
|
||||
return $this->db->table(self::TABLE)->eq('currency', $currency)->update(array('rate' => $rate));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validate(array $values)
|
||||
{
|
||||
$v = new Validator($values, array(
|
||||
new Validators\Required('currency', t('Field required')),
|
||||
new Validators\Required('rate', t('Field required')),
|
||||
));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,6 @@
|
|||
|
||||
namespace Kanboard\Model;
|
||||
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
|
||||
/**
|
||||
* Custom Filter model
|
||||
*
|
||||
|
|
@ -102,63 +99,4 @@ class CustomFilter extends Base
|
|||
{
|
||||
return $this->db->table(self::TABLE)->eq('id', $filter_id)->remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Common validation rules
|
||||
*
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
private function commonValidationRules()
|
||||
{
|
||||
return array(
|
||||
new Validators\Required('project_id', t('Field required')),
|
||||
new Validators\Required('user_id', t('Field required')),
|
||||
new Validators\Required('name', t('Field required')),
|
||||
new Validators\Required('filter', t('Field required')),
|
||||
new Validators\Integer('user_id', t('This value must be an integer')),
|
||||
new Validators\Integer('project_id', t('This value must be an integer')),
|
||||
new Validators\MaxLength('name', t('The maximum length is %d characters', 100), 100),
|
||||
new Validators\MaxLength('filter', t('The maximum length is %d characters', 100), 100)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate filter creation
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateCreation(array $values)
|
||||
{
|
||||
$v = new Validator($values, $this->commonValidationRules());
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate filter modification
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateModification(array $values)
|
||||
{
|
||||
$rules = array(
|
||||
new Validators\Required('id', t('Field required')),
|
||||
new Validators\Integer('id', t('This value must be an integer')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,59 +117,4 @@ class Group extends Base
|
|||
{
|
||||
return $this->db->table(self::TABLE)->eq('id', $values['id'])->update($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate creation
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateCreation(array $values)
|
||||
{
|
||||
$v = new Validator($values, $this->commonValidationRules());
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate modification
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateModification(array $values)
|
||||
{
|
||||
$rules = array(
|
||||
new Validators\Required('id', t('The id is required')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common validation rules
|
||||
*
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
private function commonValidationRules()
|
||||
{
|
||||
return array(
|
||||
new Validators\Required('name', t('The name is required')),
|
||||
new Validators\MaxLength('name', t('The maximum length is %d characters', 100), 100),
|
||||
new Validators\Unique('name', t('The name must be unique'), $this->db->getConnection(), self::TABLE, 'id'),
|
||||
new Validators\MaxLength('external_id', t('The maximum length is %d characters', 255), 255),
|
||||
new Validators\Integer('id', t('This value must be an integer')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
namespace Kanboard\Model;
|
||||
|
||||
use PDO;
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
|
||||
/**
|
||||
* Link model
|
||||
|
|
@ -176,47 +174,4 @@ class Link extends Base
|
|||
$this->db->table(self::TABLE)->eq('opposite_id', $link_id)->update(array('opposite_id' => 0));
|
||||
return $this->db->table(self::TABLE)->eq('id', $link_id)->remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate creation
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateCreation(array $values)
|
||||
{
|
||||
$v = new Validator($values, array(
|
||||
new Validators\Required('label', t('Field required')),
|
||||
new Validators\Unique('label', t('This label must be unique'), $this->db->getConnection(), self::TABLE),
|
||||
new Validators\NotEquals('label', 'opposite_label', t('The labels must be different')),
|
||||
));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate modification
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateModification(array $values)
|
||||
{
|
||||
$v = new Validator($values, array(
|
||||
new Validators\Required('id', t('Field required')),
|
||||
new Validators\Required('opposite_id', t('Field required')),
|
||||
new Validators\Required('label', t('Field required')),
|
||||
new Validators\Unique('label', t('This label must be unique'), $this->db->getConnection(), self::TABLE),
|
||||
));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ class ClassProvider implements ServiceProviderInterface
|
|||
'Model' => array(
|
||||
'Action',
|
||||
'ActionParameter',
|
||||
'Authentication',
|
||||
'Board',
|
||||
'Category',
|
||||
'Color',
|
||||
|
|
@ -86,7 +85,14 @@ class ClassProvider implements ServiceProviderInterface
|
|||
),
|
||||
'Validator' => array(
|
||||
'ActionValidator',
|
||||
'AuthValidator',
|
||||
'CategoryValidator',
|
||||
'ColumnValidator',
|
||||
'CommentValidator',
|
||||
'CurrencyValidator',
|
||||
'CustomFilterValidator',
|
||||
'GroupValidator',
|
||||
'LinkValidator',
|
||||
'PasswordResetValidator',
|
||||
'ProjectValidator',
|
||||
'SubtaskValidator',
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Kanboard\Model;
|
||||
namespace Kanboard\Validator;
|
||||
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
use Gregwar\Captcha\CaptchaBuilder;
|
||||
|
||||
/**
|
||||
* Authentication model
|
||||
* Authentication Validator
|
||||
*
|
||||
* @package model
|
||||
* @package validator
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Authentication extends Base
|
||||
class AuthValidator extends Base
|
||||
{
|
||||
/**
|
||||
* Validate user login form
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace Kanboard\Validator;
|
||||
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
|
||||
/**
|
||||
* Category Validator
|
||||
*
|
||||
* @package validator
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class CategoryValidator extends Base
|
||||
{
|
||||
/**
|
||||
* Validate category creation
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateCreation(array $values)
|
||||
{
|
||||
$rules = array(
|
||||
new Validators\Required('project_id', t('The project id is required')),
|
||||
new Validators\Required('name', t('The name is required')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate category modification
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateModification(array $values)
|
||||
{
|
||||
$rules = array(
|
||||
new Validators\Required('id', t('The id is required')),
|
||||
new Validators\Required('name', t('The name is required')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common validation rules
|
||||
*
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
private function commonValidationRules()
|
||||
{
|
||||
return array(
|
||||
new Validators\Integer('id', t('The id must be an integer')),
|
||||
new Validators\Integer('project_id', t('The project id must be an integer')),
|
||||
new Validators\MaxLength('name', t('The maximum length is %d characters', 50), 50)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace Kanboard\Validator;
|
||||
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
|
||||
/**
|
||||
* Comment Validator
|
||||
*
|
||||
* @package validator
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class CommentValidator extends Base
|
||||
{
|
||||
/**
|
||||
* Validate comment creation
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Required parameters to save an action
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateCreation(array $values)
|
||||
{
|
||||
$rules = array(
|
||||
new Validators\Required('task_id', t('This value is required')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate comment modification
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Required parameters to save an action
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateModification(array $values)
|
||||
{
|
||||
$rules = array(
|
||||
new Validators\Required('id', t('This value is required')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common validation rules
|
||||
*
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
private function commonValidationRules()
|
||||
{
|
||||
return array(
|
||||
new Validators\Integer('id', t('This value must be an integer')),
|
||||
new Validators\Integer('task_id', t('This value must be an integer')),
|
||||
new Validators\Integer('user_id', t('This value must be an integer')),
|
||||
new Validators\MaxLength('reference', t('The maximum length is %d characters', 50), 50),
|
||||
new Validators\Required('comment', t('Comment is required'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Kanboard\Validator;
|
||||
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
|
||||
/**
|
||||
* Currency Validator
|
||||
*
|
||||
* @package validator
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class CurrencyValidator extends Base
|
||||
{
|
||||
/**
|
||||
* Validate
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateCreation(array $values)
|
||||
{
|
||||
$v = new Validator($values, array(
|
||||
new Validators\Required('currency', t('Field required')),
|
||||
new Validators\Required('rate', t('Field required')),
|
||||
));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace Kanboard\Validator;
|
||||
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
|
||||
/**
|
||||
* Custom Filter Validator
|
||||
*
|
||||
* @package validator
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class CustomFilterValidator extends Base
|
||||
{
|
||||
/**
|
||||
* Common validation rules
|
||||
*
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
private function commonValidationRules()
|
||||
{
|
||||
return array(
|
||||
new Validators\Required('project_id', t('Field required')),
|
||||
new Validators\Required('user_id', t('Field required')),
|
||||
new Validators\Required('name', t('Field required')),
|
||||
new Validators\Required('filter', t('Field required')),
|
||||
new Validators\Integer('user_id', t('This value must be an integer')),
|
||||
new Validators\Integer('project_id', t('This value must be an integer')),
|
||||
new Validators\MaxLength('name', t('The maximum length is %d characters', 100), 100),
|
||||
new Validators\MaxLength('filter', t('The maximum length is %d characters', 100), 100)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate filter creation
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateCreation(array $values)
|
||||
{
|
||||
$v = new Validator($values, $this->commonValidationRules());
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate filter modification
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateModification(array $values)
|
||||
{
|
||||
$rules = array(
|
||||
new Validators\Required('id', t('Field required')),
|
||||
new Validators\Integer('id', t('This value must be an integer')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace Kanboard\Validator;
|
||||
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
use Kanboard\Model\Group;
|
||||
|
||||
/**
|
||||
* Group Validator
|
||||
*
|
||||
* @package validator
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class GroupValidator extends Base
|
||||
{
|
||||
/**
|
||||
* Validate creation
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateCreation(array $values)
|
||||
{
|
||||
$v = new Validator($values, $this->commonValidationRules());
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate modification
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateModification(array $values)
|
||||
{
|
||||
$rules = array(
|
||||
new Validators\Required('id', t('The id is required')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common validation rules
|
||||
*
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
private function commonValidationRules()
|
||||
{
|
||||
return array(
|
||||
new Validators\Required('name', t('The name is required')),
|
||||
new Validators\MaxLength('name', t('The maximum length is %d characters', 100), 100),
|
||||
new Validators\Unique('name', t('The name must be unique'), $this->db->getConnection(), Group::TABLE, 'id'),
|
||||
new Validators\MaxLength('external_id', t('The maximum length is %d characters', 255), 255),
|
||||
new Validators\Integer('id', t('This value must be an integer')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace Kanboard\Validator;
|
||||
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
use Kanboard\Model\Link;
|
||||
|
||||
/**
|
||||
* Link Validator
|
||||
*
|
||||
* @package validator
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class LinkValidator extends Base
|
||||
{
|
||||
/**
|
||||
* Validate creation
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateCreation(array $values)
|
||||
{
|
||||
$v = new Validator($values, array(
|
||||
new Validators\Required('label', t('Field required')),
|
||||
new Validators\Unique('label', t('This label must be unique'), $this->db->getConnection(), Link::TABLE),
|
||||
new Validators\NotEquals('label', 'opposite_label', t('The labels must be different')),
|
||||
));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate modification
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Form values
|
||||
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
|
||||
*/
|
||||
public function validateModification(array $values)
|
||||
{
|
||||
$v = new Validator($values, array(
|
||||
new Validators\Required('id', t('Field required')),
|
||||
new Validators\Required('opposite_id', t('Field required')),
|
||||
new Validators\Required('label', t('Field required')),
|
||||
new Validators\Unique('label', t('This label must be unique'), $this->db->getConnection(), Link::TABLE),
|
||||
));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue