@@ -933,4 +933,131 @@ 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
+ }
936
1063
}
0 commit comments