/**
  * 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);
 }
 /**
  * Test _beforeSaveMethod via save()
  */
 public function testSave()
 {
     $this->validatorMock->expects($this->once())->method('validate')->with($this->equalTo($this->commentModelMock))->will($this->returnValue([]));
     $this->commentModelMock->expects($this->any())->method('getData')->willReturn([]);
     $this->commentResource->save($this->commentModelMock);
     $this->assertTrue(true);
 }
Exemple #3
0
 /**
  * Validate data
  *
  * @param \Magento\Sales\Model\Order\Shipment\Comment $comment
  * @return array
  */
 public function validate(Comment $comment)
 {
     $errors = [];
     $commentData = $comment->getData();
     foreach ($this->required as $code => $label) {
         if (!$comment->hasData($code)) {
             $errors[$code] = sprintf('%s is a required field', $label);
         } elseif (empty($commentData[$code])) {
             $errors[$code] = sprintf('%s can not be empty', $label);
         }
     }
     return $errors;
 }
Exemple #4
0
 /**
  * Set up
  */
 protected function setUp()
 {
     $this->commentModelMock = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment\\Comment', [], [], '', false);
     $this->appResourceMock = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false);
     $this->adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->validatorMock = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment\\Comment\\Validator', [], [], '', false);
     $this->appResourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->adapterMock));
     $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->adapterMock->expects($this->any())->method('insert');
     $this->adapterMock->expects($this->any())->method('lastInsertId');
     $this->commentModelMock->expects($this->any())->method('hasDataChanges')->will($this->returnValue(true));
     $this->commentModelMock->expects($this->any())->method('isSaveAllowed')->will($this->returnValue(true));
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->commentResource = $objectManager->getObject('Magento\\Sales\\Model\\Resource\\Order\\Shipment\\Comment', ['resource' => $this->appResourceMock, 'validator' => $this->validatorMock]);
 }
Exemple #5
0
 /**
  * Test shipment add comment service
  */
 public function testInvoke()
 {
     $this->commentConverterMock->expects($this->once())->method('getModel')->with($this->equalTo($this->dataObjectMock))->will($this->returnValue($this->dataModelMock));
     $this->dataModelMock->expects($this->once())->method('save');
     $this->assertTrue($this->shipmentAddComment->invoke($this->dataObjectMock));
 }