EditTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Integration\Test\Unit\Controller\Adminhtml\Integration;
  7. use Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info;
  8. use Magento\Framework\Exception\IntegrationException;
  9. class EditTest extends \Magento\Integration\Test\Unit\Controller\Adminhtml\IntegrationTest
  10. {
  11. public function testEditAction()
  12. {
  13. $this->_integrationSvcMock->expects(
  14. $this->any()
  15. )->method(
  16. 'get'
  17. )->with(
  18. $this->equalTo(self::INTEGRATION_ID)
  19. )->will(
  20. $this->returnValue($this->_getSampleIntegrationData())
  21. );
  22. $this->_requestMock->expects(
  23. $this->any()
  24. )->method(
  25. 'getParam'
  26. )->with(
  27. $this->equalTo(\Magento\Integration\Controller\Adminhtml\Integration::PARAM_INTEGRATION_ID)
  28. )->will(
  29. $this->returnValue(self::INTEGRATION_ID)
  30. );
  31. // put data in session, the magic function getFormData is called so, must match __call method name
  32. $this->_backendSessionMock->expects(
  33. $this->any()
  34. )->method(
  35. '__call'
  36. )->will(
  37. $this->returnValueMap(
  38. [
  39. ['setIntegrationData'],
  40. [
  41. 'getIntegrationData',
  42. [Info::DATA_ID => self::INTEGRATION_ID, Info::DATA_NAME => 'testIntegration']
  43. ],
  44. ]
  45. )
  46. );
  47. $this->_escaper->expects($this->once())
  48. ->method('escapeHtml')
  49. ->willReturnArgument(0);
  50. $this->pageTitleMock->expects($this->atLeastOnce())
  51. ->method('prepend');
  52. $this->_verifyLoadAndRenderLayout();
  53. $controller = $this->_createIntegrationController('Edit');
  54. $controller->execute();
  55. }
  56. public function testEditActionNonExistentIntegration()
  57. {
  58. $exceptionMessage = 'This integration no longer exists.';
  59. // verify the error
  60. $this->_messageManager->expects($this->once())->method('addError')->with($this->equalTo($exceptionMessage));
  61. $this->_requestMock->expects($this->any())->method('getParam')->will($this->returnValue(self::INTEGRATION_ID));
  62. // put data in session, the magic function getFormData is called so, must match __call method name
  63. $this->_backendSessionMock->expects(
  64. $this->any()
  65. )->method(
  66. '__call'
  67. )->will(
  68. $this->returnValue(['name' => 'nonExistentInt'])
  69. );
  70. $invalidIdException = new IntegrationException(__($exceptionMessage));
  71. $this->_integrationSvcMock->expects(
  72. $this->any()
  73. )->method(
  74. 'get'
  75. )->will(
  76. $this->throwException($invalidIdException)
  77. );
  78. $this->_escaper->expects($this->once())
  79. ->method('escapeHtml')
  80. ->willReturnArgument(0);
  81. $this->_verifyLoadAndRenderLayout();
  82. $integrationContr = $this->_createIntegrationController('Edit');
  83. $integrationContr->execute();
  84. }
  85. public function testEditActionNoDataAdd()
  86. {
  87. $exceptionMessage = 'Integration ID is not specified or is invalid.';
  88. // verify the error
  89. $this->_messageManager->expects($this->once())->method('addError')->with($this->equalTo($exceptionMessage));
  90. $this->_verifyLoadAndRenderLayout();
  91. $integrationContr = $this->_createIntegrationController('Edit');
  92. $integrationContr->execute();
  93. }
  94. public function testEditException()
  95. {
  96. $exceptionMessage = 'Integration ID is not specified or is invalid.';
  97. // verify the error
  98. $this->_messageManager->expects($this->once())->method('addError')->with($this->equalTo($exceptionMessage));
  99. $this->_controller = $this->_createIntegrationController('Edit');
  100. $this->_controller->execute();
  101. }
  102. }