Ejemplo n.º 1
0
 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));
 }
Ejemplo n.º 2
0
 /**
  * test _beforeSaveMethod via save()
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage Cannot save comment:
  */
 public function testValidate()
 {
     $historyMock = $this->getMock('Magento\\Sales\\Model\\Order\\Status\\History', [], [], '', false);
     $this->entitySnapshotMock->expects($this->once())->method('isModified')->with($historyMock)->willReturn(true);
     $historyMock->expects($this->any())->method('isSaveAllowed')->will($this->returnValue(true));
     $this->validatorMock->expects($this->once())->method('validate')->with($historyMock)->will($this->returnValue(['Some warnings']));
     $this->assertEquals($this->historyResource, $this->historyResource->save($historyMock));
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }