Skip to content

Commit e38eebe

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop
- merged latest code from mainline branch
2 parents 020bbd6 + a1aaf8f commit e38eebe

File tree

11 files changed

+177
-16
lines changed

11 files changed

+177
-16
lines changed

app/code/Magento/Customer/Block/Widget/Dob.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Magento\Framework\Api\ArrayObjectSearch;
1010

1111
/**
12-
* Class Dob
12+
* Customer date of birth attribute block
1313
*
1414
* @SuppressWarnings(PHPMD.DepthOfInheritance)
1515
*/
@@ -267,7 +267,9 @@ public function getHtmlExtraParams()
267267
$validators['validate-date'] = [
268268
'dateFormat' => $this->getDateFormat()
269269
];
270-
$validators['validate-dob'] = true;
270+
$validators['validate-dob'] = [
271+
'dateFormat' => $this->getDateFormat()
272+
];
271273

272274
return 'data-validate="' . $this->_escaper->escapeHtml(json_encode($validators)) . '"';
273275
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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="AdminCustomerShowDateOfBirthActionGroup">
12+
<annotations>
13+
<description>Goes to the customer configuration. Set "Show Date of Birth" with provided value.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="value" type="string" defaultValue="{{ShowDateOfBirth.optional}}"/>
17+
</arguments>
18+
<amOnPage url="{{AdminCustomerConfigPage.url('#customer_address-link')}}" stepKey="openCustomerConfigPage"/>
19+
<waitForPageLoad stepKey="waitCustomerConfigPage"/>
20+
<scrollTo selector="{{AdminCustomerConfigSection.showDateOfBirth}}" x="0" y="-100" stepKey="scrollToShowDateOfBirth"/>
21+
<uncheckOption selector="{{AdminCustomerConfigSection.showDateOfBirthInherit}}" stepKey="uncheckUseSystem"/>
22+
<selectOption selector="{{AdminCustomerConfigSection.showDateOfBirth}}" userInput="{{value}}" stepKey="fillShowDateOfBirth"/>
23+
<click selector="{{AdminMainActionsSection.save}}" stepKey="clickSave"/>
24+
<seeElement selector="{{AdminMessagesSection.success}}" stepKey="seeSuccessMessage"/>
25+
</actionGroup>
26+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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="StorefrontCustomerCreateAccountWithDateOfBirthActionGroup" extends="SignUpNewUserFromStorefrontActionGroup">
12+
<annotations>
13+
<description>EXTENDS: SignUpNewUserFromStorefrontActionGroup. Fills birthday field.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="dob" defaultValue="{{EN_US_DATE.short4DigitYear}}" type="string"/>
17+
</arguments>
18+
<fillField userInput="{{dob}}" selector="{{StorefrontCustomerCreateFormSection.dobField}}" after="fillLastName" stepKey="fillDob"/>
19+
</actionGroup>
20+
</actionGroups>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="ShowDateOfBirth">
12+
<data key="no">No</data>
13+
<data key="optional">Optional</data>
14+
<data key="required">Required</data>
15+
</entity>
16+
</entities>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="EN_US_DATE">
12+
<data key="short">9/21/93</data>
13+
<data key="short4DigitYear">9/21/1993</data>
14+
<data key="medium">Sep 21, 1993</data>
15+
<data key="long">September 21, 1993</data>
16+
<data key="full">Tuesday, September 21, 1993</data>
17+
</entity>
18+
<entity name="FR_FR_DATE">
19+
<data key="short">21/09/1993</data>
20+
<data key="short4DigitYear">21/09/1993</data>
21+
<data key="medium">21 sept. 1993</data>
22+
<data key="long">21 septembre 1993</data>
23+
<data key="full">mardi 21 septembre 1993</data>
24+
</entity>
25+
</entities>

app/code/Magento/Customer/Test/Mftf/Section/AdminCustomerConfigSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
<element name="accountSharingOptionsTab" type="button" selector="#customer_account_share-head"/>
1212
<element name="shareCustomerAccountInherit" type="checkbox" selector="#customer_account_share_scope_inherit"/>
1313
<element name="shareCustomerAccount" type="select" selector="#customer_account_share_scope"/>
14+
<element name="showDateOfBirth" type="select" selector="#customer_address_dob_show"/>
15+
<element name="showDateOfBirthInherit" type="select" selector="#customer_address_dob_show_inherit"/>
1416
</section>
1517
</sections>

