Skip to content

Commit 9497135

Browse files
committed
Merge branch 'ACP2E-381' of https://github.com/magento-l3/magento2ce into PR-2021-12-21
2 parents 0cf6931 + 58bd0c8 commit 9497135

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

app/code/Magento/Customer/Model/Validator/Name.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
class Name extends AbstractValidator
1717
{
18-
private const PATTERN_NAME = '/(?:[\p{L}\p{M}\,\-\_\.\'\s\d]){1,255}+/u';
18+
private const PATTERN_NAME = '/(?:[\p{L}\p{M}\,\-\_\.\'\s\d]){1,255}+/u';
1919

2020
/**
2121
* Validate name fields.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Test\Unit\Model\Validator;
9+
10+
use Magento\Customer\Model\Validator\Name;
11+
use Magento\Customer\Model\Customer;
12+
use PHPUnit\Framework\MockObject\MockObject;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* Customer name validator tests
17+
*/
18+
class NameTest extends TestCase
19+
{
20+
/**
21+
* @var Name
22+
*/
23+
private Name $nameValidator;
24+
25+
/**
26+
* @var Customer|MockObject
27+
*/
28+
private MockObject $customerMock;
29+
30+
/**
31+
* @return void
32+
*/
33+
protected function setUp(): void
34+
{
35+
$this->nameValidator = new Name;
36+
$this->customerMock = $this
37+
->getMockBuilder(Customer::class)
38+
->disableOriginalConstructor()
39+
->addMethods(['getFirstname', 'getLastname', 'getMiddlename'])
40+
->getMock();
41+
}
42+
43+
/**
44+
* Test for allowed apostrophe and other punctuation characters in customer names
45+
*
46+
* @param string $firstName
47+
* @param string $middleName
48+
* @param string $lastName
49+
* @param string $message
50+
* @return void
51+
* @dataProvider expectedPunctuationInNamesDataProvider
52+
*/
53+
public function testValidateCorrectPunctuationInNames(
54+
string $firstName,
55+
string $middleName,
56+
string $lastName,
57+
string $message
58+
) {
59+
$this->customerMock->expects($this->once())->method('getFirstname')->willReturn($firstName);
60+
$this->customerMock->expects($this->once())->method('getMiddlename')->willReturn($middleName);
61+
$this->customerMock->expects($this->once())->method('getLastname')->willReturn($lastName);
62+
63+
$isValid = $this->nameValidator->isValid($this->customerMock);
64+
$this->assertTrue($isValid, $message);
65+
}
66+
67+
/**
68+
* @return array
69+
*/
70+
public function expectedPunctuationInNamesDataProvider(): array
71+
{
72+
return [
73+
[
74+
'firstName' => 'John',
75+
'middleName' => '',
76+
'lastNameName' => 'O’Doe',
77+
'message' => 'Inclined apostrophe must be allowed in names (iOS Smart Punctuation compatibility)'
78+
],
79+
[
80+
'firstName' => 'John',
81+
'middleName' => '',
82+
'lastNameName' => 'O\'Doe',
83+
'message' => 'Legacy straight apostrophe must be allowed in names'
84+
]
85+
];
86+
}
87+
}

0 commit comments

Comments
 (0)