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