5
5
*/
6
6
namespace Magento \Usps \Test \Unit \Model ;
7
7
8
+ use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
8
9
use Magento \Framework \HTTP \ZendClient ;
9
10
use Magento \Framework \HTTP \ZendClientFactory ;
10
11
use Magento \Quote \Model \Quote \Address \RateRequest ;
@@ -162,6 +163,22 @@ function ($data) {
162
163
]
163
164
);
164
165
166
+ $ productCollection = $ this ->getMockBuilder (\Magento \Catalog \Model \ResourceModel \Product \Collection::class)
167
+ ->disableOriginalConstructor ()
168
+ ->getMock ();
169
+ $ productCollection ->method ('addStoreFilter ' )
170
+ ->willReturnSelf ();
171
+ $ productCollection ->method ('addFieldToFilter ' )
172
+ ->willReturnSelf ();
173
+ $ productCollection ->method ('addAttributeToSelect ' )
174
+ ->willReturn ([]);
175
+
176
+ $ productCollectionFactory = $ this ->getMockBuilder (CollectionFactory::class)
177
+ ->disableOriginalConstructor ()
178
+ ->getMock ();
179
+ $ productCollectionFactory ->method ('create ' )
180
+ ->willReturn ($ productCollection );
181
+
165
182
$ arguments = [
166
183
'scopeConfig ' => $ this ->scope ,
167
184
'xmlSecurity ' => new \Magento \Framework \Xml \Security (),
@@ -172,6 +189,7 @@ function ($data) {
172
189
'data ' => $ data ,
173
190
'rateErrorFactory ' => $ this ->errorFactory ,
174
191
'carrierHelper ' => $ carrierHelper ,
192
+ 'productCollectionFactory ' => $ productCollectionFactory ,
175
193
];
176
194
177
195
$ this ->dataHelper = $ this ->getMockBuilder (DataHelper::class)
@@ -265,6 +283,32 @@ public function testReturnOfShipment()
265
283
$ this ->assertNotEmpty ($ this ->carrier ->returnOfShipment ($ request )->getInfo ()[0 ]['tracking_number ' ]);
266
284
}
267
285
286
+ public function testFormattingFloatValuesForIntlShipmentRequest ()
287
+ {
288
+ $ this ->httpResponse ->method ('getBody ' )
289
+ ->willReturn (
290
+ file_get_contents (__DIR__ . '/_files/success_usps_response_return_shipment.xml ' )
291
+ );
292
+ $ request = $ this ->objectManager ->getObject (
293
+ \Magento \Shipping \Model \Shipment \ReturnShipment::class,
294
+ require __DIR__ . '/_files/return_shipment_request_data.php '
295
+ );
296
+
297
+ $ request ->setRecipientAddressCountryCode ('UK ' );
298
+ $ formattedValuesRegex = '(<Value>5.00<\/Value>).* ' ;
299
+ $ formattedValuesRegex .= '(<NetOunces>0.00<\/NetOunces>).* ' ;
300
+ $ formattedValuesRegex .= '(<GrossOunces>0.00<\/GrossOunces>) ' ;
301
+
302
+ $ this ->httpClient ->expects ($ this ->exactly (2 ))
303
+ ->method ('setParameterGet ' )
304
+ ->withConsecutive (
305
+ ['API ' , 'ExpressMailIntl ' ],
306
+ ['XML ' , $ this ->matchesRegularExpression ('/ ' . $ formattedValuesRegex . '/ ' )]
307
+ );
308
+
309
+ $ this ->carrier ->returnOfShipment ($ request );
310
+ }
311
+
268
312
/**
269
313
* Emulates the config's `getValue` method.
270
314
*
0 commit comments