Skip to content

Commit de72dfe

Browse files
committed
Merge branch 'ACP2E-2125' of https://github.com/magento-l3/magento2ce into PR-L3-08112023
2 parents f360bb9 + 7545623 commit de72dfe

File tree

8 files changed

+85
-80
lines changed

8 files changed

+85
-80
lines changed

app/code/Magento/Customer/etc/di.xml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -579,22 +579,15 @@
579579
<item name="group_id" xsi:type="string">group_id</item>
580580
<item name="dob" xsi:type="string">dob</item>
581581
<item name="rp_token" xsi:type="string">rp_token</item>
582+
<item name="rp_token_created_at" xsi:type="string">rp_token_created_at</item>
583+
<item name="password_hash" xsi:type="string">password_hash</item>
582584
</item>
583585
<item name="customer_address" xsi:type="array">
584586
<item name="country_id" xsi:type="string">country_id</item>
585587
</item>
586588
</argument>
587589
</arguments>
588590
</type>
589-
<type name="Magento\Eav\Model\Attribute\Data\Text">
590-
<arguments>
591-
<argument name="allowDiacriticsForAttributes" xsi:type="array">
592-
<item name="customer" xsi:type="array">
593-
<item name="email" xsi:type="string">email</item>
594-
</item>
595-
</argument>
596-
</arguments>
597-
</type>
598591
<type name="Magento\AsynchronousOperations\Model\MassSchedule">
599592
<plugin name="anonymousAsyncCustomerRequest"
600593
type="Magento\Customer\Plugin\AsyncRequestCustomerGroupAuthorization"

app/code/Magento/Eav/Model/Attribute/Data/Text.php

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
namespace Magento\Eav\Model\Attribute\Data;
88

9+
use Magento\Eav\Model\Attribute;
910
use Magento\Framework\App\RequestInterface;
11+
use Magento\Framework\Exception\LocalizedException;
1012
use Magento\Framework\Locale\ResolverInterface;
1113
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1214
use Magento\Framework\Stdlib\StringUtils;
@@ -21,33 +23,25 @@
2123
class Text extends \Magento\Eav\Model\Attribute\Data\AbstractData
2224
{
2325
/**
24-
* @var \Magento\Framework\Stdlib\StringUtils
26+
* @var StringUtils
2527
*/
2628
protected $_string;
2729

28-
/**
29-
* @var array
30-
*/
31-
private $allowDiacriticsForAttributes;
32-
3330
/**
3431
* @param TimezoneInterface $localeDate
3532
* @param LoggerInterface $logger
3633
* @param ResolverInterface $localeResolver
3734
* @param StringUtils $stringHelper
38-
* @param array $allowDiacriticsForAttributes
3935
* @codeCoverageIgnore
4036
*/
4137
public function __construct(
42-
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
43-
\Psr\Log\LoggerInterface $logger,
44-
\Magento\Framework\Locale\ResolverInterface $localeResolver,
45-
\Magento\Framework\Stdlib\StringUtils $stringHelper,
46-
array $allowDiacriticsForAttributes = []
38+
TimezoneInterface $localeDate,
39+
LoggerInterface $logger,
40+
ResolverInterface $localeResolver,
41+
StringUtils $stringHelper
4742
) {
4843
parent::__construct($localeDate, $logger, $localeResolver);
4944
$this->_string = $stringHelper;
50-
$this->allowDiacriticsForAttributes = $allowDiacriticsForAttributes;
5145
}
5246

5347
/**
@@ -92,15 +86,6 @@ public function validateValue($value)
9286
return $errors;
9387
}
9488

95-
if (isset($this->allowDiacriticsForAttributes[$attribute->getEntityType()->getEntityTypeCode()])
96-
&& in_array(
97-
$attribute->getAttributeCode(),
98-
$this->allowDiacriticsForAttributes[$attribute->getEntityType()->getEntityTypeCode()]
99-
)) {
100-
// if string with diacritics encode it.
101-
$value = $this->encodeDiacritics($value);
102-
}
103-
10489
$validateLengthResult = $this->validateLength($attribute, $value);
10590
$errors = array_merge($errors, $validateLengthResult);
10691

@@ -119,6 +104,7 @@ public function validateValue($value)
119104
*
120105
* @param array|string $value
121106
* @return $this
107+
* @throws LocalizedException
122108
*/
123109
public function compactValue($value)
124110
{
@@ -146,6 +132,7 @@ public function restoreValue($value)
146132
* @param string $format
147133
* @return string|array
148134
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
135+
* @throws LocalizedException
149136
*/
150137
public function outputValue($format = \Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_TEXT)
151138
{
@@ -158,11 +145,11 @@ public function outputValue($format = \Magento\Eav\Model\AttributeDataFactory::O
158145
/**
159146
* Validates value length by attribute rules
160147
*
161-
* @param \Magento\Eav\Model\Attribute $attribute
148+
* @param Attribute $attribute
162149
* @param string $value
163150
* @return array errors
164151
*/
165-
private function validateLength(\Magento\Eav\Model\Attribute $attribute, string $value): array
152+
private function validateLength(Attribute $attribute, string $value): array
166153
{
167154
$errors = [];
168155
$length = $this->_string->strlen(trim($value));
@@ -195,19 +182,4 @@ private function validateInputRule(string $value): array
195182
$result = $this->_validateInputRule($value);
196183
return \is_array($result) ? $result : [];
197184
}
198-
199-
/**
200-
* Encode strings with diacritics for validate.
201-
*
202-
* @param array|string $value
203-
* @return array|string
204-
*/
205-
private function encodeDiacritics($value): array|string
206-
{
207-
$encoded = $value;
208-
if (is_string($value)) {
209-
$encoded = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $value);
210-
}
211-
return $encoded;
212-
}
213185
}

app/code/Magento/Sales/Model/Order/Address/Validator.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Eav\Model\Config as EavConfig;
1212
use Magento\Framework\App\ObjectManager;
1313
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\Validator\EmailAddress as EmailAddressValidator;
1415
use Magento\Sales\Model\Order\Address;
1516

1617
/**
@@ -48,20 +49,29 @@ class Validator
4849
*/
4950
protected $eavConfig;
5051

52+
/**
53+
* @var EmailAddressValidator
54+
*/
55+
private $emailAddressValidator;
56+
5157
/**
5258
* @param DirectoryHelper $directoryHelper
5359
* @param CountryFactory $countryFactory
54-
* @param EavConfig $eavConfig
60+
* @param EavConfig|null $eavConfig
61+
* @param EmailAddressValidator|null $emailAddressValidator
5562
*/
5663
public function __construct(
5764
DirectoryHelper $directoryHelper,
5865
CountryFactory $countryFactory,
59-
EavConfig $eavConfig = null
66+
EavConfig $eavConfig = null,
67+
EmailAddressValidator $emailAddressValidator = null
6068
) {
6169
$this->directoryHelper = $directoryHelper;
6270
$this->countryFactory = $countryFactory;
6371
$this->eavConfig = $eavConfig ?: ObjectManager::getInstance()
6472
->get(EavConfig::class);
73+
$this->emailAddressValidator = $emailAddressValidator ?: ObjectManager::getInstance()
74+
->get(EmailAddressValidator::class);
6575
}
6676

6777
/**
@@ -91,9 +101,13 @@ public function validate(Address $address)
91101
$warnings[] = sprintf('"%s" is required. Enter and try again.', $label);
92102
}
93103
}
94-
if (!filter_var($address->getEmail(), FILTER_VALIDATE_EMAIL)) {
104+
105+
$email = $address->getEmail();
106+
107+
if (empty($email) || !$this->emailAddressValidator->isValid($email)) {
95108
$warnings[] = 'Email has a wrong format';
96109
}
110+
97111
if (!in_array($address->getAddressType(), [Address::TYPE_BILLING, Address::TYPE_SHIPPING])) {
98112
$warnings[] = 'Address type doesn\'t match required options';
99113
}

app/code/Magento/Sales/Test/Unit/Model/Order/Address/ValidatorTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Directory\Model\CountryFactory;
1212
use Magento\Eav\Model\Config;
1313
use Magento\Eav\Model\Entity\Attribute;
14+
use Magento\Framework\Validator\EmailAddress;
1415
use Magento\Sales\Model\Order\Address;
1516
use Magento\Sales\Model\Order\Address\Validator;
1617
use PHPUnit\Framework\MockObject\MockObject;
@@ -38,6 +39,11 @@ class ValidatorTest extends TestCase
3839
*/
3940
protected $countryFactoryMock;
4041

42+
/**
43+
* @var EmailAddress|MockObject
44+
*/
45+
private $emailValidatorMock;
46+
4147
/**
4248
* Mock order address model
4349
*/
@@ -57,10 +63,12 @@ protected function setUp(): void
5763
$eavConfigMock->expects($this->any())
5864
->method('getAttribute')
5965
->willReturn($attributeMock);
66+
$this->emailValidatorMock = $this->createMock(EmailAddress::class);
6067
$this->validator = new Validator(
6168
$this->directoryHelperMock,
6269
$this->countryFactoryMock,
63-
$eavConfigMock
70+
$eavConfigMock,
71+
$this->emailValidatorMock
6472
);
6573
}
6674

@@ -84,6 +92,10 @@ public function testValidate($addressData, $email, $addressType, $expectedWarnin
8492
$this->addressMock->expects($this->once())
8593
->method('getAddressType')
8694
->willReturn($addressType);
95+
$this->emailValidatorMock->expects($this->once())
96+
->method('isValid')
97+
->with($email)
98+
->willReturn((stripos($email, '@') !== false));
8799
$actualWarnings = $this->validator->validate($this->addressMock);
88100
$this->assertEquals($expectedWarnings, $actualWarnings);
89101
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@ protected function setUp(): void
3636
}
3737

3838
/**
39+
* @dataProvider validEmailAddressDataProvider
3940
* @throws \Exception
4041
*/
41-
public function testCreateCustomerAccountWithPassword()
42+
public function testCreateCustomerAccountWithPassword(string $email)
4243
{
4344
$newFirstname = 'Richard';
4445
$newLastname = 'Rowe';
4546
$currentPassword = 'test123#';
46-
$newEmail = 'new_customer@example.com';
4747

4848
$query = <<<QUERY
4949
mutation {
5050
createCustomer(
5151
input: {
5252
firstname: "{$newFirstname}"
5353
lastname: "{$newLastname}"
54-
email: "{$newEmail}"
54+
email: "{$email}"
5555
password: "{$currentPassword}"
5656
is_subscribed: true
5757
}
@@ -71,10 +71,22 @@ public function testCreateCustomerAccountWithPassword()
7171
$this->assertNull($response['createCustomer']['customer']['id']);
7272
$this->assertEquals($newFirstname, $response['createCustomer']['customer']['firstname']);
7373
$this->assertEquals($newLastname, $response['createCustomer']['customer']['lastname']);
74-
$this->assertEquals($newEmail, $response['createCustomer']['customer']['email']);
74+
$this->assertEquals($email, $response['createCustomer']['customer']['email']);
7575
$this->assertTrue($response['createCustomer']['customer']['is_subscribed']);
7676
}
7777

78+
/**
79+
* @return array
80+
*/
81+
public function validEmailAddressDataProvider(): array
82+
{
83+
return [
84+
['new_customer@example.com'],
85+
['jØrgen@somedomain.com'],
86+
['“email”@example.com']
87+
];
88+
}
89+
7890
/**
7991
* @throws \Exception
8092
*/
@@ -217,15 +229,13 @@ public function invalidEmailAddressDataProvider(): array
217229
{
218230
return [
219231
['plainaddress'],
220-
['jØrgen@somedomain.com'],
221232
['#@%^%#$@#$@#.com'],
222233
['@example.com'],
223234
['Joe Smith <email@example.com>'],
224235
['email.example.com'],
225236
['email@example@example.com'],
226237
['email@example.com (Joe Smith)'],
227-
['email@example'],
228-
['“email”@example.com'],
238+
['email@example']
229239
];
230240
}
231241

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerV2Test.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,22 @@ protected function setUp(): void
3737

3838
/**
3939
* @magentoConfigFixture default_store newsletter/general/active 1
40+
* @dataProvider validEmailAddressDataProvider
4041
* @throws \Exception
4142
*/
42-
public function testCreateCustomerAccountWithPassword()
43+
public function testCreateCustomerAccountWithPassword(string $email)
4344
{
4445
$newFirstname = 'Richard';
4546
$newLastname = 'Rowe';
4647
$currentPassword = 'test123#';
47-
$newEmail = 'new_customer@example.com';
4848

4949
$query = <<<QUERY
5050
mutation {
5151
createCustomerV2(
5252
input: {
5353
firstname: "{$newFirstname}"
5454
lastname: "{$newLastname}"
55-
email: "{$newEmail}"
55+
email: "{$email}"
5656
password: "{$currentPassword}"
5757
is_subscribed: true
5858
}
@@ -72,10 +72,22 @@ public function testCreateCustomerAccountWithPassword()
7272
$this->assertNull($response['createCustomerV2']['customer']['id']);
7373
$this->assertEquals($newFirstname, $response['createCustomerV2']['customer']['firstname']);
7474
$this->assertEquals($newLastname, $response['createCustomerV2']['customer']['lastname']);
75-
$this->assertEquals($newEmail, $response['createCustomerV2']['customer']['email']);
75+
$this->assertEquals($email, $response['createCustomerV2']['customer']['email']);
7676
$this->assertTrue($response['createCustomerV2']['customer']['is_subscribed']);
7777
}
7878

79+
/**
80+
* @return array
81+
*/
82+
public function validEmailAddressDataProvider(): array
83+
{
84+
return [
85+
['new_customer@example.com'],
86+
['jØrgenV2@somedomain.com'],
87+
['“emailV2”@example.com']
88+
];
89+
}
90+
7991
/**
8092
* @throws \Exception
8193
*/
@@ -118,7 +130,7 @@ public function testCreateCustomerAccountWithoutPassword()
118130
public function testCreateCustomerIfInputDataIsEmpty()
119131
{
120132
$this->expectException(\Exception::class);
121-
$this->expectExceptionMessageMatches('/of required type String! was not provided./');
133+
$this->expectExceptionMessage('CustomerCreateInput.email of required type String! was not provided.');
122134

123135
$query = <<<QUERY
124136
mutation {
@@ -218,15 +230,13 @@ public function invalidEmailAddressDataProvider(): array
218230
{
219231
return [
220232
['plainaddress'],
221-
['jØrgen@somedomain.com'],
222233
['#@%^%#$@#$@#.com'],
223234
['@example.com'],
224235
['Joe Smith <email@example.com>'],
225236
['email.example.com'],
226237
['email@example@example.com'],
227238
['email@example.com (Joe Smith)'],
228-
['email@example'],
229-
['“email”@example.com'],
239+
['email@example']
230240
];
231241
}
232242

0 commit comments

Comments
 (0)