mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Fixes #3215, UserDefined Validation broken.
Added test for Validation::userDefined() git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5679 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
6677e0abcc
commit
0f1de003c6
2 changed files with 28 additions and 6 deletions
|
@ -708,14 +708,15 @@ class Validation extends Object {
|
|||
/**
|
||||
* Runs an user-defined validation.
|
||||
*
|
||||
* @param object $object Object that holds validation method
|
||||
* @param string $method Method name for validation to run
|
||||
* @param array $args Arguments to send to method
|
||||
* @return mixed Whatever method returns
|
||||
* @param mixed $check value that will be validated in user-defined methods.
|
||||
* @param object $object class that holds validation method
|
||||
* @param string $method class method name for validation to run
|
||||
* @param array $args arguments to send to method
|
||||
* @return mixed user-defined class class method returns
|
||||
* @access public
|
||||
*/
|
||||
function userDefined($object, $method, $args) {
|
||||
return call_user_func_array(array(&$object, $method), $args);
|
||||
function userDefined($check, $object, $method, $args = null) {
|
||||
return call_user_func_array(array(&$object, $method), array($check,$args));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -141,6 +141,13 @@ class Article extends CakeTestModel {
|
|||
'title' => array('allowEmpty' => false, 'rule' => VALID_NOT_EMPTY),
|
||||
'body' => VALID_NOT_EMPTY
|
||||
);
|
||||
|
||||
function titleDuplicate ($title) {
|
||||
if($title === 'My Article Title') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Short description for class.
|
||||
|
@ -1766,6 +1773,20 @@ class ModelTest extends CakeTestCase {
|
|||
$this->assertTrue($result);
|
||||
$result = $this->model->validates();
|
||||
$this->assertTrue($result);
|
||||
|
||||
$this->model->validate = array('title' => array('rule' => array('userDefined', 'Article', 'titleDuplicate')));
|
||||
|
||||
$data = array('TestValidate' => array('title' => 'My Article Title'));
|
||||
$result = $this->model->create($data);
|
||||
$this->assertTrue($result);
|
||||
$result = $this->model->validates();
|
||||
$this->assertFalse($result);
|
||||
|
||||
$data = array('TestValidate' => array('title' => 'My Article With a Different Title'));
|
||||
$result = $this->model->create($data);
|
||||
$this->assertTrue($result);
|
||||
$result = $this->model->validates();
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
function testSaveField() {
|
||||
|
|
Loading…
Reference in a new issue