/** * Run test validate * * @param $addressData * @param $email * @param $addressType * @param $expectedWarnings * @dataProvider providerAddressData */ public function testValidate($addressData, $email, $addressType, $expectedWarnings) { $this->addressMock->expects($this->any())->method('hasData')->will($this->returnValueMap($addressData)); $this->addressMock->expects($this->once())->method('getEmail')->will($this->returnValue($email)); $this->addressMock->expects($this->once())->method('getAddressType')->will($this->returnValue($addressType)); $actualWarnings = $this->validator->validate($this->addressMock); $this->assertEquals($expectedWarnings, $actualWarnings); }
/** * Performs validation before save * * @param \Magento\Framework\Model\AbstractModel $object * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object) { parent::_beforeSave($object); if (!$object->getParentId() && $object->getOrder()) { $object->setParentId($object->getOrder()->getId()); } // Init customer address id if customer address is assigned $customerData = $object->getCustomerAddressData(); if ($customerData) { $object->setCustomerAddressId($customerData->getId()); } $warnings = $this->_validator->validate($object); if (!empty($warnings)) { throw new \Magento\Framework\Exception\LocalizedException(__("Cannot save address:\n%1", implode("\n", $warnings))); } return $this; }
/** * Performs validation before save * * @param \Magento\Framework\Model\AbstractModel $object * @return $this * @throws \Magento\Framework\Model\Exception */ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object) { parent::_beforeSave($object); $warnings = $this->_validator->validate($object); if (!empty($warnings)) { throw new \Magento\Framework\Model\Exception(__("Cannot save address") . ":\n" . implode("\n", $warnings)); } return $this; }