From 09bad758cd11a4d4cfe297e1f3439f8b98faee45 Mon Sep 17 00:00:00 2001 From: kiraberos Date: Tue, 11 Apr 2023 09:53:46 +0300 Subject: [PATCH] magento/magento2#14623: Join extension attributes are not added to Order and Order Items - completed the implementation of tests --- .../etc/extension_attributes.xml | 12 ++++ .../Magento/Webapi/JoinDirectivesTest.php | 58 ++++++++++++++++++- .../testsuite/Magento/Sales/_files/order.php | 6 +- 3 files changed, 72 insertions(+), 4 deletions(-) diff --git a/dev/tests/api-functional/_files/Magento/TestModuleJoinDirectives/etc/extension_attributes.xml b/dev/tests/api-functional/_files/Magento/TestModuleJoinDirectives/etc/extension_attributes.xml index 8254a9d8e92cf..d849bec0d3917 100644 --- a/dev/tests/api-functional/_files/Magento/TestModuleJoinDirectives/etc/extension_attributes.xml +++ b/dev/tests/api-functional/_files/Magento/TestModuleJoinDirectives/etc/extension_attributes.xml @@ -43,4 +43,16 @@ + + + + firstname + lastname + email + + + diff --git a/dev/tests/api-functional/testsuite/Magento/Webapi/JoinDirectivesTest.php b/dev/tests/api-functional/testsuite/Magento/Webapi/JoinDirectivesTest.php index 5e278e6058dc9..fac5c661cf93b 100644 --- a/dev/tests/api-functional/testsuite/Magento/Webapi/JoinDirectivesTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Webapi/JoinDirectivesTest.php @@ -10,6 +10,8 @@ use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\Api\SortOrder; use Magento\Framework\Api\SortOrderBuilder; +use Magento\Sales\Model\Order; +use Magento\User\Model\User; /** * Test join directives. @@ -32,17 +34,23 @@ class JoinDirectivesTest extends \Magento\TestFramework\TestCase\WebapiAbstract private $filterBuilder; /** - * @var \Magento\User\Model\User + * @var User */ private $user; + /** + * @var Order|mixed + */ + private mixed $order; + protected function setUp(): void { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->searchBuilder = $objectManager->create(\Magento\Framework\Api\SearchCriteriaBuilder::class); $this->sortOrderBuilder = $objectManager->create(\Magento\Framework\Api\SortOrderBuilder::class); $this->filterBuilder = $objectManager->create(\Magento\Framework\Api\FilterBuilder::class); - $this->user = $objectManager->create(\Magento\User\Model\User::class); + $this->user = $objectManager->create(User::class); + $this->order = $objectManager->create(Order::class); } /** @@ -173,6 +181,52 @@ public function testGetOrdertList() $this->assertEquals($expectedExtensionAttributes['email'], $testAttribute['email']); } + /** + * Test get list of order items with extension attributes. + * + * @magentoApiDataFixture Magento/Sales/_files/order.php + * @magentoAppIsolation enabled + */ + public function testGetOrderItemList() + { + $orderItem = current($this->order->loadByIncrementId('100000001')->getItems()); + $orderItemId = $orderItem->getId(); + $filter = $this->filterBuilder + ->setField('item_id') + ->setValue($orderItemId) + ->setConditionType('eq') + ->create(); + $this->searchBuilder->addFilters([$filter]); + $searchData = $this->searchBuilder->create()->__toArray(); + + $requestData = ['searchCriteria' => $searchData]; + + $restResourcePath = '/V1/orders/items/'; + $soapService = 'salesOrderItemRepositoryV1'; + $expectedExtensionAttributes = $this->getExpectedExtensionAttributes(); + + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => $restResourcePath . '?' . http_build_query($requestData), + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET, + ], + 'soap' => [ + 'service' => $soapService, + 'operation' => $soapService . 'GetList', + ], + ]; + $searchResult = $this->_webApiCall($serviceInfo, $requestData); + + $this->assertArrayHasKey('items', $searchResult); + $itemData = array_pop($searchResult['items']); + $this->assertArrayHasKey('extension_attributes', $itemData); + $this->assertArrayHasKey('order_item_api_test_attribute', $itemData['extension_attributes']); + $testAttribute = $itemData['extension_attributes']['order_item_api_test_attribute']; + $this->assertEquals($expectedExtensionAttributes['firstname'], $testAttribute['first_name']); + $this->assertEquals($expectedExtensionAttributes['lastname'], $testAttribute['last_name']); + $this->assertEquals($expectedExtensionAttributes['email'], $testAttribute['email']); + } + /** * Retrieve the admin user's information. * diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/order.php b/dev/tests/integration/testsuite/Magento/Sales/_files/order.php index c2843d5397a32..26b3262a22aee 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/_files/order.php +++ b/dev/tests/integration/testsuite/Magento/Sales/_files/order.php @@ -24,6 +24,7 @@ $productRepository = $objectManager->create(ProductRepositoryInterface::class); $product = $productRepository->get('simple'); $billingAddress = $objectManager->create(OrderAddress::class, ['data' => $addressData]); +$storeId = $objectManager->get(StoreManagerInterface::class)->getStore()->getId(); $billingAddress->setAddressType('billing'); $shippingAddress = clone $billingAddress; @@ -50,7 +51,8 @@ ->setRowTotal($product->getPrice()) ->setProductType('simple') ->setName($product->getName()) - ->setSku($product->getSku()); + ->setSku($product->getSku()) + ->setStoreId($storeId); /** @var Order $order */ $order = $objectManager->create(Order::class); @@ -67,7 +69,7 @@ ->setCustomerEmail('customer@example.com') ->setBillingAddress($billingAddress) ->setShippingAddress($shippingAddress) - ->setStoreId($objectManager->get(StoreManagerInterface::class)->getStore()->getId()) + ->setStoreId($storeId) ->addItem($orderItem) ->setPayment($payment);