Skip to content

Commit a417de3

Browse files
committed
MAGETWO-33455: Cover Config-based Integration Creation with Test
1 parent f2361bd commit a417de3

File tree

12 files changed

+131
-10
lines changed

12 files changed

+131
-10
lines changed

app/code/Magento/Integration/Model/Integration.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
* @method \string getEmail()
1414
* @method Integration setEmail(\string $email)
1515
* @method Integration setStatus(\int $value)
16-
* @method \int getType()
17-
* @method Integration setType(\int $value)
16+
* @method \int getSetupType()
17+
* @method Integration setSetupType(\int $value)
1818
* @method Integration setConsumerId(\string $consumerId)
1919
* @method \string getConsumerId()
2020
* @method \string getEndpoint()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "magento/module-test-module-integration-from-config",
3+
"description": "test integration create from config",
4+
"require": {
5+
"php": "~5.5.0",
6+
"magento/magento-composer-installer": "*"
7+
},
8+
"type": "magento2-module",
9+
"version": "1.0",
10+
"extra": {
11+
"map": [
12+
[
13+
"*",
14+
"Magento/TestModuleIntegrationFromConfig"
15+
]
16+
]
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
/** @var \Magento\Integration\Model\Resource\Setup $this */
7+
$this->initIntegrationProcessing(['Test Integration1']);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
<type name="Magento\Framework\Module\Updater\SetupFactory">
10+
<arguments>
11+
<argument name="resourceTypes" xsi:type="array">
12+
<item name="testmoduleintegrationfromconfig_setup" xsi:type="string">Magento\Integration\Model\Resource\Setup</item>
13+
</argument>
14+
</arguments>
15+
</type>
16+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<integrations>
2+
<integration name="Test Integration1">
3+
<email>test-integration@magento.com</email>
4+
<endpoint_url>http://example.com/endpoint1</endpoint_url>
5+
</integration>
6+
</integrations>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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_TestModuleIntegrationFromConfig" schema_version="0.0.1" active="true">
10+
</module>
11+
</config>

dev/tests/api-functional/framework/Magento/TestFramework/Authentication/OauthHelper.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\TestFramework\Helper\Bootstrap;
1212
use OAuth\Common\Consumer\Credentials;
1313
use Zend\Stdlib\Exception\LogicException;
14+
use Magento\Integration\Model\Integration;
1415

1516
class OauthHelper
1617
{
@@ -93,6 +94,7 @@ public static function getAccessToken()
9394
* Create an access token, tied to integration which has permissions to all API resources in the system.
9495
*
9596
* @param array $resources list of resources to grant to the integration
97+
* @param \Magento\Integration\Model\Integration|null $integrationModel
9698
* @return array
9799
* <pre>
98100
* array (
@@ -104,10 +106,10 @@ public static function getAccessToken()
104106
* </pre>
105107
* @throws LogicException
106108
*/
107-
public static function getApiAccessCredentials($resources = null)
109+
public static function getApiAccessCredentials($resources = null, Integration $integrationModel = null)
108110
{
109111
if (!self::$_apiCredentials) {
110-
$integration = self::_createIntegration($resources);
112+
$integration = is_null($integrationModel) ? self::_createIntegration($resources) : $integrationModel;
111113
$objectManager = Bootstrap::getObjectManager();
112114
/** @var \Magento\Integration\Service\V1\Oauth $oauthService */
113115
$oauthService = $objectManager->get('Magento\Integration\Service\V1\Oauth');

dev/tests/api-functional/framework/Magento/TestFramework/TestCase/Webapi/Adapter/Rest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Magento\TestFramework\Helper\Bootstrap;
1212
use Magento\Webapi\Model\Rest\Config;
13+
use Magento\TestFramework\Authentication\OauthHelper;
1314

1415
class Rest implements \Magento\TestFramework\TestCase\Webapi\AdapterInterface
1516
{
@@ -64,13 +65,13 @@ public function __construct()
6465
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
6566
* @SuppressWarnings(PHPMD.NPathComplexity)
6667
*/
67-
public function call($serviceInfo, $arguments = [], $storeCode = null)
68+
public function call($serviceInfo, $arguments = [], $storeCode = null, $integration = null)
6869
{
6970
$storeCode = !is_null($storeCode) ? (string)$storeCode : $this->defaultStoreCode;
7071
$resourcePath = '/' . $storeCode . $this->_getRestResourcePath($serviceInfo);
7172
$httpMethod = $this->_getRestHttpMethod($serviceInfo);
7273
//Get a valid token
73-
$accessCredentials = \Magento\TestFramework\Authentication\OauthHelper::getApiAccessCredentials();
74+
$accessCredentials = OauthHelper::getApiAccessCredentials(null, $integration);
7475
/** @var $oAuthClient \Magento\TestFramework\Authentication\Rest\OauthClient */
7576
$oAuthClient = $accessCredentials['oauth_client'];
7677
$urlFormEncoded = false;

dev/tests/api-functional/framework/Magento/TestFramework/TestCase/Webapi/Adapter/Soap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct()
5353
/**
5454
* {@inheritdoc}
5555
*/
56-
public function call($serviceInfo, $arguments = [], $storeCode = null)
56+
public function call($serviceInfo, $arguments = [], $storeCode = null, $integration = null)
5757
{
5858
$soapOperation = $this->_getSoapOperation($serviceInfo);
5959
$arguments = $this->_converter->convertKeysToCamelCase($arguments);

dev/tests/api-functional/framework/Magento/TestFramework/TestCase/Webapi/AdapterInterface.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ interface AdapterInterface
3333
* </pre>
3434
* @param array $arguments
3535
* @param string|null $storeCode if store code not provided, default store code will be used
36+
* @param \Magento\Integration\Model\Integration|null $integration
3637
* @return array|string|int|float|bool
3738
*/
38-
public function call($serviceInfo, $arguments = [], $storeCode = null);
39+
public function call($serviceInfo, $arguments = [], $storeCode = null, $integration = null);
3940
}

dev/tests/api-functional/framework/Magento/TestFramework/TestCase/WebapiAbstract.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,18 @@ protected function tearDown()
159159
* @param array $arguments
160160
* @param string|null $webApiAdapterCode
161161
* @param string|null $storeCode
162+
* @param \Magento\Integration\Model\Integration|null $integration
162163
* @return array|int|string|float|bool Web API call results
163164
*/
164-
protected function _webApiCall($serviceInfo, $arguments = [], $webApiAdapterCode = null, $storeCode = null)
165+
protected function _webApiCall(
166+
$serviceInfo, $arguments = [], $webApiAdapterCode = null, $storeCode = null, $integration = null
167+
)
165168
{
166169
if (is_null($webApiAdapterCode)) {
167170
/** Default adapter code is defined in PHPUnit configuration */
168171
$webApiAdapterCode = strtolower(TESTS_WEB_API_ADAPTER);
169172
}
170-
return $this->_getWebApiAdapter($webApiAdapterCode)->call($serviceInfo, $arguments, $storeCode);
173+
return $this->_getWebApiAdapter($webApiAdapterCode)->call($serviceInfo, $arguments, $storeCode, $integration);
171174
}
172175

173176
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Integration\Model;
7+
8+
use Magento\TestFramework\Helper\Bootstrap;
9+
10+
class IntegrationTest extends \Magento\TestFramework\TestCase\WebapiAbstract
11+
{
12+
/** @var \Magento\Integration\Model\Integration */
13+
protected $integration;
14+
15+
public function testConfigBasedIntegrationCreation()
16+
{
17+
$objectManager = Bootstrap::getObjectManager();
18+
19+
/** @var \Magento\Integration\Model\Integration $integrationModel */
20+
$integrationModel = $objectManager->get('Magento\Integration\Model\Integration');
21+
$integrationModel->loadByConsumerId(1);
22+
$this->assertEquals('test-integration@magento.com', $integrationModel->getEmail());
23+
$this->assertEquals('http://example.com/endpoint1', $integrationModel->getEndpoint());
24+
$this->assertEquals('Test Integration1', $integrationModel->getName());
25+
$this->assertEquals(Integration::TYPE_CONFIG, $integrationModel->getSetupType());
26+
27+
/** @var $integrationService \Magento\Integration\Service\V1\IntegrationInterface */
28+
$integrationService = $objectManager->get('Magento\Integration\Service\V1\IntegrationInterface');
29+
$this->integration = $integrationService->findByName('Test Integration1');
30+
$this->integration->setStatus(Integration::STATUS_ACTIVE)->save();
31+
}
32+
33+
/**
34+
* Test simple request data
35+
*
36+
* @depends testConfigBasedIntegrationCreation
37+
*/
38+
public function testGetServiceCall()
39+
{
40+
$this->_markTestAsRestOnly();
41+
$version = 'V1';
42+
$restResourcePath = "/{$version}/testmodule4/";
43+
44+
$itemId = 1;
45+
$name = 'Test';
46+
$serviceInfo = [
47+
'rest' => [
48+
'resourcePath' => $restResourcePath . $itemId,
49+
'httpMethod' => \Magento\Webapi\Model\Rest\Config::HTTP_METHOD_GET,
50+
],
51+
];
52+
$item = $this->_webApiCall($serviceInfo, [], null, null, $this->integration);
53+
$this->assertEquals($itemId, $item['entity_id'], 'id field returned incorrectly');
54+
$this->assertEquals($name, $item['name'], 'name field returned incorrectly');
55+
}
56+
}

0 commit comments

Comments
 (0)