public function executeValidateFloat() { $myValidator = new sfNumberValidator(); $myValidator->initialize($this->getContext(), array('type' => "float")); $value = urldecode($this->getRequestParameter('value')); if (!$myValidator->execute($value, $error)) { exit(UtilsHelper::Localize('system.frontend.Validate_float_error')); } exit("ok"); }
* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; require_once $_test_dir . '/unit/sfContextMock.class.php'; require_once $_test_dir . '/unit/sfValidatorTestHelper.class.php'; $t = new lime_test(53, new lime_output_color()); $context = new sfContext(); $v = new sfNumberValidator(); $v->initialize($context); // ->execute() $t->diag('->execute()'); $number = 12; $error = null; $t->ok($v->execute($number, $error), '->execute() returns true if you don\'t define any parameter'); foreach (array('not a number', '0xFE') as $number) { $error = null; $t->ok(!$v->execute($number, $error), '->execute() returns "nan_error" if value is not a number'); $t->is($error, 'Input is not a number', '->execute() changes "$error" with a default message if it returns false'); } foreach (array('any', 'decimal', 'float', 'int', 'integer') as $type) { $t->ok($v->initialize($context, array('type' => $type)), sprintf('->execute() can take "%s" as a type argument', $type)); } try { $v->initialize($context, array('type' => 'another type')); $t->fail('->initialize() throws an sfValidatorException if "type" is invalid'); } catch (sfValidatorException $e) { $t->pass('->initialize() throws an sfValidatorException if "type" is invalid'); } $h = new sfValidatorTestHelper($context, $t);
public function executeValidateFloat() { $myValidator = new sfNumberValidator(); $myValidator->initialize($this->getContext(), array('type' => "float")); if (!$myValidator->execute(urldecode($this->getRequestParameter('value')), $error)) { exit('you must enter a decimal number'); } exit("ok"); }