Skip to content

Commit 84ff076

Browse files
committed
refactoring - unit, mftf tests
1 parent df1b766 commit 84ff076

File tree

2 files changed

+107
-115
lines changed

2 files changed

+107
-115
lines changed

app/code/Magento/Sales/Test/Mftf/Test/AdminCreateCreditmemoWithBundleProductTest.xml

Lines changed: 19 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -19,57 +19,38 @@
1919
</annotations>
2020

2121
<before>
22-
<!--Set default flat rate shipping method settings-->
2322
<createData entity="FlatRateShippingMethodDefault" stepKey="setDefaultFlatRateShippingMethod"/>
24-
25-
<!--Create simple customer-->
2623
<createData entity="Simple_US_Customer_CA" stepKey="simpleCustomer"/>
27-
28-
<!--Create simple product 1-->
2924
<createData entity="ApiProductWithDescription" stepKey="simple1" before="simple2"/>
30-
31-
<!--Create simple product 2-->
3225
<createData entity="ApiProductWithDescription" stepKey="simple2" before="product"/>
33-
34-
<!--Create bundle product with checkbox bundle option-->
3526
<createData entity="ApiBundleProduct" stepKey="product"/>
3627
<createData entity="CheckboxOption" stepKey="checkboxBundleOption">
3728
<requiredEntity createDataKey="product"/>
3829
</createData>
39-
40-
<!--Link simple product 1 to bundle option with default quantity 2-->
4130
<createData entity="ApiBundleLink" stepKey="createBundleLink1">
4231
<requiredEntity createDataKey="product"/>
4332
<requiredEntity createDataKey="checkboxBundleOption"/>
4433
<requiredEntity createDataKey="simple1"/>
4534
<field key="qty">2</field>
4635
<field key="is_default">1</field>
4736
</createData>
48-
49-
<!--Link simple product 2 to bundle option with default quantity 2-->
5037
<createData entity="ApiBundleLink" stepKey="createBundleLink2">
5138
<requiredEntity createDataKey="product"/>
5239
<requiredEntity createDataKey="checkboxBundleOption"/>
5340
<requiredEntity createDataKey="simple2"/>
5441
<field key="qty">2</field>
5542
<field key="is_default">1</field>
5643
</createData>
57-
58-
<!--Add drop-down bundle option-->
5944
<createData entity="DropDownBundleOption" stepKey="dropDownBundleOption">
6045
<requiredEntity createDataKey="product"/>
6146
</createData>
62-
63-
<!--Link simple product 1 to drop-down bundle option with default quantity 2-->
6447
<createData entity="ApiBundleLink" stepKey="createBundleLink3">
6548
<requiredEntity createDataKey="product"/>
6649
<requiredEntity createDataKey="dropDownBundleOption"/>
6750
<requiredEntity createDataKey="simple1"/>
6851
<field key="qty">2</field>
6952
<field key="is_default">1</field>
7053
</createData>
71-
72-
<!--Link simple product 2 to drop-down bundle option with default quantity 2-->
7354
<createData entity="ApiBundleLink" stepKey="createBundleLink4">
7455
<requiredEntity createDataKey="product"/>
7556
<requiredEntity createDataKey="dropDownBundleOption"/>
@@ -78,82 +59,46 @@
7859
</createData>
7960
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
8061
</before>
62+
<after>
63+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
64+
<deleteData createDataKey="product" stepKey="delete"/>
65+
<deleteData createDataKey="simpleCustomer" stepKey="deleteSimpleCustomer"/>
66+
<deleteData createDataKey="simple1" stepKey="deleteSimple1" before="deleteSimple2"/>
67+
<deleteData createDataKey="simple2" stepKey="deleteSimple2" before="delete"/>
68+
</after>
8169

