Skip to content

Commit e8a558c

Browse files
committed
ACP2E-381: Single Quotation Marks not accepted by form validation on customer account creation
1 parent 2a83c2e commit e8a558c

File tree

1 file changed

+87
-0
lines changed
  • app/code/Magento/Customer/Test/Unit/Model/Validator

1 file changed

+87
-0
lines changed
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)