Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IntegrationTest.php
Go to the documentation of this file.
1 <?php
7 
11 class IntegrationTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $integrationModel;
17 
21  protected $contextMock;
22 
26  protected $registryMock;
27 
31  protected $resourceMock;
32 
37 
38  protected function setUp()
39  {
40  $this->contextMock = $this->createPartialMock(\Magento\Framework\Model\Context::class, ['getEventDispatcher']);
41  $eventManagerMock = $this->getMockForAbstractClass(
42  \Magento\Framework\Event\ManagerInterface::class,
43  [],
44  '',
45  false,
46  true,
47  true,
48  ['dispatch']
49  );
50  $this->contextMock->expects($this->once())
51  ->method('getEventDispatcher')
52  ->will($this->returnValue($eventManagerMock));
53  $this->registryMock = $this->createMock(\Magento\Framework\Registry::class);
54  $this->resourceMock = $this->getMockForAbstractClass(
55  \Magento\Framework\Model\ResourceModel\AbstractResource::class,
56  [],
57  '',
58  false,
59  true,
60  true,
61  ['getIdFieldName', 'load', 'selectActiveIntegrationByConsumerId']
62  );
63  $this->resourceCollectionMock = $this->createMock(\Magento\Framework\Data\Collection\AbstractDb::class);
64  $this->integrationModel = new \Magento\Integration\Model\Integration(
65  $this->contextMock,
66  $this->registryMock,
67  $this->resourceMock,
68  $this->resourceCollectionMock
69  );
70  }
71 
72  public function testLoadByConsumerId()
73  {
74  $consumerId = 1;
75  $this->resourceMock->expects($this->once())
76  ->method('load')
77  ->with($this->integrationModel, $consumerId, \Magento\Integration\Model\Integration::CONSUMER_ID);
78 
79  $this->integrationModel->loadByConsumerId($consumerId);
80  $this->assertFalse($this->integrationModel->hasDataChanges());
81  }
82 
84  {
85  $consumerId = 1;
86  $integrationData = [
87  'integration_id' => 1,
88  'name' => 'Test Integration'
89  ];
90 
91  $this->resourceMock->expects($this->once())
92  ->method('selectActiveIntegrationByConsumerId')
93  ->with($consumerId)
94  ->will($this->returnValue($integrationData));
95 
96  $this->integrationModel->loadActiveIntegrationByConsumerId($consumerId);
97  $this->assertEquals($integrationData, $this->integrationModel->getData());
98  }
99 
100  public function testGetStatus()
101  {
102  $this->integrationModel->setStatus(1);
103  $this->assertEquals(1, $this->integrationModel->getStatus());
104  }
105 }