/**
  * Run test validate
  *
  * @param $commentDataMap
  * @param $commentData
  * @param $expectedWarnings
  * @dataProvider providerCommentData
  */
 public function testValidate($commentDataMap, $commentData, $expectedWarnings)
 {
     $this->commentModelMock->expects($this->any())->method('hasData')->will($this->returnValueMap($commentDataMap));
     $this->commentModelMock->expects($this->once())->method('getData')->will($this->returnValue($commentData));
     $actualWarnings = $this->validator->validate($this->commentModelMock);
     $this->assertEquals($expectedWarnings, $actualWarnings);
 }
Exemple #2
0
 /**
  * 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);
     $errors = $this->validator->validate($object);
     if (!empty($errors)) {
         throw new \Magento\Framework\Model\Exception(__("Cannot save comment") . ":\n" . implode("\n", $errors));
     }
     return $this;
 }
Exemple #3
0
 /**
  * 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)
 {
     /** @var \Magento\Sales\Model\Order\Shipment\Comment $object */
     if (!$object->getParentId() && $object->getShipment()) {
         $object->setParentId($object->getShipment()->getId());
     }
     parent::_beforeSave($object);
     $errors = $this->validator->validate($object);
     if (!empty($errors)) {
         throw new \Magento\Framework\Exception\LocalizedException(__("Cannot save comment:\n%1", implode("\n", $errors)));
     }
     return $this;
 }