Skip to content

Commit

Permalink
Merge pull request #2853 from magento-earl-grey/MAGETWO-91465
Browse files Browse the repository at this point in the history
[earl] MAGETWO-91465: Once integer is stored for State/Province field, it can not be changed to alphanumeric
  • Loading branch information
cpartica authored Jul 18, 2018
2 parents 91e10cd + b6d4e6e commit 9e9ec37
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
<element name="next" type="button" selector="button.button.action.continue.primary" timeout="30"/>
<element name="firstShippingMethod" type="radio" selector="//*[@id='checkout-shipping-method-load']//input[@class='radio']"/>
<element name="defaultShipping" type="button" selector=".billing-address-details"/>
<element name="stateInput" type="input" selector="input[name=region]"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
<test name="AddressStateFieldShouldNotAcceptJustIntegerValuesTest">
<annotations>
<features value="Checkout"/>
<stories value="MAGETWO-91465"/>
<title value="Guest Checkout"/>
<description value="Address State field should not allow just integer values"/>
<severity value="MAJOR"/>
<testCaseId value="MAGETWO-93203"/>
<group value="checkout"/>
</annotations>
<before>
<createData entity="_defaultCategory" stepKey="createCategory"/>
<createData entity="ApiSimpleProduct" stepKey="createProduct">
<requiredEntity createDataKey="createCategory"/>
</createData>
</before>
<after>
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
</after>

<amOnPage url="{{StorefrontCategoryPage.url($$createCategory.name$$)}}" stepKey="onCategoryPage"/>
<waitForPageLoad stepKey="waitForPageLoad1"/>
<moveMouseOver selector="{{StorefrontCategoryMainSection.ProductItemInfo}}" stepKey="hoverProduct"/>
<click selector="{{StorefrontCategoryMainSection.AddToCartBtn}}" stepKey="addToCart"/>
<waitForElementVisible selector="{{StorefrontCategoryMainSection.SuccessMsg}}" time="30" stepKey="waitForProductAdded"/>
<see selector="{{StorefrontCategoryMainSection.SuccessMsg}}" userInput="You added $$createProduct.name$$ to your shopping cart." stepKey="seeAddedToCartMessage"/>
<see selector="{{StorefrontMinicartSection.quantity}}" userInput="1" stepKey="seeCartQuantity"/>
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="guestGoToCheckoutFromMinicart" />
<selectOption stepKey="selectCounty" selector="{{CheckoutShippingSection.country}}" userInput="{{UK_Address.country_id}}"/>
<waitForPageLoad stepKey="waitFormToReload"/>
<fillField selector="{{CheckoutShippingSection.stateInput}}" userInput="1" stepKey="enterStateAsIntegerValue"/>
<waitForPageLoad stepKey="waitforFormValidation"/>
<see userInput="First character must be letter." stepKey="seeTheErrorMessageDisplayed"/>
<fillField selector="{{CheckoutShippingSection.stateInput}}" userInput=" 1" stepKey="enterStateAsIntegerValue1"/>
<waitForPageLoad stepKey="waitforFormValidation1"/>
<see userInput="First character must be letter." stepKey="seeTheErrorMessageDisplayed1"/>
<fillField selector="{{CheckoutShippingSection.stateInput}}" userInput="ABC1" stepKey="enterStateAsIntegerValue2"/>
<waitForPageLoad stepKey="waitforFormValidation2"/>
<dontSee userInput="First character must be letter." stepKey="seeTheErrorMessageIsNotDisplayed"/>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ private function validateCountry(AbstractAddress $address)
*
* @param AbstractAddress $address
* @return array
* @throws \Zend_Validate_Exception
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function validateRegion(AbstractAddress $address)
{
Expand All @@ -107,7 +109,7 @@ private function validateRegion(AbstractAddress $address)
//If country actually has regions and requires you to
//select one then it must be selected.
$errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'regionId']);
} elseif ($regionId && !in_array($regionId, $allowedRegions, true)) {
} elseif ($allowedRegions && $regionId && !in_array($regionId, $allowedRegions, true)) {
//If a region is selected then checking if it exists.
$errors[] = __(
'Invalid value of "%value" provided for the %fieldName field.',
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Customer/Test/Mftf/Data/AddressData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,8 @@
<data key="default_shipping">Yes</data>
<requiredEntity type="region">RegionCA</requiredEntity>
</entity>
<!--If required other field can be added to UK_Address entity, dont modify any existing data-->
<entity name="UK_Address" type="address">
<data key="country_id">GB</data>
</entity>
</entities>
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ public function validateDataProvider()
'region_id2' => [
array_merge($data, ['country_id' => $countryId, 'region_id' => 2]),
[$countryId++],
[1],
[],
[],
],
'region_id3' => [
array_merge($data, ['country_id' => $countryId, 'region_id' => 2]),
[$countryId++],
[1, 3],
['Invalid value of "2" provided for the regionId field.'],
],
'validated' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
name="region"
value="<?= $block->escapeHtmlAttr($block->getRegion()) ?>"
title="<?= $block->escapeHtmlAttr(__('State/Province')) ?>"
class="input-text <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('region')) ?>"<?= !$block->getConfig('general/region/display_all') ? ' disabled="disabled"' : '' ?>/>
class="input-text validate-not-number-first <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('region')) ?>"<?= !$block->getConfig('general/region/display_all') ? ' disabled="disabled"' : '' ?>/>
</div>
</div>
<div class="field zip required">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ define([
registry.get(this.customName, function (input) {
isRegionRequired = !!option['is_region_required'];
input.validation['required-entry'] = isRegionRequired;
input.validation['validate-not-number-first'] = true;
input.required(isRegionRequired);
});
}
Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,12 @@ define([
},
$.mage.__('Please use only letters (a-z or A-Z) or numbers (0-9) in this field. No spaces or other characters are allowed.')//eslint-disable-line max-len
],
'validate-not-number-first': [
function (value) {
return utils.isEmptyNoTrim(value) || /^[^0-9-\.].*$/.test(value.trim());
},
$.mage.__('First character must be letter.')
],
'validate-date': [
function (value, params, additionalParams) {
var test = moment(value, additionalParams.dateFormat);
Expand Down
6 changes: 6 additions & 0 deletions lib/web/mage/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,12 @@
},
$.mage.__('Please use only letters (a-z or A-Z) or numbers (0-9) in this field. No spaces or other characters are allowed.') //eslint-disable-line max-len
],
'validate-not-number-first': [
function (value) {
return $.mage.isEmptyNoTrim(value) || /^[^0-9-\.].*$/.test(value.trim());
},
$.mage.__('First character must be letter.')
],
'validate-date': [
function (value, params, additionalParams) {
var test = moment(value, additionalParams.dateFormat);
Expand Down

0 comments on commit 9e9ec37

Please sign in to comment.