Skip to content

Commit 339e10b

Browse files
committed
MAGETWO-38297: [TEST] Write integration / api-functional tests for join processor
1 parent 96da50b commit 339e10b

File tree

5 files changed

+80
-29
lines changed

5 files changed

+80
-29
lines changed

dev/tests/api-functional/_files/Magento/TestJoinDirectives/Model/TestRepository.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ public function getList(\Magento\Framework\Api\SearchCriteria $searchCriteria)
5050
{
5151
$searchData = $this->searchResultsDataFactory->create();
5252
$searchData->setSearchCriteria($searchCriteria);
53-
54-
// $this->extensionAttributesJoinProcessor->process($this->quoteCollection);
55-
53+
$this->extensionAttributesJoinProcessor->process($this->quoteCollection);
5654
$searchData->setItems($this->quoteCollection->getItems());
57-
5855
return $searchData;
5956
}
6057
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
9+
<preference for="Magento\TestJoinDirectives\Api\TestRepositoryInterface" type="Magento\TestJoinDirectives\Model\TestRepository" />
10+
</config>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="../../../../../../../../lib/internal/Magento/Framework/Api/etc/extension_attributes.xsd">
10+
<extension_attributes for="Magento\Quote\Api\Data\CartInterface">
11+
<attribute code="quoteTestAttribute" type="Magento\User\Model\UserInterface">
12+
<join reference_table="admin_user"
13+
join_on_field="store_id"
14+
reference_field="user_id"
15+
>
16+
<select_field>firstname</select_field>
17+
<select_field>lastname</select_field>
18+
<select_field>email</select_field>
19+
</join>
20+
</attribute>
21+
</extension_attributes>
22+
</config>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
9+
<module name="Magento_TestJoinDirectives" setup_version="1.0"/>
10+
</config>

dev/tests/api-functional/testsuite/Magento/Webapi/JoinDirectivesTest.php

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,66 @@
77
namespace Magento\Webapi;
88

99
use Magento\Framework\Api\SearchCriteriaBuilder;
10+
use Magento\Framework\Api\SortOrderBuilder;
11+
use Magento\Framework\Api\SortOrder;
12+
use Magento\Framework\Api\SearchCriteria;
1013

1114
class JoinDirectivesTest extends \Magento\TestFramework\TestCase\WebapiAbstract
1215
{
1316
/**
14-
* @var string
15-
*/
16-
protected $_version;
17-
18-
/**
19-
* @var string
20-
*/
21-
protected $_restResourcePath;
22-
23-
/**
24-
* @var string
17+
* @var SearchCriteriaBuilder
2518
*/
26-
protected $_soapService;
19+
private $searchBuilder;
2720

2821
/**
29-
* @var SearchCriteriaBuilder
22+
* @var SortOrderBuilder
3023
*/
31-
private $searchBuilder;
24+
private $sortOrderBuilder;
3225

3326
protected function setUp()
3427
{
3528
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
36-
$this->_version = 'V1';
37-
$this->_restResourcePath = "/{$this->_version}/TestJoinDirectives/";
38-
$this->_soapService = "testJoinDirectivesTestRepository{$this->_version}";
39-
$this->searchBuilder = $objectManager->create(
40-
'Magento\Framework\Api\SearchCriteriaBuilder'
41-
);
29+
$this->searchBuilder = $objectManager->create('Magento\Framework\Api\SearchCriteriaBuilder');
30+
$this->sortOrderBuilder = $objectManager->create('Magento\Framework\Api\SortOrderBuilder');
4231
}
4332

33+
/**
34+
* @magentoApiDataFixture Magento/Sales/_files/quote.php
35+
*/
4436
public function testGetList()
4537
{
38+
/** @var SortOrder $sortOrder */
39+
$sortOrder = $this->sortOrderBuilder->setField('store_id')->setDirection(SearchCriteria::SORT_ASC)->create();
40+
$this->searchBuilder->setSortOrders([$sortOrder]);
41+
$searchCriteria = $this->searchBuilder->create()->__toArray();
42+
$requestData = ['searchCriteria' => $searchCriteria];
43+
44+
$restResourcePath = '/V1/TestJoinDirectives/';
45+
$soapService = 'testJoinDirectivesTestRepositoryV1';
46+
4647
$serviceInfo = [
4748
'rest' => [
48-
'resourcePath' => $this->_restResourcePath,
49+
'resourcePath' => $restResourcePath . '?' . http_build_query($requestData),
4950
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
5051
],
5152
'soap' => [
52-
'service' => $this->_soapService,
53-
'operation' => $this->_soapService . 'GetList',
53+
'service' => $soapService,
54+
'operation' => $soapService . 'GetList',
5455
],
5556
];
56-
$searchCriteria = $this->searchBuilder->create()->__toArray();
57-
$requestData = ['searchCriteria' => $searchCriteria];
5857
$searchResult = $this->_webApiCall($serviceInfo, $requestData);
58+
59+
$expectedExtensionAttributes = [
60+
'firstname' => 'Admin',
61+
'lastname' => 'Admin',
62+
'email' => 'admin@example.com'
63+
];
64+
65+
$this->assertArrayHasKey('items', $searchResult);
66+
$cartData = array_pop($searchResult['items']);
67+
$testAttribute = $cartData['extension_attributes']['quote_test_attribute'];
68+
$this->assertEquals($expectedExtensionAttributes['firstname'], $testAttribute['first_name']);
69+
$this->assertEquals($expectedExtensionAttributes['lastname'], $testAttribute['last_name']);
70+
$this->assertEquals($expectedExtensionAttributes['email'], $testAttribute['email']);
5971
}
6072
}

0 commit comments

Comments
 (0)