Skip to content

Commit

Permalink
Merge pull request #2760 from magento-borg/MAGETWO-91555
Browse files Browse the repository at this point in the history
[borg] MAGETWO-91555: Admin orders can result in a customer with an example email address
  • Loading branch information
cpartica authored Jul 4, 2018
2 parents 2375461 + 77b74f7 commit d8a95c9
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected function _addAdditionalFormElementData(AbstractElement $element)
{
switch ($element->getId()) {
case 'email':
$element->setRequired(0);
$element->setRequired(1);
$element->setClass('validate-email admin__control-text');
break;
}
Expand Down
17 changes: 2 additions & 15 deletions app/code/Magento/Sales/Model/AdminOrder/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -2012,26 +2012,13 @@ protected function _validate()
}

/**
* Retrieve or generate new customer email.
* Retrieve new customer email.
*
* @return string
*/
protected function _getNewCustomerEmail()
{
$email = $this->getData('account/email');
if (empty($email)) {
$host = $this->_scopeConfig->getValue(
self::XML_PATH_DEFAULT_EMAIL_DOMAIN,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
$account = time();
$email = $account . '@' . $host;
$account = $this->getData('account');
$account['email'] = $email;
$this->setData('account', $account);
}

return $email;
return $this->getData('account/email');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@

<!--Create Store view -->
<amOnPage url="{{AdminSystemStorePage.url}}" stepKey="amOnAdminSystemStorePage"/>
<click selector="{{AdminStoresMainActionsSection.createStoreViewButton}}" stepKey="createStoreViewButton"/>
<click selector="{{AdminStoresMainActionsSection.createStoreViewButton}}" stepKey="clickCreateStoreViewButton"/>
<waitForPageLoad stepKey="waitForProductPageLoad"/>
<waitForElementVisible selector="//legend[contains(., 'Store View Information')]" stepKey="waitFornewStorePageToOpen" after="clickCreateStoreViewButton"/>
<selectOption userInput="Second Store" selector="{{AdminNewStoreSection.storeGrpDropdown}}" stepKey="selectStoreGroup"/>
<fillField userInput="Second Store View" selector="{{AdminNewStoreSection.storeNameTextField}}" stepKey="fillStoreViewName"/>
<fillField userInput="second_store_view" selector="{{AdminNewStoreSection.storeCodeTextField}}" stepKey="fillStoreViewCode"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<testCaseId value="MAGETWO-91436"/>
<group value="product"/>
</annotations>
<before>
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
<!--Create new website -->
<actionGroup ref="AdminCreateWebsiteActionGroup" stepKey="createAdditionalWebsite">
Expand Down Expand Up @@ -46,7 +45,7 @@
<conditionalClick selector="{{AdminNewStoreSection.acceptNewStoreViewCreation}}" dependentSelector="{{AdminNewStoreSection.acceptNewStoreViewCreation}}" visible="true" stepKey="AcceptNewStoreViewCreation"/>
<waitForElementVisible selector="{{AdminStoresGridSection.storeFilterTextField}}" stepKey="waitForPageReolad"/>
<see userInput="You saved the store view." stepKey="seeSaveMessage" />
</before>

<after>
<actionGroup ref="ResetWebUrlOptions" stepKey="resetUrlOption"/>
<actionGroup ref="AdminDeleteWebsiteActionGroup" stepKey="deleteTestWebsite">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<!--Check the required fields are actually required-->
<actionGroup name="checkRequiredFieldsNewOrderForm">
<seeElement selector="{{AdminOrderFormAccountSection.requiredGroup}}" stepKey="seeCustomerGroupRequired"/>
<seeElement selector="{{AdminOrderFormAccountSection.requiredEmail}}" stepKey="seeEmailRequired"/>
<clearField selector="{{AdminOrderFormAccountSection.email}}" stepKey="clearEmailField"/>
<clearField selector="{{AdminOrderFormBillingAddressSection.FirstName}}" stepKey="clearFirstNameField"/>
<clearField selector="{{AdminOrderFormBillingAddressSection.LastName}}" stepKey="clearLastNameField"/>
<clearField selector="{{AdminOrderFormBillingAddressSection.StreetLine1}}" stepKey="clearStreetField"/>
Expand All @@ -35,6 +37,7 @@
<clearField selector="{{AdminOrderFormBillingAddressSection.Phone}}" stepKey="clearPhoneField"/>
<seeElement selector="{{AdminOrderFormPaymentSection.getShippingMethods}}" stepKey="seeShippingMethodNotSelected"/>
<click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="trySubmitOrder"/>
<see selector="{{AdminOrderFormBillingAddressSection.emailError}}" userInput="This is a required field." stepKey="seeThatEmailIsRequired"/>
<see selector="{{AdminOrderFormBillingAddressSection.firstNameError}}" userInput="This is a required field." stepKey="seeFirstNameRequired"/>
<see selector="{{AdminOrderFormBillingAddressSection.lastNameError}}" userInput="This is a required field." stepKey="seeLastNameRequired"/>
<see selector="{{AdminOrderFormBillingAddressSection.streetAddressError}}" userInput="This is a required field." stepKey="seeStreetRequired"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<element name="group" type="select" selector="#group_id"/>
<element name="email" type="input" selector="#email"/>
<element name="requiredGroup" type="text" selector=".admin__field.required[data-ui-id='billing-address-fieldset-element-form-field-group-id']"/>
<element name="requiredEmail" type="text" selector=".admin__field.required[data-ui-id='billing-address-fieldset-element-form-field-email']"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<element name="ValidateVatNumber" type="button" selector="#order-billing_address_vat_id + .actions>button.action-default" timeout="30"/>
<element name="SaveAddress" type="checkbox" selector="#order-billing_address_save_in_address_book"/>

<element name="emailError" type="text" selector="#email-error"/>
<element name="firstNameError" type="text" selector="#order-billing_address_firstname-error"/>
<element name="lastNameError" type="text" selector="#order-billing_address_lastname-error"/>
<element name="streetAddressError" type="text" selector="#order-billing_address_street0-error"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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="../../../../../../vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
<test name="AdminSubmitsOrderWithAndWithoutEmailTest">
<annotations>
<title value="Email is required to create an order from Admin Panel"/>
<description value="Admin should not be able to submit orders without an email address"/>
<severity value="MAJOR"/>
<testCaseId value="MAGETWO-92980"/>
<group value="sales"/>

</annotations>
<before>
<createData entity="_defaultCategory" stepKey="createCategory"/>
<createData entity="_defaultProduct" stepKey="createSimpleProduct">
<requiredEntity createDataKey="createCategory"/>
</createData>
</before>
<after>
<deleteData createDataKey="createSimpleProduct" stepKey="deleteProduct"/>
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
<amOnPage url="admin/admin/auth/logout/" stepKey="amOnLogoutPage"/>
</after>
<!--Create order via Admin-->
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
<comment userInput="Admin creates order" stepKey="adminCreateOrderComment"/>
<!--<actionGroup ref="navigateToNewOrderPageNewCustomer" stepKey="navigateToNewOrderPage"/>-->
<amOnPage url="{{AdminOrdersPage.url}}" stepKey="navigateToOrderIndexPage"/>
<waitForPageLoad stepKey="waitForIndexPageLoad"/>
<see selector="{{AdminHeaderSection.pageTitle}}" userInput="Orders" stepKey="seeIndexPageTitle"/>
<click selector="{{AdminOrdersGridSection.createNewOrder}}" stepKey="clickCreateNewOrder"/>
<click selector="{{AdminOrderFormActionSection.CreateNewCustomer}}" stepKey="clickCreateCustomer"/>
<see selector="{{AdminHeaderSection.pageTitle}}" userInput="Create New Order" stepKey="seeNewOrderPageTitle"/>

<!--Check if order can be submitted without the required fields including email address-->
<actionGroup ref="checkRequiredFieldsNewOrderForm" stepKey="checkRequiredFieldsNewOrder" after="seeNewOrderPageTitle"/>
<scrollToTopOfPage stepKey="scrollToTopOfOrderFormPage" after="checkRequiredFieldsNewOrder"/>
<actionGroup ref="addSimpleProductToOrder" stepKey="addSimpleProductToOrder" after="scrollToTopOfOrderFormPage">
<argument name="product" value="_defaultProduct"/>
</actionGroup>

<!--Fill customer group and customer email-->
<selectOption selector="{{AdminOrderFormAccountSection.group}}" userInput="{{GeneralCustomerGroup.code}}" stepKey="selectCustomerGroup" after="addSimpleProductToOrder"/>
<fillField selector="{{AdminOrderFormAccountSection.email}}" userInput="{{Simple_US_Customer.email}}" stepKey="fillCustomerEmail" after="selectCustomerGroup"/>

<!--Fill customer address information-->
<actionGroup ref="fillOrderCustomerInformation" stepKey="fillCustomerAddress" after="fillCustomerEmail">
<argument name="customer" value="Simple_US_Customer"/>
<argument name="address" value="US_Address_TX"/>
</actionGroup>
<!-- Select shipping -->
<actionGroup ref="orderSelectFlatRateShipping" stepKey="selectFlatRateShipping" after="fillCustomerAddress"/>

<!--Verify totals on Order page-->
<see selector="{{AdminOrderFormTotalSection.total('Subtotal')}}" userInput="${{AdminOrderSimpleProduct.subtotal}}" stepKey="seeOrderSubTotal" after="selectFlatRateShipping"/>
<see selector="{{AdminOrderFormTotalSection.total('Shipping')}}" userInput="${{AdminOrderSimpleProduct.shipping}}" stepKey="seeOrderShipping" after="seeOrderSubTotal"/>
<scrollTo selector="{{AdminOrderFormTotalSection.grandTotal}}" stepKey="scrollToOrderGrandTotal"/>
<see selector="{{AdminOrderFormTotalSection.grandTotal}}" userInput="${{AdminOrderSimpleProduct.grandTotal}}" stepKey="seeCorrectGrandTotal" after="scrollToOrderGrandTotal"/>

<!--Submit Order and verify information-->
<click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="clickSubmitOrder" after="seeCorrectGrandTotal"/>
<seeInCurrentUrl url="{{AdminOrderDetailsPage.url}}" stepKey="seeViewOrderPage" after="clickSubmitOrder"/>
<see selector="{{AdminOrderDetailsMessagesSection.successMessage}}" userInput="You created the order." stepKey="seeSuccessMessage" after="seeViewOrderPage"/>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -519,20 +519,14 @@ public function testCreateOrderNewCustomerWithFailedFirstPlaceOrderAction(
* Email before and after failed first place order action.
*
* @case #1 Is the same.
* @case #2 Is empty.
* @case #3 Filled after failed first place order action.
* @case #4 Empty after failed first place order action.
* @case #5 Changed after failed first place order action.
* @case #2 Changed after failed first place order action.
* @return array
*/
public function createOrderNewCustomerWithFailedFirstPlaceOrderActionDataProvider()
{
return [
1 => ['customer@email.com', 'customer@email.com'],
2 => ['', ''],
3 => ['', 'customer@email.com'],
4 => ['customer@email.com', ''],
5 => ['customer@email.com', 'changed_customer@email.com'],
2 => ['customer@email.com', 'changed_customer@email.com'],
];
}

Expand Down

0 comments on commit d8a95c9

Please sign in to comment.