Пример #1
0
 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');
     }
 }
Пример #2
0
 public function testGlobValidatesAndSetsPatternFlag()
 {
     $mockVal = $this->getMock('Zend_Validate_Abstract');
     $mockFactory = $this->getMock('Zend_Validate_Builder_ValidatorFactory');
     $mockFactory->expects($this->once())->method('create')->with($this->equalTo('testVal'), $this->equalTo(array('a', 'b', 'c')))->will($this->returnValue($mockVal));
     $zvb = $this->getMock('Zend_Validate_Builder');
     $zvb->expects($this->once())->method('addFlags')->with($this->isType('int'), $this->equalTo(Zend_Validate_Builder::OPTIONAL));
     $zvb->expects($this->once())->method('add')->with($this->equalTo($mockVal), $this->equalTo('/.*/'), $this->equalTo(Zend_Validate_Builder::PATTERN))->will($this->returnValue(1));
     $ff = new Zend_Validate_Builder_FluentFacade($zvb);
     $ff->setFactory($mockFactory);
     $ff->glob('/.*/')->testVal('a', 'b', 'c')->optional();
 }