Skip to content

Commit 84ada2c

Browse files
committed
Merge remote-tracking branch 'origin/2.3-develop-pr13' into MAGETWO-90327
# Conflicts: # app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php
2 parents 510a565 + 80a47b5 commit 84ada2c

File tree

11 files changed

+479
-118
lines changed

11 files changed

+479
-118
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: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Magento\Store\Model\Website;
3333
use PHPUnit_Framework_MockObject_MockObject as MockObject;
3434
use Psr\Log\LoggerInterface;
35+
use Magento\Store\Model\ScopeInterface;
3536

3637
/**
3738
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -115,8 +116,6 @@ protected function setUp()
115116
->getMock();
116117

117118
$this->scope = $this->getMockForAbstractClass(ScopeConfigInterface::class);
118-
$this->scope->method('getValue')
119-
->willReturnCallback([$this, 'scopeConfigGetValue']);
120119

121120
$xmlElFactory = $this->getXmlFactory();
122121
$rateFactory = $this->getRateFactory();
@@ -250,6 +249,9 @@ protected function _invokePrepareShippingLabelContent(\SimpleXMLElement $xml)
250249

251250
public function testCollectRates()
252251
{
252+
$this->scope->method('getValue')
253+
->willReturnCallback([$this, 'scopeConfigGetValue']);
254+
253255
$this->scope->method('isSetFlag')
254256
->willReturn(true);
255257

@@ -279,6 +281,9 @@ public function testCollectRates()
279281

280282
public function testCollectRatesErrorMessage()
281283
{
284+
$this->scope->method('getValue')
285+
->willReturnCallback([$this, 'scopeConfigGetValue']);
286+
282287
$this->scope->expects($this->once())->method('isSetFlag')->willReturn(false);
283288

284289
$this->error->expects($this->once())->method('setCarrier')->with('dhl');
@@ -306,6 +311,9 @@ public function testCollectRatesFail()
306311
*/
307312
public function testRequestToShipment()
308313
{
314+
$this->scope->method('getValue')
315+
->willReturnCallback([$this, 'scopeConfigGetValue']);
316+
309317
$this->httpResponse->method('getBody')
310318
->willReturn(utf8_encode(file_get_contents(__DIR__ . '/_files/response_shipping_label.xml')));
311319

@@ -326,7 +334,7 @@ public function testRequestToShipment()
326334
'name' => 'item_name',
327335
],
328336
],
329-
]
337+
],
330338
];
331339

332340
$order = $this->getMockBuilder(Order::class)
@@ -393,6 +401,78 @@ public function requestToShipmentDataProvider()
393401
]
394402
];
395403
}
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+
}
396476

397477
/**
398478
* @dataProvider dhlProductsDataProvider

0 commit comments

Comments
 (0)