82-
<!--Create new customer order-->
8370
<actionGroup ref="NavigateToNewOrderPageExistingCustomerActionGroup" stepKey="navigateToNewOrderWithExistingCustomer">
8471
<argument name="customer" value="$$simpleCustomer$$"/>
8572
</actionGroup>
86-
87-
<!--Add bundle product to order and check product price in grid-->
8873
<actionGroup ref="AddBundleProductToOrderAndCheckPriceInGridActionGroup" stepKey="addBundleProductToOrder">
8974
<argument name="product" value="$$product$$"/>
9075
<argument name="quantity" value="1"/>
9176
<argument name="price" value="$738.00"/>
9277
</actionGroup>
93-
94-
<!--Select FlatRate shipping method-->
9578
<actionGroup ref="OrderSelectFlatRateShippingActionGroup" stepKey="orderSelectFlatRateShippingMethod"/>
96-
97-
<!--Submit order-->
98-
<click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="submitOrder"/>
99-
100-
<!--Verify order information-->
101-
<actionGroup ref="VerifyCreatedOrderInformationActionGroup" stepKey="verifyCreatedOrderInformation"/>
102-
103-
104-
<!-- Create Invoice -->
79+
<actionGroup ref="AdminSubmitOrderActionGroup" stepKey="submitOrder"/>
10580
<actionGroup ref="StartCreateInvoiceFromOrderPageActionGroup" stepKey="startInvoice"/>
106-
<click selector="{{AdminInvoiceMainActionsSection.submitInvoice}}" stepKey="clickSubmitInvoice"/>
107-
<waitForElementVisible selector="{{AdminMessagesSection.success}}" stepKey="waitForMessageAppears"/>
108-
<see selector="{{AdminMessagesSection.success}}" userInput="The invoice has been created." stepKey="seeInvoiceCreateSuccess"/>
109-
110-
<!-- Go to Sales > Orders > find out placed order and open -->
111-
<grabTextFrom selector="|Order # (\d+)|" stepKey="grabOrderId" />
112-
<assertNotEmpty stepKey="assertOrderIdIsNotEmpty" after="grabOrderId">
113-
<actualResult type="const">$grabOrderId</actualResult>
114-
</assertNotEmpty>
81+
<actionGroup ref="SubmitInvoiceActionGroup" stepKey="submitInvoice"/>
82+
<grabFromCurrentUrl regex="~/order_id/(\d+)/~" stepKey="grabOrderId"/>
11583
<actionGroup ref="OpenOrderByIdActionGroup" stepKey="openOrder">
116-
<argument name="orderId" value="{$grabOrderId}"/>
84+
<argument name="orderId" value="$grabOrderId"/>
11785
</actionGroup>
118-
119-
<!-- Click 'Credit Memo' button and fill data from dataset: partial refund -->
12086
<actionGroup ref="AdminOpenAndFillCreditMemoRefundBundleWithQtyActionGroup" stepKey="fillCreditMemoRefund">
12187
<argument name="itemQtyToRefund" value="0"/>
12288
<argument name="rowNumberItemOne" value="3"/>
12389
<argument name="rowNumberItemTwo" value="5"/>
12490
<argument name="rowNumberItemThree" value="6"/>
12591
<argument name="adjustmentRefund" value="10"/>
12692
</actionGroup>
93+
<actionGroup ref="SubmitCreditMemoActionGroup" stepKey="submitCreditMemo" />
12794

