Skip to content

Commit 55f06e6

Browse files
author
Gabriel Galvao da Gama
committed
Added tests coverage and small improvements
1 parent 6db35d8 commit 55f06e6

File tree

3 files changed

+167
-14
lines changed

3 files changed

+167
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminLoginAsCustomerLoginFromOrderPageManualChooseActionGroup">
12+
<annotations>
13+
<description>Verify Login as Customer Login action is works properly from Order page with manual Store View choose.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="orderId" type="string"/>
17+
<argument name="storeName" type="string" defaultValue="default"/>
18+
</arguments>
19+
20+
<amOnPage url="{{AdminOrderPage.url(orderId)}}" stepKey="gotoOrderPage"/>
21+
<waitForPageLoad stepKey="waitForCustomerPageLoad"/>
22+
<click selector="{{AdminOrderDetailsMainActionsSection.loginAsCustomer}}" stepKey="clickLoginAsCustomerLink"/>
23+
<see selector="{{AdminConfirmationModalSection.title}}" userInput="Login as Customer: Select Store" stepKey="seeModal"/>
24+
<see selector="{{AdminConfirmationModalSection.message}}" userInput="Actions taken while in &quot;Login as Customer&quot; will affect actual customer data." stepKey="seeModalMessage"/>
25+
<selectOption selector="{{AdminLoginAsCustomerConfirmationModalSection.store}}" userInput="{{storeName}}" stepKey="selectStore"/>
26+
<click selector="{{AdminConfirmationModalSection.ok}}" stepKey="clickLogin"/>
27+
<switchToNextTab stepKey="switchToNewTab"/>
28+
<waitForPageLoad stepKey="waitForPageLoad"/>
29+
</actionGroup>
30+
</actionGroups>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminLoginAsCustomerManualChooseFromOrderPageTest">
12+
<annotations>
13+
<features value="Login as Customer"/>
14+
<stories value="Select Store based on 'Store View To Login In' setting"/>
15+
<title
16+
value="Admin user directly login into customer account with store View To Login In = Manual Choose on Order Page"/>
17+
<description
18+
value="Verify admin user can directly login into customer account to Custom store view when Store View To Login In = Manual Choose on Order Page"/>
19+
<severity value="CRITICAL"/>
20+
<group value="login_as_customer"/>
21+
</annotations>
22+
<before>
23+
<createData entity="Simple_US_Customer_Assistance_Allowed" stepKey="createCustomer"/>
24+
<createData entity="_defaultCategory" stepKey="createCategory"/>
25+
<createData entity="SimpleProduct" stepKey="createProduct">
26+
<requiredEntity createDataKey="createCategory"/>
27+
</createData>
28+
<magentoCLI command="config:set {{LoginAsCustomerConfigDataEnabled.path}} 1"
29+
stepKey="enableLoginAsCustomer"/>
30+
<magentoCLI command="config:set {{LoginAsCustomerStoreViewLogin.path}} 1"
31+
stepKey="enableLoginAsCustomerManualChoose"/>
32+
<magentoCLI command="cache:flush config" stepKey="flushCacheBeforeTestRun"/>
33+
<actionGroup ref="AdminLoginActionGroup" stepKey="adminLogin"/>
34+
<actionGroup ref="AdminCreateNewStoreGroupActionGroup" stepKey="createCustomStore">
35+
<argument name="website" value="{{_defaultWebsite.name}}"/>
36+
<argument name="storeGroupName" value="{{customStoreGroup.name}}"/>
37+
<argument name="storeGroupCode" value="{{customStoreGroup.code}}"/>
38+
</actionGroup>
39+
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createFirstCustomStoreView">
40+
<argument name="StoreGroup" value="customStoreGroup"/>
41+
<argument name="customStore" value="customStoreEN"/>
42+
</actionGroup>
43+
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createSecondCustomStoreView">
44+
<argument name="StoreGroup" value="customStoreGroup"/>
45+
<argument name="customStore" value="customStoreFR"/>
46+
</actionGroup>
47+
</before>
48+
<after>
49+
<actionGroup ref="DeleteCustomStoreActionGroup" stepKey="deleteCustomStore">
50+
<argument name="storeGroupName" value="customStoreGroup.name"/>
51+
</actionGroup>
52+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
53+
<magentoCLI command="config:set {{LoginAsCustomerConfigDataEnabled.path}} 0"
54+
stepKey="disableLoginAsCustomer"/>
55+
<magentoCLI command="config:set {{LoginAsCustomerStoreViewLogin.path}} 0"
56+
stepKey="enableLoginAsCustomerAutoDetection"/>
57+
<magentoCLI command="cache:flush config" stepKey="flushCacheAfterTestRun"/>
58+
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
59+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
60+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
61+
</after>
62+
63+
<!-- Login as Customer from Customer page -->
64+
<actionGroup ref="AdminLoginAsCustomerLoginFromCustomerPageManualChooseActionGroup"
65+
stepKey="loginAsCustomerFromCustomerPage">
66+
<argument name="customerId" value="$$createCustomer.id$$"/>
67+
<argument name="storeName" value="{{customStoreGroup.name}}"/>
68+
</actionGroup>
69+
70+
<!-- Place Order as Customer -->
71+
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openProductPage">
72+
<argument name="productUrl" value="$$createProduct.sku$$"/>
73+
</actionGroup>
74+
<actionGroup ref="StorefrontAddProductToCartActionGroup" stepKey="addProductToCart">
75+
<argument name="product" value="$$createProduct$$"/>
76+
<argument name="productCount" value="1"/>
77+
</actionGroup>
78+
<actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="openCart"/>
79+
<actionGroup ref="PlaceOrderWithLoggedUserActionGroup" stepKey="placeOrder"/>
80+
<grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber22}}" stepKey="grabOrderId"/>
81+
82+
<!-- Login as Customer from Customer page -->
83+
<actionGroup ref="AdminLoginAsCustomerLoginFromOrderPageManualChooseActionGroup"
84+
stepKey="loginAsCustomerFromOrderPage">
85+
<argument name="orderId" value="{$grabOrderId}"/>
86+
<argument name="storeName" value="{{customStoreGroup.name}}"/>
87+
</actionGroup>
88+
89+
<!-- Assert Customer logged on on custom store view -->
90+
<actionGroup ref="StorefrontAssertLoginAsCustomerLoggedInActionGroup" stepKey="assertLoggedInFromCustomerGird">
91+
<argument name="customerFullName" value="$$createCustomer.firstname$$ $$createCustomer.lastname$$"/>
92+
<argument name="customerEmail" value="$$createCustomer.email$$"/>
93+
</actionGroup>
94+
<actionGroup ref="StorefrontAssertCustomerOnStoreViewActionGroup" stepKey="assertCustomStoreView">
95+
<argument name="storeViewName" value="{{customStoreEN.name}}"/>
96+
</actionGroup>
97+
98+
<!-- Log out Customer and close tab -->
99+
<actionGroup ref="StorefrontSignOutAndCloseTabActionGroup" stepKey="signOutAndCloseTab"/>
100+
</test>
101+
</tests>

