Esempio n. 1
0
 /**
  * @group ZF-11267
  * If we pass in a validator instance that has a preset custom message, this
  * message should be used.
  */
 function testIfCustomMessagesOnValidatorInstancesCanBeUsed()
 {
     // test with a Digits validator
     $data = array('field1' => 'invalid data');
     $customMessage = 'Hey, that\'s not a Digit!!!';
     $validator = new Validator\Digits();
     $validator->setMessage($customMessage, 'notDigits');
     $this->assertFalse($validator->isValid('foo'), 'standalone validator thinks \'foo\' is a valid digit');
     $messages = $validator->getMessages();
     $this->assertSame($messages['notDigits'], $customMessage, 'stanalone validator does not have custom message');
     $validators = array('field1' => $validator);
     $input = new InputFilter(null, $validators, $data);
     $this->assertFalse($input->isValid(), 'invalid input is valid');
     $messages = $input->getMessages();
     $this->assertSame($messages['field1']['notDigits'], $customMessage, 'The custom message is not used');
     // test with a NotEmpty validator
     $data = array('field1' => '');
     $customMessage = 'You should really supply a value...';
     $validator = new Validator\NotEmpty();
     $validator->setMessage($customMessage, 'isEmpty');
     $this->assertFalse($validator->isValid(''), 'standalone validator thinks \'\' is not empty');
     $messages = $validator->getMessages();
     $this->assertSame($messages['isEmpty'], $customMessage, 'stanalone NotEmpty validator does not have custom message');
     $validators = array('field1' => $validator);
     $input = new InputFilter(null, $validators, $data);
     $this->assertFalse($input->isValid(), 'invalid input is valid');
     $messages = $input->getMessages();
     $this->assertSame($messages['field1']['isEmpty'], $customMessage, 'For the NotEmpty validator the custom message is not used');
 }
Esempio n. 2
0
 /**
  * @group ZF-7394
  */
 public function testSettingMultipleNotEmptyMessages()
 {
     $filters = array();
     $validators = array('name' => array('NotEmpty', 'messages' => 'Please enter your name'), 'subject' => array('NotEmpty', 'messages' => 'Please enter a subject'), 'email' => array('EmailAddress', 'messages' => 'Please enter a valid Email address'), 'content' => array('NotEmpty', 'messages' => 'Please enter message contents'));
     $data = array('name' => '', 'subject' => '', 'content' => '');
     $filter = new InputFilter($filters, $validators, $data);
     $this->assertFalse($filter->isValid());
     $message = $filter->getMessages();
     $this->assertContains('Please enter your name', $message['name']['isEmpty']);
     $this->assertContains('Please enter a subject', $message['subject']['isEmpty']);
     $this->assertContains('Please enter message contents', $message['content']['isEmpty']);
 }
Esempio n. 3
0
 /**
  * This test doesn't include any assertions as it's purpose is to 
  * ensure that passing an empty array value into a $validators rule 
  * doesn't cause a notice to be emitted
  *  
  * @group ZF-11819
  */
 public function testValidatorRuleCanHaveEmptyArrayAsMetacommandValue()
 {
     $validators = array('perms' => array('Int', 'default' => array()));
     $validate = new InputFilter(NULL, $validators);
     $validate->isValid();
 }