mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Fixed some validation tests
This commit is contained in:
parent
30761f9153
commit
8700f3c7a2
3 changed files with 7 additions and 13 deletions
|
@ -311,13 +311,12 @@ class ModelValidator {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->_validate) && $this->_validate === $this->_model->validate) {
|
if ($this->_validate === $this->_model->validate) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_validate = $this->_model->validate;
|
$this->_validate = $this->_model->validate;
|
||||||
$this->_processWhitelist();
|
$this->_processWhitelist();
|
||||||
|
|
||||||
$this->_fields = array();
|
$this->_fields = array();
|
||||||
$methods = $this->getMethods();
|
$methods = $this->getMethods();
|
||||||
foreach ($this->_validate as $fieldName => $ruleSet) {
|
foreach ($this->_validate as $fieldName => $ruleSet) {
|
||||||
|
|
|
@ -171,12 +171,13 @@ class CakeRule {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function checkRequired(&$data) {
|
public function checkRequired(&$data) {
|
||||||
$required = !isset($data[$this->_field]) && $this->required === true;
|
return (
|
||||||
$required = $required || (
|
(!isset($data[$this->_field]) && $this->required === true) ||
|
||||||
isset($this->data[$this->_field]) && (empty($data[$this->_field]) &&
|
(
|
||||||
|
isset($data[$this->_field]) && (empty($data[$this->_field]) &&
|
||||||
!is_numeric($data[$this->_field])) && $this->allowEmpty === false
|
!is_numeric($data[$this->_field])) && $this->allowEmpty === false
|
||||||
|
)
|
||||||
);
|
);
|
||||||
return $required;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -346,8 +346,6 @@ class ModelValidationTest extends BaseModelTest {
|
||||||
$this->assertEquals($data, $result);
|
$this->assertEquals($data, $result);
|
||||||
$result = $TestModel->validates();
|
$result = $TestModel->validates();
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
$result = $Validator->validates();
|
|
||||||
$this->assertTrue($result);
|
|
||||||
|
|
||||||
$data = array('TestValidate' => array(
|
$data = array('TestValidate' => array(
|
||||||
'user_id' => '1',
|
'user_id' => '1',
|
||||||
|
@ -517,8 +515,6 @@ class ModelValidationTest extends BaseModelTest {
|
||||||
'title' => array('tooShort')
|
'title' => array('tooShort')
|
||||||
);
|
);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$result = $Validator->validates();
|
|
||||||
$this->assertFalse($result);
|
|
||||||
|
|
||||||
$TestModel->validate = array(
|
$TestModel->validate = array(
|
||||||
'title' => array(
|
'title' => array(
|
||||||
|
@ -540,8 +536,6 @@ class ModelValidationTest extends BaseModelTest {
|
||||||
'title' => array('tooShort', 'onlyLetters')
|
'title' => array('tooShort', 'onlyLetters')
|
||||||
);
|
);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
$result = $Validator->validates();
|
|
||||||
$this->assertFalse($result);
|
|
||||||
$result = $TestModel->validationErrors;
|
$result = $TestModel->validationErrors;
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue