Skip to content

Commit ff5ca90

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-90309' into 2.3-develop-pr13
2 parents 431d0d3 + 73db4ba commit ff5ca90

File tree

2 files changed

+97
-25
lines changed

2 files changed

+97
-25
lines changed

app/code/Magento/Dhl/Model/Carrier.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,9 @@ protected function _doRequest()
14091409
if (!$originRegion) {
14101410
$xml->addChild('RequestedPickupTime', 'N', '');
14111411
}
1412-
$xml->addChild('NewShipper', 'N', '');
1412+
if ($originRegion !== 'AP') {
1413+
$xml->addChild('NewShipper', 'N', '');
1414+
}
14131415
$xml->addChild('LanguageCode', 'EN', '');
14141416
$xml->addChild('PiecesEnabled', 'Y', '');
14151417

@@ -1451,7 +1453,9 @@ protected function _doRequest()
14511453
}
14521454

14531455
$nodeConsignee->addChild('City', $rawRequest->getRecipientAddressCity());
1454-
$nodeConsignee->addChild('Division', $rawRequest->getRecipientAddressStateOrProvinceCode());
1456+
if ($originRegion !== 'AP') {
1457+
$nodeConsignee->addChild('Division', $rawRequest->getRecipientAddressStateOrProvinceCode());
1458+
}
14551459
$nodeConsignee->addChild('PostalCode', $rawRequest->getRecipientAddressPostalCode());
14561460
$nodeConsignee->addChild('CountryCode', $rawRequest->getRecipientAddressCountryCode());
14571461
$nodeConsignee->addChild(
@@ -1500,7 +1504,9 @@ protected function _doRequest()
15001504
$nodeShipper = $xml->addChild('Shipper', '', '');
15011505
$nodeShipper->addChild('ShipperID', (string)$this->getConfigData('account'));
15021506
$nodeShipper->addChild('CompanyName', $rawRequest->getShipperContactCompanyName());
1503-
$nodeShipper->addChild('RegisteredAccount', (string)$this->getConfigData('account'));
1507+
if ($originRegion !== 'AP') {
1508+
$nodeShipper->addChild('RegisteredAccount', (string)$this->getConfigData('account'));
1509+
}
15041510

15051511
$address = $rawRequest->getShipperAddressStreet1() . ' ' . $rawRequest->getShipperAddressStreet2();
15061512
$address = $this->string->split($address, 35, false, true);
@@ -1513,7 +1519,9 @@ protected function _doRequest()
15131519
}
15141520

