IntegrationTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Integration\Model;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. use Magento\TestFramework\Authentication\OauthHelper;
  9. class IntegrationTest extends \Magento\TestFramework\TestCase\WebapiAbstract
  10. {
  11. /** @var \Magento\Integration\Model\Integration */
  12. protected $integration;
  13. protected function setUp()
  14. {
  15. $objectManager = Bootstrap::getObjectManager();
  16. /** @var $integrationService \Magento\Integration\Api\IntegrationServiceInterface */
  17. $integrationService = $objectManager->get(\Magento\Integration\Api\IntegrationServiceInterface::class);
  18. $params = [
  19. 'all_resources' => true,
  20. 'integration_id' => 1,
  21. 'status' => Integration::STATUS_ACTIVE,
  22. 'name' => 'Test Integration1'
  23. ];
  24. $this->integration = $integrationService->update($params);
  25. parent::setUp();
  26. }
  27. protected function tearDown()
  28. {
  29. $this->integration = null;
  30. OauthHelper::clearApiAccessCredentials();
  31. parent::tearDown();
  32. }
  33. public function testConfigBasedIntegrationCreation()
  34. {
  35. $this->assertEquals('test-integration@magento.com', $this->integration->getEmail());
  36. $this->assertEquals('http://example.com/endpoint1', $this->integration->getEndpoint());
  37. $this->assertEquals('Test Integration1', $this->integration->getName());
  38. $this->assertEquals(Integration::TYPE_CONFIG, $this->integration->getSetupType());
  39. }
  40. /**
  41. * Test simple request data
  42. *
  43. * @depends testConfigBasedIntegrationCreation
  44. */
  45. public function testGetServiceCall()
  46. {
  47. $this->_markTestAsRestOnly();
  48. $itemId = 1;
  49. $name = 'Test';
  50. $serviceInfo = [
  51. 'rest' => [
  52. 'resourcePath' => '/V1/testmodule4/' . $itemId,
  53. 'httpMethod' => \Magento\Webapi\Model\Rest\Config::HTTP_METHOD_GET,
  54. ],
  55. ];
  56. $item = $this->_webApiCall($serviceInfo, [], null, null, $this->integration);
  57. $this->assertEquals($itemId, $item['entity_id'], 'id field returned incorrectly');
  58. $this->assertEquals($name, $item['name'], 'name field returned incorrectly');
  59. }
  60. }