32
32
use Magento \Store \Model \Website ;
33
33
use PHPUnit_Framework_MockObject_MockObject as MockObject ;
34
34
use Psr \Log \LoggerInterface ;
35
+ use Magento \Store \Model \ScopeInterface ;
35
36
36
37
/**
37
38
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -115,8 +116,6 @@ protected function setUp()
115
116
->getMock ();
116
117
117
118
$ this ->scope = $ this ->getMockForAbstractClass (ScopeConfigInterface::class);
118
- $ this ->scope ->method ('getValue ' )
119
- ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
120
119
121
120
$ xmlElFactory = $ this ->getXmlFactory ();
122
121
$ rateFactory = $ this ->getRateFactory ();
@@ -250,6 +249,9 @@ protected function _invokePrepareShippingLabelContent(\SimpleXMLElement $xml)
250
249
251
250
public function testCollectRates ()
252
251
{
252
+ $ this ->scope ->method ('getValue ' )
253
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
254
+
253
255
$ this ->scope ->method ('isSetFlag ' )
254
256
->willReturn (true );
255
257
@@ -279,6 +281,9 @@ public function testCollectRates()
279
281
280
282
public function testCollectRatesErrorMessage ()
281
283
{
284
+ $ this ->scope ->method ('getValue ' )
285
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
286
+
282
287
$ this ->scope ->expects ($ this ->once ())->method ('isSetFlag ' )->willReturn (false );
283
288
284
289
$ this ->error ->expects ($ this ->once ())->method ('setCarrier ' )->with ('dhl ' );
@@ -306,6 +311,9 @@ public function testCollectRatesFail()
306
311
*/
307
312
public function testRequestToShipment ()
308
313
{
314
+ $ this ->scope ->method ('getValue ' )
315
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
316
+
309
317
$ this ->httpResponse ->method ('getBody ' )
310
318
->willReturn (utf8_encode (file_get_contents (__DIR__ . '/_files/response_shipping_label.xml ' )));
311
319
@@ -326,7 +334,7 @@ public function testRequestToShipment()
326
334
'name ' => 'item_name ' ,
327
335
],
328
336
],
329
- ]
337
+ ],
330
338
];
331
339
332
340
$ order = $ this ->getMockBuilder (Order::class)
@@ -393,6 +401,78 @@ public function requestToShipmentDataProvider()
393
401
]
394
402
];
395
403
}
404
+
405
+ /**
406
+ * Test that shipping label request for origin country from AP region doesn't contain restricted fields.
407
+ *
408
+ * @return void
409
+ */
410
+ public function testShippingLabelRequestForAsiaPacificRegion ()
411
+ {
412
+ $ this ->scope ->method ('getValue ' )
413
+ ->willReturnMap (
414
+ [
415
+ ['shipping/origin/country_id ' , ScopeInterface::SCOPE_STORE , null , 'SG ' ],
416
+ ['carriers/dhl/gateway_url ' , ScopeInterface::SCOPE_STORE , null , 'https://xmlpi-ea.dhl.com ' ],
417
+ ]
418
+ );
419
+
420
+ $ this ->httpResponse ->method ('getBody ' )
421
+ ->willReturn (utf8_encode (file_get_contents (__DIR__ . '/_files/response_shipping_label.xml ' )));
422
+
423
+ $ packages = [
424
+ 'package ' => [
425
+ 'params ' => [
426
+ 'width ' => '1 ' ,
427
+ 'length ' => '1 ' ,
428
+ 'height ' => '1 ' ,
429
+ 'dimension_units ' => 'INCH ' ,
430
+ 'weight_units ' => 'POUND ' ,
431
+ 'weight ' => '0.45 ' ,
432
+ 'customs_value ' => '10.00 ' ,
433
+ 'container ' => Carrier::DHL_CONTENT_TYPE_NON_DOC ,
434
+ ],
435
+ 'items ' => [
436
+ 'item1 ' => [
437
+ 'name ' => 'item_name ' ,
438
+ ],
439
+ ],
440
+ ],
441
+ ];
442
+
443
+ $ this ->request ->method ('getPackages ' )->willReturn ($ packages );
444
+ $ this ->request ->method ('getOrigCountryId ' )->willReturn ('SG ' );
445
+ $ this ->request ->method ('setPackages ' )->willReturnSelf ();
446
+ $ this ->request ->method ('setPackageWeight ' )->willReturnSelf ();
447
+ $ this ->request ->method ('setPackageValue ' )->willReturnSelf ();
448
+ $ this ->request ->method ('setValueWithDiscount ' )->willReturnSelf ();
449
+ $ this ->request ->method ('setPackageCustomsValue ' )->willReturnSelf ();
450
+
451
+ $ result = $ this ->model ->requestToShipment ($ this ->request );
452
+
453
+ $ reflectionClass = new \ReflectionObject ($ this ->httpClient );
454
+ $ rawPostData = $ reflectionClass ->getProperty ('raw_post_data ' );
455
+ $ rawPostData ->setAccessible (true );
456
+
457
+ $ this ->assertNotNull ($ result );
458
+ $ requestXml = $ rawPostData ->getValue ($ this ->httpClient );
459
+
460
+ $ this ->assertNotContains (
461
+ 'NewShipper ' ,
462
+ $ requestXml ,
463
+ 'NewShipper is restricted field for AP region '
464
+ );
465
+ $ this ->assertNotContains (
466
+ 'Division ' ,
467
+ $ requestXml ,
468
+ 'Division is restricted field for AP region '
469
+ );
470
+ $ this ->assertNotContains (
471
+ 'RegisteredAccount ' ,
472
+ $ requestXml ,
473
+ 'RegisteredAccount is restricted field for AP region '
474
+ );
475
+ }
396
476
397
477
/**
398
478
* @dataProvider dhlProductsDataProvider
0 commit comments