Skip to content

Commit a243294

Browse files
committed
Merge remote-tracking branch 'origin/2.4.3-develop' into MC-41018
2 parents 0f74367 + 2f06a5d commit a243294

File tree

11 files changed

+321
-12
lines changed

11 files changed

+321
-12
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Gallery/Upload.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ public function execute()
108108

109109
$result['url'] = $this->productMediaConfig->getTmpMediaUrl($result['file']);
110110
$result['file'] = $result['file'] . '.tmp';
111-
} catch (\Exception $e) {
111+
} catch (LocalizedException $e) {
112112
$result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
113+
} catch (\Throwable $e) {
114+
$result = ['error' => 'Something went wrong while saving the file(s).', 'errorcode' => 0];
113115
}
114116

115117
/** @var \Magento\Framework\Controller\Result\Raw $response */
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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="StorefrontRemoveFirstProductFromCompareActionGroup">
12+
<annotations>
13+
<description>Open Compare Products list and remove a product</description>
14+
</annotations>
15+
16+
<amOnPage url="{{StorefrontProductComparePage.url}}" stepKey="navigateToComparePage"/>
17+
<waitForElementVisible selector="{{StorefrontProductCompareMainSection.removeFirstItem}}" stepKey="waitForButton"/>
18+
<click selector="{{StorefrontProductCompareMainSection.removeFirstItem}}" stepKey="clickOnButton"/>
19+
<waitForElementVisible selector="{{ModalConfirmationSection.OkButton}}" stepKey="waitForModal"/>
20+
<scrollTo selector="{{ModalConfirmationSection.OkButton}}" stepKey="scrollToModal"/>
21+
<click selector="{{ModalConfirmationSection.OkButton}}" stepKey="ClickOkButton"/>
22+
<waitForElementVisible selector="{{StorefrontMessagesSection.success}}" stepKey="waitForSuccessMessage"/>
23+
</actionGroup>
24+
</actionGroups>

app/code/Magento/Catalog/Test/Mftf/Section/StorefrontProductCompareMainSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
<element name="ProductPriceByName" type="text" selector="//*[@id='product-comparison']//td[.//strong[@class='product-item-name']/a[contains(text(), '{{var1}}')]]//span[@class='price']" parameterized="true"/>
1515
<element name="ProductImageByName" type="text" selector="//*[@id='product-comparison']//td[.//strong[@class='product-item-name']/a[contains(text(), '{{var1}}')]]//img[@class='product-image-photo']" parameterized="true"/>
1616
<element name="ProductAttributeByCodeAndProductName" type="text" selector="//*[@id='product-comparison']//tr[.//th[./span[contains(text(), '{{var1}}')]]]//td[count(//*[@id='product-comparison']//tr//td[.//strong[@class='product-item-name']/a[contains(text(), '{{var2}}')]]/preceding-sibling::td)+1]/div" parameterized="true"/>
17+
<element name="removeFirstItem" type="button" selector="table.table-comparison a.delete"/>
1718
</section>
1819
</sections>

app/code/Magento/Catalog/Test/Mftf/Test/AddOutOfStockProductToCompareListTest.xml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@
7878
<actionGroup ref="StorefrontGoToCategoryPageActionGroup" stepKey="openCategoryPage">
7979
<argument name="categoryName" value="$$category.name$$"/>
8080
</actionGroup>
81-
82-
<actionGroup ref="StorefrontOpenAndCheckComparisionActionGroup" stepKey="navigateToComparePage"/>
81+
<comment userInput="Comment is kept to preserve the step key for backward compatibility" stepKey="navigateToComparePage"/>
8382
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForStorefrontProductComparePageLoad"/>
8483

8584
<actionGroup ref="SeeProductInComparisonListActionGroup" stepKey="seeProductInCompareList">
@@ -92,11 +91,13 @@
9291
<argument name="categoryName" value="$$category.name$$"/>
9392
</actionGroup>
9493

