OrderInterfaceBuilderTest.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Model;
  6. use Magento\Customer\Model\Address;
  7. use Magento\Quote\Model\Quote\Address\RateRequest;
  8. use Magento\TestFramework\Helper\Bootstrap;
  9. /**
  10. * Temando Order Interface Builder Test
  11. *
  12. * @package Temando\Shipping\Test\Integration
  13. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  14. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  15. * @link http://www.temando.com/
  16. */
  17. class OrderInterfaceBuilderTest extends \PHPUnit\Framework\TestCase
  18. {
  19. /**
  20. * @return Address
  21. */
  22. private function getInstantPurchaseAddress()
  23. {
  24. $addressData = [
  25. 'country_id' => 'GB',
  26. 'region_id' => '0',
  27. 'street' => '909 Foo Road',
  28. 'city' => 'London',
  29. 'postcode' => 'SE17 1LB',
  30. ];
  31. $address = Bootstrap::getObjectManager()->create(Address::class, ['data' => $addressData]);
  32. return $address;
  33. }
  34. /**
  35. * The Magento_InstantPurchase module passes a very "streamlined" rates
  36. * request to the shipping carriers. Make sure the order request builder
  37. * handles this well.
  38. *
  39. * @see \Magento\InstantPurchase\Model\ShippingMethodChoose\ShippingRateFinder::getRatesForCustomerAddress
  40. *
  41. * @magentoConfigFixture default_store general/store_information/name Foo Store
  42. * @test
  43. */
  44. public function buildInstantPurchaseOrderRequest()
  45. {
  46. $address = $this->getInstantPurchaseAddress();
  47. /** @var $rateRequest RateRequest */
  48. $rateRequest = Bootstrap::getObjectManager()->create(RateRequest::class);
  49. $rateRequest->setDestCountryId($address->getCountryId());
  50. $rateRequest->setDestRegionId($address->getRegionId());
  51. $rateRequest->setDestRegionCode($address->getRegionCode());
  52. $rateRequest->setDestStreet($address->getStreetFull());
  53. $rateRequest->setDestCity($address->getCity());
  54. $rateRequest->setDestPostcode($address->getPostcode());
  55. $rateRequest->setStoreId('1');
  56. $rateRequest->setWebsiteId('1');
  57. $rateRequest->setBaseCurrency('GBP');
  58. $rateRequest->setPackageCurrency('EUR');
  59. $rateRequest->setPackageQty(-1);
  60. /** @var OrderInterfaceBuilder $builder */
  61. $builder = Bootstrap::getObjectManager()->create(OrderInterfaceBuilder::class);
  62. $builder->setRateRequest($rateRequest);
  63. /** @var OrderInterface $orderType */
  64. $orderType = $builder->create();
  65. $this->assertSame($address->getCountryId(), $orderType->getRecipient()->getCountryCode());
  66. $this->assertSame($address->getCity(), $orderType->getRecipient()->getCity());
  67. $this->assertSame($address->getPostcode(), $orderType->getRecipient()->getPostalCode());
  68. }
  69. }