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 ;
@@ -49,106 +49,6 @@ public function testCarrierLinksManagement(array $carrierLinks)
49
49
self ::assertEquals ($ expectedData [SourceInterface::CARRIER_LINKS ], $ sourceData [SourceInterface::CARRIER_LINKS ]);
50
50
}
51
51
52
- /**
53
- * @return array
54
- */
55
- public function dataProviderCarrierLinks (): array
56
- {
57
- return [
58
- 'add_carrier_new_links ' => [
59
- [
60
- [
61
- SourceCarrierLinkInterface::CARRIER_CODE => 'ups ' ,
62
- SourceCarrierLinkInterface::POSITION => 100 ,
63
- ],
64
- [
65
- SourceCarrierLinkInterface::CARRIER_CODE => 'usps ' ,
66
- SourceCarrierLinkInterface::POSITION => 200 ,
67
- ],
68
- [
69
- SourceCarrierLinkInterface::CARRIER_CODE => 'dhl ' ,
70
- SourceCarrierLinkInterface::POSITION => 300 ,
71
- ],
72
- [
73
- SourceCarrierLinkInterface::CARRIER_CODE => 'fedex ' ,
74
- SourceCarrierLinkInterface::POSITION => 400 ,
75
- ],
76
- ],
77
- ],
78
- 'replace_carrier_links ' => [
79
- [
80
- [
81
- SourceCarrierLinkInterface::CARRIER_CODE => 'dhl ' ,
82
- SourceCarrierLinkInterface::POSITION => 100 ,
83
- ],
84
- [
85
- SourceCarrierLinkInterface::CARRIER_CODE => 'fedex ' ,
86
- SourceCarrierLinkInterface::POSITION => 200 ,
87
- ],
88
- ],
89
- ],
90
- 'delete_carrier_links ' => [
91
- [],
92
- ],
93
- ];
94
- }
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
52
/**
153
53
* @param int $sourceId
154
54
* @param array $data
@@ -198,24 +98,13 @@ private function getSourceDataById(int $sourceId): array
198
98
return $ response ;
199
99
}
200
100
201
- public function testFailedValidationOnCreate ()
101
+ /**
102
+ * @param array $carrierLinks
103
+ * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source.php
104
+ * @dataProvider dataProviderForValidationFailed
105
+ */
106
+ public function testCarrierLinksValidation (array $ carrierData , array $ expectedErrorData )
202
107
{
203
- $ expectedData = [
204
- SourceInterface::NAME => 'source-name-1 ' ,
205
- SourceInterface::POSTCODE => 'source-postcode ' ,
206
- SourceInterface::COUNTRY_ID => 'US ' ,
207
- SourceInterface::USE_DEFAULT_CARRIER_CONFIG => 0 ,
208
- SourceInterface::CARRIER_LINKS => [
209
- [
210
- SourceCarrierLinkInterface::CARRIER_CODE => 'no_exists_1 ' ,
211
- SourceCarrierLinkInterface::POSITION => 100 ,
212
- ],
213
- [
214
- SourceCarrierLinkInterface::CARRIER_CODE => 'no_exists_2 ' ,
215
- SourceCarrierLinkInterface::POSITION => 200 ,
216
- ],
217
- ],
218
- ];
219
108
$ serviceInfo = [
220
109
'rest ' => [
221
110
'resourcePath ' => self ::RESOURCE_PATH ,
@@ -227,29 +116,151 @@ public function testFailedValidationOnCreate()
227
116
],
228
117
];
229
118
230
- $ expectedErrorData = [
231
- 'message ' => 'Validation Failed ' ,
232
- 'errors ' => [
119
+ try {
120
+ $ this ->_webApiCall ($ serviceInfo , ['source ' => $ carrierData ]);
121
+ $ this ->fail ('Expected throwing exception ' );
122
+ } catch (\Exception $ e ) {
123
+ self ::assertEquals ($ expectedErrorData , $ this ->processRestExceptionResult ($ e ));
124
+ self ::assertEquals (\Magento \Framework \Webapi \Exception::HTTP_BAD_REQUEST , $ e ->getCode ());
125
+ }
126
+ }
127
+
128
+ /**
129
+ * @return array
130
+ */
131
+ public function dataProviderCarrierLinks (): array
132
+ {
133
+ return [
134
+ 'add_carrier_new_links ' => [
233
135
[
234
- 'message ' => 'You can \'t configure because carrier with code: "%carrier" don \'t exists. ' ,
235
- 'parameters ' => [
236
- 'carrier ' => 'no_exists_1 '
136
+ [
137
+ SourceCarrierLinkInterface::CARRIER_CODE => 'ups ' ,
138
+ SourceCarrierLinkInterface::POSITION => 100 ,
139
+ ],
140
+ [
141
+ SourceCarrierLinkInterface::CARRIER_CODE => 'usps ' ,
142
+ SourceCarrierLinkInterface::POSITION => 200 ,
143
+ ],
144
+ [
145
+ SourceCarrierLinkInterface::CARRIER_CODE => 'dhl ' ,
146
+ SourceCarrierLinkInterface::POSITION => 300 ,
147
+ ],
148
+ [
149
+ SourceCarrierLinkInterface::CARRIER_CODE => 'fedex ' ,
150
+ SourceCarrierLinkInterface::POSITION => 400 ,
237
151
],
238
152
],
153
+ ],
154
+ 'replace_carrier_links ' => [
239
155
[
240
- 'message ' => 'You can \'t configure because carrier with code: "%carrier" don \'t exists. ' ,
241
- 'parameters ' => [
242
- 'carrier ' => 'no_exists_2 '
156
+ [
157
+ SourceCarrierLinkInterface::CARRIER_CODE => 'dhl ' ,
158
+ SourceCarrierLinkInterface::POSITION => 100 ,
159
+ ],
160
+ [
161
+ SourceCarrierLinkInterface::CARRIER_CODE => 'fedex ' ,
162
+ SourceCarrierLinkInterface::POSITION => 200 ,
243
163
],
244
- ]
164
+ ],
165
+ ],
166
+ 'delete_carrier_links ' => [
167
+ [],
245
168
],
246
169
];
170
+ }
247
171
248
- try {
249
- $ this ->_webApiCall ($ serviceInfo , ['source ' => $ expectedData ]);
250
- } catch (\Exception $ e ) {
251
- self ::assertEquals ($ expectedErrorData , $ this ->processRestExceptionResult ($ e ));
252
- self ::assertEquals (\Magento \Framework \Webapi \Exception::HTTP_BAD_REQUEST , $ e ->getCode ());
253
- }
172
+ /**
173
+ * @return array
174
+ */
175
+ public function dataProviderForValidationFailed (): array
176
+ {
177
+ return [
178
+ 'not_list_of_SourceCarrierLinkInterface ' => [
179
+ [
180
+ SourceInterface::NAME => 'source-name-1 ' ,
181
+ SourceInterface::POSTCODE => 'source-postcode ' ,
182
+ SourceInterface::COUNTRY_ID => 'US ' ,
183
+ SourceInterface::USE_DEFAULT_CARRIER_CONFIG => 0 ,
184
+ SourceInterface::CARRIER_LINKS => 1222
185
+ ],
186
+ [
187
+ 'message ' => 'Validation Failed ' ,
188
+ 'errors ' => [
189
+ [
190
+ 'message ' => '"%field" must be list of SourceCarrierLinkInterface. ' ,
191
+ 'parameters ' => [
192
+ 'field ' => SourceInterface::CARRIER_LINKS ,
193
+ ],
194
+ ],
195
+ ],
196
+ ],
197
+ ],
198
+ 'use_global_configuration_chosen ' => [
199
+ [
200
+ SourceInterface::NAME => 'source-name-1 ' ,
201
+ SourceInterface::POSTCODE => 'source-postcode ' ,
202
+ SourceInterface::COUNTRY_ID => 'US ' ,
203
+ SourceInterface::USE_DEFAULT_CARRIER_CONFIG => 1 ,
204
+ SourceInterface::CARRIER_LINKS => [
205
+ [
206
+ SourceCarrierLinkInterface::CARRIER_CODE => 'ups ' ,
207
+ SourceCarrierLinkInterface::POSITION => 100 ,
208
+ ],
209
+ [
210
+ SourceCarrierLinkInterface::CARRIER_CODE => 'usps ' ,
211
+ SourceCarrierLinkInterface::POSITION => 200 ,
212
+ ],
213
+ ],
214
+ ],
215
+ [
216
+ 'message ' => 'Validation Failed ' ,
217
+ 'errors ' => [
218
+ [
219
+ 'message ' =>
220
+ 'You can \'t configure "%field" because you have chosen Global Shipping configuration. ' ,
221
+ 'parameters ' => [
222
+ 'field ' => SourceInterface::CARRIER_LINKS ,
223
+ ],
224
+ ],
225
+ ],
226
+ ],
227
+ ],
228
+ 'carrier_codes_not_exits ' => [
229
+ [
230
+ SourceInterface::NAME => 'source-name-1 ' ,
231
+ SourceInterface::POSTCODE => 'source-postcode ' ,
232
+ SourceInterface::COUNTRY_ID => 'US ' ,
233
+ SourceInterface::USE_DEFAULT_CARRIER_CONFIG => 0 ,
234
+ SourceInterface::CARRIER_LINKS => [
235
+ [
236
+ SourceCarrierLinkInterface::CARRIER_CODE => 'no_exists_1 ' ,
237
+ SourceCarrierLinkInterface::POSITION => 100 ,
238
+ ],
239
+ [
240
+ SourceCarrierLinkInterface::CARRIER_CODE => 'no_exists_2 ' ,
241
+ SourceCarrierLinkInterface::POSITION => 200 ,
242
+ ],
243
+ ],
244
+ ],
245
+ [
246
+ 'message ' => 'Validation Failed ' ,
247
+ 'errors ' => [
248
+ [
249
+ 'message ' => 'You can \'t configure because carrier with code: "%carrier" don \'t exists. ' ,
250
+ 'parameters ' => [
251
+ 'carrier ' => 'no_exists_1 '
252
+ ],
253
+ ],
254
+ [
255
+ 'message ' => 'You can \'t configure because carrier with code: "%carrier" don \'t exists. ' ,
256
+ 'parameters ' => [
257
+ 'carrier ' => 'no_exists_2 '
258
+ ],
259
+ ]
260
+ ],
261
+ ],
262
+ ]
263
+
264
+ ];
254
265
}
255
266
}
0 commit comments