public function testZvbClassesReportCustomMsgsWithErrorManager() { $testData1 = array('field1' => 'This string is 34 characters long.', 'field2' => 'However, this string contains 44 characters.'); $em = new Zend_Validate_Builder_ErrorManager(); $em->setTemplate('field1', 'Zend_Validate_StringLength', 'stringLengthTooShort', '\'%value%\' should be longer than %min% chars'); $em->setTemplate('field2', 'Zend_Validate_StringLength', 'stringLengthTooLong', '\'%value%\' should not be longer than %max% chars'); $zvb = new Zend_Validate_Builder(); $zvb->setErrorManager($em); $ff = new Zend_Validate_Builder_FluentFacade($zvb); $ff->field1->stringLength(40); $ff->field2->stringLength(30, 40); if (!$ff->isValid($testData1)) { $expected = array('field1' => array('Zend_Validate_StringLength' => array('stringLengthTooShort' => "'This string is 34 characters long.' should be longer than 40 chars")), 'field2' => array('Zend_Validate_StringLength' => array('stringLengthTooLong' => "'However, this string contains 44 characters.' should not be longer than 40 chars"))); $actual = $ff->getMessages(); $this->assertEquals($expected, $actual); } else { $this->fail('Failed to catch invalid fields'); } }
/** * Call magic method * * Maps the method call to a validator name and adds that validator to the * Builder object. * * @param string Base name of the validator * @param array Constructor arguments * @returns Zend_Validate_Builder_FluentAdder * @throws none */ public function __call($name, $args) { // Append the returned id to our list $this->_rowIds[] = $this->_builder->add($this->_factory->create($name, $args), $this->_fieldSpec, $this->_flags); return $this; }
/** * Proxies to the underlying Builder class. * * @see Zend_Validate_Interface::getErrors() * @deprecated Since 1.5.0 * * @return array */ public function getErrors() { return $this->_builder->getErrors(); }
public function testGetErrorsReturnsOnlyErrorCodes() { $testMsgs = array('field' => array('val' => array('reason' => 'Message'))); $expected = array('field' => array('val' => array('reason'))); $mockEm = $this->getMock('Zend_Validate_Builder_ErrorManager'); $mockEm->expects($this->once())->method('getMessages')->will($this->returnValue($testMsgs)); $zvb = new Zend_Validate_Builder(); $zvb->setErrorManager($mockEm); $actual = $zvb->getErrors(); $this->assertEquals($expected, $actual); }