Commit 1ba28ca0c84ca2223ac53560bedb2327d31ed4f1
1 parent
8f80761f
Exists in
master
Atualizada classe {{{CoreExt_Validate_Numeric}}} para considerar o valor {{{NULL…
…}}} quando o valor não for obrigatório
Showing
2 changed files
with
10 additions
and
0 deletions
Show diff stats
ieducar/lib/CoreExt/Validate/Numeric.php
| ... | ... | @@ -64,6 +64,10 @@ class CoreExt_Validate_Numeric extends CoreExt_Validate_Abstract |
| 64 | 64 | */ |
| 65 | 65 | protected function _validate($value) |
| 66 | 66 | { |
| 67 | + if (FALSE === $this->getOption('required') && is_null($value)) { | |
| 68 | + return TRUE; | |
| 69 | + } | |
| 70 | + | |
| 67 | 71 | if (!is_numeric($value)) { |
| 68 | 72 | throw new Exception($this->_getErrorMessage('invalid', array('@value' => $value))); |
| 69 | 73 | } | ... | ... |
ieducar/tests/unit/CoreExt/Validate/NumericTest.php
| ... | ... | @@ -85,6 +85,12 @@ class CoreExt_Validate_NumericTest extends UnitBaseTest |
| 85 | 85 | $this->_validator->isValid('zero'); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | + public function testValorNullNaoLancaExcecaoSeRequiredForFalse() | |
| 89 | + { | |
| 90 | + $this->_validator->setOptions(array('required' => FALSE)); | |
| 91 | + $this->_validator->isValid(NULL); | |
| 92 | + } | |
| 93 | + | |
| 88 | 94 | public function testValorNumericoSemConfigurarOValidador() |
| 89 | 95 | { |
| 90 | 96 | $this->assertTrue($this->_validator->isValid(0)); | ... | ... |