3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \InventoryApi \Test \Api \SourceRepository ;
7
8
8
- use Magento \Framework \Webapi \Exception ;
9
9
use Magento \Framework \Webapi \Rest \Request ;
10
10
use Magento \InventoryApi \Api \Data \SourceCarrierLinkInterface ;
11
11
use Magento \InventoryApi \Api \Data \SourceInterface ;
@@ -66,23 +66,23 @@ public function dataProviderCarrierLinks(): array
66
66
SourceCarrierLinkInterface::POSITION => 200 ,
67
67
],
68
68
[
69
- SourceCarrierLinkInterface::CARRIER_CODE => 'new-link-1 ' ,
69
+ SourceCarrierLinkInterface::CARRIER_CODE => 'dhl ' ,
70
70
SourceCarrierLinkInterface::POSITION => 300 ,
71
71
],
72
72
[
73
- SourceCarrierLinkInterface::CARRIER_CODE => 'new-link-2 ' ,
73
+ SourceCarrierLinkInterface::CARRIER_CODE => 'fedex ' ,
74
74
SourceCarrierLinkInterface::POSITION => 400 ,
75
75
],
76
76
],
77
77
],
78
78
'replace_carrier_links ' => [
79
79
[
80
80
[
81
- SourceCarrierLinkInterface::CARRIER_CODE => 'new-link-1 ' ,
81
+ SourceCarrierLinkInterface::CARRIER_CODE => 'dhl ' ,
82
82
SourceCarrierLinkInterface::POSITION => 100 ,
83
83
],
84
84
[
85
- SourceCarrierLinkInterface::CARRIER_CODE => 'new-link-2 ' ,
85
+ SourceCarrierLinkInterface::CARRIER_CODE => 'fedex ' ,
86
86
SourceCarrierLinkInterface::POSITION => 200 ,
87
87
],
88
88
],
@@ -93,62 +93,6 @@ public function dataProviderCarrierLinks(): array
93
93
];
94
94
}
95
95
96
- /**
97
- * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source.php
98
- */
99
- public function testAssignCarrierLinksIfUseGlobalConfigurationChosen ()
100
- {
101
- $ sourceId = 10 ;
102
- $ expectedData = [
103
- SourceInterface::NAME => 'source-name-1 ' ,
104
- SourceInterface::POSTCODE => 'source-postcode ' ,
105
- SourceInterface::COUNTRY_ID => 'US ' ,
106
- SourceInterface::USE_DEFAULT_CARRIER_CONFIG => 1 ,
107
- SourceInterface::CARRIER_LINKS => [
108
- [
109
- SourceCarrierLinkInterface::CARRIER_CODE => 'ups ' ,
110
- SourceCarrierLinkInterface::POSITION => 100 ,
111
- ],
112
- [
113
- SourceCarrierLinkInterface::CARRIER_CODE => 'usps ' ,
114
- SourceCarrierLinkInterface::POSITION => 200 ,
115
- ],
116
- ],
117
- ];
118
-
119
- $ expectedErrorData = [
120
- 'message ' => 'Validation Failed ' ,
121
- 'errors ' => [
122
- [
123
- 'message ' => 'You can \'t configure "%field" because you have chosen Global Shipping configuration. ' ,
124
- 'parameters ' => [
125
- 'field ' => SourceInterface::CARRIER_LINKS ,
126
- ],
127
- ],
128
- ],
129
- ];
130
-
131
- try {
132
- $ this ->saveSource ($ sourceId , $ expectedData );
133
- $ this ->fail ('Expected throwing exception ' );
134
- } catch (\Exception $ e ) {
135
- if (TESTS_WEB_API_ADAPTER == self ::ADAPTER_REST ) {
136
- self ::assertEquals ($ expectedErrorData , $ this ->processRestExceptionResult ($ e ));
137
- self ::assertEquals (Exception::HTTP_BAD_REQUEST , $ e ->getCode ());
138
- } elseif (TESTS_WEB_API_ADAPTER == self ::ADAPTER_SOAP ) {
139
- $ this ->assertInstanceOf ('SoapFault ' , $ e );
140
- // @see \Magento\TestFramework\TestCase\WebapiAbstract::getActualWrappedErrors()
141
- $ expectedWrappedErrors = $ expectedErrorData ['errors ' ];
142
- $ expectedWrappedErrors [0 ]['params ' ] = $ expectedWrappedErrors [0 ]['parameters ' ];
143
- unset($ expectedWrappedErrors [0 ]['parameters ' ]);
144
-
145
- $ this ->checkSoapFault ($ e , $ expectedErrorData ['message ' ], 'env:Sender ' , [], $ expectedWrappedErrors );
146
- } else {
147
- throw $ e ;
148
- }
149
- }
150
- }
151
-
152
96
/**
153
97
* @param int $sourceId
154
98
* @param array $data
@@ -197,4 +141,105 @@ private function getSourceDataById(int $sourceId): array
197
141
self ::assertArrayHasKey (SourceInterface::SOURCE_ID , $ response );
198
142
return $ response ;
199
143
}
144
+
145
+ /**
146
+ * @param array $carrierData
147
+ * @param array $expectedErrorData
148
+ * @dataProvider failedValidationDataProvider
149
+ */
150
+ public function testCarrierLinksValidation (array $ carrierData , array $ expectedErrorData )
151
+ {
152
+ $ serviceInfo = [
153
+ 'rest ' => [
154
+ 'resourcePath ' => self ::RESOURCE_PATH ,
155
+ 'httpMethod ' => Request::HTTP_METHOD_POST ,
156
+ ],
157
+ 'soap ' => [
158
+ 'service ' => self ::SERVICE_NAME ,
159
+ 'operation ' => self ::SERVICE_NAME . 'Save ' ,
160
+ ],
161
+ ];
162
+
163
+ try {
164
+ $ this ->_webApiCall ($ serviceInfo , ['source ' => $ carrierData ]);
165
+ $ this ->fail ('Expected throwing exception ' );
166
+ } catch (\Exception $ e ) {
167
+ self ::assertEquals ($ expectedErrorData , $ this ->processRestExceptionResult ($ e ));
168
+ self ::assertEquals (\Magento \Framework \Webapi \Exception::HTTP_BAD_REQUEST , $ e ->getCode ());
169
+ }
170
+ }
171
+
172
+ /**
173
+ * @return array
174
+ */
175
+ public function failedValidationDataProvider (): array
176
+ {
177
+ return [
178
+ 'use_global_configuration_chosen ' => [
179
+ [
180
+ SourceInterface::NAME => 'source-name-1 ' ,
181
+ SourceInterface::POSTCODE => 'source-postcode ' ,
182
+ SourceInterface::COUNTRY_ID => 'US ' ,
183
+ SourceInterface::USE_DEFAULT_CARRIER_CONFIG => 1 ,
184
+ SourceInterface::CARRIER_LINKS => [
185
+ [
186
+ SourceCarrierLinkInterface::CARRIER_CODE => 'ups ' ,
187
+ SourceCarrierLinkInterface::POSITION => 100 ,
188
+ ],
189
+ [
190
+ SourceCarrierLinkInterface::CARRIER_CODE => 'usps ' ,
191
+ SourceCarrierLinkInterface::POSITION => 200 ,
192
+ ],
193
+ ],
194
+ ],
195
+ [
196
+ 'message ' => 'Validation Failed ' ,
197
+ 'errors ' => [
198
+ [
199
+ 'message ' =>
200
+ 'You can \'t configure "%field" because you have chosen Global Shipping configuration. ' ,
201
+ 'parameters ' => [
202
+ 'field ' => SourceInterface::CARRIER_LINKS ,
203
+ ],
204
+ ],
205
+ ],
206
+ ],
207
+ ],
208
+ 'carrier_codes_not_exits ' => [
209
+ [
210
+ SourceInterface::NAME => 'source-name-1 ' ,
211
+ SourceInterface::POSTCODE => 'source-postcode ' ,
212
+ SourceInterface::COUNTRY_ID => 'US ' ,
213
+ SourceInterface::USE_DEFAULT_CARRIER_CONFIG => 0 ,
214
+ SourceInterface::CARRIER_LINKS => [
215
+ [
216
+ SourceCarrierLinkInterface::CARRIER_CODE => 'no_exists_1 ' ,
217
+ SourceCarrierLinkInterface::POSITION => 100 ,
218
+ ],
219
+ [
220
+ SourceCarrierLinkInterface::CARRIER_CODE => 'no_exists_2 ' ,
221
+ SourceCarrierLinkInterface::POSITION => 200 ,
222
+ ],
223
+ ],
224
+ ],
225
+ [
226
+ 'message ' => 'Validation Failed ' ,
227
+ 'errors ' => [
228
+ [
229
+ 'message ' => 'Carrier with code: "%carrier" don \'t exists. ' ,
230
+ 'parameters ' => [
231
+ 'carrier ' => 'no_exists_1 '
232
+ ],
233
+ ],
234
+ [
235
+ 'message ' => 'Carrier with code: "%carrier" don \'t exists. ' ,
236
+ 'parameters ' => [
237
+ 'carrier ' => 'no_exists_2 '
238
+ ],
239
+ ],
240
+ ],
241
+ ],
242
+ ],
243
+ ];
244
+ }
200
245
}
0 commit comments