/** * Adds a validator to the end of the chain * * @param Magento_Validator_ValidatorInterface $validator * @param boolean $breakChainOnFailure * @return Magento_Validator */ public function addValidator(Magento_Validator_ValidatorInterface $validator, $breakChainOnFailure = false) { if (!$validator->hasTranslator()) { $validator->setTranslator($this->getTranslator()); } $this->_validators[] = array('instance' => $validator, 'breakChainOnFailure' => (bool) $breakChainOnFailure); return $this; }
/** * Test isValid method * * @dataProvider isValidDataProvider * * @param mixed $value * @param mixed $validateValue * @param bool $expectedResult * @param array $validatorMessages * @param array $expectedMessages */ public function testIsValid($value, $validateValue, $expectedResult, $validatorMessages = array(), $expectedMessages = array()) { $this->_validatorMock->expects($this->once())->method('isValid')->with($validateValue)->will($this->returnValue($expectedResult)); if ($expectedResult) { $this->_validatorMock->expects($this->never())->method('getMessages'); } else { $this->_validatorMock->expects($this->once())->method('getMessages')->will($this->returnValue($validatorMessages)); } $this->assertEquals($expectedResult, $this->_constraint->isValid($value)); $this->assertEquals($expectedMessages, $this->_constraint->getMessages()); }
/** * Check translator was set into wrapped validator */ public function testSetTranslator() { /** @var Magento_Translate_AdapterAbstract $translator */ $translator = $this->getMockBuilder('Magento_Translate_AdapterInterface')->getMockForAbstractClass(); $this->_constraint->setTranslator($translator); $this->assertEquals($translator, $this->_validatorMock->getTranslator()); $this->assertEquals($translator, $this->_constraint->getTranslator()); }
/** * Get translator instance of wrapped validator * * @return Magento_Translate_AdapterInterface|null */ public function getTranslator() { return $this->_wrappedValidator->getTranslator(); }