/**
  * @covers FormValidatorEmail
  * @covers FormValidator
  */
 public function testIsValid()
 {
     $form = new Form('some template');
     $form->setData('testData', '*****@*****.**');
     $validator = new FormValidatorEmail($form, 'testData', FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key');
     self::assertTrue($validator->isValid());
     self::assertEquals(array('testData' => array('required', 'email')), $form->cssValidation);
     $form->setData('testData', 'anything else');
     $validator = new FormValidatorEmail($form, 'testData', FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key');
     self::assertFalse($validator->isValid());
 }
Beispiel #2
0
 /**
  * Constructor.
  */
 function MetadataForm($paper)
 {
     $roleDao =& DAORegistry::getDAO('RoleDAO');
     $schedConf =& Request::getSchedConf();
     $user =& Request::getUser();
     $roleId = $roleDao->getRoleIdFromPath(Request::getRequestedPage());
     // If the user is a director of this paper, make the form editable.
     $this->canEdit = false;
     if ($roleId != null && ($roleId == ROLE_ID_DIRECTOR || $roleId == ROLE_ID_TRACK_DIRECTOR)) {
         $this->canEdit = true;
     }
     // Check if the author can modify metadata.
     if ($roleId == ROLE_ID_AUTHOR) {
         if (AuthorAction::mayEditPaper($paper)) {
             $this->canEdit = true;
         }
     }
     if ($this->canEdit) {
         parent::Form('submission/metadata/metadataEdit.tpl');
         $this->addCheck(new FormValidatorLocale($this, 'title', 'required', 'author.submit.form.titleRequired'));
         $this->addCheck(new FormValidatorArray($this, 'authors', 'required', 'author.submit.form.authorRequiredFields', array('firstName', 'lastName')));
         $this->addCheck(new FormValidatorArrayCustom($this, 'authors', 'required', 'author.submit.form.authorRequiredFields', create_function('$email, $regExp', 'return String::regexp_match($regExp, $email);'), array(FormValidatorEmail::getRegexp()), false, array('email')));
         $this->addCheck(new FormValidatorArrayCustom($this, 'authors', 'required', 'user.profile.form.urlInvalid', create_function('$url, $regExp', 'return empty($url) ? true : String::regexp_match($regExp, $url);'), array(FormValidatorUrl::getRegexp()), false, array('url')));
     } else {
         parent::Form('submission/metadata/metadataView.tpl');
     }
     // If the user is a reviewer of this paper, do not show authors.
     $this->canViewAuthors = true;
     if ($roleId != null && $roleId == ROLE_ID_REVIEWER) {
         $this->canViewAuthors = false;
     }
     $this->paper = $paper;
     $this->addCheck(new FormValidatorPost($this));
 }
 function elementsAreEmails($elements)
 {
     if (!is_array($elements)) {
         return false;
     }
     $regexp = FormValidatorEmail::getRegexp();
     foreach ($elements as $element) {
         if (!String::regexp_match($regexp, $element)) {
             echo "{$element} failed {$regexp}<br/>\n";
             return false;
         }
     }
     return true;
 }
 /**
  * Constructor.
  */
 function AuthorSubmitStep3Form($paper)
 {
     parent::AuthorSubmitForm($paper, 3);
     // Validation checks for this form
     $this->addCheck(new FormValidatorCustom($this, 'authors', 'required', 'author.submit.form.authorRequired', create_function('$authors', 'return count($authors) > 0;')));
     $this->addCheck(new FormValidatorArray($this, 'authors', 'required', 'author.submit.form.authorRequiredFields', array('firstName', 'lastName')));
     $this->addCheck(new FormValidatorArrayCustom($this, 'authors', 'required', 'author.submit.form.authorRequiredFields', create_function('$email, $regExp', 'return String::regexp_match($regExp, $email);'), array(FormValidatorEmail::getRegexp()), false, array('email')));
     $this->addCheck(new FormValidatorArrayCustom($this, 'authors', 'required', 'user.profile.form.urlInvalid', create_function('$url, $regExp', 'return empty($url) ? true : String::regexp_match($regExp, $url);'), array(FormValidatorUrl::getRegexp()), false, array('url')));
     $this->addCheck(new FormValidatorLocale($this, 'title', 'required', 'author.submit.form.titleRequired'));
     $schedConf =& Request::getSchedConf();
     $reviewMode = $paper->getReviewMode();
     if ($reviewMode != REVIEW_MODE_PRESENTATIONS_ALONE) {
         $this->addCheck(new FormValidatorLocale($this, 'abstract', 'required', 'author.submit.form.abstractRequired'));
         $trackDao =& DAORegistry::getDAO('TrackDAO');
         $track = $trackDao->getTrack($paper->getTrackId());
         $abstractWordCount = $track->getAbstractWordCount();
         if (isset($abstractWordCount) && $abstractWordCount > 0) {
             $this->addCheck(new FormValidatorCustom($this, 'abstract', 'required', 'author.submit.form.wordCountAlert', create_function('$abstract, $wordCount', 'foreach ($abstract as $localizedAbstract) {return count(explode(" ",$localizedAbstract)) < $wordCount; }'), array($abstractWordCount)));
         }
     }
 }
 function getMessage()
 {
     $primaryLocale = Locale::getPrimaryLocale();
     $allLocales = Locale::getAllLocales();
     return parent::getMessage() . ' (' . $allLocales[$primaryLocale] . ')';
 }
 /**
  * Constructor.
  * @see FormValidatorRegExp::FormValidatorRegExp()
  */
 function FormValidatorEmail(&$form, $field, $type, $message)
 {
     parent::FormValidatorRegExp($form, $field, $type, $message, FormValidatorEmail::getRegexp());
 }