Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 1eaafd1

Browse files
author
Magento CICD
authored
merge magento/2.3-develop into magento-borg/MAGETWO-77744-file-error-message
2 parents 3dadf94 + 9e9ec37 commit 1eaafd1

File tree

9 files changed

+81
-3
lines changed

9 files changed

+81
-3
lines changed

app/code/Magento/Checkout/Test/Mftf/Section/CheckoutShippingSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
<element name="next" type="button" selector="button.button.action.continue.primary" timeout="30"/>
3232
<element name="firstShippingMethod" type="radio" selector="//*[@id='checkout-shipping-method-load']//input[@class='radio']"/>
3333
<element name="defaultShipping" type="button" selector=".billing-address-details"/>
34+
<element name="stateInput" type="input" selector="input[name=region]"/>
3435
</section>
3536
</sections>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
11+
<test name="AddressStateFieldShouldNotAcceptJustIntegerValuesTest">
12+
<annotations>
13+
<features value="Checkout"/>
14+
<stories value="MAGETWO-91465"/>
15+
<title value="Guest Checkout"/>
16+
<description value="Address State field should not allow just integer values"/>
17+
<severity value="MAJOR"/>
18+
<testCaseId value="MAGETWO-93203"/>
19+
<group value="checkout"/>
20+
</annotations>
21+
<before>
22+
<createData entity="_defaultCategory" stepKey="createCategory"/>
23+
<createData entity="ApiSimpleProduct" stepKey="createProduct">
24+
<requiredEntity createDataKey="createCategory"/>
25+
</createData>
26+
</before>
27+
<after>
28+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
29+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
30+
</after>
31+
32+
<amOnPage url="{{StorefrontCategoryPage.url($$createCategory.name$$)}}" stepKey="onCategoryPage"/>
33+
<waitForPageLoad stepKey="waitForPageLoad1"/>
34+
<moveMouseOver selector="{{StorefrontCategoryMainSection.ProductItemInfo}}" stepKey="hoverProduct"/>
35+
<click selector="{{StorefrontCategoryMainSection.AddToCartBtn}}" stepKey="addToCart"/>
36+
<waitForElementVisible selector="{{StorefrontCategoryMainSection.SuccessMsg}}" time="30" stepKey="waitForProductAdded"/>
37+
<see selector="{{StorefrontCategoryMainSection.SuccessMsg}}" userInput="You added $$createProduct.name$$ to your shopping cart." stepKey="seeAddedToCartMessage"/>
38+
<see selector="{{StorefrontMinicartSection.quantity}}" userInput="1" stepKey="seeCartQuantity"/>
39+
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="guestGoToCheckoutFromMinicart" />
40+
<selectOption stepKey="selectCounty" selector="{{CheckoutShippingSection.country}}" userInput="{{UK_Address.country_id}}"/>
41+
<waitForPageLoad stepKey="waitFormToReload"/>
42+
<fillField selector="{{CheckoutShippingSection.stateInput}}" userInput="1" stepKey="enterStateAsIntegerValue"/>
43+
<waitForPageLoad stepKey="waitforFormValidation"/>
44+
<see userInput="First character must be letter." stepKey="seeTheErrorMessageDisplayed"/>
45+
<fillField selector="{{CheckoutShippingSection.stateInput}}" userInput=" 1" stepKey="enterStateAsIntegerValue1"/>
46+
<waitForPageLoad stepKey="waitforFormValidation1"/>
47+
<see userInput="First character must be letter." stepKey="seeTheErrorMessageDisplayed1"/>
48+
<fillField selector="{{CheckoutShippingSection.stateInput}}" userInput="ABC1" stepKey="enterStateAsIntegerValue2"/>
49+
<waitForPageLoad stepKey="waitforFormValidation2"/>
50+
<dontSee userInput="First character must be letter." stepKey="seeTheErrorMessageIsNotDisplayed"/>
51+
</test>
52+
</tests>

app/code/Magento/Customer/Model/Address/Validator/Country.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ private function validateCountry(AbstractAddress $address)
8888
*
8989
* @param AbstractAddress $address
9090
* @return array
91+
* @throws \Zend_Validate_Exception
92+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
9193
*/
9294
private function validateRegion(AbstractAddress $address)
9395
{
@@ -107,7 +109,7 @@ private function validateRegion(AbstractAddress $address)
107109
//If country actually has regions and requires you to
108110
//select one then it must be selected.
109111
$errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'regionId']);
110-
} elseif ($regionId && !in_array($regionId, $allowedRegions, true)) {
112+
} elseif ($allowedRegions && $regionId && !in_array($regionId, $allowedRegions, true)) {
111113
//If a region is selected then checking if it exists.
112114
$errors[] = __(
113115
'Invalid value of "%value" provided for the %fieldName field.',

app/code/Magento/Customer/Test/Mftf/Data/AddressData.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,8 @@
8383
<data key="default_shipping">Yes</data>
8484
<requiredEntity type="region">RegionCA</requiredEntity>
8585
</entity>
86+
<!--If required other field can be added to UK_Address entity, dont modify any existing data-->
87+
<entity name="UK_Address" type="address">
88+
<data key="country_id">GB</data>
89+
</entity>
8690
</entities>

app/code/Magento/Customer/Test/Unit/Model/Address/Validator/CountryTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,13 @@ public function validateDataProvider()
161161
'region_id2' => [
162162
array_merge($data, ['country_id' => $countryId, 'region_id' => 2]),
163163
[$countryId++],
164-
[1],
164+
[],
165+
[],
166+
],
167+
'region_id3' => [
168+
array_merge($data, ['country_id' => $countryId, 'region_id' => 2]),
169+
[$countryId++],
170+
[1, 3],
165171
['Invalid value of "2" provided for the regionId field.'],
166172
],
167173
'validated' => [

app/code/Magento/Customer/view/frontend/templates/address/edit.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
name="region"
113113
value="<?= $block->escapeHtmlAttr($block->getRegion()) ?>"
114114
title="<?= $block->escapeHtmlAttr(__('State/Province')) ?>"
115-
class="input-text <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('region')) ?>"<?= !$block->getConfig('general/region/display_all') ? ' disabled="disabled"' : '' ?>/>
115+
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"' : '' ?>/>
116116
</div>
117117
</div>
118118
<div class="field zip required">

app/code/Magento/Ui/view/base/web/js/form/element/region.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ define([
5757
registry.get(this.customName, function (input) {
5858
isRegionRequired = !!option['is_region_required'];
5959
input.validation['required-entry'] = isRegionRequired;
60+
input.validation['validate-not-number-first'] = true;
6061
input.required(isRegionRequired);
6162
});
6263
}

app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,12 @@ define([
755755
},
756756
$.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
757757
],
758+
'validate-not-number-first': [
759+
function (value) {
760+
return utils.isEmptyNoTrim(value) || /^[^0-9-\.].*$/.test(value.trim());
761+
},
762+
$.mage.__('First character must be letter.')
763+
],
758764
'validate-date': [
759765
function (value, params, additionalParams) {
760766
var test = moment(value, additionalParams.dateFormat);

lib/web/mage/validation.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,12 @@
990990
},
991991
$.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
992992
],
993+
'validate-not-number-first': [
994+
function (value) {
995+
return $.mage.isEmptyNoTrim(value) || /^[^0-9-\.].*$/.test(value.trim());
996+
},
997+
$.mage.__('First character must be letter.')
998+
],
993999
'validate-date': [
9941000
function (value, params, additionalParams) {
9951001
var test = moment(value, additionalParams.dateFormat);

0 commit comments

Comments
 (0)