Commit 9afff835780cf874afafa79a43edb34afab736af

Authored by Eriksen Costa Paixão
1 parent 173ca484
Exists in master

Atualizada interface de CoreExt_Validate_Abstract. Método {{{_getOption()}}} pro…

…tected agora é public, com a assinatura {{{getOption()}}}
ieducar/lib/CoreExt/Validate/Abstract.php
... ... @@ -140,7 +140,7 @@ abstract class CoreExt_Validate_Abstract implements CoreExt_Validate_Interface
140 140 * @param string $key
141 141 * @return mixed|NULL
142 142 */
143   - protected function _getOption($key)
  143 + public function getOption($key)
144 144 {
145 145 return $this->_hasOption($key) ? $this->_options[$key] : NULL;
146 146 }
... ... @@ -161,13 +161,13 @@ abstract class CoreExt_Validate_Abstract implements CoreExt_Validate_Interface
161 161 $this->_value = $value;
162 162 $value = $this->_sanitize($value);
163 163  
164   - if (TRUE == $this->_getOption('trim')) {
  164 + if (TRUE == $this->getOption('trim')) {
165 165 $value = trim($value);
166 166 }
167 167  
168 168 $this->_sanitized = $value;
169 169  
170   - if (TRUE == $this->_getOption('required') && $this->_isEmpty($value)) {
  170 + if (TRUE == $this->getOption('required') && $this->_isEmpty($value)) {
171 171 throw new Exception($this->_requiredMessage);
172 172 }
173 173  
... ... @@ -244,7 +244,7 @@ abstract class CoreExt_Validate_Abstract implements CoreExt_Validate_Interface
244 244 */
245 245 protected function _getErrorMessage($key, array $options = array())
246 246 {
247   - $message = $this->_getOption($key);
  247 + $message = $this->getOption($key);
248 248  
249 249 if (is_array($message)) {
250 250 // Verifica o tipo de @value para determinar a quantidade de $count
... ...
ieducar/lib/CoreExt/Validate/Choice.php
... ... @@ -69,9 +69,9 @@ class CoreExt_Validate_Choice extends CoreExt_Validate_Abstract
69 69 {
70 70 if ($this->_hasOption('choices')) {
71 71 $value = $this->_getStringArray($value);
72   - $choices = $this->_getStringArray($this->_getOption('choices'));
  72 + $choices = $this->_getStringArray($this->getOption('choices'));
73 73  
74   - if ($this->_hasOption('multiple') && FALSE == $this->_getOption('multiple')) {
  74 + if ($this->_hasOption('multiple') && FALSE == $this->getOption('multiple')) {
75 75 if (in_array($value, $choices, TRUE)) {
76 76 return TRUE;
77 77 }
... ... @@ -83,7 +83,7 @@ class CoreExt_Validate_Choice extends CoreExt_Validate_Abstract
83 83 }
84 84 throw new Exception($this->_getErrorMessage(
85 85 'multiple_error',
86   - array('@value' => array_diff($value, $this->_getOption('choices'))))
  86 + array('@value' => array_diff($value, $this->getOption('choices'))))
87 87 );
88 88 }
89 89 }
... ...
ieducar/lib/CoreExt/Validate/Numeric.php
... ... @@ -72,16 +72,16 @@ class CoreExt_Validate_Numeric extends CoreExt_Validate_Abstract
72 72 $value = floatval($value);
73 73  
74 74 if ($this->_hasOption('min') &&
75   - $value < floatval($this->_getOption('min'))) {
  75 + $value < floatval($this->getOption('min'))) {
76 76 throw new Exception($this->_getErrorMessage('min_error', array(
77   - '@value' => $value, '@min' => $this->_getOption('min')
  77 + '@value' => $value, '@min' => $this->getOption('min')
78 78 )));
79 79 }
80 80  
81 81 if ($this->_hasOption('max') &&
82   - $value > floatval($this->_getOption('max'))) {
  82 + $value > floatval($this->getOption('max'))) {
83 83 throw new Exception($this->_getErrorMessage('max_error', array(
84   - '@value' => $value, '@max' => $this->_getOption('max')
  84 + '@value' => $value, '@max' => $this->getOption('max')
85 85 )));
86 86 }
87 87  
... ...
ieducar/lib/CoreExt/Validate/String.php
... ... @@ -62,15 +62,15 @@ class CoreExt_Validate_String extends CoreExt_Validate_Abstract
62 62 {
63 63 $length = strlen($value);
64 64  
65   - if ($this->_hasOption('min') && $length < $this->_getOption('min')) {
  65 + if ($this->_hasOption('min') && $length < $this->getOption('min')) {
66 66 throw new Exception($this->_getErrorMessage('min_error',
67   - array('@value' => $this->getSanitizedValue(), '@min' => $this->_getOption('min')))
  67 + array('@value' => $this->getSanitizedValue(), '@min' => $this->getOption('min')))
68 68 );
69 69 }
70 70  
71   - if ($this->_hasOption('max') && $length > $this->_getOption('max')) {
  71 + if ($this->_hasOption('max') && $length > $this->getOption('max')) {
72 72 throw new Exception($this->_getErrorMessage('max_error',
73   - array('@value' => $this->getSanitizedValue(), '@max' => $this->_getOption('max')))
  73 + array('@value' => $this->getSanitizedValue(), '@max' => $this->getOption('max')))
74 74 );
75 75 }
76 76  
... ...
ieducar/modules/FormulaMedia/Validate/Formula.php
... ... @@ -132,10 +132,10 @@ class FormulaMedia_Validate_Formula extends CoreExt_Validate_Abstract
132 132 $tokensAvailable = array();
133 133  
134 134 if ($this->_hasOption('excludeToken') &&
135   - is_array($this->_getOption('excludeToken')) &&
136   - 0 < count($this->_getOption('excludeToken'))
  135 + is_array($this->getOption('excludeToken')) &&
  136 + 0 < count($this->getOption('excludeToken'))
137 137 ) {
138   - $excludeToken = $this->_getOption('excludeToken');
  138 + $excludeToken = $this->getOption('excludeToken');
139 139 foreach ($tokens as $token) {
140 140 if (!in_array($token, $excludeToken)) {
141 141 $tokensAvailable[] = $token;
... ...
ieducar/tests/unit/CoreExt/Validate/ValidateTest.php
... ... @@ -60,6 +60,16 @@ class CoreExt_ValidateTest extends UnitBaseTest
60 60 $this->_validator->setOptions(array('invalidOption' => TRUE));
61 61 }
62 62  
  63 + public function testConfiguraOpcaoDoValidator()
  64 + {
  65 + $this->_validator->setOptions(array('required' => FALSE));
  66 +
  67 + $options = $this->_validator->getOptions();
  68 + $this->assertFalse($options['required']);
  69 +
  70 + $this->assertFalse($this->_validator->getOption('required'));
  71 + }
  72 +
63 73 /**
64 74 * @expectedException Exception
65 75 */
... ...