Skip to content

Commit 547ab18

Browse files
committed
Merge remote-tracking branch 'mpi/MC-23093' into Chaika-PR-2019-11-19
2 parents 148d6cc + 82c6446 commit 547ab18

File tree

3 files changed

+107
-33
lines changed

3 files changed

+107
-33
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ protected function _getDimension($dimension, $configWeightUnit = false)
940940
);
941941
}
942942

943-
return sprintf('%.3f', $dimension);
943+
return round($dimension, 3);
944944
}
945945

946946
/**

app/code/Magento/Dhl/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
3333
<divide_order_weight>1</divide_order_weight>
3434
<unit_of_measure>K</unit_of_measure>
35-
<size>R</size>
35+
<size>0</size>
3636
<handling_type>F</handling_type>
3737
<handling_action>O</handling_action>
3838
<shipment_days>Mon,Tue,Wed,Thu,Fri</shipment_days>

dev/tests/integration/testsuite/Magento/Dhl/Model/CarrierTest.php

Lines changed: 105 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
use Magento\Quote\Model\Quote\Address\RateRequest;
1616
use Magento\Shipping\Model\Shipment\Request;
1717
use Magento\Shipping\Model\Tracking\Result\Status;
18+
use Magento\Store\Model\ScopeInterface;
1819
use Magento\TestFramework\Helper\Bootstrap;
1920
use Magento\TestFramework\HTTP\AsyncClientInterfaceMock;
2021
use Magento\Shipping\Model\Simplexml\Element as ShippingElement;
2122

2223
/**
2324
* Test for DHL integration.
25+
*
26+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2427
*/
2528
class CarrierTest extends \PHPUnit\Framework\TestCase
2629
{
@@ -411,7 +414,108 @@ private function getExpectedLabelRequestXml(
411414
*/
412415
public function testCollectRates()
413416
{
414-
$requestData = [
417+
$requestData = $this->getRequestData();
418+
//phpcs:disable Magento2.Functions.DiscouragedFunction
419+
$response = new Response(
420+
200,
421+
[],
422+
file_get_contents(__DIR__ . '/../_files/dhl_quote_response.xml')
423+
);
424+
//phpcs:enable Magento2.Functions.DiscouragedFunction
425+
$this->httpClient->nextResponses(array_fill(0, Carrier::UNAVAILABLE_DATE_LOOK_FORWARD + 1, $response));
426+
/** @var RateRequest $request */
427+
$request = Bootstrap::getObjectManager()->create(RateRequest::class, $requestData);
428+
$expectedRates = [
429+
['carrier' => 'dhl', 'carrier_title' => 'DHL Title', 'cost' => 45.85, 'method' => 'E', 'price' => 45.85],
430+
['carrier' => 'dhl', 'carrier_title' => 'DHL Title', 'cost' => 35.26, 'method' => 'Q', 'price' => 35.26],
431+
['carrier' => 'dhl', 'carrier_title' => 'DHL Title', 'cost' => 37.38, 'method' => 'Y', 'price' => 37.38],
432+
['carrier' => 'dhl', 'carrier_title' => 'DHL Title', 'cost' => 35.26, 'method' => 'P', 'price' => 35.26]
433+
];
434+
435+
$actualRates = $this->dhlCarrier->collectRates($request)->getAllRates();
436+
437+
self::assertEquals(count($expectedRates), count($actualRates));
438+
foreach ($actualRates as $i => $actualRate) {
439+
$actualRate = $actualRate->getData();
440+
unset($actualRate['method_title']);
441+
self::assertEquals($expectedRates[$i], $actualRate);
442+
}
443+
$requestXml = $this->httpClient->getLastRequest()->getBody();
444+
self::assertContains('<Weight>18.223</Weight>', $requestXml);
445+
self::assertContains('<Height>0.63</Height>', $requestXml);
446+
self::assertContains('<Width>0.63</Width>', $requestXml);
447+
self::assertContains('<Depth>0.63</Depth>', $requestXml);
448+
}
449+
450+
/**
451+
* Tests that quotes request doesn't contain dimensions when it shouldn't.
452+
*
453+
* @param string|null $size
454+
* @param string|null $height
455+
* @param string|null $width
456+
* @param string|null $depth
457+
* @magentoConfigFixture default_store carriers/dhl/active 1
458+
* @dataProvider collectRatesWithoutDimensionsDataProvider
459+
*/
460+
public function testCollectRatesWithoutDimensions(?string $size, ?string $height, ?string $width, ?string $depth)
461+
{
462+
$requestData = $this->getRequestData();
463+
$this->setDhlConfig(['size' => $size, 'height' => $height, 'width' => $width, 'depth' => $depth]);
464+
465+
/** @var RateRequest $request */
466+
$request = Bootstrap::getObjectManager()->create(RateRequest::class, $requestData);
467+
$this->dhlCarrier = Bootstrap::getObjectManager()->create(Carrier::class);
468+
$this->dhlCarrier->collectRates($request)->getAllRates();
469+
470+
$requestXml = $this->httpClient->getLastRequest()->getBody();
471+
$this->assertNotContains('<Width>', $requestXml);
472+
$this->assertNotContains('<Height>', $requestXml);
473+
$this->assertNotContains('<Depth>', $requestXml);
474+
475+
$this->config->reinit();
476+
}
477+
478+
/**
479+
* @return array
480+
*/
481+
public function collectRatesWithoutDimensionsDataProvider()
482+
{
483+
return [
484+
['size' => '0', 'height' => '1.1', 'width' => '0.6', 'depth' => '0.7'],
485+
['size' => '1', 'height' => '', 'width' => '', 'depth' => ''],
486+
['size' => null, 'height' => '1.1', 'width' => '0.6', 'depth' => '0.7'],
487+
['size' => '1', 'height' => '1', 'width' => '', 'depth' => ''],
488+
['size' => null, 'height' => null, 'width' => null, 'depth' => null],
489+
];
490+
}
491+
492+
/**
493+
* Sets DHL config value.
494+
*
495+
* @param array $params
496+
* @return void
497+
*/
498+
private function setDhlConfig(array $params)
499+
{
500+
foreach ($params as $name => $val) {
501+
if ($val !== null) {
502+
$this->config->setValue(
503+
'carriers/dhl/' . $name,
504+
$val,
505+
ScopeInterface::SCOPE_STORE
506+
);
507+
}
508+
}
509+
}
510+
511+
/**
512+
* Returns request data.
513+
*
514+
* @return array
515+
*/
516+
private function getRequestData(): array
517+
{
518+
return [
415519
'data' => [
416520
'dest_country_id' => 'DE',
417521
'dest_region_id' => '82',
@@ -454,35 +558,5 @@ public function testCollectRates()
454558
'all_items' => [],
455559
]
456560
];
457-
//phpcs:disable Magento2.Functions.DiscouragedFunction
458-
$response = new Response(
459-
200,
460-
[],
461-
file_get_contents(__DIR__ . '/../_files/dhl_quote_response.xml')
462-
);
463-
//phpcs:enable Magento2.Functions.DiscouragedFunction
464-
$this->httpClient->nextResponses(array_fill(0, Carrier::UNAVAILABLE_DATE_LOOK_FORWARD + 1, $response));
465-
/** @var RateRequest $request */
466-
$request = Bootstrap::getObjectManager()->create(RateRequest::class, $requestData);
467-
$expectedRates = [
468-
['carrier' => 'dhl', 'carrier_title' => 'DHL Title', 'cost' => 45.85, 'method' => 'E', 'price' => 45.85],
469-
['carrier' => 'dhl', 'carrier_title' => 'DHL Title', 'cost' => 35.26, 'method' => 'Q', 'price' => 35.26],
470-
['carrier' => 'dhl', 'carrier_title' => 'DHL Title', 'cost' => 37.38, 'method' => 'Y', 'price' => 37.38],
471-
['carrier' => 'dhl', 'carrier_title' => 'DHL Title', 'cost' => 35.26, 'method' => 'P', 'price' => 35.26]
472-
];
473-
474-
$actualRates = $this->dhlCarrier->collectRates($request)->getAllRates();
475-
476-
self::assertEquals(count($expectedRates), count($actualRates));
477-
foreach ($actualRates as $i => $actualRate) {
478-
$actualRate = $actualRate->getData();
479-
unset($actualRate['method_title']);
480-
self::assertEquals($expectedRates[$i], $actualRate);
481-
}
482-
$requestXml = $this->httpClient->getLastRequest()->getBody();
483-
self::assertContains('<Weight>18.223</Weight>', $requestXml);
484-
self::assertContains('<Height>0.630</Height>', $requestXml);
485-
self::assertContains('<Width>0.630</Width>', $requestXml);
486-
self::assertContains('<Depth>0.630</Depth>', $requestXml);
487561
}
488562
}

0 commit comments

Comments
 (0)