128-
<!-- On order's page click 'Refund offline' button -->
129-
<click selector="{{AdminCreditMemoTotalSection.submitRefundOffline}}" stepKey="clickRefundOffline"/>
130-
<waitForPageLoad stepKey="waitForResultPage"/>
131-
132-
<!-- Perform all assertions: assert refund success create message -->
133-
<see selector="{{AdminIndexManagementSection.successMessage}}" userInput="You created the credit memo." stepKey="assertRefundSuccessCreateMessage"/>
134-
135-
<!--Assert refund in Credit Memo Tab -->
136-
<click selector="{{AdminOrderDetailsOrderViewSection.creditMemos}}" stepKey="clickCreditMemoTab"/>
137-
<waitForPageLoad stepKey="waitForTabLoad"/>
138-
<grabTextFrom selector="{{AdminCreditMemosGridSection.memoId}}" stepKey="grabMemoId"/>
139-
<assertNotEmpty stepKey="assertMemoIdIsNotEmpty" after="grabMemoId">
140-
<actualResult type="const">$grabMemoId</actualResult>
141-
</assertNotEmpty>
142-
<click selector="{{AdminCreditMemosGridSection.memoId}}" stepKey="clickView"/>
143-
<waitForPageLoad stepKey="waitForCreditMemo"/>
95+
<actionGroup ref="AdminOpenCreditMemoFromOrderPageActionGroup" stepKey="openCreditMemo" />
14496
<scrollTo selector="{{AdminCreditMemoViewTotalSection.subtotal}}" stepKey="scrollToTotal"/>
145-
<see selector="{{AdminCreditMemoViewTotalSection.subtotal}}" userInput="$0.00" stepKey="seeSubtotal"/>
146-
<see selector="{{AdminCreditMemoViewTotalSection.adjustmentRefund}}" userInput="$10.00" stepKey="seeAdjustmentRefund"/>
147-
<see selector="{{AdminCreditMemoViewTotalSection.adjustmentFee}}" userInput="$0.00" stepKey="seeAdjustmentFee"/>
148-
<see selector="{{AdminCreditMemoViewTotalSection.grandTotal}}" userInput="$10.00" stepKey="assertRefundOnCreditMemoTab"/>
149-
150-
<after>
151-
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
152-
153-
<deleteData createDataKey="product" stepKey="delete"/>
154-
<deleteData createDataKey="simpleCustomer" stepKey="deleteSimpleCustomer"/>
155-
<deleteData createDataKey="simple1" stepKey="deleteSimple1" before="deleteSimple2"/>
156-
<deleteData createDataKey="simple2" stepKey="deleteSimple2" before="delete"/>
157-
</after>
97+
<actionGroup ref="AssertAdminCreditMemoViewPageTotalsActionGroup" stepKey="assertCreditMemoViewPageTotals">
98+
<argument name="subtotal" value="$0.00"/>
99+
<argument name="adjustmentRefund" value="$10.00"/>
100+
<argument name="adjustmentFee" value="$0.00"/>
101+
<argument name="grandTotal" value="$10.00"/>
102+
</actionGroup>
158103
</test>
159104
</tests>

app/code/Magento/Sales/Test/Unit/Model/Order/CreditmemoFactoryTest.php

Lines changed: 88 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,74 +3,121 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Sales\Test\Unit\Model\Order;
89

