1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sales\Test\Unit\Controller\Adminhtml;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
class PdfDocumentsMassActionTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Sales\Controller\Adminhtml\Order\PdfDocumentsMassAction
*/
private $controller;
/**
* @var \Magento\Backend\Model\View\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject
*/
private $resultRedirect;
/**
* @var \Magento\Framework\Message\Manager|\PHPUnit_Framework_MockObject_MockObject
*/
private $messageManager;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $orderCollectionFactoryMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $orderCollectionMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $filterMock;
/**
* Test setup
*/
protected function setUp()
{
$objectManagerHelper = new ObjectManagerHelper($this);
$this->messageManager = $this->createPartialMock(
\Magento\Framework\Message\Manager::class,
['addSuccessMessage', 'addErrorMessage']
);
$this->orderCollectionMock = $this->createMock(\Magento\Sales\Model\ResourceModel\Order\Collection::class);
$this->filterMock = $this->createMock(\Magento\Ui\Component\MassAction\Filter::class);
$this->orderCollectionFactoryMock = $this->createPartialMock(
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory::class,
['create']
);
$this->orderCollectionFactoryMock
->expects($this->once())
->method('create')
->willReturn($this->orderCollectionMock);
$this->resultRedirect = $this->createMock(\Magento\Backend\Model\View\Result\Redirect::class);
$resultRedirectFactory = $this->createMock(\Magento\Framework\Controller\ResultFactory::class);
$resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
$this->controller = $objectManagerHelper->getObject(
\Magento\Sales\Controller\Adminhtml\Order\Pdfinvoices::class,
[
'filter' => $this->filterMock,
'resultFactory' => $resultRedirectFactory,
'messageManager' => $this->messageManager
]
);
$objectManagerHelper
->setBackwardCompatibleProperty(
$this->controller,
'orderCollectionFactory',
$this->orderCollectionFactoryMock
);
}
/**
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function testExecute()
{
$exception = new \Exception();
$this->filterMock
->expects($this->once())
->method('getCollection')
->with($this->orderCollectionMock)
->willThrowException($exception);
$this->messageManager->expects($this->once())->method('addErrorMessage');
$this->resultRedirect->expects($this->once())->method('setPath')->willReturnSelf();
$this->controller->execute($exception);
}
}