forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
magento#27338 Add testmodule with extension attribute
- Loading branch information
Showing
4 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
.../api-functional/_files/Magento/TestModuleExtensionAttributes/etc/extension_attributes.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd"> | ||
<extension_attributes for="Magento\Quote\Api\Data\AddressInterface"> | ||
<attribute code="test_attribute" type="int" /> | ||
</extension_attributes> | ||
</config> |
9 changes: 9 additions & 0 deletions
9
dev/tests/api-functional/_files/Magento/TestModuleExtensionAttributes/etc/module.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> | ||
<module name="'Magento_TestModuleExtensionAttributes" setup_version="1.0.0"> | ||
<sequence> | ||
<module name="Magento_Quote"/> | ||
</sequence> | ||
</module> | ||
</config> |
6 changes: 6 additions & 0 deletions
6
dev/tests/api-functional/_files/Magento/TestModuleExtensionAttributes/registration.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
\Magento\Framework\Component\ComponentRegistrar::register( | ||
\Magento\Framework\Component\ComponentRegistrar::MODULE, | ||
'Magento_TestModuleExtensionAttributes', | ||
__DIR__ | ||
); |
116 changes: 116 additions & 0 deletions
116
...tional/testsuite/Magento/Quote/Api/GuestShipmentEstimationWithExtensionAttributesTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Quote\Api; | ||
|
||
use Magento\TestFramework\ObjectManager; | ||
use Magento\TestFramework\TestCase\WebapiAbstract; | ||
use Magento\Quote\Api\Data\AddressInterface; | ||
|
||
class GuestShipmentEstimationWithExtensionAttributesTest extends WebapiAbstract | ||
{ | ||
const SERVICE_VERSION = 'V1'; | ||
const SERVICE_NAME = 'quoteGuestShipmentEstimationV1'; | ||
const RESOURCE_PATH = '/V1/guest-carts/'; | ||
|
||
/** | ||
* @var ObjectManager | ||
*/ | ||
private $objectManager; | ||
|
||
protected function setUp() | ||
{ | ||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); | ||
} | ||
|
||
/** | ||
* @magentoApiDataFixture Magento/SalesRule/_files/cart_rule_free_shipping.php | ||
* @magentoApiDataFixture Magento/Sales/_files/quote.php | ||
*/ | ||
public function testEstimateByExtendedAddress() | ||
{ | ||
/** @var \Magento\Quote\Model\Quote $quote */ | ||
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class); | ||
$quote->load('test01', 'reserved_order_id'); | ||
$cartId = $quote->getId(); | ||
if (!$cartId) { | ||
$this->fail('quote fixture failed'); | ||
} | ||
|
||
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */ | ||
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() | ||
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class) | ||
->create(); | ||
$quoteIdMask->load($cartId, 'quote_id'); | ||
//Use masked cart Id | ||
$cartId = $quoteIdMask->getMaskedId(); | ||
$serviceInfo = [ | ||
'rest' => [ | ||
'resourcePath' => '/V1/guest-carts/' . $cartId . '/estimate-shipping-methods', | ||
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, | ||
], | ||
'soap' => [ | ||
'service' => self::SERVICE_NAME, | ||
'serviceVersion' => 'V1', | ||
'operation' => self::SERVICE_NAME . 'EstimateByExtendedAddress', | ||
], | ||
]; | ||
if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) { | ||
/** @var \Magento\Quote\Model\Quote\Address $address */ | ||
$address = $quote->getBillingAddress(); | ||
|
||
$data = [ | ||
AddressInterface::KEY_ID => (int)$address->getId(), | ||
AddressInterface::KEY_REGION => $address->getRegion(), | ||
AddressInterface::KEY_REGION_ID => $address->getRegionId(), | ||
AddressInterface::KEY_REGION_CODE => $address->getRegionCode(), | ||
AddressInterface::KEY_COUNTRY_ID => $address->getCountryId(), | ||
AddressInterface::KEY_STREET => $address->getStreet(), | ||
AddressInterface::KEY_COMPANY => $address->getCompany(), | ||
AddressInterface::KEY_TELEPHONE => $address->getTelephone(), | ||
AddressInterface::KEY_POSTCODE => $address->getPostcode(), | ||
AddressInterface::KEY_CITY => $address->getCity(), | ||
AddressInterface::KEY_FIRSTNAME => $address->getFirstname(), | ||
AddressInterface::KEY_LASTNAME => $address->getLastname(), | ||
AddressInterface::KEY_CUSTOMER_ID => $address->getCustomerId(), | ||
AddressInterface::KEY_EMAIL => $address->getEmail(), | ||
AddressInterface::SAME_AS_BILLING => $address->getSameAsBilling(), | ||
AddressInterface::CUSTOMER_ADDRESS_ID => $address->getCustomerAddressId(), | ||
AddressInterface::SAVE_IN_ADDRESS_BOOK => $address->getSaveInAddressBook(), | ||
|
||
'custom_attributes' => [ | ||
[ | ||
'attribute_code' => 'test_attribute', | ||
'value' => 1, | ||
], | ||
] | ||
]; | ||
|
||
$requestData = [ | ||
'cartId' => $cartId, | ||
'address' => $data | ||
]; | ||
} else { | ||
$requestData = [ | ||
'address' => [ | ||
'country_id' => "US", | ||
'postcode' => null, | ||
'region' => null, | ||
'region_id' => null | ||
], | ||
]; | ||
} | ||
// Cart must be anonymous (see fixture) | ||
$this->assertEmpty($quote->getCustomerId()); | ||
|
||
$result = $this->_webApiCall($serviceInfo, $requestData); | ||
$this->assertNotEmpty($result); | ||
$this->assertEquals(1, count($result)); | ||
foreach ($result as $rate) { | ||
$this->assertEquals("flatrate", $rate['carrier_code']); | ||
$this->assertEquals(0, $rate['amount']); | ||
} | ||
} | ||
} |