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'); } }
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); }