IntegrationTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. *
  6. */
  7. namespace Magento\Integration\Controller\Adminhtml;
  8. use Magento\TestFramework\Bootstrap;
  9. use Magento\Framework\App\Request\Http as HttpRequest;
  10. /**
  11. * \Magento\Integration\Controller\Adminhtml\Integration
  12. *
  13. * @magentoDataFixture Magento/Integration/_files/integration_all_permissions.php
  14. * @magentoAppArea adminhtml
  15. * @magentoDbIsolation enabled
  16. */
  17. class IntegrationTest extends \Magento\TestFramework\TestCase\AbstractBackendController
  18. {
  19. /** @var \Magento\Integration\Model\Integration */
  20. private $_integration;
  21. /**
  22. * @inheritDoc
  23. */
  24. protected function setUp()
  25. {
  26. parent::setUp();
  27. /** @var $integration \Magento\Integration\Model\Integration */
  28. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  29. $integration = $objectManager->create(\Magento\Integration\Model\Integration::class);
  30. $this->_integration = $integration->load('Fixture Integration', 'name');
  31. }
  32. /**
  33. * Test view page.
  34. */
  35. public function testIndexAction()
  36. {
  37. $this->dispatch('backend/admin/integration/index');
  38. $response = $this->getResponse()->getBody();
  39. $this->assertContains('Integrations', $response);
  40. $this->assertEquals(
  41. 1,
  42. \Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
  43. '//*[@id="integrationGrid"]',
  44. $response
  45. )
  46. );
  47. }
  48. /**
  49. * Test creation form.
  50. */
  51. public function testNewAction()
  52. {
  53. $this->dispatch('backend/admin/integration/new');
  54. $response = $this->getResponse()->getBody();
  55. $this->assertEquals('new', $this->getRequest()->getActionName());
  56. $this->assertContains('entry-edit form-inline', $response);
  57. $this->assertContains('New Integration', $response);
  58. $this->assertEquals(
  59. 1,
  60. \Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
  61. '//*[@id="integration_properties_base_fieldset"]',
  62. $response
  63. )
  64. );
  65. }
  66. /**
  67. * Test update form.
  68. */
  69. public function testEditAction()
  70. {
  71. $integrationId = $this->_integration->getId();
  72. $this->getRequest()->setParam('id', $integrationId);
  73. $this->dispatch('backend/admin/integration/edit');
  74. $response = $this->getResponse()->getBody();
  75. $saveLink = 'integration/save/';
  76. $this->assertContains('entry-edit form-inline', $response);
  77. $this->assertContains('Edit &quot;' . $this->_integration->getName() . '&quot; Integration', $response);
  78. $this->assertContains($saveLink, $response);
  79. $this->assertEquals(
  80. 1,
  81. \Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
  82. '//*[@id="integration_properties_base_fieldset"]',
  83. $response
  84. )
  85. );
  86. $this->assertEquals(
  87. 1,
  88. \Magento\TestFramework\Helper\Xpath::getElementsCountForXpath(
  89. '//*[@id="integration_edit_tabs_info_section_content"]',
  90. $response
  91. )
  92. );
  93. }
  94. /**
  95. * Test saving.
  96. */
  97. public function testSaveActionUpdateIntegration()
  98. {
  99. $integrationId = $this->_integration->getId();
  100. $integrationName = $this->_integration->getName();
  101. $this->getRequest()->setParam('id', $integrationId);
  102. $url = 'http://magento.ll/endpoint_url';
  103. $this->getRequest()->setMethod(HttpRequest::METHOD_POST);
  104. $this->getRequest()->setPostValue(
  105. [
  106. 'name' => $integrationName,
  107. 'email' => 'test@magento.com',
  108. 'authentication' => '1',
  109. 'endpoint' => $url,
  110. 'current_password' => Bootstrap::ADMIN_PASSWORD,
  111. ]
  112. );
  113. $this->dispatch('backend/admin/integration/save');
  114. $this->assertSessionMessages(
  115. $this->equalTo(["The integration '{$integrationName}' has been saved."]),
  116. \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
  117. );
  118. $this->assertRedirect($this->stringContains('backend/admin/integration/index/'));
  119. }
  120. /**
  121. * Test saving.
  122. */
  123. public function testSaveActionNewIntegration()
  124. {
  125. $url = 'http://magento.ll/endpoint_url';
  126. $integrationName = md5(rand());
  127. $this->getRequest()->setMethod(HttpRequest::METHOD_POST);
  128. $this->getRequest()->setPostValue(
  129. [
  130. 'name' => $integrationName,
  131. 'email' => 'test@magento.com',
  132. 'authentication' => '1',
  133. 'endpoint' => $url,
  134. 'current_password' => Bootstrap::ADMIN_PASSWORD,
  135. ]
  136. );
  137. $this->dispatch('backend/admin/integration/save');
  138. $this->assertSessionMessages(
  139. $this->equalTo(["The integration '{$integrationName}' has been saved."]),
  140. \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
  141. );
  142. $this->assertRedirect($this->stringContains('backend/admin/integration/index/'));
  143. }
  144. }