EditTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. *
  6. */
  7. namespace Magento\Integration\Block\Adminhtml\Integration;
  8. use Magento\Integration\Controller\Adminhtml\Integration as IntegrationController;
  9. use Magento\Integration\Model\Integration;
  10. use Magento\TestFramework\Helper\Bootstrap;
  11. /**
  12. * Test class for \Magento\Integration\Block\Adminhtml\Integration\Edit
  13. *
  14. * @magentoAppArea adminhtml
  15. */
  16. class EditTest extends \PHPUnit\Framework\TestCase
  17. {
  18. /**
  19. * @var \Magento\Integration\Block\Adminhtml\Integration\Edit
  20. */
  21. protected $editBlock;
  22. protected function setUp()
  23. {
  24. $this->editBlock = Bootstrap::getObjectManager()
  25. ->create(\Magento\Integration\Block\Adminhtml\Integration\Edit::class);
  26. }
  27. public function testGetHeaderTextNewIntegration()
  28. {
  29. $this->assertEquals('New Integration', $this->editBlock->getHeaderText()->getText());
  30. $buttonList = Bootstrap::getObjectManager()
  31. ->get(\Magento\Backend\Block\Widget\Context::class)
  32. ->getButtonList()
  33. ->getItems();
  34. // Assert that there is a 'save' and 'activate' button when creating a new integration
  35. $haveSaveButton = false;
  36. foreach ($buttonList as $button) {
  37. foreach ($button as $key => $value) {
  38. if ($key === 'save') {
  39. $haveSaveButton = true;
  40. $this->assertNotNull($value->getDataByKey('options'));
  41. $this->assertEquals(
  42. 'activate',
  43. $value->getDataByKey('options')['save_activate']['id'],
  44. "'Activate' button is expected when creating a new integration."
  45. );
  46. }
  47. }
  48. }
  49. $this->assertTrue($haveSaveButton, "'Save' button is expected when creating a new integration.");
  50. }
  51. public function testGetHeaderTextEditIntegration()
  52. {
  53. $integrationId = 1;
  54. $integrationName = 'Test Name';
  55. $integrationData = [
  56. Integration::ID => $integrationId,
  57. Integration::NAME => $integrationName,
  58. ];
  59. /** @var \Magento\Framework\Registry $registry */
  60. $registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
  61. $registry->register(IntegrationController::REGISTRY_KEY_CURRENT_INTEGRATION, $integrationData);
  62. $headerText = $this->editBlock->getHeaderText();
  63. $this->assertEquals("Edit Integration '%1'", $headerText->getText());
  64. $this->assertEquals($integrationName, $headerText->getArguments()[0]);
  65. // Tear down
  66. $registry->unregister(IntegrationController::REGISTRY_KEY_CURRENT_INTEGRATION);
  67. }
  68. public function testGetHeaderTextEditIntegrationConfigType()
  69. {
  70. $integrationId = 2;
  71. $integrationName = 'Test Name 2';
  72. $integrationData = [
  73. Integration::ID => $integrationId,
  74. Integration::NAME => $integrationName,
  75. Integration::SETUP_TYPE => Integration::TYPE_CONFIG
  76. ];
  77. /** @var \Magento\Framework\Registry $registry */
  78. $registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
  79. $registry->register(IntegrationController::REGISTRY_KEY_CURRENT_INTEGRATION, $integrationData);
  80. /** @var \Magento\Integration\Block\Adminhtml\Integration\Edit $editBlock */
  81. $editBlock = Bootstrap::getObjectManager()
  82. ->create(\Magento\Integration\Block\Adminhtml\Integration\Edit::class);
  83. $headerText = $editBlock->getHeaderText();
  84. $this->assertEquals("Edit Integration '%1'", $headerText->getText());
  85. $this->assertEquals($integrationName, $headerText->getArguments()[0]);
  86. $buttonList = Bootstrap::getObjectManager()
  87. ->get(\Magento\Backend\Block\Widget\Context::class)
  88. ->getButtonList()
  89. ->getItems();
  90. // Assert that 'save' button is removed for integration of config type
  91. foreach ($buttonList as $button) {
  92. $this->assertFalse(array_key_exists('save', $button));
  93. }
  94. // Tear down
  95. $registry->unregister(IntegrationController::REGISTRY_KEY_CURRENT_INTEGRATION);
  96. }
  97. public function testGetFormActionUrl()
  98. {
  99. $baseUrl = Bootstrap::getObjectManager()->get(\Magento\Framework\Url::class)->getBaseUrl();
  100. $this->assertContains($baseUrl, $this->editBlock->getFormActionUrl());
  101. }
  102. }