Skip to content
Snippets Groups Projects
Commit 08b6497c authored by Pelipenko, Vladimir(vpelipenko)'s avatar Pelipenko, Vladimir(vpelipenko)
Browse files

Merge pull request #190 from magento-mpi/MAGETWO-35385

[MPI] Bug fix
parents 7f98433d 1550d511
Branches
No related merge requests found
......@@ -8,6 +8,7 @@ namespace Magento\Shipping\Controller\Adminhtml\Order\Shipment;
use Magento\Sales\Model\Order\Email\Sender\ShipmentSender;
use Magento\Backend\App\Action;
use Magento\Framework\View\Result\LayoutFactory;
class AddComment extends \Magento\Backend\App\Action
{
......@@ -21,18 +22,26 @@ class AddComment extends \Magento\Backend\App\Action
*/
protected $shipmentSender;
/**
* @var LayoutFactory
*/
protected $resultLayoutFactory;
/**
* @param Action\Context $context
* @param \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader
* @param ShipmentSender $shipmentSender
* @param LayoutFactory $resultLayoutFactory
*/
public function __construct(
Action\Context $context,
\Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader,
ShipmentSender $shipmentSender
ShipmentSender $shipmentSender,
LayoutFactory $resultLayoutFactory
) {
$this->shipmentLoader = $shipmentLoader;
$this->shipmentSender = $shipmentSender;
$this->resultLayoutFactory = $resultLayoutFactory;
parent::__construct($context);
}
......@@ -72,10 +81,9 @@ class AddComment extends \Magento\Backend\App\Action
$this->shipmentSender->send($shipment, !empty($data['is_customer_notified']), $data['comment']);
$shipment->save();
$this->_view->loadLayout(false);
$this->_view->getPage()->getConfig()->getTitle()->prepend(__('Shipments'));
$response = $this->_view->getLayout()->getBlock('shipment_comments')->toHtml();
$resultLayout = $this->resultLayoutFactory->create();
$resultLayout->addDefaultHandle();
$response = $resultLayout->getLayout()->getBlock('shipment_comments')->toHtml();
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$response = ['error' => true, 'message' => $e->getMessage()];
} catch (\Exception $e) {
......
......@@ -30,21 +30,11 @@ class AddCommentTest extends \PHPUnit_Framework_TestCase
*/
protected $responseMock;
/**
* @var \Magento\Framework\View\Page\Title|\PHPUnit_Framework_MockObject_MockObject
*/
protected $titleMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $resultPageMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $pageConfigMock;
/**
* @var \Magento\Sales\Model\Order\Shipment|\PHPUnit_Framework_MockObject_MockObject
*/
......@@ -55,6 +45,11 @@ class AddCommentTest extends \PHPUnit_Framework_TestCase
*/
protected $viewInterfaceMock;
/**
* @var \Magento\Framework\View\Result\LayoutFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $resultLayoutFactoryMock;
/**
* @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
......@@ -95,9 +90,9 @@ class AddCommentTest extends \PHPUnit_Framework_TestCase
'',
false
);
$this->titleMock = $this->getMock(
'Magento\Framework\View\Page\Title',
['prepend', '__wakeup'],
$this->resultLayoutFactoryMock = $this->getMock(
'Magento\Framework\View\Result\LayoutFactory',
['create'],
[],
'',
false
......@@ -106,9 +101,6 @@ class AddCommentTest extends \PHPUnit_Framework_TestCase
$this->resultPageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page')
->disableOriginalConstructor()
->getMock();
$this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config')
->disableOriginalConstructor()
->getMock();
$this->shipmentMock = $this->getMock(
'Magento\Sales\Model\Order\Shipment',
......@@ -136,15 +128,9 @@ class AddCommentTest extends \PHPUnit_Framework_TestCase
$this->viewInterfaceMock->expects($this->any())->method('getPage')->will(
$this->returnValue($this->resultPageMock)
);
$this->resultPageMock->expects($this->any())->method('getConfig')->will(
$this->returnValue($this->pageConfigMock)
);
$this->pageConfigMock->expects($this->any())->method('getTitle')->will($this->returnValue($this->titleMock));
$contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock));
$contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->responseMock));
$contextMock->expects($this->any())->method('getTitle')->will($this->returnValue($this->titleMock));
$contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->viewInterfaceMock));
$contextMock->expects($this->any())
->method('getObjectManager')
......@@ -153,7 +139,8 @@ class AddCommentTest extends \PHPUnit_Framework_TestCase
$this->controller = new \Magento\Shipping\Controller\Adminhtml\Order\Shipment\AddComment(
$contextMock,
$this->shipmentLoaderMock,
$this->shipmentSenderMock
$this->shipmentSenderMock,
$this->resultLayoutFactoryMock
);
}
......@@ -189,15 +176,19 @@ class AddCommentTest extends \PHPUnit_Framework_TestCase
$shipment = [];
$tracking = [];
$layoutMock = $this->getMock('Magento\Framework\View\Layout', ['getBlock'], [], '', false);
$blockMock = $this->getMock('Magento\Shipping\Block\Adminhtml\View\Comments', ['toHtml'], [], '', false);
$resultLayoutMock = $this->getMock(
'Magento\Framework\View\Result\Layout',
['getBlock', 'getDefaultLayoutHandle', 'addDefaultHandle', 'getLayout'],
[],
'',
false
);
$this->requestMock->expects($this->once())->method('setParam')->with('shipment_id', $shipmentId);
$this->requestMock->expects($this->once())
->method('getPost')
->with('comment')
->will($this->returnValue($data));
$this->titleMock->expects($this->once())->method('prepend');
$this->requestMock->expects($this->any())
->method('getParam')
->will(
......@@ -221,10 +212,15 @@ class AddCommentTest extends \PHPUnit_Framework_TestCase
$this->shipmentMock->expects($this->once())->method('addComment');
$this->shipmentSenderMock->expects($this->once())->method('send');
$this->shipmentMock->expects($this->once())->method('save');
$this->viewInterfaceMock->expects($this->once())->method('loadLayout')->with(false);
$this->viewInterfaceMock->expects($this->once())->method('getLayout')->will($this->returnValue($layoutMock));
$layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($blockMock));
$blockMock->expects($this->once())->method('toHtml')->will($this->returnValue($result));
$layoutMock = $this->getMock('Magento\Framework\View\Layout', ['getBlock'], [], '', false);
$blockMock = $this->getMock('Magento\Shipping\Block\Adminhtml\View\Comments', ['toHtml'], [], '', false);
$blockMock->expects($this->once())->method('toHtml')->willReturn($result);
$layoutMock->expects($this->once())->method('getBlock')
->with('shipment_comments')->willReturn($blockMock);
$resultLayoutMock->expects($this->once())->method('getLayout')->willReturn($layoutMock);
$resultLayoutMock->expects($this->once())->method('addDefaultHandle');
$this->resultLayoutFactoryMock->expects($this->once())->method('create')
->will($this->returnValue($resultLayoutMock));
$this->responseMock->expects($this->once())->method('setBody')->with($result);
$this->assertNull($this->controller->execute());
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment