public function configure()
 {
     $user = $this->getOption('user');
     $this->widgetSchema['sf_guard_user_id'] = new sfWidgetFormInputHidden();
     $this->widgetSchema['language'] = new sfWidgetFormI18nChoiceLanguage(array('culture' => $user->getLanguage(), 'languages' => CultureTools::getAvailableLanguages()));
     $this->widgetSchema['country'] = new sfWidgetFormI18nChoiceCountry(array('add_empty' => true, 'culture' => $user->getLanguage(), 'countries' => CultureTools::getCountriesForLanguage($this->getOption('language'))));
     $this->widgetSchema['search_filter'] = new sfWidgetFormSelect(array('choices' => InvoiceSearchForm::getQuickDates()));
     $this->widgetSchema['series'] = new sfWidgetFormSelect(array('choices' => SeriesTable::getChoicesForSelect()));
     $this->widgetSchema['old_password'] = new sfWidgetFormInputPassword();
     $this->widgetSchema['new_password'] = new sfWidgetFormInputPassword();
     $this->widgetSchema['new_password2'] = new sfWidgetFormInputPassword();
     $this->validatorSchema['sf_guard_user_id'] = new sfValidatorAnd(array(new sfValidatorDoctrineChoice(array('model' => 'sfGuardUser', 'required' => true), array('invalid' => "The user does not exist!")), new CompareValueValidator(array('value' => $user->getGuardUser()->getId()))));
     $this->validatorSchema['language'] = new sfValidatorI18nChoiceLanguage(array('required' => true));
     $this->validatorSchema['country'] = new sfValidatorI18nChoiceCountry(array('required' => false));
     $this->validatorSchema['series'] = new sfValidatorDoctrineChoice(array('model' => 'Series'), array('required' => 'The default invoicing series is mandatory'));
     $this->validatorSchema['search_filter'] = new sfValidatorChoice(array('required' => false, 'choices' => array_keys(InvoiceSearchForm::getQuickDates())));
     $this->validatorSchema['email'] = new sfValidatorEmail(array('max_length' => 100, 'required' => true));
     $this->validatorSchema['old_password'] = new sfValidatorPass();
     $vdPassword = new sfValidatorCallback(array('callback' => array($this, 'checkPassword')), array('invalid' => 'Wrong password', 'required' => 'Old password required'));
     $passwd_min_length = sfConfig::get('app_password_min_length', 4);
     $this->validatorSchema['new_password'] = new sfValidatorPass();
     $vdNewPassword = new sfValidatorString(array('min_length' => 1, 'required' => false), array('min_length' => 'Password length must be ' . "greater than {$passwd_min_length}"));
     $this->validatorSchema['new_password2'] = new sfValidatorPass();
     $vd = new sfValidatorSchema(array('old_password' => $vdPassword, 'new_password' => $vdNewPassword, 'new_password2' => new sfValidatorPass()));
     $vd->setPostValidator(new sfValidatorSchemaCompare('new_password', '==', 'new_password2', array(), array('invalid' => "Passwords don't match")));
     $this->validatorSchema->setPostValidator(new SiwappConditionalValidator(array('control_field' => 'new_password', 'validator_schema' => $vd, 'callback' => array('Tools', 'checkLength'))));
     $this->widgetSchema->setLabels(array('nb_display_results' => 'Results to display in listings', 'language' => 'Interface language', 'series' => 'Default invoicing series', 'old_password' => 'Old password', 'new_password' => 'New password', 'new_password2' => 'New password (confirmation)', 'first_name' => 'First Name', 'last_name' => 'Last Name'));
     $this->setDefaults(array('nb_display_results' => 10, 'language' => $user->getLanguage(), 'country' => $user->getCountry()));
     $this->widgetSchema->setNameFormat('config[%s]');
 }
Beispiel #2
0
    $v->clean(array('left' => 'foo', 'right' => 'bar', 'password' => 'oof', 'password_bis' => 'rab', 'user' => array('left' => 'foo', 'right' => 'bar', 'password' => 'oof', 'password_bis' => 'rab')));
    $t->skip('', 7);
} catch (sfValidatorErrorSchema $e) {
    $t->is(count($e->getNamedErrors()), 2, '->clean() throws an exception with all error messages');
    $t->is(count($e->getGlobalErrors()), 1, '->clean() throws an exception with all error messages');
    $t->is(count($e['user']->getNamedErrors()), 1, '->clean() throws an exception with all error messages');
    $t->is(count($e['user']->getGlobalErrors()), 1, '->clean() throws an exception with all error messages');
    $t->is(isset($e['user']) ? $e['user']->getCode() : '', 'invalid password [invalid]', '->clean() throws an exception with all error messages');
    $t->is(isset($e['user']['password']) ? $e['user']['password']->getCode() : '', 'invalid', '->clean() throws an exception with all error messages');
    $t->is($e->getCode(), 'invalid user [invalid password [invalid]] password [invalid]', '->clean() throws an exception with all error messages');
}
// __clone()
$t->diag('__clone()');
$v = new sfValidatorSchema(array('v1' => $v1, 'v2' => $v2));
$v1 = clone $v;
$f1 = $v1->getFields();
$f = $v->getFields();
$t->is(array_keys($f1), array_keys($f), '__clone() clones embedded validators');
foreach ($f1 as $name => $validator) {
    $t->ok($validator !== $f[$name], '__clone() clones embedded validators');
    $t->ok($validator == $f[$name], '__clone() clones embedded validators');
}
$t->is($v1->getPreValidator(), null, '__clone() clones the pre validator');
$t->is($v1->getPostValidator(), null, '__clone() clones the post validator');
$v->setPreValidator(new sfValidatorString(array('min_length' => 4)));
$v->setPostValidator(new sfValidatorString(array('min_length' => 4)));
$v1 = clone $v;
$t->ok($v1->getPreValidator() !== $v->getPreValidator(), '__clone() clones the pre validator');
$t->ok($v1->getPreValidator() == $v->getPreValidator(), '__clone() clones the pre validator');
$t->ok($v1->getPostValidator() !== $v->getPostValidator(), '__clone() clones the post validator');
$t->ok($v1->getPostValidator() == $v->getPostValidator(), '__clone() clones the post validator');