10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
11+
use Magento\Sales\Model\Order\CreditmemoFactory;
12+
use Magento\Sales\Model\Order\Item;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
use ReflectionMethod;
16+
917
/**
1018
* Unit test for creditmemo factory class.
11-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1219
*/
13-
class CreditmemoFactoryTest extends \PHPUnit\Framework\TestCase
20+
class CreditmemoFactoryTest extends TestCase
1421
{
1522
/**
16-
* Subject of testing.
17-
*
18-
* @var \Magento\Sales\Model\Order\CreditmemoFactory
23+
* @var CreditmemoFactory
1924
*/
2025
protected $subject;
2126

2227
/**
23-
* @return void
24-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
28+
* @var ReflectionMethod
2529
*/
26-
protected function setUp()
27-
{
28-
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
29-
$this->subject = $objectManager->getObject(\Magento\Sales\Model\Order\CreditmemoFactory::class, []);
30-
}
30+
protected $testMethod;
3131

3232
/**
33-
* Check if order item can be refunded
33+
* @var Item|MockObject
34+
*/
35+
protected $orderItemMock;
36+
37+
/**
38+
* @var Item|MockObject
39+
*/
40+
protected $orderChildItemOneMock;
41+
42+
/**
43+
* @var Item|MockObject
3444
*/
35-
public function testCanRefundItem()
45+
protected $orderChildItemTwoMock;
46+
47+
/**
48+
* @inheritDoc
49+
*/
50+
protected function setUp(): void
3651
{
37-
$orderItem = $this->createPartialMock(
38-
\Magento\Sales\Model\Order\Item::class,
52+
$this->orderItemMock = $this->createPartialMock(
53+
Item::class,
3954
['getChildrenItems', 'isDummy', 'getHasChildren', 'getId', 'getParentItemId']
4055
);
41-
$orderItem->expects($this->any())
42-
->method('getId')
43-
->willReturn(1);
44-
$orderItem->expects($this->any())->method('getParentItemId')->willReturn(false);
45-
$orderItem->expects($this->any())->method('isDummy')->willReturn(true);
46-
$orderItem->expects($this->any())->method('getHasChildren')->willReturn(true);
47-
$orderChildItemOne = $this->createPartialMock(
48-
\Magento\Sales\Model\Order\Item::class,
56+
$this->orderChildItemOneMock = $this->createPartialMock(
57+
Item::class,
4958
['getQtyToRefund', 'getId']
5059
);
51-
$orderChildItemOne->expects($this->any())->method('getQtyToRefund')->willReturn(1);
52-
$orderChildItemOne->expects($this->any())->method('getId')->willReturn(2);
53-
$orderChildItemTwo = $this->createPartialMock(
54-
\Magento\Sales\Model\Order\Item::class,
60+
$this->orderChildItemTwoMock = $this->createPartialMock(
61+
Item::class,
5562
['getQtyToRefund', 'getId']
5663
);
57-
$orderChildItemTwo->expects($this->any())->method('getQtyToRefund')->willReturn(1);
58-
$orderChildItemTwo->expects($this->any())->method('getId')->willReturn(3);
59-
$orderItem->expects($this->any())
60-
->method('getChildrenItems')
61-
->willReturn([$orderChildItemOne, $orderChildItemTwo]);
62-
$testMethod = new \ReflectionMethod(
63-
\Magento\Sales\Model\Order\CreditmemoFactory::class,
64-
'canRefundItem'
65-
);
64+
$this->testMethod = new ReflectionMethod(CreditmemoFactory::class, 'canRefundItem');
65+
66+
$objectManagerHelper = new ObjectManagerHelper($this);
67+
$this->subject = $objectManagerHelper->getObject(CreditmemoFactory::class, []);
68+
}
69+
70+
/**
71+
* Check if order item can be refunded
72+
* @return void
73+
*/
74+
public function testCanRefundItem(): void
75+
{
6676
$orderItemQtys = [
6777
2 => 0,
6878
3 => 0
6979
];
7080
$invoiceQtysRefundLimits = [];
71-
$testMethod->setAccessible(true);
72-
$result = $testMethod->invoke($this->subject, $orderItem, $orderItemQtys, $invoiceQtysRefundLimits);
73-
$expectedResult = true;
74-
$this->assertEquals($expectedResult, $result);
81+
82+
$this->orderItemMock->expects($this->any())
83+
->method('getId')
84+
->willReturn(1);
85+
$this->orderItemMock->expects($this->any())
86+
->method('getParentItemId')
87+
->willReturn(false);
88+
$this->orderItemMock->expects($this->any())
89+
->method('isDummy')
90+
->willReturn(true);
91+
$this->orderItemMock->expects($this->any())
92+
->method('getHasChildren')
93+
->willReturn(true);
94+
95+
$this->orderChildItemOneMock->expects($this->any())
96+
->method('getQtyToRefund')
97+
->willReturn(1);
98+
$this->orderChildItemOneMock->expects($this->any())
99+
->method('getId')
100+
->willReturn(2);
101+
102+
$this->orderChildItemTwoMock->expects($this->any())
103+
->method('getQtyToRefund')
104+
->willReturn(1);
105+
$this->orderChildItemTwoMock->expects($this->any())
106+
->method('getId')
107+
->willReturn(3);
108+
$this->orderItemMock->expects($this->any())
109+
->method('getChildrenItems')
110+
->willReturn([$this->orderChildItemOneMock, $this->orderChildItemTwoMock]);
111+
112+
$this->testMethod->setAccessible(true);
113+
114+
$this->assertTrue(
115+
$this->testMethod->invoke(
116+
$this->subject,
117+
$this->orderItemMock,
118+
$orderItemQtys,
119+
$invoiceQtysRefundLimits
120+
)
121+
);
75122
}
76123
}

0 commit comments

Comments
 (0)