app/code/Magento/Customer/Test/Mftf/Section/StorefrontCustomerCreateFormSection/StorefrontCustomerCreateFormSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<element name="firstnameField" type="input" selector="#firstname"/>
1212
<element name="lastnameField" type="input" selector="#lastname"/>
1313
<element name="lastnameLabel" type="text" selector="//label[@for='lastname']"/>
14+
<element name="dobField" type="input" selector="#dob"/>
1415
<element name="signUpForNewsletter" type="checkbox" selector="//div/input[@name='is_subscribed']"/>
1516
<element name="emailField" type="input" selector="#email_address"/>
1617
<element name="passwordField" type="input" selector="#password"/>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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="StorefrontCreateCustomerWithDateOfBirthTest">
12+
<annotations>
13+
<features value="Customer"/>
14+
<stories value="Create a Customer via the Storefront"/>
15+
<title value="Customer should be able to create an account with date of birth via the storefront"/>
16+
<description value="Customer should be able to create an account with date of birth via the storefront"/>
17+
<severity value="CRITICAL"/>
18+
<testCaseId value="MC-32413"/>
19+
<group value="customer"/>
20+
<group value="create"/>
21+
</annotations>
22+
<before>
23+
<actionGroup ref="LoginAsAdmin" stepKey="login"/>
24+
<actionGroup ref="AdminCustomerShowDateOfBirthActionGroup" stepKey="showDateOfBirth">
25+
<argument name="value" value="{{ShowDateOfBirth.required}}"/>
26+
</actionGroup>
27+
</before>
28+
<after>
29+
<actionGroup ref="AdminCustomerShowDateOfBirthActionGroup" stepKey="hideDateOfBirth">
30+
<argument name="value" value="{{ShowDateOfBirth.no}}"/>
31+
</actionGroup>
32+
<actionGroup ref="logout" stepKey="logout"/>
33+
</after>
34+
<actionGroup ref="StorefrontCustomerCreateAccountWithDateOfBirthActionGroup" stepKey="SignUpNewUser">
35+
<argument name="Customer" value="CustomerEntityOne"/>
36+
<argument name="dob" value="{{EN_US_DATE.short4DigitYear}}"/>
37+
</actionGroup>
38+
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
39+
<actionGroup ref="DeleteCustomerByEmailActionGroup" stepKey="deleteNewUser">
40+
<argument name="email" value="{{CustomerEntityOne.email}}"/>
41+
</actionGroup>
42+
</test>
43+
</tests>

app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
/**
3131
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
32+
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
3233
*/
3334
class DobTest extends TestCase
3435
{
@@ -542,18 +543,30 @@ public function testGetMaxDateRangeWithException()
542543
*/
543544
public function testGetHtmlExtraParamsWithoutRequiredOption()
544545
{
546+
$validation = json_encode(
547+
[
548+
'validate-date' => [
549+
'dateFormat' => self::DATE_FORMAT
550+
],
551+
'validate-dob' => [
552+
'dateFormat' => self::DATE_FORMAT
553+
],
554+
]
555+
);
545556
$this->escaper->expects($this->any())
546557
->method('escapeHtml')
547-
->with('{"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}')
548-
->will($this->returnValue('{"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}'));
558+
->with($validation)
559+
->will(
560+
$this->returnValue($validation)
561+
);
549562

550563
$this->attribute->expects($this->once())
551564
->method("isRequired")
552565
->willReturn(false);
553566

554567
$this->assertEquals(
555-
$this->_block->getHtmlExtraParams(),
556-
'data-validate="{"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}"'
568+
"data-validate=\"$validation\"",
569+
$this->_block->getHtmlExtraParams()
557570
);
558571
}
559572

@@ -562,22 +575,31 @@ public function testGetHtmlExtraParamsWithoutRequiredOption()
562575
*/
563576
public function testGetHtmlExtraParamsWithRequiredOption()
564577
{
578+
$validation = json_encode(
579+
[
580+
'required' => true,
581+
'validate-date' => [
582+
'dateFormat' => self::DATE_FORMAT
583+
],
584+
'validate-dob' => [
585+
'dateFormat' => self::DATE_FORMAT
586+
],
587+
]
588+
);
565589
$this->attribute->expects($this->once())
566590
->method("isRequired")
567591
->willReturn(true);
568592
$this->escaper->expects($this->any())
569593
->method('escapeHtml')
570-
->with('{"required":true,"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}')
594+
->with($validation)
571595
->will(
572-
$this->returnValue(
573-
'{"required":true,"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}'
574-
)
596+
$this->returnValue($validation)
575597
);
576598

577599
$this->context->expects($this->any())->method('getEscaper')->will($this->returnValue($this->escaper));
578600

579601
$this->assertEquals(
580-
'data-validate="{"required":true,"validate-date":{"dateFormat":"M\/d\/Y"},"validate-dob":true}"',
602+
"data-validate=\"$validation\"",
581603
$this->_block->getHtmlExtraParams()
582604
);
583605
}

app/code/Magento/Customer/view/frontend/web/js/validation.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
define([
22
'jquery',
33
'moment',
4+
'mageUtils',
45
'jquery/validate',
56
'validation',
67
'mage/translate'
7-
], function ($, moment) {
8+
], function ($, moment, utils) {
89
'use strict';
910

1011
$.validator.addMethod(
1112
'validate-dob',
12-
function (value) {
13+
function (value, element, params) {
14+
var dateFormat = utils.convertToMomentFormat(params.dateFormat);
15+
1316
if (value === '') {
1417
return true;
1518
}
1619

17-
return moment(value).isBefore(moment());
20+
return moment(value, dateFormat).isBefore(moment());
1821
},
1922
$.mage.__('The Date of Birth should not be greater than today.')
2023
);

lib/web/mage/validation.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
define([
77
'jquery',
88
'moment',
9+
'mageUtils',
910
'jquery-ui-modules/widget',
1011
'jquery/validate',
1112
'mage/translate'
12-
], function ($, moment) {
13+
], function ($, moment, utils) {
1314
'use strict';
1415

1516
var creditCartTypes, rules, showLabel, originValidateDelegate;
@@ -1032,7 +1033,7 @@ define([
10321033
],
10331034
'validate-date': [
10341035
function (value, params, additionalParams) {
1035-
var test = moment(value, additionalParams.dateFormat);
1036+
var test = moment(value, utils.convertToMomentFormat(additionalParams.dateFormat));
10361037

10371038
return $.mage.isEmptyNoTrim(value) || test.isValid();
10381039
},

0 commit comments

Comments
 (0)