95-
<actionGroup ref="StorefrontClearCompareActionGroup" stepKey="clickClearAll"/>
94+
<actionGroup ref="StorefrontRemoveFirstProductFromCompareActionGroup" stepKey="clickClearAll"/>
9695
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForConfirmPageLoad"/>
9796
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="confirmProdDelate"/>
9897
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForConfirmLoad"/>
99-
<comment userInput="Add product to compare list fom Category page | Comment is kept to preserve the step key for backward compatibility" stepKey="addToCmpFromCategPage"/>
98+
<actionGroup ref="StorefrontGoToCategoryPageActionGroup" stepKey="addToCmpFromCategPage">
99+
<argument name="categoryName" value="$$category.name$$"/>
100+
</actionGroup>
100101

101102
<actionGroup ref="StorefrontHoverProductOnCategoryPageActionGroup" stepKey="hoverOverProduct"/>
102103

@@ -108,11 +109,11 @@
108109
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="grabTextFromSuccessMessage2"/>
109110
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="assertSuccessMessage2"/>
110111

111-
<comment userInput="Check that product displays on add to compare widget | Comment is kept to preserve the step key for backward compatibility" stepKey="checkProdNameOnWidget"/>
112-
<seeElement selector="{{StorefrontComparisonSidebarSection.ProductTitleByName($$product.name$$)}}" stepKey="seeProdNameOnCmpWidget"/>
112+
<comment userInput="Comment is kept to preserve the step key for backward compatibility" stepKey="checkProdNameOnWidget"/>
113+
<comment userInput="Comment is kept to preserve the step key for backward compatibility" stepKey="seeProdNameOnCmpWidget"/>
113114

114115
<comment userInput="See product in the compare page" stepKey="seeProductInComparePage"/>
115-
<actionGroup ref="StorefrontOpenAndCheckComparisionActionGroup" stepKey="navigateToComparePage2"/>
116+
<comment userInput="Comment is kept to preserve the step key for backward compatibility" stepKey="navigateToComparePage2"/>
116117
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="waitForStorefrontProductComparePageLoad2"/>
117118

118119
<actionGroup ref="SeeProductInComparisonListActionGroup" stepKey="seeProductInCompareList2">
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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\Model\Validator;
9+
10+
use Magento\Customer\Model\Customer;
11+
use Magento\Framework\Validator\AbstractValidator;
12+
13+
/**
14+
* Customer name fields validator.
15+
*/
16+
class Name extends AbstractValidator
17+
{
18+
private const PATTERN_NAME = '/(?:[\p{L}\p{M}\,\-\_\.\'\s\d]){1,255}+/u';
19+
20+
/**
21+
* Validate name fields.
22+
*
23+
* @param Customer $customer
24+
* @return bool
25+
*/
26+
public function isValid($customer)
27+
{
28+
if (!$this->isValidName($customer->getFirstname())) {
29+
parent::_addMessages([['firstname' => 'First Name is not valid!']]);
30+
}
31+
32+
if (!$this->isValidName($customer->getLastname())) {
33+
parent::_addMessages([['lastname' => 'Last Name is not valid!']]);
34+
}
35+
36+
if (!$this->isValidName($customer->getMiddlename())) {
37+
parent::_addMessages([['middlename' => 'Middle Name is not valid!']]);
38+
}
39+
40+
return count($this->_messages) == 0;
41+
}
42+
43+
/**
44+
* Check if name field is valid.
45+
*
46+
* @param string|null $nameValue
47+
* @return bool
48+
*/
49+
private function isValidName($nameValue)
50+
{
51+
if ($nameValue != null) {
52+
if (preg_match(self::PATTERN_NAME, $nameValue, $matches)) {
53+
return $matches[0] == $nameValue;
54+
}
55+
}
56+
57+
return true;
58+
}
59+
}

app/code/Magento/Customer/Test/Mftf/Test/AdminExactMatchSearchInCustomerGridTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<before>
2222
<createData entity="Simple_US_Customer" stepKey="createFirstCustomer"/>
2323
<createData entity="Simple_US_Customer" stepKey="createSecondCustomer">
24-
<field key="firstname">&quot;Jane Doe&quot;</field>
24+
<field key="firstname">Jane Doe</field>
2525
</createData>
2626
<actionGroup ref="AdminLoginActionGroup" stepKey="login"/>
2727
</before>

