@@ -1058,4 +1058,204 @@ protected function _createCustomer(?array $additionalData = [])
1058
1058
$ this ->currentCustomerId [] = $ customerData ['id ' ];
1059
1059
return $ customerData ;
1060
1060
}
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
+ }
1061
1261
}
0 commit comments