Esempio n. 1
0
 public function validateAddPerson()
 {
     $has_errors = false;
     $msg = "Required";
     $type = $this->getRequestParameter('type');
     $person_name = $this->getRequestParameter('event_person_name_' . $type);
     $email = $this->getRequestParameter('event_email_' . $type);
     $validator = new sfStringValidator();
     $validator->initialize($this->getContext(), array('min' => 1));
     $email_validator = new sfEmailValidator();
     $email_validator->initialize($this->getContext());
     if (!$validator->execute($person_name, $msg)) {
         $this->getRequest()->setError('event_person_name_' . $type, 'Required');
         $has_errors = true;
     } elseif (!$email_validator->execute($email, $msg)) {
         $this->getRequest()->setError('event_email_' . $type, 'Invalid email address');
         $has_errors = true;
     }
     if (!$validator->execute($email, $msg)) {
         $this->getRequest()->setError('event_email_' . $type, 'Required');
         $has_errors = true;
     }
     if ($has_errors) {
         return false;
     }
     return true;
 }
Esempio n. 2
0
 public function executeValidateString()
 {
     $myValidator = new sfStringValidator();
     $myValidator->initialize($this->getContext(), array());
     $value = urldecode($this->getRequestParameter('value'));
     if (!$myValidator->execute($value, $error)) {
         exit(UtilsHelper::Localize('system.frontend.Validate_string_error'));
     }
     exit("ok");
 }
 * (c) 2004-2006 Fabien Potencier <*****@*****.**>
 * 
 * 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 . '/../../../../test/unit/sfContextMock.class.php';
require_once dirname(__FILE__) . '/sfValidatorTestHelper.class.php';
$t = new lime_test(36, new lime_output_color());
$context = sfContext::getInstance();
$v = new sfStringValidator($context);
// ->execute()
$t->diag('->execute()');
$text = 'a random string to test string validator';
$error = null;
$t->ok($v->execute($text, $error), '->execute() returns true if you don\'t define any parameter');
$h = new sfValidatorTestHelper($context, $t);
// min
$t->diag('->execute() - min parameter');
$h->launchTests($v, '123456', true, 'min', null, array('min' => 5));
$h->launchTests($v, '12345', true, 'min', null, array('min' => 5));
$h->launchTests($v, '123', false, 'min', 'min_error', array('min' => 5));
// max
$t->diag('->execute() - max parameter');
$h->launchTests($v, '123', true, 'max', null, array('max' => 5));
$h->launchTests($v, '12345', true, 'max', null, array('max' => 5));
$h->launchTests($v, '123456', false, 'max', 'max_error', array('max' => 5));
// values
$t->diag('->execute() - values parameter');
$h->launchTests($v, 'foo', true, 'values', null, array('values' => array('foo')));
$h->launchTests($v, 'bar', true, 'values', null, array('values' => array('foo', 'bar')));
Esempio n. 4
0
 public function executeValidateString()
 {
     $myValidator = new sfStringValidator();
     $myValidator->initialize($this->getContext(), array());
     if (!$myValidator->execute(urldecode($this->getRequestParameter('value')), $error)) {
         exit('invalid data');
     }
     exit("ok");
 }
Esempio n. 5
0
 public function validateEdit()
 {
     $has_errors = false;
     $msg = "Required";
     $guest_data = $this->getRequestParameter('guest');
     $event_id = $this->getRequestParameter('event_id');
     $c = new Criteria();
     $c->add(EventPeer::ID, $event_id);
     $event = EventPeer::doSelectOne($c);
     if (is_array($guest_data)) {
         $validator = new sfStringValidator();
         $validator->initialize($this->getContext(), array('min' => 1));
         foreach ($guest_data as $field => $data) {
             $c = new Criteria();
             $c->add(RegFieldPeer::NAME, $field);
             $regField = RegFieldPeer::doSelectOne($c);
             if ($regField) {
                 $c = new Criteria();
                 $c->add(RegFormPeer::EVENT_ID, $event->getId());
                 $c->add(RegFormPeer::REG_FIELD_ID, $regField->getId());
                 $regForm = RegFormPeer::doSelectOne($c);
                 if ($regForm->getRequiredField() && !$validator->execute($data, $msg)) {
                     $this->getRequest()->setError('guest{' . $field . '}', 'Required');
                     $has_errors = true;
                 }
             }
         }
         if ($has_errors) {
             return false;
         }
         return true;
     }
     return false;
 }