app/code/Magento/Customer/Test/Mftf/Test/StorefrontVerifyNoXssInjectionOnUpdateCustomerInformationAddAddressTest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
<test name="StorefrontVerifyNoXssInjectionOnUpdateCustomerInformationAddAddressTest">
1212
<annotations>
1313
<stories value="Update Customer Address"/>
14-
<title value="[Security] Verify No XSS Injection on Update Customer Information Add Address"/>
14+
<title value="DEPRECATED [Security] Verify No XSS Injection on Update Customer Information Add Address"/>
1515
<description value="Test log in to Storefront and Verify No XSS Injection on Update Customer Information Add Address"/>
1616
<testCaseId value="MC-10910"/>
1717
<severity value="CRITICAL"/>
1818
<group value="customer"/>
1919
<group value="mtf_migrated"/>
20+
<skip>
21+
<issueId value="DEPRECATED">Test outdated</issueId>
22+
</skip>
2023
</annotations>
2124

2225
<before>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@
1818
<constraint alias="metadata_data_validator" class="Magento\Customer\Model\Metadata\Validator" />
1919
</entity_constraints>
2020
</rule>
21+
<rule name="check_name">
22+
<entity_constraints>
23+
<constraint alias="name_validator" class="Magento\Customer\Model\Validator\Name" />
24+
</entity_constraints>
25+
</rule>
2126
</rules>
2227
<groups>
2328
<group name="save">
2429
<uses>
2530
<use rule="check_eav"/>
31+
<use rule="check_name"/>
2632
</uses>
2733
</group>
2834
<group name="form">

dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerRepositoryTest.php

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,4 +1058,204 @@ protected function _createCustomer(?array $additionalData = [])
10581058
$this->currentCustomerId[] = $customerData['id'];
10591059
return $customerData;
10601060
}
1061+
1062+
/**
1063+
* Test customer create with invalid name's.
1064+
*
1065+
* @param string $fieldName
1066+
* @param string $fieldValue
1067+
* @param string $expectedMessage
1068+
* @return void
1069+
*
1070+
* @dataProvider customerDataProvider
1071+
*/
1072+
public function testCreateCustomerWithInvalidCustomerFirstName(string $fieldName, string $fieldValue, string $expectedMessage): void
1073+
{
1074+
$customerData = $this->dataObjectProcessor->buildOutputDataArray(
1075+
$this->customerHelper->createSampleCustomerDataObject(),
1076+
Customer::class
1077+
);
1078+
$customerData[$fieldName] = $fieldValue;
1079+
1080+
$serviceInfo = [
1081+
'rest' => [
1082+
'resourcePath' => self::RESOURCE_PATH,
1083+
'httpMethod' => Request::HTTP_METHOD_POST,
1084+
],
1085+
'soap' => [
1086+
'service' => self::SERVICE_NAME,
1087+
'serviceVersion' => self::SERVICE_VERSION,
1088+
'operation' => self::SERVICE_NAME . 'Save',
1089+
],
1090+
];
1091+
1092+
$requestData = ['customer' => $customerData];
1093+
1094+
try {
1095+
$this->_webApiCall($serviceInfo, $requestData);
1096+
$this->fail('Expected exception was not raised');
1097+
} catch (\SoapFault $e) {
1098+
$this->assertStringContainsString($expectedMessage, $e->getMessage());
1099+
} catch (\Exception $e) {
1100+
$errorObj = $this->processRestExceptionResult($e);
1101+
$this->assertEquals(HTTPExceptionCodes::HTTP_BAD_REQUEST, $e->getCode());
1102+
$this->assertEquals($expectedMessage, $errorObj['message']);
1103+
}
1104+
}
1105+
1106+
/**
1107+
* Invalid customer data provider
1108+
*
1109+
* @return array
1110+
*/
1111+
public function customerDataProvider(): array
1112+
{
1113+
return [
1114+
['firstname', 'Jane ☺ ', 'First Name is not valid!'],
1115+
['lastname', '☏ - Doe', 'Last Name is not valid!'],
1116+
['middlename', '⚐ $(date)', 'Middle Name is not valid!'],
1117+
[
1118+
'firstname',
1119+
str_repeat('खाना अच्छा है', 20),
1120+
'First Name is not valid!',
1121+
],
1122+
[
1123+
'lastname',
1124+
str_repeat('المغلوطة حول استنكار النشوة وتمجيد الألمالمغلوطة حول', 5),
1125+
'Last Name is not valid!',
1126+
],
1127+
];
1128+
}
1129+
1130+
/**
1131+
* Test customer create with ultibyte chanracters in name's.
1132+
*
1133+
* @param string $fieldName
1134+
* @param string $fieldValue
1135+
* @return void
1136+
*
1137+
* @dataProvider customerWithMultiByteDataProvider
1138+
*/
1139+
public function testCreateCustomerWithMultibyteCharacters(string $fieldName, string $fieldValue): void
1140+
{
1141+
$customerData = $this->dataObjectProcessor->buildOutputDataArray(
1142+
$this->customerHelper->createSampleCustomerDataObject(),
1143+
Customer::class
1144+
);
1145+
$customerData[$fieldName] = $fieldValue;
1146+
1147+
$serviceInfo = [
1148+
'rest' => [
1149+
'resourcePath' => self::RESOURCE_PATH,
1150+
'httpMethod' => Request::HTTP_METHOD_POST,
1151+
],
1152+
'soap' => [
1153+
'service' => self::SERVICE_NAME,
1154+
'serviceVersion' => self::SERVICE_VERSION,
1155+
'operation' => self::SERVICE_NAME . 'Save',
1156+
],
1157+
];
1158+
1159+
$requestData = ['customer' => $customerData];
1160+
1161+
$response = $this->_webApiCall($serviceInfo, $requestData);
1162+
1163+
$this->assertNotNull($response);
1164+
$this->assertEquals($fieldValue, $response[$fieldName]);
1165+
}
1166+
1167+
/**
1168+
* Customer with multibyte characters data provider.
1169+
*
1170+
* @return array
1171+
*/
1172+
public function customerWithMultiByteDataProvider(): array
1173+
{
1174+
return [
1175+
[
1176+
'firstname',
1177+
str_repeat('हैखान', 51),
1178+
],
1179+
[
1180+
'lastname',
1181+
str_repeat('مغلوطة حول استنكار النشوة وتمجيد الألمالمغلوطة حول', 5),
1182+
],
1183+
];
1184+
}
1185+
1186+
/**
1187+
* Test customer create with valid name's.
1188+
*
1189+
* @param string $fieldName
1190+
* @param string $fieldValue
1191+
* @return void
1192+
*
1193+
* @dataProvider customerValidNameDataProvider
1194+
*/
1195+
public function testCreateCustomerWithValidName(string $fieldName, string $fieldValue): void
1196+
{
1197+
$customerData = $this->dataObjectProcessor->buildOutputDataArray(
1198+
$this->customerHelper->createSampleCustomerDataObject(),
1199+
Customer::class
1200+
);
1201+
$customerData[$fieldName] = $fieldValue;
1202+
1203+
$serviceInfo = [
1204+
'rest' => [
1205+
'resourcePath' => self::RESOURCE_PATH,
1206+
'httpMethod' => Request::HTTP_METHOD_POST,
1207+
],
1208+
'soap' => [
1209+
'service' => self::SERVICE_NAME,
1210+
'serviceVersion' => self::SERVICE_VERSION,
1211+
'operation' => self::SERVICE_NAME . 'Save',
1212+
],
1213+
];
1214+
1215+
$requestData = ['customer' => $customerData];
1216+
1217+
$response = $this->_webApiCall($serviceInfo, $requestData);
1218+
1219+
$this->assertNotNull($response);
1220+
$this->assertEquals($fieldValue, $response[$fieldName]);
1221+
}
1222+
1223+
/**
1224+
* Customer valid name data provider.
1225+
*
1226+
* @return array
1227+
*/
1228+
public function customerValidNameDataProvider(): array
1229+
{
1230+
return [
1231+
[
1232+
'firstname',
1233+
'Anne-Marie',
1234+
],
1235+
[
1236+
'lastname',
1237+
'D\'Artagnan',
1238+
],
1239+
[
1240+
'lastname',
1241+
'Guðmundsdóttir',
1242+
],
1243+
[
1244+
'lastname',
1245+
'María José Carreño Quiñones',
1246+
],
1247+
[
1248+
'lastname',
1249+
'Q. Public',
1250+
],
1251+
[
1252+
'firstname',
1253+
'Elizabeth II',
1254+
],
1255+
[
1256+
'firstname',
1257+
'X Æ A-12 Musk',
1258+
],
1259+
];
1260+
}
10611261
}

0 commit comments

Comments
 (0)