app/code/Magento/LoginAsCustomerAdminUi/Ui/Customer/Component/ConfirmationPopup/Options.php

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\App\RequestInterface;
1515
use Magento\Framework\Data\OptionSourceInterface;
1616
use Magento\Framework\Escaper;
17+
use Magento\Framework\Exception\LocalizedException;
1718
use Magento\Sales\Api\CreditmemoRepositoryInterface;
1819
use Magento\Sales\Api\InvoiceRepositoryInterface;
1920
use Magento\Sales\Api\OrderRepositoryInterface;
@@ -116,6 +117,7 @@ public function __construct(
116117

117118
/**
118119
* @inheritdoc
120+
* @throws LocalizedException
119121
*/
120122
public function toOptionArray(): array
121123
{
@@ -213,25 +215,45 @@ private function fillStoreGroupOptions(Website $website, CustomerInterface $cust
213215
* Get Customer id from request param.
214216
*
215217
* @return int
218+
* @throws LocalizedException
216219
*/
217220
private function getCustomerId(): int
218221
{
219222
$customerId = $this->request->getParam('id');
220-
if (!$customerId) {
221-
$orderId = $this->request->getParam('order_id');
222-
$shipmentId = $this->request->getParam('shipment_id');
223-
$creditmemoId = $this->request->getParam('creditmemo_id');
224-
$invoiceId = $this->request->getParam('invoice_id');
225-
if ($invoiceId) {
226-
$orderId = $this->invoiceRepository->get($invoiceId)->getOrderId();
227-
} elseif ($shipmentId) {
228-
$orderId = $this->shipmentRepository->get($shipmentId)->getOrderId();
229-
} elseif ($creditmemoId) {
230-
$orderId = $this->creditmemoRepository->get($creditmemoId)->getOrderId();
231-
}
232-
$customerId = $this->orderRepository->get($orderId)->getCustomerId();
223+
if ($customerId) {
224+
return (int)$customerId;
225+
}
226+
try {
227+
$orderId = $this->getOrderId();
228+
} catch (LocalizedException $exception) {
229+
throw new LocalizedException(__('Unable to get Customer ID.'));
233230
}
234231

235-
return (int)$customerId;
232+
return (int)$this->orderRepository->get($orderId)->getCustomerId();
233+
}
234+
235+
/**
236+
* Get Order id from request param
237+
*
238+
* @return int
239+
* @throws LocalizedException
240+
*/
241+
private function getOrderId(): int
242+
{
243+
$orderId = $this->request->getParam('order_id');
244+
if ($orderId) {
245+
return (int)$orderId;
246+
}
247+
$shipmentId = $this->request->getParam('shipment_id');
248+
$creditmemoId = $this->request->getParam('creditmemo_id');
249+
$invoiceId = $this->request->getParam('invoice_id');
250+
if ($invoiceId) {
251+
return $this->invoiceRepository->get($invoiceId)->getOrderId();
252+
} elseif ($shipmentId) {
253+
return $this->shipmentRepository->get($shipmentId)->getOrderId();
254+
} elseif ($creditmemoId) {
255+
return $this->creditmemoRepository->get($creditmemoId)->getOrderId();
256+
}
257+
throw new LocalizedException(__('Unable to get Order ID.'));
236258
}
237259
}

0 commit comments

Comments
 (0)