IntegrationTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Integration\Test\Unit\Model;
  7. /**
  8. * Unit test for \Magento\Integration\Model\Integration
  9. */
  10. class IntegrationTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Integration\Model\Integration
  14. */
  15. protected $integrationModel;
  16. /**
  17. * @var \Magento\Framework\Model\Context|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $contextMock;
  20. /**
  21. * @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. protected $registryMock;
  24. /**
  25. * @var \Magento\Framework\Model\ResourceModel\AbstractResource|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. protected $resourceMock;
  28. /**
  29. * @var \Magento\Framework\Data\Collection\AbstractDb|\PHPUnit_Framework_MockObject_MockObject
  30. */
  31. protected $resourceCollectionMock;
  32. protected function setUp()
  33. {
  34. $this->contextMock = $this->createPartialMock(\Magento\Framework\Model\Context::class, ['getEventDispatcher']);
  35. $eventManagerMock = $this->getMockForAbstractClass(
  36. \Magento\Framework\Event\ManagerInterface::class,
  37. [],
  38. '',
  39. false,
  40. true,
  41. true,
  42. ['dispatch']
  43. );
  44. $this->contextMock->expects($this->once())
  45. ->method('getEventDispatcher')
  46. ->will($this->returnValue($eventManagerMock));
  47. $this->registryMock = $this->createMock(\Magento\Framework\Registry::class);
  48. $this->resourceMock = $this->getMockForAbstractClass(
  49. \Magento\Framework\Model\ResourceModel\AbstractResource::class,
  50. [],
  51. '',
  52. false,
  53. true,
  54. true,
  55. ['getIdFieldName', 'load', 'selectActiveIntegrationByConsumerId']
  56. );
  57. $this->resourceCollectionMock = $this->createMock(\Magento\Framework\Data\Collection\AbstractDb::class);
  58. $this->integrationModel = new \Magento\Integration\Model\Integration(
  59. $this->contextMock,
  60. $this->registryMock,
  61. $this->resourceMock,
  62. $this->resourceCollectionMock
  63. );
  64. }
  65. public function testLoadByConsumerId()
  66. {
  67. $consumerId = 1;
  68. $this->resourceMock->expects($this->once())
  69. ->method('load')
  70. ->with($this->integrationModel, $consumerId, \Magento\Integration\Model\Integration::CONSUMER_ID);
  71. $this->integrationModel->loadByConsumerId($consumerId);
  72. $this->assertFalse($this->integrationModel->hasDataChanges());
  73. }
  74. public function testLoadActiveIntegrationByConsumerId()
  75. {
  76. $consumerId = 1;
  77. $integrationData = [
  78. 'integration_id' => 1,
  79. 'name' => 'Test Integration'
  80. ];
  81. $this->resourceMock->expects($this->once())
  82. ->method('selectActiveIntegrationByConsumerId')
  83. ->with($consumerId)
  84. ->will($this->returnValue($integrationData));
  85. $this->integrationModel->loadActiveIntegrationByConsumerId($consumerId);
  86. $this->assertEquals($integrationData, $this->integrationModel->getData());
  87. }
  88. public function testGetStatus()
  89. {
  90. $this->integrationModel->setStatus(1);
  91. $this->assertEquals(1, $this->integrationModel->getStatus());
  92. }
  93. }