@@ -933,4 +933,207 @@ protected function _createCustomer()
933
933
$ this ->currentCustomerId [] = $ customerData ['id ' ];
934
934
return $ customerData ;
935
935
}
936
+
937
+ /**
938
+ * Test customer create with invalid name's.
939
+ *
940
+ * @param string $fieldName
941
+ * @param string $fieldValue
942
+ * @param string $expectedMessage
943
+ * @return void
944
+ *
945
+ * @dataProvider customerDataProvider
946
+ */
947
+ public function testCreateCustomerWithInvalidCustomerFirstName (
948
+ string $ fieldName ,
949
+ string $ fieldValue ,
950
+ string $ expectedMessage
951
+ ): void {
952
+ $ customerData = $ this ->dataObjectProcessor ->buildOutputDataArray (
953
+ $ this ->customerHelper ->createSampleCustomerDataObject (),
954
+ Customer::class
955
+ );
956
+ $ customerData [$ fieldName ] = $ fieldValue ;
957
+
958
+ $ serviceInfo = [
959
+ 'rest ' => [
960
+ 'resourcePath ' => self ::RESOURCE_PATH ,
961
+ 'httpMethod ' => Request::HTTP_METHOD_POST ,
962
+ ],
963
+ 'soap ' => [
964
+ 'service ' => self ::SERVICE_NAME ,
965
+ 'serviceVersion ' => self ::SERVICE_VERSION ,
966
+ 'operation ' => self ::SERVICE_NAME . 'Save ' ,
967
+ ],
968
+ ];
969
+
970
+ $ requestData = ['customer ' => $ customerData ];
971
+
972
+ try {
973
+ $ this ->_webApiCall ($ serviceInfo , $ requestData );
974
+ $ this ->fail ('Expected exception was not raised ' );
975
+ } catch (\SoapFault $ e ) {
976
+ $ this ->assertEquals ($ expectedMessage , $ e ->getMessage ());
977
+ } catch (\Exception $ e ) {
978
+ $ errorObj = $ this ->processRestExceptionResult ($ e );
979
+ $ this ->assertEquals (HTTPExceptionCodes::HTTP_BAD_REQUEST , $ e ->getCode ());
980
+ $ this ->assertEquals ($ expectedMessage , $ errorObj ['message ' ]);
981
+ }
982
+ }
983
+
984
+ /**
985
+ * Invalid customer data provider
986
+ *
987
+ * @return array
988
+ */
989
+ public function customerDataProvider (): array
990
+ {
991
+ return [
992
+ ['firstname ' , 'Jane ☺ ' , 'First Name is not valid! ' ],
993
+ ['lastname ' , '☏ - Doe ' , 'Last Name is not valid! ' ],
994
+ ['middlename ' , '⚐ $(date) ' , 'Middle Name is not valid! ' ],
995
+ [
996
+ 'firstname ' ,
997
+ str_repeat ('खाना अच्छा है ' , 20 ),
998
+ 'First Name is not valid! ' ,
999
+ ],
1000
+ [
1001
+ 'lastname ' ,
1002
+ str_repeat ('المغلوطة حول استنكار النشوة وتمجيد الألمالمغلوطة حول ' , 5 ),
1003
+ 'Last Name is not valid! ' ,
1004
+ ],
1005
+ ];
1006
+ }
1007
+
1008
+ /**
1009
+ * Test customer create with ultibyte chanracters in name's.
1010
+ *
1011
+ * @param string $fieldName
1012
+ * @param string $fieldValue
1013
+ * @return void
1014
+ *
1015
+ * @dataProvider customerWithMultiByteDataProvider
1016
+ */
1017
+ public function testCreateCustomerWithMultibyteCharacters (string $ fieldName , string $ fieldValue ): void
1018
+ {
1019
+ $ customerData = $ this ->dataObjectProcessor ->buildOutputDataArray (
1020
+ $ this ->customerHelper ->createSampleCustomerDataObject (),
1021
+ Customer::class
1022
+ );
1023
+ $ customerData [$ fieldName ] = $ fieldValue ;
1024
+
1025
+ $ serviceInfo = [
1026
+ 'rest ' => [
1027
+ 'resourcePath ' => self ::RESOURCE_PATH ,
1028
+ 'httpMethod ' => Request::HTTP_METHOD_POST ,
1029
+ ],
1030
+ 'soap ' => [
1031
+ 'service ' => self ::SERVICE_NAME ,
1032
+ 'serviceVersion ' => self ::SERVICE_VERSION ,
1033
+ 'operation ' => self ::SERVICE_NAME . 'Save ' ,
1034
+ ],
1035
+ ];
1036
+
1037
+ $ requestData = ['customer ' => $ customerData ];
1038
+
1039
+ $ response = $ this ->_webApiCall ($ serviceInfo , $ requestData );
1040
+
1041
+ $ this ->assertNotNull ($ response );
1042
+ $ this ->assertEquals ($ fieldValue , $ response [$ fieldName ]);
1043
+ }
1044
+
1045
+ /**
1046
+ * Customer with multibyte characters data provider.
1047
+ *
1048
+ * @return array
1049
+ */
1050
+ public function customerWithMultiByteDataProvider (): array
1051
+ {
1052
+ return [
1053
+ [
1054
+ 'firstname ' ,
1055
+ str_repeat ('हैखान ' , 51 ),
1056
+ ],
1057
+ [
1058
+ 'lastname ' ,
1059
+ str_repeat ('مغلوطة حول استنكار النشوة وتمجيد الألمالمغلوطة حول ' , 5 ),
1060
+ ],
1061
+ ];
1062
+ }
1063
+
1064
+ /**
1065
+ * Test customer create with valid name's.
1066
+ *
1067
+ * @param string $fieldName
1068
+ * @param string $fieldValue
1069
+ * @return void
1070
+ *
1071
+ * @dataProvider customerValidNameDataProvider
1072
+ */
1073
+ public function testCreateCustomerWithValidName (string $ fieldName , string $ fieldValue ): void
1074
+ {
1075
+ $ customerData = $ this ->dataObjectProcessor ->buildOutputDataArray (
1076
+ $ this ->customerHelper ->createSampleCustomerDataObject (),
1077
+ Customer::class
1078
+ );
1079
+ $ customerData [$ fieldName ] = $ fieldValue ;
1080
+
1081
+ $ serviceInfo = [
1082
+ 'rest ' => [
1083
+ 'resourcePath ' => self ::RESOURCE_PATH ,
1084
+ 'httpMethod ' => Request::HTTP_METHOD_POST ,
1085
+ ],
1086
+ 'soap ' => [
1087
+ 'service ' => self ::SERVICE_NAME ,
1088
+ 'serviceVersion ' => self ::SERVICE_VERSION ,
1089
+ 'operation ' => self ::SERVICE_NAME . 'Save ' ,
1090
+ ],
1091
+ ];
1092
+
1093
+ $ requestData = ['customer ' => $ customerData ];
1094
+
1095
+ $ response = $ this ->_webApiCall ($ serviceInfo , $ requestData );
1096
+
1097
+ $ this ->assertNotNull ($ response );
1098
+ $ this ->assertEquals ($ fieldValue , $ response [$ fieldName ]);
1099
+ }
1100
+
1101
+ /**
1102
+ * Customer valid name data provider.
1103
+ *
1104
+ * @return array
1105
+ */
1106
+ public function customerValidNameDataProvider (): array
1107
+ {
1108
+ return [
1109
+ [
1110
+ 'firstname ' ,
1111
+ 'Anne-Marie ' ,
1112
+ ],
1113
+ [
1114
+ 'lastname ' ,
1115
+ 'D \'Artagnan ' ,
1116
+ ],
1117
+ [
1118
+ 'lastname ' ,
1119
+ 'Guðmundsdóttir ' ,
1120
+ ],
1121
+ [
1122
+ 'lastname ' ,
1123
+ 'María José Carreño Quiñones ' ,
1124
+ ],
1125
+ [
1126
+ 'lastname ' ,
1127
+ 'Q. Public ' ,
1128
+ ],
1129
+ [
1130
+ 'firstname ' ,
1131
+ 'Elizabeth II ' ,
1132
+ ],
1133
+ [
1134
+ 'firstname ' ,
1135
+ 'X Æ A-12 Musk ' ,
1136
+ ],
1137
+ ];
1138
+ }
936
1139
}
0 commit comments