-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Fix Downloadable product after refund #28413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
magento-engcom-team
merged 21 commits into
magento:2.4-develop
from
ProkopovVitaliy:fix-28388
Sep 2, 2020
Merged
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a6f460d
fixed refund issue for downloadable items
ProkopovVitaliy 9a83830
added unit test
ProkopovVitaliy 96c9d54
Merge branch '2.4-develop' into fix-28388
ProkopovVitaliy 59cf9f7
added short description
ProkopovVitaliy c6c3231
Merge branch 'fix-28388' of github.com:ProkopovVitaliy/magento2 into …
ProkopovVitaliy eafdb17
Merge branch '2.4-develop' into fix-28388
engcom-Kilo 92fd06b
Merge branch '2.4-develop' into fix-28388
engcom-Kilo 1f7eace
MFTF test.
engcom-Kilo db84d3a
MFTF test, updated testCaseId.
engcom-Kilo d0a0962
Merge branch '2.4-develop' into fix-28388
engcom-Kilo aea9276
Merge branch '2.4-develop' into fix-28388
slavvka 1be2cd7
Merge branch '2.4-develop' into fix-28388
slavvka dee9b16
Merge branch '2.4-develop' into fix-28388
engcom-Kilo a49709f
Fix MFTF tests.
engcom-Kilo 8023f42
Merge branch '2.4-develop' into fix-28388
engcom-Kilo 9e31246
Merge branch '2.4-develop' into fix-28388
engcom-Kilo d91b305
Merge branch '2.4-develop' into fix-28388
engcom-Kilo 62e4866
Merge branch '2.4-develop' into fix-28388
engcom-Kilo 97df424
Merge branch '2.4-develop' into fix-28388
engcom-Kilo 2d58988
MFTF update.
engcom-Kilo 87d8984
Merge branch '2.4-develop' into fix-28388
engcom-Kilo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...tf/ActionGroup/StorefrontNotAssertDownloadableProductLinkInCustomerAccountActionGroup.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| --> | ||
|
|
||
| <actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd"> | ||
| <actionGroup name="StorefrontNotAssertDownloadableProductLinkInCustomerAccountActionGroup"> | ||
| <annotations> | ||
| <description>Goes to the Storefront Customer Dashboard page. Clicks on 'My Downloadable Products'. Validates that the provided Downloadable Product is present and Downloadable link not exist.</description> | ||
| </annotations> | ||
| <arguments> | ||
| <argument name="product"/> | ||
| </arguments> | ||
|
|
||
| <amOnPage url="{{StorefrontCustomerDashboardPage.url}}" stepKey="goToMyAccountPage"/> | ||
| <click selector="{{StorefrontCustomerSidebarSection.sidebarTab('My Downloadable Products')}}" stepKey="clickDownloadableProducts"/> | ||
| <waitForPageLoad stepKey="waitForDownloadableProductsPageLoad"/> | ||
| <seeElement selector="{{StorefrontCustomerDownloadableProductsSection.productName(product.name)}}" stepKey="seeStorefrontDownloadableProductsProductName"/> | ||
| <dontSeeElement selector="{{StorefrontCustomerDownloadableProductsSection.downloadableLink}}" stepKey="dontSeeStorefrontMyDownloadableProductsLink"/> | ||
|
|
||
| </actionGroup> | ||
| </actionGroups> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...oadable/Test/Mftf/Test/StorefrontAccountDownloadableProductLinkAfterPartialRefundTest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| --> | ||
| <tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> | ||
| <test name="StorefrontAccountDownloadableProductLinkAfterPartialRefundTest"> | ||
| <annotations> | ||
| <features value="Catalog"/> | ||
| <stories value="Customer Account Downloadable Products Link"/> | ||
| <title value="My Account Downloadable Product Link after Partially Refunded"/> | ||
| <description value="Verify that Downloadable product is not available in My Download Products tab after it has been partially refunded."/> | ||
| <severity value="CRITICAL"/> | ||
| <group value="Downloadable"/> | ||
| </annotations> | ||
|
|
||
| <before> | ||
| <magentoCLI stepKey="addDownloadableDomain" command="downloadable:domains:add example.com static.magento.com"/> | ||
| <magentoCLI command="config:set {{EnableFlatRateConfigData.path}} {{EnableFlatRateConfigData.value}}" stepKey="enableFlatRate"/> | ||
|
|
||
| <createData entity="ApiCategory" stepKey="createCategory"/> | ||
| <createData entity="ApiSimpleProduct" stepKey="createSimpleProduct"> | ||
| <requiredEntity createDataKey="createCategory"/> | ||
| </createData> | ||
| <createData entity="ApiDownloadableProduct" stepKey="createDownloadableProduct"/> | ||
| <createData entity="downloadableLink1" stepKey="addDownloadableLink1"> | ||
| <requiredEntity createDataKey="createDownloadableProduct"/> | ||
| </createData> | ||
|
|
||
| <magentoCLI command="indexer:reindex" stepKey="reindex"/> | ||
| <magentoCLI command="cache:flush" stepKey="flushCache"/> | ||
|
|
||
| <createData entity="Simple_US_Customer_Multiple_Addresses" stepKey="createCustomer"/> | ||
| <actionGroup ref="LoginToStorefrontActionGroup" stepKey="signIn"> | ||
| <argument name="Customer" value="$$createCustomer$$"/> | ||
| </actionGroup> | ||
| </before> | ||
|
|
||
| <after> | ||
| <actionGroup ref="AdminLogoutActionGroup" stepKey="logoutFromAdmin"/> | ||
| <actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="customerLogout"/> | ||
|
|
||
| <deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/> | ||
| <deleteData createDataKey="createCategory" stepKey="deleteCategory"/> | ||
| <deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/> | ||
| <deleteData createDataKey="createDownloadableProduct" stepKey="deleteDownloadableProduct"/> | ||
|
|
||
| <magentoCLI stepKey="removeDownloadableDomain" command="downloadable:domains:remove example.com static.magento.com"/> | ||
| <magentoCLI command="config:set {{EnableFlatRateConfigData.path}} {{EnableFlatRateConfigData.value}}" stepKey="enableFlatRate"/> | ||
| <magentoCLI command="cache:flush" stepKey="flushCache"/> | ||
| </after> | ||
|
|
||
| <actionGroup ref="StorefrontAddSimpleProductToShoppingCartActionGroup" stepKey="addSimpleProductToCart"> | ||
| <argument name="product" value="$$createSimpleProduct$$"/> | ||
| </actionGroup> | ||
|
|
||
| <amOnPage url="{{StorefrontProductPage.url($$createDownloadableProduct.custom_attributes[url_key]$$)}}" stepKey="OpenStoreFrontProductPage"/> | ||
| <waitForPageLoad stepKey="waitForPageToLoad"/> | ||
|
|
||
| <actionGroup ref="StorefrontAddToCartCustomOptionsProductPageActionGroup" stepKey="addToTheCart"> | ||
| <argument name="productName" value="$$createDownloadableProduct.name$$"/> | ||
| </actionGroup> | ||
|
|
||
| <actionGroup ref="ClickViewAndEditCartFromMiniCartActionGroup" stepKey="goToShoppingCartFromMinicart"/> | ||
| <click selector="{{CheckoutCartSummarySection.proceedToCheckout}}" stepKey="clickProceedToCheckout"/> | ||
| <waitForPageLoad stepKey="waitForProceedToCheckout"/> | ||
| <waitForElementVisible selector="{{CheckoutShippingSection.shipHereButton(UK_Not_Default_Address.street[0])}}" stepKey="waitForShipHereVisible"/> | ||
| <click selector="{{CheckoutShippingSection.shipHereButton(UK_Not_Default_Address.street[0])}}" stepKey="clickShipHere"/> | ||
| <click selector="{{CheckoutShippingGuestInfoSection.next}}" stepKey="clickNext"/> | ||
| <waitForPageLoad stepKey="waitForShipmentPageLoad"/> | ||
| <checkOption selector="{{CheckoutPaymentSection.billingAddressNotSameCheckbox}}" stepKey="selectPaymentSolution"/> | ||
| <waitForElement selector="{{CheckoutPaymentSection.paymentSectionTitle}}" stepKey="waitForPaymentSectionLoaded"/> | ||
| <click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrderButton"/> | ||
| <seeElement selector="{{CheckoutSuccessMainSection.success}}" stepKey="orderIsSuccessfullyPlaced"/> | ||
| <grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber22}}" stepKey="grabOrderNumber"/> | ||
|
|
||
| <actionGroup ref="AdminLoginActionGroup" stepKey="LoginAsAdmin"/> | ||
|
|
||
| <amOnPage url="{{AdminOrdersPage.url}}" stepKey="onOrdersPage"/> | ||
| <actionGroup ref="SearchAdminDataGridByKeywordActionGroup" stepKey="searchOrder"> | ||
| <argument name="keyword" value="$grabOrderNumber"/> | ||
| </actionGroup> | ||
| <actionGroup ref="AdminOrderGridClickFirstRowActionGroup" stepKey="clickOrderRow"/> | ||
|
|
||
| <actionGroup ref="AdminCreateInvoiceActionGroup" stepKey="createCreditMemo"/> | ||
|
|
||
| <actionGroup ref="OpenOrderByIdActionGroup" stepKey="openOrder"> | ||
| <argument name="orderId" value="{$grabOrderNumber}"/> | ||
| </actionGroup> | ||
|
|
||
| <actionGroup ref="AdminOpenAndFillCreditMemoRefundActionGroup" stepKey="fillCreditMemoRefund"> | ||
| <argument name="itemQtyToRefund" value="0"/> | ||
| <argument name="rowNumber" value="1"/> | ||
| </actionGroup> | ||
|
|
||
| <click selector="{{AdminCreditMemoTotalSection.submitRefundOffline}}" stepKey="clickRefundOffline"/> | ||
| <waitForPageLoad stepKey="waitForResultPage"/> | ||
|
|
||
| <actionGroup ref="StorefrontNotAssertDownloadableProductLinkInCustomerAccountActionGroup" stepKey="dontSeeStorefrontMyAccountDownloadableProductsLink"> | ||
| <argument name="product" value="$$createDownloadableProduct$$"/> | ||
| </actionGroup> | ||
|
|
||
| </test> | ||
| </tests> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,7 +189,7 @@ public function testSetLinkStatusPending($orderState, array $orderStateMapping) | |
| ] | ||
| ); | ||
|
|
||
| $this->itemsFactory->expects($this->once()) | ||
| $this->itemsFactory->expects($this->any()) | ||
| ->method('create') | ||
| ->willReturn( | ||
| $this->createLinkItemCollection( | ||
|
|
@@ -243,7 +243,7 @@ public function testSetLinkStatusClosed() | |
| ] | ||
| ); | ||
|
|
||
| $this->itemsFactory->expects($this->once()) | ||
| $this->itemsFactory->expects($this->any()) | ||
| ->method('create') | ||
| ->willReturn( | ||
| $this->createLinkItemCollection( | ||
|
|
@@ -308,7 +308,7 @@ public function testSetLinkStatusInvoiced() | |
| ] | ||
| ); | ||
|
|
||
| $this->itemsFactory->expects($this->once()) | ||
| $this->itemsFactory->expects($this->any()) | ||
| ->method('create') | ||
| ->willReturn( | ||
| $this->createLinkItemCollection( | ||
|
|
@@ -344,6 +344,137 @@ public function testSetLinkStatusEmptyOrder() | |
| $this->assertInstanceOf(SetLinkStatusObserver::class, $result); | ||
| } | ||
|
|
||
| public function testSetLinkStatusExpired() | ||
| { | ||
| $this->scopeConfig->expects($this->once()) | ||
| ->method('getValue') | ||
| ->with( | ||
| \Magento\Downloadable\Model\Link\Purchased\Item::XML_PATH_ORDER_ITEM_STATUS, | ||
| ScopeInterface::SCOPE_STORE, | ||
| 1 | ||
| ) | ||
| ->willReturn(Item::STATUS_PENDING); | ||
|
|
||
| $this->observerMock->expects($this->once()) | ||
| ->method('getEvent') | ||
| ->willReturn($this->eventMock); | ||
|
|
||
| $this->eventMock->expects($this->once()) | ||
| ->method('getOrder') | ||
| ->willReturn($this->orderMock); | ||
|
|
||
| $this->orderMock->expects($this->once()) | ||
| ->method('getId') | ||
| ->willReturn(1); | ||
|
|
||
| $this->orderMock->expects($this->once()) | ||
| ->method('getStoreId') | ||
| ->willReturn(1); | ||
|
|
||
| $this->orderMock->expects($this->atLeastOnce()) | ||
| ->method('getState') | ||
| ->willReturn(Order::STATE_PROCESSING); | ||
|
|
||
| $this->orderMock->expects($this->any()) | ||
| ->method('getAllItems') | ||
| ->willReturn( | ||
| [ | ||
| $this->createRefundOrderItem(2, 2, 2), | ||
| $this->createRefundOrderItem(3, 2, 1), | ||
| $this->createRefundOrderItem(4, 3, 3), | ||
| ] | ||
| ); | ||
|
|
||
| $this->itemsFactory->expects($this->any()) | ||
| ->method('create') | ||
| ->willReturn( | ||
| $this->createLinkItemToExpireCollection( | ||
| [2, 4], | ||
| [ | ||
| $this->createLinkItem( | ||
| 'available', | ||
| 2, | ||
| true, | ||
| \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_EXPIRED | ||
| ), | ||
| $this->createLinkItem( | ||
| 'pending_payment', | ||
| 4, | ||
| true, | ||
| \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_EXPIRED | ||
| ), | ||
| ] | ||
| ) | ||
| ); | ||
|
|
||
| $result = $this->setLinkStatusObserver->execute($this->observerMock); | ||
| $this->assertInstanceOf(SetLinkStatusObserver::class, $result); | ||
| } | ||
|
|
||
| /** | ||
| * @param $id | ||
| * @param int $qtyOrdered | ||
| * @param int $qtyRefunded | ||
| * @param string $productType | ||
| * @param string $realProductType | ||
| * @return \Magento\Sales\Model\Order\Item|MockObject | ||
| */ | ||
| private function createRefundOrderItem( | ||
| $id, | ||
| $qtyOrdered, | ||
| $qtyRefunded, | ||
| $productType = DownloadableProductType::TYPE_DOWNLOADABLE, | ||
| $realProductType = DownloadableProductType::TYPE_DOWNLOADABLE | ||
| ) { | ||
| $item = $this->getMockBuilder(Item::class) | ||
| ->disableOriginalConstructor() | ||
| ->setMethods([ | ||
| 'getId', | ||
| 'getQtyOrdered', | ||
| 'getQtyRefunded', | ||
| 'getProductType', | ||
| 'getRealProductType' | ||
| ])->getMock(); | ||
| $item->expects($this->any()) | ||
| ->method('getId') | ||
| ->willReturn($id); | ||
| $item->expects($this->any()) | ||
| ->method('getQtyOrdered') | ||
| ->willReturn($qtyOrdered); | ||
| $item->expects($this->any()) | ||
| ->method('getQtyRefunded') | ||
| ->willReturn($qtyRefunded); | ||
| $item->expects($this->any()) | ||
| ->method('getProductType') | ||
| ->willReturn($productType); | ||
| $item->expects($this->any()) | ||
| ->method('getRealProductType') | ||
| ->willReturn($realProductType); | ||
|
|
||
| return $item; | ||
| } | ||
|
|
||
| /** | ||
| * @param array $expectedOrderItemIds | ||
| * @param array $items | ||
| * @return LinkItemCollection|MockObject | ||
| */ | ||
| private function createLinkItemToExpireCollection(array $expectedOrderItemIds, array $items) | ||
| { | ||
| $linkItemCollection = $this->getMockBuilder( | ||
| \Magento\Downloadable\Model\ResourceModel\Link\Purchased\Item\Collection::class | ||
| ) | ||
| ->disableOriginalConstructor() | ||
| ->setMethods(['addFieldToFilter']) | ||
| ->getMock(); | ||
| $linkItemCollection->expects($this->any()) | ||
| ->method('addFieldToFilter') | ||
| ->with('order_item_id', ['in' => $expectedOrderItemIds]) | ||
| ->willReturn($items); | ||
|
|
||
| return $linkItemCollection; | ||
| } | ||
|
|
||
| /** | ||
| * @param $id | ||
| * @param int $statusId | ||
|
|
@@ -359,7 +490,7 @@ private function createOrderItem( | |
| ) { | ||
| $item = $this->getMockBuilder(Item::class) | ||
| ->disableOriginalConstructor() | ||
| ->setMethods(['getId', 'getProductType', 'getRealProductType', 'getStatusId']) | ||
| ->setMethods(['getId', 'getProductType', 'getRealProductType', 'getStatusId', 'getQtyOrdered']) | ||
| ->getMock(); | ||
| $item->expects($this->any()) | ||
| ->method('getId') | ||
|
|
@@ -373,6 +504,9 @@ private function createOrderItem( | |
| $item->expects($this->any()) | ||
| ->method('getStatusId') | ||
| ->willReturn($statusId); | ||
| $item->expects($this->any()) | ||
| ->method('getQtyOrdered') | ||
| ->willReturn(1); | ||
|
|
||
| return $item; | ||
| } | ||
|
|
@@ -390,7 +524,7 @@ private function createLinkItemCollection(array $expectedOrderItemIds, array $it | |
| ->disableOriginalConstructor() | ||
| ->setMethods(['addFieldToFilter']) | ||
| ->getMock(); | ||
| $linkItemCollection->expects($this->once()) | ||
| $linkItemCollection->expects($this->any()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to use atLeastOnce instead. |
||
| ->method('addFieldToFilter') | ||
| ->with('order_item_id', ['in' => $expectedOrderItemIds]) | ||
| ->willReturn($items); | ||
|
|
@@ -415,11 +549,11 @@ private function createLinkItem($status, $orderItemId, $isSaved = false, $expect | |
| ->method('getStatus') | ||
| ->willReturn($status); | ||
| if ($isSaved) { | ||
| $linkItem->expects($this->once()) | ||
| $linkItem->expects($this->any()) | ||
| ->method('setStatus') | ||
| ->with($expectedStatus) | ||
| ->willReturnSelf(); | ||
| $linkItem->expects($this->once()) | ||
| $linkItem->expects($this->any()) | ||
| ->method('save') | ||
| ->willReturnSelf(); | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use atLeastOnce instead.