Skip to content

Commit eb34e34

Browse files
committed
Merge branch 'ACP2E-2037' of https://github.com/magento-l3/magento2ce into PR-L3-2023-07-14
2 parents 3af0d65 + 0d11d3d commit eb34e34

File tree

5 files changed

+77
-11
lines changed

5 files changed

+77
-11
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,13 +578,23 @@
578578
<item name="store_id" xsi:type="string">store_id</item>
579579
<item name="group_id" xsi:type="string">group_id</item>
580580
<item name="dob" xsi:type="string">dob</item>
581+
<item name="rp_token" xsi:type="string">rp_token</item>
581582
</item>
582583
<item name="customer_address" xsi:type="array">
583584
<item name="country_id" xsi:type="string">country_id</item>
584585
</item>
585586
</argument>
586587
</arguments>
587588
</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>
588598
<type name="Magento\AsynchronousOperations\Model\MassSchedule">
589599
<plugin name="anonymousAsyncCustomerRequest"
590600
type="Magento\Customer\Plugin\AsyncRequestCustomerGroupAuthorization"

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
namespace Magento\Eav\Model\Attribute\Data;
88

99
use Magento\Framework\App\RequestInterface;
10+
use Magento\Framework\Locale\ResolverInterface;
11+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
12+
use Magento\Framework\Stdlib\StringUtils;
13+
use Psr\Log\LoggerInterface;
1014

1115
/**
1216
* EAV Entity Attribute Text Data Model
1317
*
1418
* @author Magento Core Team <[email protected]>
19+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
1520
*/
1621
class Text extends \Magento\Eav\Model\Attribute\Data\AbstractData
1722
{
@@ -21,20 +26,28 @@ class Text extends \Magento\Eav\Model\Attribute\Data\AbstractData
2126
protected $_string;
2227

2328
/**
24-
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
25-
* @param \Psr\Log\LoggerInterface $logger
26-
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
27-
* @param \Magento\Framework\Stdlib\StringUtils $stringHelper
29+
* @var array
30+
*/
31+
private $allowDiacriticsForAttributes;
32+
33+
/**
34+
* @param TimezoneInterface $localeDate
35+
* @param LoggerInterface $logger
36+
* @param ResolverInterface $localeResolver
37+
* @param StringUtils $stringHelper
38+
* @param array $allowDiacriticsForAttributes
2839
* @codeCoverageIgnore
2940
*/
3041
public function __construct(
3142
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
3243
\Psr\Log\LoggerInterface $logger,
3344
\Magento\Framework\Locale\ResolverInterface $localeResolver,
34-
\Magento\Framework\Stdlib\StringUtils $stringHelper
45+
\Magento\Framework\Stdlib\StringUtils $stringHelper,
46+
array $allowDiacriticsForAttributes = []
3547
) {
3648
parent::__construct($localeDate, $logger, $localeResolver);
3749
$this->_string = $stringHelper;
50+
$this->allowDiacriticsForAttributes = $allowDiacriticsForAttributes;
3851
}
3952

4053
/**
@@ -79,8 +92,14 @@ public function validateValue($value)
7992
return $errors;
8093
}
8194

82-
// if string with diacritics encode it.
83-
$value = $this->encodeDiacritics($value);
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+
}
84103

85104
$validateLengthResult = $this->validateLength($attribute, $value);
86105
$errors = array_merge($errors, $validateLengthResult);

app/code/Magento/Eav/Test/Unit/Model/Attribute/Data/MultilineTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Eav\Model\Attribute;
1111
use Magento\Eav\Model\Attribute\Data\Multiline;
1212
use Magento\Eav\Model\AttributeDataFactory;
13+
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
14+
use Magento\Eav\Model\Entity\Type;
1315
use Magento\Framework\App\RequestInterface;
1416
use Magento\Framework\Locale\ResolverInterface;
1517
use Magento\Framework\Model\AbstractModel;
@@ -109,7 +111,6 @@ public function testOutputValue($format, $expectedResult)
109111

110112
/** @var MockObject|Attribute $attributeMock */
111113
$attributeMock = $this->createMock(Attribute::class);
112-
113114
$this->model->setEntity($entityMock);
114115
$this->model->setAttribute($attributeMock);
115116
$this->assertEquals($expectedResult, $this->model->outputValue($format));
@@ -158,6 +159,8 @@ public function testValidateValue($value, $isAttributeRequired, $rules, $expecte
158159
->method('getDataUsingMethod')
159160
->willReturn("value1\nvalue2");
160161

162+
$entityTypeMock = $this->createMock(Type::class);
163+
161164
/** @var MockObject|Attribute $attributeMock */
162165
$attributeMock = $this->createMock(Attribute::class);
163166
$attributeMock->expects($this->any())->method('getMultilineCount')->willReturn(2);
@@ -170,6 +173,10 @@ public function testValidateValue($value, $isAttributeRequired, $rules, $expecte
170173
->method('getIsRequired')
171174
->willReturn($isAttributeRequired);
172175

176+
$attributeMock->expects($this->any())
177+
->method('getEntityType')
178+
->willReturn($entityTypeMock);
179+
173180
$this->stringMock->expects($this->any())->method('strlen')->willReturn(5);
174181

175182
$this->model->setEntity($entityMock);

app/code/Magento/Eav/Test/Unit/Model/Attribute/Data/TextTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Eav\Model\Attribute;
1111
use Magento\Eav\Model\Attribute\Data\Text;
1212
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
13+
use Magento\Eav\Model\Entity\Type;
1314
use Magento\Eav\Model\Entity\TypeFactory;
1415
use Magento\Framework\Exception\LocalizedException;
1516
use Magento\Framework\Locale\ResolverInterface;
@@ -223,12 +224,18 @@ protected function createAttribute($attributeData): AbstractAttribute
223224
['eavTypeFactory' => $eavTypeFactory, 'data' => $attributeData]
224225
);
225226

227+
$entityTypeMock = $this->createMock(Type::class);
228+
226229
/** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute|MockObject $attribute
227230
*/
228231
$attribute = $this->getMockBuilder($attributeClass)
229-
->setMethods(['_init'])
232+
->onlyMethods(['_init', 'getEntityType'])
230233
->setConstructorArgs($arguments)
231234
->getMock();
235+
236+
$attribute->expects($this->any())
237+
->method('getEntityType')
238+
->willReturn($entityTypeMock);
232239
return $attribute;
233240
}
234241
}

