/** * @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'); }
/** * @group ZF-3736 */ public function testTranslateNotEmptyMessagesByUsingRegistry() { $translator = new Translator\Adapter\ArrayAdapter(array('locale' => 'en_US', 'content' => array('missingMessage' => 'Still missing'))); \Zend\Registry::set('Zend_Translate', $translator); $validators = array('rule1' => array('presence' => 'required', 'fields' => array('field1', 'field2'), 'default' => array('field1default'))); $data = array(); $input = new InputFilter(null, $validators, $data); $this->assertTrue($input->hasMissing(), 'Expected hasMissing() to return true'); $this->assertFalse($input->hasInvalid(), 'Expected hasInvalid() to return false'); $this->assertFalse($input->hasUnknown(), 'Expected hasUnknown() to return false'); $this->assertFalse($input->hasValid(), 'Expected hasValid() to return false'); $missing = $input->getMissing(); $this->assertInternalType('array', $missing); $this->assertEquals(array('rule1'), array_keys($missing)); $this->assertEquals(array("Still missing"), $missing['rule1']); }
/** * 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(); }