/** * Perform actions before object 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); $warnings = $this->validator->validate($object); if (!empty($warnings)) { throw new \Magento\Framework\Exception\LocalizedException(__("Cannot save comment:\n%1", implode("\n", $warnings))); } return $this; }
public function testValidateNegative() { $history = $this->getMock('Magento\\Sales\\Model\\Order\\Status\\History', ['hasData'], [], '', false); $history->expects($this->any())->method('hasData')->with('parent_id')->will($this->returnValue(false)); $validator = new Validator(); $this->assertEquals(['Order Id is a required field'], $validator->validate($history)); }