123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Integration\Test\Unit\Controller\Adminhtml\Integration;
- use Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info;
- use Magento\Integration\Model\Integration as IntegrationModel;
- use Magento\Framework\Exception\IntegrationException;
- class DeleteTest extends \Magento\Integration\Test\Unit\Controller\Adminhtml\IntegrationTest
- {
- /**
- * @var \Magento\Integration\Controller\Adminhtml\Integration\Delete
- */
- protected $integrationController;
- protected function setUp()
- {
- parent::setUp();
- $this->integrationController = $this->_createIntegrationController('Delete');
- $resultRedirect = $this->getMockBuilder(\Magento\Backend\Model\View\Result\Redirect::class)
- ->disableOriginalConstructor()
- ->getMock();
- $resultRedirect->expects($this->any())
- ->method('setPath')
- ->with('*/*/')
- ->willReturnSelf();
- $this->resultFactory->expects($this->any())
- ->method('create')
- ->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT)
- ->willReturn($resultRedirect);
- }
- public function testDeleteAction()
- {
- $intData = $this->_getSampleIntegrationData();
- $this->_requestMock->expects($this->once())
- ->method('getParam')
- ->willReturn(self::INTEGRATION_ID);
- $this->_integrationSvcMock->expects($this->any())
- ->method('get')
- ->with($this->anything())
- ->willReturn($intData);
- $this->_integrationSvcMock->expects($this->any())
- ->method('delete')
- ->with($this->anything())
- ->willReturn($intData);
- // Use real translate model
- $this->_translateModelMock = null;
- // verify success message
- $this->_messageManager->expects($this->once())
- ->method('addSuccess')
- ->with(__('The integration \'%1\' has been deleted.', $intData[Info::DATA_NAME]));
- $this->_escaper->expects($this->once())
- ->method('escapeHtml')
- ->willReturnArgument(0);
- $this->integrationController->execute();
- }
- public function testDeleteActionWithConsumer()
- {
- $intData = $this->_getSampleIntegrationData();
- $intData[Info::DATA_CONSUMER_ID] = 1;
- $this->_requestMock->expects($this->once())
- ->method('getParam')
- ->willReturn(self::INTEGRATION_ID);
- $this->_integrationSvcMock->expects($this->any())
- ->method('get')
- ->with($this->anything())
- ->willReturn($intData);
- $this->_integrationSvcMock->expects($this->once())
- ->method('delete')
- ->with($this->anything())
- ->willReturn($intData);
- $this->_oauthSvcMock->expects($this->once())
- ->method('deleteConsumer')
- ->with($this->anything())
- ->willReturn($intData);
- // Use real translate model
- $this->_translateModelMock = null;
- // verify success message
- $this->_messageManager->expects($this->once())
- ->method('addSuccess')
- ->with(__('The integration \'%1\' has been deleted.', $intData[Info::DATA_NAME]));
- $this->_escaper->expects($this->once())
- ->method('escapeHtml')
- ->willReturnArgument(0);
- $this->integrationController->execute();
- }
- public function testDeleteActionConfigSetUp()
- {
- $intData = $this->_getSampleIntegrationData();
- $intData[Info::DATA_SETUP_TYPE] = IntegrationModel::TYPE_CONFIG;
- $this->_requestMock->expects($this->once())
- ->method('getParam')
- ->willReturn(self::INTEGRATION_ID);
- $this->_integrationSvcMock->expects($this->any())
- ->method('get')
- ->with($this->anything())
- ->willReturn($intData);
- $this->_integrationHelperMock->expects($this->once())
- ->method('isConfigType')
- ->with($intData)
- ->willReturn(true);
- // verify error message
- $this->_messageManager->expects($this->once())
- ->method('addError')
- ->with(__('Uninstall the extension to remove integration \'%1\'.', $intData[Info::DATA_NAME]));
- $this->_integrationSvcMock->expects($this->never())->method('delete');
- // Use real translate model
- $this->_translateModelMock = null;
- // verify success message
- $this->_messageManager->expects($this->never())->method('addSuccess');
- $this->_escaper->expects($this->once())
- ->method('escapeHtml')
- ->willReturnArgument(0);
- $this->integrationController->execute();
- }
- public function testDeleteActionMissingId()
- {
- $this->_integrationSvcMock->expects($this->never())->method('get');
- $this->_integrationSvcMock->expects($this->never())->method('delete');
- // Use real translate model
- $this->_translateModelMock = null;
- // verify error message
- $this->_messageManager->expects($this->once())
- ->method('addError')
- ->with(__('Integration ID is not specified or is invalid.'));
- $this->integrationController->execute();
- }
- public function testDeleteActionForServiceIntegrationException()
- {
- $intData = $this->_getSampleIntegrationData();
- $this->_integrationSvcMock->expects($this->any())
- ->method('get')
- ->with($this->anything())
- ->willReturn($intData);
- $this->_requestMock->expects($this->once())
- ->method('getParam')
- ->willReturn(self::INTEGRATION_ID);
- // Use real translate model
- $this->_translateModelMock = null;
- $exceptionMessage = __('The integration with ID "%1" doesn\'t exist.', $intData[Info::DATA_ID]);
- $invalidIdException = new IntegrationException($exceptionMessage);
- $this->_integrationSvcMock->expects($this->once())
- ->method('delete')
- ->willThrowException($invalidIdException);
- $this->_messageManager->expects($this->once())->method('addError');
- $this->integrationController->execute();
- }
- public function testDeleteActionForServiceGenericException()
- {
- $intData = $this->_getSampleIntegrationData();
- $this->_integrationSvcMock->expects($this->any())
- ->method('get')
- ->with($this->anything())
- ->willReturn($intData);
- $this->_requestMock->expects($this->once())
- ->method('getParam')
- ->willReturn(self::INTEGRATION_ID);
- // Use real translate model
- $this->_translateModelMock = null;
- $exceptionMessage = __('The integration with ID "%1" doesn\'t exist.', $intData[Info::DATA_ID]);
- $invalidIdException = new \Exception($exceptionMessage);
- $this->_integrationSvcMock->expects($this->once())
- ->method('delete')
- ->willThrowException($invalidIdException);
- $this->_messageManager->expects($this->never())->method('addError');
- $this->integrationController->execute();
- }
- }
|