dev/tests/integration/testsuite/Magento/Customer/Model/ResourceModel/CustomerRepositoryTest.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
1515
use Magento\Customer\Model\Customer;
1616
use Magento\Customer\Model\CustomerRegistry;
17+
use Magento\Customer\Test\Fixture\Customer as CustomerFixture;
1718
use Magento\Framework\Api\DataObjectHelper;
1819
use Magento\Framework\Api\ExtensibleDataObjectConverter;
1920
use Magento\Framework\Api\FilterBuilder;
@@ -27,11 +28,10 @@
2728
use Magento\Framework\Validator\Exception as ValidatorException;
2829
use Magento\Sales\Api\Data\OrderInterface;
2930
use Magento\Sales\Api\OrderRepositoryInterface;
30-
use Magento\TestFramework\Helper\Bootstrap;
31-
use Magento\TestFramework\Fixture\Config as ConfigFixture;
3231
use Magento\TestFramework\Fixture\DataFixture;
3332
use Magento\TestFramework\Fixture\DataFixtureStorage;
3433
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
34+
use Magento\TestFramework\Helper\Bootstrap;
3535

3636
/**
3737
* Checks Customer insert, update, search with repository
@@ -73,6 +73,11 @@ class CustomerRepositoryTest extends \PHPUnit\Framework\TestCase
7373
/** @var CustomerRegistry */
7474
protected $customerRegistry;
7575

76+
/**
77+
* @var DataFixtureStorage
78+
*/
79+
private $fixtures;
80+
7681
/**
7782
* @inheritdoc
7883
*/
@@ -88,6 +93,7 @@ protected function setUp(): void
8893
$this->dataObjectHelper = $this->objectManager->create(DataObjectHelper::class);
8994
$this->encryptor = $this->objectManager->create(EncryptorInterface::class);
9095
$this->customerRegistry = $this->objectManager->create(CustomerRegistry::class);
96+
$this->fixtures = DataFixtureStorageManager::getStorage();
9197

9298
/** @var CacheInterface $cache */
9399
$cache = $this->objectManager->create(CacheInterface::class);
@@ -732,4 +738,21 @@ public function testSaveCustomerWithInvalidAttrValue(): void
732738
$this->expectExceptionMessage('Attribute gender does not contain option with Id 123');
733739
$this->customerRepository->save($customer);
734740
}
741+
742+
#[
743+
DataFixture(
744+
CustomerFixture::class,
745+
[
746+
'email' => 'émâí[email protected]',
747+
'rp_token' => 'random_token_123'
748+
],
749+
as: 'customer'
750+
)
751+
]
752+
public function testSaveCustomerWithEmailWithDiacritics(): void
753+
{
754+
$customer = $this->fixtures->get('customer');
755+
$this->assertEquals('émâí[email protected]', $customer->getEmail());
756+
$this->assertNotEquals('random_token_123', $customer->getRpToken());
757+
}
735758
}

0 commit comments

Comments
 (0)