21 private $integrationServiceMock;
26 private $oauthServiceMock;
36 private $integrationMock;
41 private $integrationManager;
45 $objectManagerHelper =
new ObjectManagerHelper($this);
46 $this->integrationServiceMock = $this->getMockBuilder(IntegrationServiceInterface::class)
48 $this->configMock = $this->getMockBuilder(Config::class)
49 ->disableOriginalConstructor()
51 $this->oauthServiceMock = $this->getMockBuilder(OauthServiceInterface::class)
53 $this->integrationMock = $this->getMockBuilder(Integration::class)
54 ->disableOriginalConstructor()
60 $this->integrationManager = $objectManagerHelper->getObject(
61 IntegrationManager::class,
63 'integrationService' => $this->integrationServiceMock,
64 'oauthService' => $this->oauthServiceMock,
65 'config' => $this->configMock
75 private function getIntegrationUserData(
$status)
78 'name' =>
'ma-integration-user',
80 'all_resources' =>
false,
82 'Magento_Analytics::analytics',
83 'Magento_Analytics::analytics_api' 93 $this->integrationServiceMock->expects($this->once())
94 ->method(
'findByName')
95 ->with(
'ma-integration-user')
96 ->willReturn($this->integrationMock);
97 $this->integrationMock->expects($this->exactly(2))
101 $integrationData[
'integration_id'] = 100500;
102 $this->configMock->expects($this->exactly(2))
103 ->method(
'getConfigDataValue')
104 ->with(
'analytics/integration_name',
null,
null)
105 ->willReturn(
'ma-integration-user');
106 $this->integrationServiceMock->expects($this->once())
108 ->with($integrationData);
109 $this->assertTrue($this->integrationManager->activateIntegration());
117 $this->integrationServiceMock->expects($this->once())
118 ->method(
'findByName')
119 ->with(
'ma-integration-user')
120 ->willReturn($this->integrationMock);
121 $this->integrationMock->expects($this->once())
124 $this->configMock->expects($this->once())
125 ->method(
'getConfigDataValue')
126 ->with(
'analytics/integration_name',
null,
null)
127 ->willReturn(
'ma-integration-user');
128 $this->integrationServiceMock->expects($this->never())
130 $this->integrationManager->activateIntegration();
141 $this->configMock->expects($this->atLeastOnce())
142 ->method(
'getConfigDataValue')
143 ->with(
'analytics/integration_name',
null,
null)
144 ->willReturn(
'ma-integration-user');
145 $this->integrationServiceMock->expects($this->once())
146 ->method(
'findByName')
147 ->with(
'ma-integration-user')
148 ->willReturn($this->integrationMock);
149 $this->integrationMock->expects($this->once())
150 ->method(
'getConsumerId')
151 ->willReturn(100500);
152 $this->integrationMock->expects($this->once())
154 ->willReturn($integrationId);
155 if (!$integrationId) {
156 $this->integrationServiceMock
157 ->expects($this->once())
160 ->willReturn($this->integrationMock);
162 $this->oauthServiceMock->expects($this->at(0))
163 ->method(
'getAccessToken')
166 $this->oauthServiceMock->expects($this->at(2))
167 ->method(
'getAccessToken')
169 ->willReturn(
'IntegrationToken');
170 $this->oauthServiceMock->expects($this->once())
171 ->method(
'createAccessToken')
174 $this->assertEquals(
'IntegrationToken', $this->integrationManager->generateToken());
185 $this->configMock->expects($this->atLeastOnce())
186 ->method(
'getConfigDataValue')
187 ->with(
'analytics/integration_name',
null,
null)
188 ->willReturn(
'ma-integration-user');
189 $this->integrationServiceMock->expects($this->once())
190 ->method(
'findByName')
191 ->with(
'ma-integration-user')
192 ->willReturn($this->integrationMock);
193 $this->integrationMock->expects($this->once())
194 ->method(
'getConsumerId')
195 ->willReturn(100500);
196 $this->integrationMock->expects($this->once())
198 ->willReturn($integrationId);
199 if (!$integrationId) {
200 $this->integrationServiceMock
201 ->expects($this->once())
204 ->willReturn($this->integrationMock);
206 $this->oauthServiceMock->expects($this->once())
207 ->method(
'getAccessToken')
209 ->willReturn(
'IntegrationToken');
210 $this->oauthServiceMock->expects($this->never())
211 ->method(
'createAccessToken');
212 $this->assertEquals(
'IntegrationToken', $this->integrationManager->generateToken());
testActivateIntegrationFailureNoSuchEntity()
testActivateIntegrationSuccess()
testGetTokenNewIntegration($integrationId)
testGetTokenExistingIntegration($integrationId)
integrationIdDataProvider()