15151521
$nodeShipper->addChild('City', $rawRequest->getShipperAddressCity());
1516-
$nodeShipper->addChild('Division', $rawRequest->getShipperAddressStateOrProvinceCode());
1522+
if ($originRegion !== 'AP') {
1523+
$nodeShipper->addChild('Division', $rawRequest->getShipperAddressStateOrProvinceCode());
1524+
}
15171525
$nodeShipper->addChild('PostalCode', $rawRequest->getShipperAddressPostalCode());
15181526
$nodeShipper->addChild('CountryCode', $rawRequest->getShipperAddressCountryCode());
15191527
$nodeShipper->addChild(

app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php

Lines changed: 85 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Dhl\Test\Unit\Model;
77

8+
use Magento\Dhl\Model\Carrier;
89
use Magento\Framework\App\Config\ScopeConfigInterface;
910
use Magento\Framework\HTTP\ZendClient;
1011
use Magento\Framework\HTTP\ZendClientFactory;
@@ -13,6 +14,7 @@
1314
use Magento\Quote\Model\Quote\Address\RateRequest;
1415
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1516
use Magento\Dhl\Model\Validator\XmlValidator;
17+
use Magento\Store\Model\ScopeInterface;
1618

1719
/**
1820
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -30,7 +32,7 @@ class CarrierTest extends \PHPUnit\Framework\TestCase
3032
private $httpResponse;
3133

3234
/**
33-
* @var \Magento\Dhl\Model\Carrier
35+
* @var Carrier
3436
*/
3537
private $model;
3638

@@ -92,8 +94,6 @@ protected function setUp()
9294
->getMock();
9395

9496
$this->scope = $this->getMockForAbstractClass(ScopeConfigInterface::class);
95-
$this->scope->method('getValue')
96-
->willReturnCallback([$this, 'scopeConfigGetValue']);
9797

9898
// xml element factory
9999
$xmlElFactory = $this->getMockBuilder(
@@ -219,7 +219,7 @@ function ($data) {
219219
->getMock();
220220

221221
$this->model = $this->objectManager->getObject(
222-
\Magento\Dhl\Model\Carrier::class,
222+
Carrier::class,
223223
[
224224
'scopeConfig' => $this->scope,
225225
'xmlSecurity' => new Security(),
@@ -314,14 +314,17 @@ public function prepareShippingLabelContentExceptionDataProvider()
314314
*/
315315
protected function _invokePrepareShippingLabelContent(\SimpleXMLElement $xml)
316316
{
317-
$model = $this->objectManager->getObject(\Magento\Dhl\Model\Carrier::class);
317+
$model = $this->objectManager->getObject(Carrier::class);
318318
$method = new \ReflectionMethod($model, '_prepareShippingLabelContent');
319319
$method->setAccessible(true);
320320
return $method->invoke($model, $xml);
321321
}
322322

323323
public function testCollectRates()
324324
{
325+
$this->scope->method('getValue')
326+
->willReturnCallback([$this, 'scopeConfigGetValue']);
327+
325328
$this->scope->method('isSetFlag')
326329
->willReturn(true);
327330

@@ -348,6 +351,9 @@ public function testCollectRates()
348351

349352
public function testCollectRatesErrorMessage()
350353
{
354+
$this->scope->method('getValue')
355+
->willReturnCallback([$this, 'scopeConfigGetValue']);
356+
351357
$this->scope->expects($this->once())->method('isSetFlag')->willReturn(false);
352358

353359
$this->error->expects($this->once())->method('setCarrier')->with('dhl');
@@ -375,6 +381,9 @@ public function testCollectRatesFail()
375381
*/
376382
public function testRequestToShipment()
377383
{
384+
$this->scope->method('getValue')
385+
->willReturnCallback([$this, 'scopeConfigGetValue']);
386+
378387
$this->httpResponse->method('getBody')
379388
->willReturn(utf8_encode(file_get_contents(__DIR__ . '/_files/response_shipping_label.xml')));
380389
$this->xmlValidator->expects($this->any())->method('validate');
@@ -389,14 +398,14 @@ public function testRequestToShipment()
389398
'weight_units' => 'POUND',
390399
'weight' => '0.454000000001',
391400
'customs_value' => '10.00',
392-
'container' => \Magento\Dhl\Model\Carrier::DHL_CONTENT_TYPE_NON_DOC,
401+
'container' => Carrier::DHL_CONTENT_TYPE_NON_DOC,
393402
],
394403
'items' => [
395404
'item1' => [
396405
'name' => 'item_name',
397406
],
398407
],
399-
]
408+
],
400409
];
401410

402411
$order = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
@@ -432,20 +441,75 @@ public function testRequestToShipment()
432441
}
433442

434443
/**
435-
* Data provider to testRequestToShipment
444+
* Test that shipping label request for origin country from AP region doesn't contain restricted fields.
436445
*
437-
* @return array
446+
* @return void
438447
*/
439-
public function requestToShipmentDataProvider()
448+
public function testShippingLabelRequestForAsiaPacificRegion()
440449
{
441-
return [
442-
[
443-
'GB'
450+
$this->scope->method('getValue')
451+
->willReturnMap(
452+
[
453+
['shipping/origin/country_id', ScopeInterface::SCOPE_STORE, null, 'SG'],
454+
['carriers/dhl/gateway_url', ScopeInterface::SCOPE_STORE, null, 'https://xmlpi-ea.dhl.com'],
455+
]
456+
);
457+
458+
$this->httpResponse->method('getBody')
459+
->willReturn(utf8_encode(file_get_contents(__DIR__ . '/_files/response_shipping_label.xml')));
460+
461+
$packages = [
462+
'package' => [
463+
'params' => [
464+
'width' => '1',
465+
'length' => '1',
466+
'height' => '1',
467+
'dimension_units' => 'INCH',
468+
'weight_units' => 'POUND',
469+
'weight' => '0.45',
470+
'customs_value' => '10.00',
471+
'container' => Carrier::DHL_CONTENT_TYPE_NON_DOC,
472+
],
473+
'items' => [
474+
'item1' => [
475+
'name' => 'item_name',
476+
],
477+
],
444478
],
445-
[
446-
null
447-
]
448479
];
480+
481+
$this->request->method('getPackages')->willReturn($packages);
482+
$this->request->method('getOrigCountryId')->willReturn('SG');
483+
$this->request->method('setPackages')->willReturnSelf();
484+
$this->request->method('setPackageWeight')->willReturnSelf();
485+
$this->request->method('setPackageValue')->willReturnSelf();
486+
$this->request->method('setValueWithDiscount')->willReturnSelf();
487+
$this->request->method('setPackageCustomsValue')->willReturnSelf();
488+
489+
$result = $this->model->requestToShipment($this->request);
490+
491+
$reflectionClass = new \ReflectionObject($this->httpClient);
492+
$rawPostData = $reflectionClass->getProperty('raw_post_data');
493+
$rawPostData->setAccessible(true);
494+
495+
$this->assertNotNull($result);
496+
$requestXml = $rawPostData->getValue($this->httpClient);
497+
498+
$this->assertNotContains(
499+
'NewShipper',
500+
$requestXml,
501+
'NewShipper is restricted field for AP region'
502+
);
503+
$this->assertNotContains(
504+
'Division',
505+
$requestXml,
506+
'Division is restricted field for AP region'
507+
);
508+
$this->assertNotContains(
509+
'RegisteredAccount',
510+
$requestXml,
511+
'RegisteredAccount is restricted field for AP region'
512+
);
449513
}
450514

451515
/**
@@ -466,7 +530,7 @@ public function dhlProductsDataProvider() : array
466530
{
467531
return [
468532
'doc' => [
469-
'docType' => \Magento\Dhl\Model\Carrier::DHL_CONTENT_TYPE_DOC,
533+
'docType' => Carrier::DHL_CONTENT_TYPE_DOC,
470534
'products' => [
471535
'2' => 'Easy shop',
472536
'5' => 'Sprintline',
@@ -488,10 +552,10 @@ public function dhlProductsDataProvider() : array
488552
'S' => 'Same day',
489553
'T' => 'Express 12:00',
490554
'X' => 'Express envelope',
491-
]
555+
],
492556
],
493557
'non-doc' => [
494-
'docType' => \Magento\Dhl\Model\Carrier::DHL_CONTENT_TYPE_NON_DOC,
558+
'docType' => Carrier::DHL_CONTENT_TYPE_NON_DOC,
495559
'products' => [
496560
'1' => 'Domestic express 12:00',
497561
'3' => 'Easy shop',
@@ -506,8 +570,8 @@ public function dhlProductsDataProvider() : array
506570
'M' => 'Express 10:30',
507571
'V' => 'Europack',
508572
'Y' => 'Express 12:00',
509-
]
510-
]
573+
],
574+
],
511575
];
512576
}
513577
}

0 commit comments

Comments
 (0)