From ecf97bce95c9862fecd5349cef06738861b60d32 Mon Sep 17 00:00:00 2001 From: Patrick McLain Date: Tue, 20 Aug 2019 20:25:27 -0400 Subject: [PATCH] Introduce mock for UPS shipping testing Fixes magento/graphql-ce#815 --- .../Magento/TestModuleUps/Model/Carrier.php | 111 ++++++++++++++++++ .../Model/MockResponseBodyLoader.php | 63 ++++++++++ .../TestModuleUps/_files/mock_response_ca.txt | 5 + .../TestModuleUps/_files/mock_response_us.txt | 5 + .../_files/Magento/TestModuleUps/etc/di.xml | 10 ++ .../Magento/TestModuleUps/etc/module.xml | 14 +++ .../Magento/TestModuleUps/registration.php | 13 ++ 7 files changed, 221 insertions(+) create mode 100644 dev/tests/api-functional/_files/Magento/TestModuleUps/Model/Carrier.php create mode 100644 dev/tests/api-functional/_files/Magento/TestModuleUps/Model/MockResponseBodyLoader.php create mode 100644 dev/tests/api-functional/_files/Magento/TestModuleUps/_files/mock_response_ca.txt create mode 100644 dev/tests/api-functional/_files/Magento/TestModuleUps/_files/mock_response_us.txt create mode 100644 dev/tests/api-functional/_files/Magento/TestModuleUps/etc/di.xml create mode 100644 dev/tests/api-functional/_files/Magento/TestModuleUps/etc/module.xml create mode 100644 dev/tests/api-functional/_files/Magento/TestModuleUps/registration.php diff --git a/dev/tests/api-functional/_files/Magento/TestModuleUps/Model/Carrier.php b/dev/tests/api-functional/_files/Magento/TestModuleUps/Model/Carrier.php new file mode 100644 index 0000000000000..b3c3c124cfe47 --- /dev/null +++ b/dev/tests/api-functional/_files/Magento/TestModuleUps/Model/Carrier.php @@ -0,0 +1,111 @@ +mockResponseLoader = $mockResponseLoader; + } + + /** + * @inheritdoc + */ + protected function _getCgiQuotes() + { + $responseBody = $this->mockResponseLoader->loadForRequest($this->_rawRequest->getDestCountry()); + return $this->_parseCgiResponse($responseBody); + } +} diff --git a/dev/tests/api-functional/_files/Magento/TestModuleUps/Model/MockResponseBodyLoader.php b/dev/tests/api-functional/_files/Magento/TestModuleUps/Model/MockResponseBodyLoader.php new file mode 100644 index 0000000000000..fe1750fa648f3 --- /dev/null +++ b/dev/tests/api-functional/_files/Magento/TestModuleUps/Model/MockResponseBodyLoader.php @@ -0,0 +1,63 @@ +moduleDirectory = $moduleDirectory; + $this->fileIo = $fileIo; + } + + /** + * Loads mock cgi response body for a given country + * + * @param string $country + * @return string + * @throws NotFoundException + */ + public function loadForRequest(string $country): string + { + $country = strtolower($country); + $moduleDir = $this->moduleDirectory->getDir('Magento_TestModuleUps'); + + $responsePath = sprintf(static::RESPONSE_FILE_PATTERN, $moduleDir, $country); + + if (!$this->fileIo->fileExists($responsePath)) { + throw new NotFoundException(__('%1 is not a valid destination country.', $country)); + } + + return $this->fileIo->read($responsePath); + } +} diff --git a/dev/tests/api-functional/_files/Magento/TestModuleUps/_files/mock_response_ca.txt b/dev/tests/api-functional/_files/Magento/TestModuleUps/_files/mock_response_ca.txt new file mode 100644 index 0000000000000..eca3e47a7e138 --- /dev/null +++ b/dev/tests/api-functional/_files/Magento/TestModuleUps/_files/mock_response_ca.txt @@ -0,0 +1,5 @@ +UPSOnLine4%XDM%90034%US%M4L 1V3%CA%081%1%138.17%0.00%138.17%-1% +4%XPR%90034%US%M4L 1V3%CA%081%1%95.07%0.00%95.07%12:00 P.M.% +4%WXS%90034%US%M4L 1V3%CA%481%1%93.99%0.00%93.99%-1% +4%XPD%90034%US%M4L 1V3%CA%071%1%85.85%0.00%85.85%-1% +4%STD%90034%US%M4L 1V3%CA%053%1%27.08%0.00%27.08%-1% \ No newline at end of file diff --git a/dev/tests/api-functional/_files/Magento/TestModuleUps/_files/mock_response_us.txt b/dev/tests/api-functional/_files/Magento/TestModuleUps/_files/mock_response_us.txt new file mode 100644 index 0000000000000..56f73dbd93a5a --- /dev/null +++ b/dev/tests/api-functional/_files/Magento/TestModuleUps/_files/mock_response_us.txt @@ -0,0 +1,5 @@ +UPSOnLine4%1DM%90034%US%75477%US%106%1%112.44%0.00%112.44%12:00 P.M.% +4%1DA%90034%US%75477%US%106%1%80.42%0.00%80.42%End of Day% +4%2DA%90034%US%75477%US%206%1%39.05%0.00%39.05%End of Day% +4%3DS%90034%US%75477%US%306%1%31.69%0.00%31.69%End of Day% +4%GND%90034%US%75477%US%006%1%15.61%0.00%15.61%End of Day% \ No newline at end of file diff --git a/dev/tests/api-functional/_files/Magento/TestModuleUps/etc/di.xml b/dev/tests/api-functional/_files/Magento/TestModuleUps/etc/di.xml new file mode 100644 index 0000000000000..28c2fa8e4d45f --- /dev/null +++ b/dev/tests/api-functional/_files/Magento/TestModuleUps/etc/di.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/dev/tests/api-functional/_files/Magento/TestModuleUps/etc/module.xml b/dev/tests/api-functional/_files/Magento/TestModuleUps/etc/module.xml new file mode 100644 index 0000000000000..77d1d15f78d7d --- /dev/null +++ b/dev/tests/api-functional/_files/Magento/TestModuleUps/etc/module.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/dev/tests/api-functional/_files/Magento/TestModuleUps/registration.php b/dev/tests/api-functional/_files/Magento/TestModuleUps/registration.php new file mode 100644 index 0000000000000..0668a2522e874 --- /dev/null +++ b/dev/tests/api-functional/_files/Magento/TestModuleUps/registration.php @@ -0,0 +1,13 @@ +getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleUps') === null) { + ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleUps', __DIR__); +}