From e6b279b815b80065fdb7a70ed0fea16d26960425 Mon Sep 17 00:00:00 2001 From: Graham Wharton Date: Fri, 30 Nov 2018 18:20:19 +0000 Subject: [PATCH 1/5] Updated label for Content Type configuration field. Changed Allowable Methods (Non Doc and Doc) to always be displayed no matter what the content type mode is. Changed the isDutiable function to only look at whether a shipment is domestic or not. Previously it would return dutiable for everything if the Content Type mode is non document (which causes problems for domestic shipments in Non Document mode). Fixes #19485 --- app/code/Magento/Dhl/Model/Carrier.php | 4 +--- app/code/Magento/Dhl/etc/adminhtml/system.xml | 13 ++++--------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/Dhl/Model/Carrier.php b/app/code/Magento/Dhl/Model/Carrier.php index 55df0748b1f06..731b1d9c7c201 100644 --- a/app/code/Magento/Dhl/Model/Carrier.php +++ b/app/code/Magento/Dhl/Model/Carrier.php @@ -1968,8 +1968,6 @@ protected function isDutiable($origCountryId, $destCountryId) { $this->_checkDomesticStatus($origCountryId, $destCountryId); - return - self::DHL_CONTENT_TYPE_NON_DOC == $this->getConfigData('content_type') - || !$this->_isDomestic; + return !$this->_isDomestic; } } diff --git a/app/code/Magento/Dhl/etc/adminhtml/system.xml b/app/code/Magento/Dhl/etc/adminhtml/system.xml index 91ed6c6568a70..f239e4f382bf1 100644 --- a/app/code/Magento/Dhl/etc/adminhtml/system.xml +++ b/app/code/Magento/Dhl/etc/adminhtml/system.xml @@ -32,7 +32,8 @@ - + + Whether to use Documents or NonDocuments service for non domestic shipments. (Shipments within the EU are classed as domestic) Magento\Dhl\Model\Source\Contenttype @@ -81,18 +82,12 @@ - + Magento\Dhl\Model\Source\Method\Doc - - D - - + Magento\Dhl\Model\Source\Method\Nondoc - - N - From ce7b5602466b47777cfa9de1cec31fa9f02ac644 Mon Sep 17 00:00:00 2001 From: gwharton <30697781+gwharton@users.noreply.github.com> Date: Fri, 30 Nov 2018 18:27:21 +0000 Subject: [PATCH 2/5] Fixed typo --- app/code/Magento/Dhl/etc/adminhtml/system.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Dhl/etc/adminhtml/system.xml b/app/code/Magento/Dhl/etc/adminhtml/system.xml index f239e4f382bf1..37b653225c7b9 100644 --- a/app/code/Magento/Dhl/etc/adminhtml/system.xml +++ b/app/code/Magento/Dhl/etc/adminhtml/system.xml @@ -86,7 +86,7 @@ Magento\Dhl\Model\Source\Method\Doc - + Magento\Dhl\Model\Source\Method\Nondoc From 49e26db2a7ab099258cdd9307ad572f5b8075333 Mon Sep 17 00:00:00 2001 From: Graham Wharton Date: Sun, 24 Feb 2019 16:30:14 +0000 Subject: [PATCH 3/5] Updated Carrier Test to be broadly inline with 2.3-develop. There are differences in the DHL API version that is used between 2.2 and 2.3 branches, therefore there had to be some modifications to the tests. Unfortunately it means it is difficult to readacross directly to 2.3 tests. --- .../Dhl/Test/Unit/Model/CarrierTest.php | 403 +++++++------ .../_files/apregion_shipment_request.xml | 85 +++ .../Dhl/Test/Unit/Model/_files/countries.xml | 58 +- .../Model/_files/dhl_quote_request_data.php | 48 ++ .../Unit/Model/_files/dhl_quote_response.xml | 530 ++++++++++++++++++ .../Model/_files/dhl_quote_response_rates.php | 31 + .../euregion_dutiable_shipment_request.xml | 89 +++ .../_files/euregion_shipment_request.xml | 85 +++ 8 files changed, 1119 insertions(+), 210 deletions(-) create mode 100644 app/code/Magento/Dhl/Test/Unit/Model/_files/apregion_shipment_request.xml create mode 100644 app/code/Magento/Dhl/Test/Unit/Model/_files/dhl_quote_request_data.php create mode 100644 app/code/Magento/Dhl/Test/Unit/Model/_files/dhl_quote_response.xml create mode 100644 app/code/Magento/Dhl/Test/Unit/Model/_files/dhl_quote_response_rates.php create mode 100644 app/code/Magento/Dhl/Test/Unit/Model/_files/euregion_dutiable_shipment_request.xml create mode 100644 app/code/Magento/Dhl/Test/Unit/Model/_files/euregion_shipment_request.xml diff --git a/app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php b/app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php index 949311bb65d05..8f90bac0b7f28 100644 --- a/app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php +++ b/app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Dhl\Test\Unit\Model; use Magento\Dhl\Model\Carrier; @@ -32,7 +33,6 @@ use Magento\Store\Model\Website; use PHPUnit_Framework_MockObject_MockObject as MockObject; use Psr\Log\LoggerInterface; -use Magento\Store\Model\ScopeInterface; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -79,11 +79,6 @@ class CarrierTest extends \PHPUnit\Framework\TestCase */ private $xmlValidator; - /** - * @var Request|MockObject - */ - private $request; - /** * @var LoggerInterface|MockObject */ @@ -96,35 +91,8 @@ protected function setUp() { $this->objectManager = new ObjectManager($this); - $this->request = $this->getMockBuilder(Request::class) - ->disableOriginalConstructor() - ->setMethods( - [ - 'getPackages', - 'getOrigCountryId', - 'setPackages', - 'setPackageWeight', - 'setPackageValue', - 'setValueWithDiscount', - 'setPackageCustomsValue', - 'setFreeMethodWeight', - 'getPackageWeight', - 'getFreeMethodWeight', - 'getOrderShipment', - ] - ) - ->getMock(); - $this->scope = $this->getMockForAbstractClass(ScopeConfigInterface::class); - $xmlElFactory = $this->getXmlFactory(); - $rateFactory = $this->getRateFactory(); - $rateMethodFactory = $this->getRateMethodFactory(); - $httpClientFactory = $this->getHttpClientFactory(); - $configReader = $this->getConfigReader(); - $readFactory = $this->getReadFactory(); - $storeManager = $this->getStoreManager(); - $this->error = $this->getMockBuilder(Error::class) ->setMethods(['setCarrier', 'setCarrierTitle', 'setErrorMessage']) ->getMock(); @@ -135,8 +103,6 @@ protected function setUp() $this->errorFactory->method('create') ->willReturn($this->error); - $carrierHelper = $this->getCarrierHelper(); - $this->xmlValidator = $this->getMockBuilder(XmlValidator::class) ->disableOriginalConstructor() ->getMock(); @@ -149,17 +115,17 @@ protected function setUp() 'scopeConfig' => $this->scope, 'xmlSecurity' => new Security(), 'logger' => $this->logger, - 'xmlElFactory' => $xmlElFactory, - 'rateFactory' => $rateFactory, + 'xmlElFactory' => $this->getXmlFactory(), + 'rateFactory' => $this->getRateFactory(), 'rateErrorFactory' => $this->errorFactory, - 'rateMethodFactory' => $rateMethodFactory, - 'httpClientFactory' => $httpClientFactory, - 'readFactory' => $readFactory, - 'storeManager' => $storeManager, - 'configReader' => $configReader, - 'carrierHelper' => $carrierHelper, + 'rateMethodFactory' => $this->getRateMethodFactory(), + 'httpClientFactory' => $this->getHttpClientFactory(), + 'readFactory' => $this->getReadFactory(), + 'storeManager' => $this->getStoreManager(), + 'configReader' => $this->getConfigReader(), + 'carrierHelper' => $this->getCarrierHelper(), 'data' => ['id' => 'dhl', 'store' => '1'], - 'xmlValidator' => $this->xmlValidator, + 'xmlValidator' => $this->xmlValidator ] ); } @@ -176,14 +142,14 @@ public function scopeConfigGetValue($path) 'carriers/dhl/shipment_days' => 'Mon,Tue,Wed,Thu,Fri,Sat', 'carriers/dhl/intl_shipment_days' => 'Mon,Tue,Wed,Thu,Fri,Sat', 'carriers/dhl/allowed_methods' => 'IE', - 'carriers/dhl/international_searvice' => 'IE', + 'carriers/dhl/international_service' => 'IE', 'carriers/dhl/gateway_url' => 'https://xmlpi-ea.dhl.com/XMLShippingServlet', 'carriers/dhl/id' => 'some ID', 'carriers/dhl/password' => 'some password', 'carriers/dhl/content_type' => 'N', 'carriers/dhl/nondoc_methods' => '1,3,4,8,P,Q,E,F,H,J,M,V,Y', 'carriers/dhl/showmethod' => 1, - 'carriers/dhl/title' => 'dhl Title', + 'carriers/dhl/title' => 'DHL Title', 'carriers/dhl/specificerrmsg' => 'dhl error message', 'carriers/dhl/unit_of_measure' => 'K', 'carriers/dhl/size' => '1', @@ -191,11 +157,16 @@ public function scopeConfigGetValue($path) 'carriers/dhl/width' => '1.6', 'carriers/dhl/depth' => '1.6', 'carriers/dhl/debug' => 1, - 'shipping/origin/country_id' => 'GB', + 'shipping/origin/country_id' => 'GB' ]; return isset($pathMap[$path]) ? $pathMap[$path] : null; } + /** + * Prepare shipping label content test + * + * @throws \ReflectionException + */ public function testPrepareShippingLabelContent() { $xml = simplexml_load_file( @@ -207,6 +178,8 @@ public function testPrepareShippingLabelContent() } /** + * Prepare shipping label content exception test + * * @dataProvider prepareShippingLabelContentExceptionDataProvider * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Unable to retrieve shipping label @@ -217,6 +190,8 @@ public function testPrepareShippingLabelContentException(\SimpleXMLElement $xml) } /** + * Prepare shipping label content exception data provider + * * @return array */ public function prepareShippingLabelContentExceptionDataProvider() @@ -236,8 +211,11 @@ public function prepareShippingLabelContentExceptionDataProvider() } /** + * Invoke prepare shipping label content + * * @param \SimpleXMLElement $xml * @return \Magento\Framework\DataObject + * @throws \ReflectionException */ protected function _invokePrepareShippingLabelContent(\SimpleXMLElement $xml) { @@ -247,8 +225,14 @@ protected function _invokePrepareShippingLabelContent(\SimpleXMLElement $xml) return $method->invoke($model, $xml); } + /** + * Tests that valid rates are returned when sending a quotes request. + */ public function testCollectRates() { + $requestData = require __DIR__ . '/_files/dhl_quote_request_data.php'; + $responseXml = file_get_contents(__DIR__ . '/_files/dhl_quote_response.xml'); + $this->scope->method('getValue') ->willReturnCallback([$this, 'scopeConfigGetValue']); @@ -256,29 +240,39 @@ public function testCollectRates() ->willReturn(true); $this->httpResponse->method('getBody') - ->willReturn(file_get_contents(__DIR__ . '/_files/success_dhl_response_rates.xml')); + ->willReturn($responseXml); - /** @var RateRequest $request */ - $request = $this->objectManager->getObject( - RateRequest::class, - require __DIR__ . '/_files/rates_request_data_dhl.php' - ); + $request = $this->objectManager->getObject(RateRequest::class, $requestData); $reflectionClass = new \ReflectionObject($this->httpClient); $rawPostData = $reflectionClass->getProperty('raw_post_data'); $rawPostData->setAccessible(true); - $this->logger->expects(self::once()) + $this->logger->expects($this->once()) ->method('debug') - ->with(self::stringContains('********')); + ->with($this->stringContains('********')); + + $expectedRates = require __DIR__ . '/_files/dhl_quote_response_rates.php'; + $actualRates = $this->model->collectRates($request)->getAllRates(); + + self::assertEquals(count($expectedRates), count($actualRates)); - self::assertNotEmpty($this->model->collectRates($request)->getAllRates()); - self::assertContains('18.223', $rawPostData->getValue($this->httpClient)); - self::assertContains('0.630', $rawPostData->getValue($this->httpClient)); - self::assertContains('0.630', $rawPostData->getValue($this->httpClient)); - self::assertContains('0.630', $rawPostData->getValue($this->httpClient)); + foreach ($actualRates as $i => $actualRate) { + $actualRate = $actualRate->getData(); + unset($actualRate['method_title']); + self::assertEquals($expectedRates[$i], $actualRate); + } + + $requestXml = $rawPostData->getValue($this->httpClient); + self::assertContains('18.223', $requestXml); + self::assertContains('0.630', $requestXml); + self::assertContains('0.630', $requestXml); + self::assertContains('0.630', $requestXml); } + /** + * Tests that an error is returned when attempting to collect rates for an inactive shipping method. + */ public function testCollectRatesErrorMessage() { $this->scope->method('getValue') @@ -296,26 +290,79 @@ public function testCollectRatesErrorMessage() $this->assertSame($this->error, $this->model->collectRates($request)); } - public function testCollectRatesFail() - { - $this->scope->expects($this->once())->method('isSetFlag')->willReturn(true); + /** + * Test request to shipment sends valid xml values. + * + * @dataProvider requestToShipmentDataProvider + * @param string $origCountryId + * @param string $expectedRegionCode + * @param string $destCountryId + * @throws \Magento\Framework\Exception\LocalizedException + * @throws \ReflectionException + */ + public function testRequestToShipment( + string $origCountryId, + string $expectedRegionCode, + string $destCountryId, + bool $dutiable + ) { + $scopeConfigValueMap = [ + ['carriers/dhl/account', 'store', null, '1234567890'], + ['carriers/dhl/gateway_url', 'store', null, 'https://xmlpi-ea.dhl.com/XMLShippingServlet'], + ['carriers/dhl/id', 'store', null, 'some ID'], + ['carriers/dhl/password', 'store', null, 'some password'], + ['carriers/dhl/content_type', 'store', null, 'N'], + ['carriers/dhl/nondoc_methods', 'store', null, '1,3,4,8,P,Q,E,F,H,J,M,V,Y'], + ['shipping/origin/country_id', 'store', null, $origCountryId], + ]; - $request = new RateRequest(); - $request->setPackageWeight(1); + $this->scope->method('getValue') + ->willReturnMap($scopeConfigValueMap); - $this->assertFalse(false, $this->model->collectRates($request)); + $this->httpResponse->method('getBody') + ->willReturn(utf8_encode(file_get_contents(__DIR__ . '/_files/response_shipping_label.xml'))); + + $request = $this->getRequest($origCountryId, $destCountryId); + + $this->logger->method('debug') + ->with($this->stringContains('********')); + + $result = $this->model->requestToShipment($request); + + $reflectionClass = new \ReflectionObject($this->httpClient); + $rawPostData = $reflectionClass->getProperty('raw_post_data'); + $rawPostData->setAccessible(true); + + $this->assertNotNull($result); + $requestXml = $rawPostData->getValue($this->httpClient); + $requestElement = new Element($requestXml); + + $this->assertXmlStringEqualsXmlString( + $this->getExpectedRequestXml($origCountryId, $destCountryId, $expectedRegionCode, $dutiable)->asXML(), + $requestElement->asXML() + ); } /** - * Test request to shipment sends valid xml values. + * Prepare and retrieve request object + * + * @param string $origCountryId + * @param string $destCountryId + * @return Request|MockObject */ - public function testRequestToShipment() + private function getRequest(string $origCountryId, string $destCountryId) { - $this->scope->method('getValue') - ->willReturnCallback([$this, 'scopeConfigGetValue']); + $order = $this->getMockBuilder(Order::class) + ->disableOriginalConstructor() + ->getMock(); + $order->method('getSubtotal') + ->willReturn('10.00'); - $this->httpResponse->method('getBody') - ->willReturn(utf8_encode(file_get_contents(__DIR__ . '/_files/response_shipping_label.xml'))); + $shipment = $this->getMockBuilder(Order\Shipment::class) + ->disableOriginalConstructor() + ->getMock(); + $shipment->method('getOrder') + ->willReturn($order); $packages = [ 'package' => [ @@ -334,130 +381,108 @@ public function testRequestToShipment() 'name' => 'item_name', ], ], - ] + ], ]; - $order = $this->getMockBuilder(Order::class) - ->disableOriginalConstructor() - ->getMock(); - $order->method('getSubtotal') - ->willReturn('10.00'); + $methods = [ + 'getPackages' => $packages, + 'getOrigCountryId' => $origCountryId, + 'getDestCountryId' => $destCountryId, + 'getShipperAddressCountryCode' => $origCountryId, + 'getRecipientAddressCountryCode' => $destCountryId, + 'setPackages' => null, + 'setPackageWeight' => null, + 'setPackageValue' => null, + 'setValueWithDiscount' => null, + 'setPackageCustomsValue' => null, + 'setFreeMethodWeight' => null, + 'getPackageWeight' => '0.454000000001', + 'getFreeMethodWeight' => '0.454000000001', + 'getOrderShipment' => $shipment, + ]; - $shipment = $this->getMockBuilder(Order\Shipment::class) + /** @var Request|MockObject $request */ + $request = $this->getMockBuilder(Request::class) ->disableOriginalConstructor() + ->setMethods(array_keys($methods)) ->getMock(); - $shipment->method('getOrder') - ->willReturn($order); - $this->request->method('getPackages') - ->willReturn($packages); - $this->request->method('getOrigCountryId') - ->willReturn('GB'); - $this->request->method('setPackages') - ->willReturnSelf(); - $this->request->method('setPackageWeight') - ->willReturnSelf(); - $this->request->method('setPackageValue') - ->willReturnSelf(); - $this->request->method('setValueWithDiscount') - ->willReturnSelf(); - $this->request->method('setPackageCustomsValue') - ->willReturnSelf(); - $this->request->method('setFreeMethodWeight') - ->willReturnSelf(); - $this->request->method('getPackageWeight') - ->willReturn('0.454000000001'); - $this->request->method('getFreeMethodWeight') - ->willReturn('0.454000000001'); - $this->request->method('getOrderShipment') - ->willReturn($shipment); + foreach ($methods as $method => $return) { + $return ? $request->method($method)->willReturn($return) : $request->method($method)->willReturnSelf(); + } - $this->logger->method('debug') - ->with(self::stringContains('********')); + return $request; + } - $result = $this->model->requestToShipment($this->request); + /** + * Prepare and retrieve expected request xml element + * + * @param string $origCountryId + * @param string $destCountryId + * @return Element + */ + private function getExpectedRequestXml( + string $origCountryId, + string $destCountryId, + string $regionCode, + bool $dutiable + ) { + $requestXmlPath = $regionCode === "EU" + ? ($dutiable ? '/_files/euregion_dutiable_shipment_request.xml' : '/_files/euregion_shipment_request.xml') + : '/_files/apregion_shipment_request.xml'; - $reflectionClass = new \ReflectionObject($this->httpClient); - $rawPostData = $reflectionClass->getProperty('raw_post_data'); - $rawPostData->setAccessible(true); + $expectedRequestElement = new Element(file_get_contents(__DIR__ . $requestXmlPath)); - $this->assertNotNull($result); - $this->assertContains('0.454', $rawPostData->getValue($this->httpClient)); + $expectedRequestElement->Consignee->CountryCode = $destCountryId; + $expectedRequestElement->Consignee->CountryName = $this->getCountryName($destCountryId); + + $expectedRequestElement->Shipper->CountryCode = $origCountryId; + $expectedRequestElement->Shipper->CountryName = $this->getCountryName($origCountryId); + + return $expectedRequestElement; } /** - * Test that shipping label request for origin country from AP region doesn't contain restricted fields. + * Get Country Name by Country Code + * + * @param string $countryCode + * @return string */ - public function testShippingLabelRequestForAsiaPacificRegion() + private function getCountryName($countryCode) { - $this->scope->method('getValue') - ->willReturnMap( - [ - ['shipping/origin/country_id', ScopeInterface::SCOPE_STORE, null, 'SG'], - ['carriers/dhl/gateway_url', ScopeInterface::SCOPE_STORE, null, 'https://xmlpi-ea.dhl.com'], - ] - ); - - $this->httpResponse->method('getBody') - ->willReturn(utf8_encode(file_get_contents(__DIR__ . '/_files/response_shipping_label.xml'))); + $countryNames = [ + 'US' => 'United States Of America', + 'SG' => 'Singapore', + 'GB' => 'United Kingdom', + 'DE' => 'Germany', + ]; + return $countryNames[$countryCode]; + } - $packages = [ - 'package' => [ - 'params' => [ - 'width' => '1', - 'length' => '1', - 'height' => '1', - 'dimension_units' => 'INCH', - 'weight_units' => 'POUND', - 'weight' => '0.45', - 'customs_value' => '10.00', - 'container' => Carrier::DHL_CONTENT_TYPE_NON_DOC, - ], - 'items' => [ - 'item1' => [ - 'name' => 'item_name', - ], - ], + /** + * Data provider to testRequestToShipment + * + * @return array + */ + public function requestToShipmentDataProvider() + { + return [ + [ + 'GB', 'EU', 'US', 1 + ], + [ + 'SG', 'AP', 'US', 0 + ], + [ + 'DE', 'EU', 'DE', 0 ] ]; - - $this->request->method('getPackages')->willReturn($packages); - $this->request->method('getOrigCountryId')->willReturn('SG'); - $this->request->method('setPackages')->willReturnSelf(); - $this->request->method('setPackageWeight')->willReturnSelf(); - $this->request->method('setPackageValue')->willReturnSelf(); - $this->request->method('setValueWithDiscount')->willReturnSelf(); - $this->request->method('setPackageCustomsValue')->willReturnSelf(); - - $result = $this->model->requestToShipment($this->request); - - $reflectionClass = new \ReflectionObject($this->httpClient); - $rawPostData = $reflectionClass->getProperty('raw_post_data'); - $rawPostData->setAccessible(true); - - $this->assertNotNull($result); - $requestXml = $rawPostData->getValue($this->httpClient); - - $this->assertNotContains( - 'NewShipper', - $requestXml, - 'NewShipper is restricted field for AP region' - ); - $this->assertNotContains( - 'Division', - $requestXml, - 'Division is restricted field for AP region' - ); - $this->assertNotContains( - 'RegisteredAccount', - $requestXml, - 'RegisteredAccount is restricted field for AP region' - ); } /** - * @dataProvider dhlProductsDataProvider + * Get DHL products test * + * @dataProvider dhlProductsDataProvider * @param string $docType * @param array $products */ @@ -467,6 +492,8 @@ public function testGetDhlProducts(string $docType, array $products) } /** + * DHL products data provider + * * @return array */ public function dhlProductsDataProvider() : array @@ -576,19 +603,25 @@ private function getRateMethodFactory(): MockObject ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $rateMethod = $this->getMockBuilder(Method::class) - ->disableOriginalConstructor() - ->setMethods(['setPrice']) - ->getMock(); - $rateMethod->method('setPrice') - ->willReturnSelf(); + $rateMethodFactory->method('create') - ->willReturn($rateMethod); + ->willReturnCallback(function () { + $rateMethod = $this->getMockBuilder(Method::class) + ->disableOriginalConstructor() + ->setMethods(['setPrice']) + ->getMock(); + $rateMethod->method('setPrice') + ->willReturnSelf(); + + return $rateMethod; + }); return $rateMethodFactory; } /** + * Get config reader + * * @return MockObject */ private function getConfigReader(): MockObject @@ -603,6 +636,8 @@ private function getConfigReader(): MockObject } /** + * Get read factory + * * @return MockObject */ private function getReadFactory(): MockObject @@ -621,6 +656,8 @@ private function getReadFactory(): MockObject } /** + * Get store manager + * * @return MockObject */ private function getStoreManager(): MockObject @@ -642,6 +679,8 @@ private function getStoreManager(): MockObject } /** + * Get carrier helper + * * @return CarrierHelper */ private function getCarrierHelper(): CarrierHelper @@ -660,6 +699,8 @@ private function getCarrierHelper(): CarrierHelper } /** + * Get HTTP client factory + * * @return MockObject */ private function getHttpClientFactory(): MockObject diff --git a/app/code/Magento/Dhl/Test/Unit/Model/_files/apregion_shipment_request.xml b/app/code/Magento/Dhl/Test/Unit/Model/_files/apregion_shipment_request.xml new file mode 100644 index 0000000000000..91f8372cd8dbb --- /dev/null +++ b/app/code/Magento/Dhl/Test/Unit/Model/_files/apregion_shipment_request.xml @@ -0,0 +1,85 @@ + + + + + + some ID + some password + + + EN + Y + + 1234567890 + S + 1234567890 + S + 1234567890 + + + + + + + + + + + + + + + 1 + + + 10.00 + USD + + + shipment reference + St + + + 1 + USD + + + 1 + CP + 0.5 + 3 + 3 + 3 + item_name + + + CP + 0.454 + C + K + + + DD + + DHL Parcel TEST + + + 1234567890 + + + + + + + + + + + + PDF + diff --git a/app/code/Magento/Dhl/Test/Unit/Model/_files/countries.xml b/app/code/Magento/Dhl/Test/Unit/Model/_files/countries.xml index 3f28111f229d1..792465ce45942 100644 --- a/app/code/Magento/Dhl/Test/Unit/Model/_files/countries.xml +++ b/app/code/Magento/Dhl/Test/Unit/Model/_files/countries.xml @@ -1,4 +1,4 @@ - + + + + + + 2014-01-09T12:13:29.498+00:00 + EvgeniyUSA + + + + + + NUQ + NUQ + + + BER + BER + + E + E + EXPRESS 9:00 + EXPRESS 9:00 NONDOC + TD + N + Y + 2014-01-09 + PT16H15M + PT15H15M + USD + 1.000000 + 42.060 + 0.000 + 2 + 0 + 0 + + 2014-01-13 11:59:00 + +00:00 + + PT9H + 2.205 + LB + 4 + 1 + + FF + FF + FUEL SURCHARGE + FUEL SURCHARGE + SCH + USD + 3.790 + + 3.790 + USD + BILLC + + + 3.790 + USD + PULCL + + + 3.790 + USD + BASEC + + + 2014-01-09 + 45.850 + 0.000 + + USD + BILLC + 42.060 + 45.850 + 0.000 + 0.000 + + + USD + PULCL + 42.060 + 45.850 + 0.000 + 0.000 + + + USD + BASEC + 42.060 + 45.850 + 0.000 + 0.000 + + 09:00:00 + 17:00:00 + PT1H + + + + NUQ + NUQ + + + BER + BER + + Q + Q + MEDICAL EXPRESS + MEDICAL EXPRESS + TD + Y + N + 2014-01-09 + PT16H15M + PT15H15M + USD + 1.000000 + 32.350 + 0.000 + 2 + 0 + 0 + + 2014-01-13 11:59:00 + +00:00 + + PT9H + 2.205 + LB + 4 + 1 + + FF + FF + FUEL SURCHARGE + FUEL SURCHARGE + SCH + USD + 2.910 + + 2.910 + USD + BILLC + + + 2.910 + USD + PULCL + + + 2.910 + USD + BASEC + + + 2014-01-09 + 35.260 + 0.000 + + USD + BILLC + 32.350 + 35.260 + 0.000 + 0.000 + + + USD + PULCL + 32.350 + 35.260 + 0.000 + 0.000 + + + USD + BASEC + 32.350 + 35.260 + 0.000 + 0.000 + + 09:00:00 + 17:00:00 + PT1H + + + + NUQ + NUQ + + + BER + BER + + Y + Y + EXPRESS 12:00 + EXPRESS 12:00 NONDOC + TD + N + Y + 2014-01-09 + PT16H15M + PT15H15M + USD + 1.000000 + 34.290 + 0.000 + 2 + 0 + 0 + + 2014-01-13 11:59:00 + +00:00 + + PT12H + 2.205 + LB + 4 + 1 + + FF + FF + FUEL SURCHARGE + FUEL SURCHARGE + SCH + USD + 3.090 + + 3.090 + USD + BILLC + + + 3.090 + USD + PULCL + + + 3.090 + USD + BASEC + + + 2014-01-09 + 37.380 + 0.000 + + USD + BILLC + 34.290 + 37.380 + 0.000 + 0.000 + + + USD + PULCL + 34.290 + 37.380 + 0.000 + 0.000 + + + USD + BASEC + 34.290 + 37.380 + 0.000 + 0.000 + + 09:00:00 + 17:00:00 + PT1H + + + + NUQ + NUQ + + + BER + BER + + 3 + 3 + B2C + EXPRESS WORLDWIDE (B2C) + TD + Y + N + 2014-01-09 + PT16H15M + PT15H15M + 1.000000 + 0 + 0.000 + 2 + 0 + 0 + + 2014-01-13 11:59:00 + +00:00 + + PT23H59M + 2.205 + LB + 4 + 1 + 2014-01-09 + 0.000 + 0.000 + + BILLC + 0 + 0.000 + 0.000 + 0.000 + + + USD + PULCL + 0 + 0.000 + 0.000 + 0.000 + + + USD + BASEC + 0 + 0.000 + 0.000 + 0.000 + + 09:00:00 + 17:00:00 + PT1H + + + + NUQ + NUQ + + + BER + BER + + P + P + EXPRESS WORLDWIDE + EXPRESS WORLDWIDE NONDOC + TD + N + Y + 2014-01-09 + PT16H15M + PT15H15M + USD + 1.000000 + 32.350 + 0.000 + 2 + 0 + 0 + + 2014-01-13 11:59:00 + +00:00 + + PT23H59M + 2.205 + LB + 4 + 1 + + FF + FF + FUEL SURCHARGE + FUEL SURCHARGE + SCH + USD + 2.910 + + 2.910 + USD + BILLC + + + 2.910 + USD + PULCL + + + 2.910 + USD + BASEC + + + 2014-01-09 + 35.260 + 0.000 + + USD + BILLC + 32.350 + 35.260 + 0.000 + 0.000 + + + USD + PULCL + 32.350 + 35.260 + 0.000 + 0.000 + + + USD + BASEC + 32.350 + 35.260 + 0.000 + 0.000 + + 09:00:00 + 17:00:00 + PT1H + + + + + E + + E + EXPRESS 9:00 + EXPRESS 9:00 NONDOC + TD + N + Y + + + FF + FUEL SURCHARGE + FUEL SURCHARGE + SCH + N + + + + Q + + Q + MEDICAL EXPRESS + MEDICAL EXPRESS + TD + Y + N + + + FF + FUEL SURCHARGE + FUEL SURCHARGE + SCH + N + + + + Y + + Y + EXPRESS 12:00 + EXPRESS 12:00 NONDOC + TD + N + Y + + + FF + FUEL SURCHARGE + FUEL SURCHARGE + SCH + N + + + + 3 + + 3 + B2C + EXPRESS WORLDWIDE (B2C) + TD + Y + N + + + + P + + P + EXPRESS WORLDWIDE + EXPRESS WORLDWIDE NONDOC + TD + N + Y + + + FF + FUEL SURCHARGE + FUEL SURCHARGE + SCH + N + + + + + diff --git a/app/code/Magento/Dhl/Test/Unit/Model/_files/dhl_quote_response_rates.php b/app/code/Magento/Dhl/Test/Unit/Model/_files/dhl_quote_response_rates.php new file mode 100644 index 0000000000000..ddd7b2e4f97c5 --- /dev/null +++ b/app/code/Magento/Dhl/Test/Unit/Model/_files/dhl_quote_response_rates.php @@ -0,0 +1,31 @@ + 'dhl', + 'carrier_title' => 'DHL Title', + 'cost' => 45.85, + 'method' => 'E' + ], + [ + 'carrier' => 'dhl', + 'carrier_title' => 'DHL Title', + 'cost' => 35.26, + 'method' => 'Q' + ], + [ + 'carrier' => 'dhl', + 'carrier_title' => 'DHL Title', + 'cost' => 37.38, + 'method' => 'Y' + ], + [ + 'carrier' => 'dhl', + 'carrier_title' => 'DHL Title', + 'cost' => 35.26, + 'method' => 'P' + ] +]; diff --git a/app/code/Magento/Dhl/Test/Unit/Model/_files/euregion_dutiable_shipment_request.xml b/app/code/Magento/Dhl/Test/Unit/Model/_files/euregion_dutiable_shipment_request.xml new file mode 100644 index 0000000000000..50a8c1b7a02a9 --- /dev/null +++ b/app/code/Magento/Dhl/Test/Unit/Model/_files/euregion_dutiable_shipment_request.xml @@ -0,0 +1,89 @@ + + + + + + some ID + some password + + + N + EN + Y + + 1234567890 + S + 1234567890 + S + 1234567890 + + + + + + + + + + + + + + + + 1 + + + 10.00 + USD + + + shipment reference + St + + + 1 + USD + + + 1 + CP + 0.5 + 3 + 3 + 3 + item_name + + + CP + 0.454 + C + K + + + DD + + DHL Parcel TEST + + + 1234567890 + + 1234567890 + + + + + + + + + + + + PDF + \ No newline at end of file diff --git a/app/code/Magento/Dhl/Test/Unit/Model/_files/euregion_shipment_request.xml b/app/code/Magento/Dhl/Test/Unit/Model/_files/euregion_shipment_request.xml new file mode 100644 index 0000000000000..6dccea89f8f6a --- /dev/null +++ b/app/code/Magento/Dhl/Test/Unit/Model/_files/euregion_shipment_request.xml @@ -0,0 +1,85 @@ + + + + + + some ID + some password + + + N + EN + Y + + 1234567890 + S + 1234567890 + S + 1234567890 + + + + + + + + + + + + + + + + 1 + + + shipment reference + St + + + 1 + USD + + + 1 + CP + 0.5 + 3 + 3 + 3 + item_name + + + CP + 0.454 + C + K + + + DD + + DHL Parcel TEST + + + 1234567890 + + 1234567890 + + + + + + + + + + + + PDF + \ No newline at end of file From a497c95712e1682904d62b80525efd3bce380fef Mon Sep 17 00:00:00 2001 From: gwharton <30697781+gwharton@users.noreply.github.com> Date: Sun, 24 Feb 2019 17:31:45 +0000 Subject: [PATCH 4/5] Reduced excessive variable lengths --- app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php b/app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php index 8f90bac0b7f28..681bd089b556b 100644 --- a/app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php +++ b/app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php @@ -431,15 +431,15 @@ private function getExpectedRequestXml( ? ($dutiable ? '/_files/euregion_dutiable_shipment_request.xml' : '/_files/euregion_shipment_request.xml') : '/_files/apregion_shipment_request.xml'; - $expectedRequestElement = new Element(file_get_contents(__DIR__ . $requestXmlPath)); + $requestElement = new Element(file_get_contents(__DIR__ . $requestXmlPath)); - $expectedRequestElement->Consignee->CountryCode = $destCountryId; - $expectedRequestElement->Consignee->CountryName = $this->getCountryName($destCountryId); + $requestElement->Consignee->CountryCode = $destCountryId; + $requestElement->Consignee->CountryName = $this->getCountryName($destCountryId); - $expectedRequestElement->Shipper->CountryCode = $origCountryId; - $expectedRequestElement->Shipper->CountryName = $this->getCountryName($origCountryId); + $requestElement->Shipper->CountryCode = $origCountryId; + $requestElement->Shipper->CountryName = $this->getCountryName($origCountryId); - return $expectedRequestElement; + return $requestElement; } /** From 5557b9d06c169fbd8b38f7c598e51c8c49e94739 Mon Sep 17 00:00:00 2001 From: gwharton <30697781+gwharton@users.noreply.github.com> Date: Sun, 24 Feb 2019 17:34:22 +0000 Subject: [PATCH 5/5] Reduced incorrect indentation on function declaration --- app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php b/app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php index 681bd089b556b..41e545412aea1 100644 --- a/app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php +++ b/app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php @@ -422,10 +422,10 @@ private function getRequest(string $origCountryId, string $destCountryId) * @return Element */ private function getExpectedRequestXml( - string $origCountryId, - string $destCountryId, - string $regionCode, - bool $dutiable + string $origCountryId, + string $destCountryId, + string $regionCode, + bool $dutiable ) { $requestXmlPath = $regionCode === "EU" ? ($dutiable ? '/_files/euregion_dutiable_shipment_request.xml' : '/_files/euregion_shipment_request.xml')