Skip to content

Commit e145cea

Browse files
committed
MAGETWO-62556: Subscription Request
1 parent 15884cd commit e145cea

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

app/code/Magento/Analytics/Test/Unit/Model/IntegrationManagerTest.php

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public function setUp()
7070
);
7171
}
7272

73+
/**
74+
* @param string $status
75+
*
76+
* @return array
77+
*/
7378
private function getIntegrationUserData($status)
7479
{
7580
return [
@@ -83,6 +88,9 @@ private function getIntegrationUserData($status)
8388
];
8489
}
8590

91+
/**
92+
* @return void
93+
*/
8694
public function testActivateIntegrationSuccess()
8795
{
8896
$this->integrationServiceMock->expects($this->once())
@@ -125,7 +133,13 @@ public function testActivateIntegrationFailureNoSuchEntity()
125133
$this->integrationManager->activateIntegration();
126134
}
127135

128-
public function testGetTokenNewIntegration()
136+
/**
137+
* @dataProvider integrationIdDataProvider
138+
*
139+
* @param int|null $integrationId If null integration is absent.
140+
* @return void
141+
*/
142+
public function testGetTokenNewIntegration($integrationId)
129143
{
130144
$this->configMock->expects($this->atLeastOnce())
131145
->method('getConfigDataValue')
@@ -140,7 +154,14 @@ public function testGetTokenNewIntegration()
140154
->willReturn(100500);
141155
$this->integrationMock->expects($this->once())
142156
->method('getId')
143-
->willReturn(1);
157+
->willReturn($integrationId);
158+
if (!$integrationId) {
159+
$this->integrationServiceMock
160+
->expects($this->once())
161+
->method('create')
162+
->with($this->getIntegrationUserData(Integration::STATUS_INACTIVE))
163+
->willReturn($this->integrationMock);
164+
}
144165
$this->oauthServiceMock->expects($this->at(0))
145166
->method('getAccessToken')
146167
->with(100500)
@@ -156,7 +177,13 @@ public function testGetTokenNewIntegration()
156177
$this->assertEquals('IntegrationToken', $this->integrationManager->generateToken());
157178
}
158179

159-
public function testGetTokenExistingIntegration()
180+
/**
181+
* @dataProvider integrationIdDataProvider
182+
*
183+
* @param int|null $integrationId If null integration is absent.
184+
* @return void
185+
*/
186+
public function testGetTokenExistingIntegration($integrationId)
160187
{
161188
$this->configMock->expects($this->atLeastOnce())
162189
->method('getConfigDataValue')
@@ -171,7 +198,14 @@ public function testGetTokenExistingIntegration()
171198
->willReturn(100500);
172199
$this->integrationMock->expects($this->once())
173200
->method('getId')
174-
->willReturn(1);
201+
->willReturn($integrationId);
202+
if (!$integrationId) {
203+
$this->integrationServiceMock
204+
->expects($this->once())
205+
->method('create')
206+
->with($this->getIntegrationUserData(Integration::STATUS_INACTIVE))
207+
->willReturn($this->integrationMock);
208+
}
175209
$this->oauthServiceMock->expects($this->once())
176210
->method('getAccessToken')
177211
->with(100500)
@@ -180,4 +214,15 @@ public function testGetTokenExistingIntegration()
180214
->method('createAccessToken');
181215
$this->assertEquals('IntegrationToken', $this->integrationManager->generateToken());
182216
}
217+
218+
/**
219+
* @return array
220+
*/
221+
public function integrationIdDataProvider()
222+
{
223+
return [
224+
[1],
225+
[null],
226+
];
227+
}
183228
}

0 commit comments

Comments
 (0)