71 $objectManagerHelper =
new ObjectManagerHelper($this);
72 $context = $this->createMock(\
Magento\Backend\
App\Action\Context::class);
74 $this->request = $this->getMockForAbstractClass(
75 \
Magento\Framework\
App\RequestInterface::class,
96 $response = $this->getMockForAbstractClass(
97 \
Magento\Framework\
App\ResponseInterface::class,
105 $context->expects($this->any())->method(
'getResponse')->willReturn(
$response);
106 $context->expects($this->any())->method(
'getRequest')->willReturn($this->request);
108 $this->messageManager = $this->createMock(\
Magento\Framework\Message\ManagerInterface::class);
109 $context->expects($this->any())->method(
'getMessageManager')->willReturn($this->messageManager);
111 $this->eventManager = $this->createMock(\
Magento\Framework\Event\ManagerInterface::class);
112 $context->expects($this->any())->method(
'getEventManager')->willReturn($this->eventManager);
114 $this->objectManager = $this->createMock(\
Magento\Framework\ObjectManagerInterface::class);
115 $context->expects($this->any())->method(
'getObjectManager')->willReturn($this->objectManager);
117 $this->session = $this->createMock(\
Magento\Backend\Model\Session\Quote::class);
118 $context->expects($this->any())->method(
'getSession')->willReturn($this->session);
119 $this->escaper = $this->createPartialMock(\
Magento\Framework\Escaper::class, [
'escapeHtml']);
121 $this->resultForward = $this->getMockBuilder(\
Magento\Backend\Model\View\Result\Forward::class)
122 ->disableOriginalConstructor()
124 $this->resultForwardFactory = $this->getMockBuilder(\
Magento\Backend\Model\View\Result\ForwardFactory::class)
125 ->disableOriginalConstructor()
126 ->setMethods([
'create'])
129 $this->resultForwardFactory->expects($this->once())
131 ->willReturn($this->resultForward);
133 $this->processData = $objectManagerHelper->getObject(
136 'context' => $context,
137 'escaper' => $this->escaper,
138 'resultForwardFactory' => $this->resultForwardFactory,
152 $quote = $this->createPartialMock(
154 [
'getCouponCode',
'isVirtual',
'getAllItems']
156 $create = $this->createMock(\
Magento\Sales\Model\AdminOrder\Create::class);
159 [
'customer_id',
null,
null],
160 [
'store_id',
null,
null],
161 [
'currency_id',
null,
null]
163 $this->request->expects($this->atLeastOnce())->method(
'getParam')->willReturnMap($paramReturnMap);
165 $objectManagerParamMap = [
166 [\Magento\Sales\Model\AdminOrder\Create::class, $create],
169 $this->objectManager->expects($this->atLeastOnce())->method(
'get')->willReturnMap($objectManagerParamMap);
171 $this->eventManager->expects($this->any())->method(
'dispatch');
176 [
'reset_shipping',
false],
177 [
'collect_shipping_rates',
false],
179 [
'add_product',
false],
181 [
'update_items',
false],
190 [
'giftmessage',
false],
191 [
'add_products',
false],
192 [
'update_items',
false],
195 $this->request->expects($this->atLeastOnce())->method(
'getPost')->willReturnMap($postReturnMap);
197 $create->expects($this->once())->method(
'importPostData')->willReturnSelf();
198 $create->expects($this->once())->method(
'initRuleData')->willReturnSelf();
199 $create->expects($this->any())->method(
'getQuote')->willReturn(
$quote);
202 $create->expects($this->once())->method(
'getBillingAddress')->willReturn(
$address);
204 $quote->expects($this->any())->method(
'isVirtual')->willReturn(
true);
206 $this->request->expects($this->once())->method(
'has')->with(
'item')->willReturn(
false);
208 $create->expects($this->once())->method(
'saveQuote')->willReturnSelf();
210 $this->session->expects($this->any())->method(
'getQuote')->willReturn(
$quote);
211 $item = $this->getMockForAbstractClass(
220 $quote->expects($this->any())->method(
'getAllItems')->willReturn([
$item]);
221 $item->expects($this->any())->method(
'getNoDiscount')->willReturn($noDiscount);
223 $quote->expects($this->once())->method(
'getCouponCode')->willReturn($actualCouponCode);
226 $errorMessageManager =
__(
232 $this->messageManager
233 ->expects($this->once())
234 ->method(
'addErrorMessage')
235 ->with($errorMessageManager)
238 $this->resultForward->expects($this->once())
242 $this->assertInstanceOf(\
Magento\Backend\Model\View\Result\Forward::class, $this->processData->execute());
251 [
true,
'123',
'"%1" coupon code was not applied. Do not apply discount is selected for item(s)',
null],
252 [
false,
'123',
'The "%1" coupon code isn\'t valid. Verify the code and try again.',
'132'],
testExecute($noDiscount, $couponCode, $errorMessage, $actualCouponCode)
isApplyDiscountDataProvider()