|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| - * Copyright © Magento, Inc. All rights reserved. |
4 |
| - * See COPYING.txt for license details. |
| 3 | + * Copyright 2014 Adobe |
| 4 | + * All Rights Reserved. |
5 | 5 | */
|
6 | 6 | declare(strict_types=1);
|
7 | 7 |
|
|
29 | 29 | use Magento\Sales\Model\Order\Creditmemo;
|
30 | 30 | use Magento\Sales\Model\Order\Creditmemo\Item;
|
31 | 31 | use Magento\Sales\Model\Order\Email\Sender\CreditmemoSender;
|
| 32 | +use Magento\Catalog\Model\Product\Type\AbstractType; |
32 | 33 | use PHPUnit\Framework\MockObject\MockObject;
|
33 | 34 | use PHPUnit\Framework\TestCase;
|
34 | 35 |
|
@@ -413,4 +414,57 @@ public function testExecuteEmails(
|
413 | 414 | }
|
414 | 415 | $this->assertEquals($this->resultRedirectMock, $this->_controller->execute());
|
415 | 416 | }
|
| 417 | + |
| 418 | + /** |
| 419 | + * Test execute method with bundle products |
| 420 | + */ |
| 421 | + public function testExecuteWithBundleProductCreditMemo() |
| 422 | + { |
| 423 | + $orderId = 1; |
| 424 | + $creditmemoId = 2; |
| 425 | + $invoiceId = 3; |
| 426 | + $creditmemoData = ['items' => [], 'comment_text' => '']; |
| 427 | + $this->_requestMock->expects($this->any()) |
| 428 | + ->method('getParam') |
| 429 | + ->willReturnMap([ |
| 430 | + ['order_id', null, $orderId], |
| 431 | + ['creditmemo_id', null, $creditmemoId], |
| 432 | + ['creditmemo', null, $creditmemoData], |
| 433 | + ['invoice_id', null, $invoiceId] |
| 434 | + ]); |
| 435 | + |
| 436 | + $this->_requestMock->expects($this->once()) |
| 437 | + ->method('getPost') |
| 438 | + ->with('creditmemo') |
| 439 | + ->willReturn($creditmemoData); |
| 440 | + $orderMock = $this->createMock(Order::class); |
| 441 | + $parentOrderItemMock = $this->createMock(Order\Item::class); |
| 442 | + $parentOrderItemMock->expects($this->any())->method('getProductType')->willReturn('bundle'); |
| 443 | + $parentOrderItemMock->expects($this->any()) |
| 444 | + ->method('getProductOptions') |
| 445 | + ->willReturn([ |
| 446 | + 'product_calculations' => AbstractType::CALCULATE_PARENT |
| 447 | + ]); |
| 448 | + $childOrderItemMock = $this->createMock(Order\Item::class); |
| 449 | + $childOrderItemMock->expects($this->any())->method('getParentItemId')->willReturn(1); |
| 450 | + $childOrderItemMock->expects($this->any())->method('getParentItem')->willReturn($parentOrderItemMock); |
| 451 | + $creditMemoItemMock = $this->createMock(Item::class); |
| 452 | + $creditMemoItemMock->expects($this->any())->method('getOrderItem')->willReturn($childOrderItemMock); |
| 453 | + $creditMemoItemMock->expects($this->never())->method('setQty'); |
| 454 | + $creditmemoMock = $this->createMock(Creditmemo::class); |
| 455 | + $creditmemoMock->expects($this->once())->method('isValidGrandTotal')->willReturn(true); |
| 456 | + $creditmemoMock->expects($this->once())->method('getOrder')->willReturn($orderMock); |
| 457 | + $creditmemoMock->expects($this->once())->method('getOrderId')->willReturn($orderId); |
| 458 | + $creditmemoMock->expects($this->once())->method('getAllItems')->willReturn([$creditMemoItemMock]); |
| 459 | + $this->memoLoaderMock->expects($this->once())->method('load')->willReturn($creditmemoMock); |
| 460 | + $this->resultRedirectFactoryMock->expects($this->once()) |
| 461 | + ->method('create') |
| 462 | + ->willReturn($this->resultRedirectMock); |
| 463 | + $this->resultRedirectMock->expects($this->once()) |
| 464 | + ->method('setPath') |
| 465 | + ->with('sales/order/view', ['order_id' => $orderId]) |
| 466 | + ->willReturnSelf(); |
| 467 | + $result = $this->_controller->execute(); |
| 468 | + $this->assertEquals($this->resultRedirectMock, $result); |
| 469 | + } |
416 | 470 | }
|
0 commit comments