5
5
*/
6
6
namespace Magento \Dhl \Test \Unit \Model ;
7
7
8
+ use Magento \Dhl \Model \Carrier ;
8
9
use Magento \Framework \App \Config \ScopeConfigInterface ;
9
10
use Magento \Framework \HTTP \ZendClient ;
10
11
use Magento \Framework \HTTP \ZendClientFactory ;
13
14
use Magento \Quote \Model \Quote \Address \RateRequest ;
14
15
use PHPUnit_Framework_MockObject_MockObject as MockObject ;
15
16
use Magento \Dhl \Model \Validator \XmlValidator ;
17
+ use Magento \Store \Model \ScopeInterface ;
16
18
17
19
/**
18
20
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -30,7 +32,7 @@ class CarrierTest extends \PHPUnit\Framework\TestCase
30
32
private $ httpResponse ;
31
33
32
34
/**
33
- * @var \Magento\Dhl\Model\ Carrier
35
+ * @var Carrier
34
36
*/
35
37
private $ model ;
36
38
@@ -92,8 +94,6 @@ protected function setUp()
92
94
->getMock ();
93
95
94
96
$ this ->scope = $ this ->getMockForAbstractClass (ScopeConfigInterface::class);
95
- $ this ->scope ->method ('getValue ' )
96
- ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
97
97
98
98
// xml element factory
99
99
$ xmlElFactory = $ this ->getMockBuilder (
@@ -219,7 +219,7 @@ function ($data) {
219
219
->getMock ();
220
220
221
221
$ this ->model = $ this ->objectManager ->getObject (
222
- \ Magento \ Dhl \ Model \ Carrier::class,
222
+ Carrier::class,
223
223
[
224
224
'scopeConfig ' => $ this ->scope ,
225
225
'xmlSecurity ' => new Security (),
@@ -314,14 +314,17 @@ public function prepareShippingLabelContentExceptionDataProvider()
314
314
*/
315
315
protected function _invokePrepareShippingLabelContent (\SimpleXMLElement $ xml )
316
316
{
317
- $ model = $ this ->objectManager ->getObject (\ Magento \ Dhl \ Model \ Carrier::class);
317
+ $ model = $ this ->objectManager ->getObject (Carrier::class);
318
318
$ method = new \ReflectionMethod ($ model , '_prepareShippingLabelContent ' );
319
319
$ method ->setAccessible (true );
320
320
return $ method ->invoke ($ model , $ xml );
321
321
}
322
322
323
323
public function testCollectRates ()
324
324
{
325
+ $ this ->scope ->method ('getValue ' )
326
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
327
+
325
328
$ this ->scope ->method ('isSetFlag ' )
326
329
->willReturn (true );
327
330
@@ -348,6 +351,9 @@ public function testCollectRates()
348
351
349
352
public function testCollectRatesErrorMessage ()
350
353
{
354
+ $ this ->scope ->method ('getValue ' )
355
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
356
+
351
357
$ this ->scope ->expects ($ this ->once ())->method ('isSetFlag ' )->willReturn (false );
352
358
353
359
$ this ->error ->expects ($ this ->once ())->method ('setCarrier ' )->with ('dhl ' );
@@ -375,6 +381,9 @@ public function testCollectRatesFail()
375
381
*/
376
382
public function testRequestToShipment ()
377
383
{
384
+ $ this ->scope ->method ('getValue ' )
385
+ ->willReturnCallback ([$ this , 'scopeConfigGetValue ' ]);
386
+
378
387
$ this ->httpResponse ->method ('getBody ' )
379
388
->willReturn (utf8_encode (file_get_contents (__DIR__ . '/_files/response_shipping_label.xml ' )));
380
389
$ this ->xmlValidator ->expects ($ this ->any ())->method ('validate ' );
@@ -389,7 +398,7 @@ public function testRequestToShipment()
389
398
'weight_units ' => 'POUND ' ,
390
399
'weight ' => '0.454000000001 ' ,
391
400
'customs_value ' => '10.00 ' ,
392
- 'container ' => \ Magento \ Dhl \ Model \ Carrier::DHL_CONTENT_TYPE_NON_DOC ,
401
+ 'container ' => Carrier::DHL_CONTENT_TYPE_NON_DOC ,
393
402
],
394
403
'items ' => [
395
404
'item1 ' => [
@@ -432,20 +441,73 @@ public function testRequestToShipment()
432
441
}
433
442
434
443
/**
435
- * Data provider to testRequestToShipment
436
- *
437
- * @return array
444
+ * Test that shipping label request for origin country from AP region doesn't contain restricted fields.
438
445
*/
439
- public function requestToShipmentDataProvider ()
446
+ public function testShippingLabelRequestForAsiaPacificRegion ()
440
447
{
441
- return [
442
- [
443
- 'GB '
444
- ],
445
- [
446
- null
448
+ $ this ->scope ->method ('getValue ' )
449
+ ->willReturnMap (
450
+ [
451
+ ['shipping/origin/country_id ' , ScopeInterface::SCOPE_STORE , null , 'SG ' ],
452
+ ['carriers/dhl/gateway_url ' , ScopeInterface::SCOPE_STORE , null , 'https://xmlpi-ea.dhl.com ' ],
453
+ ]
454
+ );
455
+
456
+ $ this ->httpResponse ->method ('getBody ' )
457
+ ->willReturn (utf8_encode (file_get_contents (__DIR__ . '/_files/response_shipping_label.xml ' )));
458
+
459
+ $ packages = [
460
+ 'package ' => [
461
+ 'params ' => [
462
+ 'width ' => '1 ' ,
463
+ 'length ' => '1 ' ,
464
+ 'height ' => '1 ' ,
465
+ 'dimension_units ' => 'INCH ' ,
466
+ 'weight_units ' => 'POUND ' ,
467
+ 'weight ' => '0.45 ' ,
468
+ 'customs_value ' => '10.00 ' ,
469
+ 'container ' => Carrier::DHL_CONTENT_TYPE_NON_DOC ,
470
+ ],
471
+ 'items ' => [
472
+ 'item1 ' => [
473
+ 'name ' => 'item_name ' ,
474
+ ],
475
+ ],
447
476
]
448
477
];
478
+
479
+ $ this ->request ->method ('getPackages ' )->willReturn ($ packages );
480
+ $ this ->request ->method ('getOrigCountryId ' )->willReturn ('SG ' );
481
+ $ this ->request ->method ('setPackages ' )->willReturnSelf ();
482
+ $ this ->request ->method ('setPackageWeight ' )->willReturnSelf ();
483
+ $ this ->request ->method ('setPackageValue ' )->willReturnSelf ();
484
+ $ this ->request ->method ('setValueWithDiscount ' )->willReturnSelf ();
485
+ $ this ->request ->method ('setPackageCustomsValue ' )->willReturnSelf ();
486
+
487
+ $ result = $ this ->model ->requestToShipment ($ this ->request );
488
+
489
+ $ reflectionClass = new \ReflectionObject ($ this ->httpClient );
490
+ $ rawPostData = $ reflectionClass ->getProperty ('raw_post_data ' );
491
+ $ rawPostData ->setAccessible (true );
492
+
493
+ $ this ->assertNotNull ($ result );
494
+ $ requestXml = $ rawPostData ->getValue ($ this ->httpClient );
495
+
496
+ $ this ->assertNotContains (
497
+ 'NewShipper ' ,
498
+ $ requestXml ,
499
+ 'NewShipper is restricted field for AP region '
500
+ );
501
+ $ this ->assertNotContains (
502
+ 'Division ' ,
503
+ $ requestXml ,
504
+ 'Division is restricted field for AP region '
505
+ );
506
+ $ this ->assertNotContains (
507
+ 'RegisteredAccount ' ,
508
+ $ requestXml ,
509
+ 'RegisteredAccount is restricted field for AP region '
510
+ );
449
511
}
450
512
451
513
/**
@@ -466,7 +528,7 @@ public function dhlProductsDataProvider() : array
466
528
{
467
529
return [
468
530
'doc ' => [
469
- 'docType ' => \ Magento \ Dhl \ Model \ Carrier::DHL_CONTENT_TYPE_DOC ,
531
+ 'docType ' => Carrier::DHL_CONTENT_TYPE_DOC ,
470
532
'products ' => [
471
533
'2 ' => 'Easy shop ' ,
472
534
'5 ' => 'Sprintline ' ,
@@ -491,7 +553,7 @@ public function dhlProductsDataProvider() : array
491
553
]
492
554
],
493
555
'non-doc ' => [
494
- 'docType ' => \ Magento \ Dhl \ Model \ Carrier::DHL_CONTENT_TYPE_NON_DOC ,
556
+ 'docType ' => Carrier::DHL_CONTENT_TYPE_NON_DOC ,
495
557
'products ' => [
496
558
'1 ' => 'Domestic express 12:00 ' ,
497
559
'3 ' => 'Easy shop ' ,
0 commit comments