30 private $_integrationFactory;
33 private $_integrationMock;
36 private $_emptyIntegrationMock;
42 private $_integrationData;
46 $this->_integrationFactory = $this->getMockBuilder(\
Magento\
Integration\Model\IntegrationFactory::class)
47 ->disableOriginalConstructor()
48 ->setMethods([
'create'])
50 $this->_integrationMock = $this->getMockBuilder(
52 )->disableOriginalConstructor()->setMethods(
66 $this->_integrationData = [
73 $this->_integrationFactory->expects(
78 $this->returnValue($this->_integrationMock)
81 $oauthConsumerHelper = $this->getMockBuilder(
83 )->disableOriginalConstructor()->getMock();
84 $oauthConsumer = $this->getMockBuilder(
86 )->disableOriginalConstructor()->getMock();
87 $oauthConsumerHelper->expects(
92 $this->returnValue($oauthConsumer)
94 $oauthConsumerHelper->expects($this->any())->method(
'loadConsumer')->will($this->returnValue($oauthConsumer));
96 $this->_service = new \Magento\Integration\Model\IntegrationService(
97 $this->_integrationFactory,
100 $this->_emptyIntegrationMock = $this->getMockBuilder(
102 )->disableOriginalConstructor()->setMethods(
116 $this->_emptyIntegrationMock->expects($this->any())->method(
'getId')->will($this->returnValue(
null));
121 $this->_integrationMock->expects(
126 $this->returnValue(self::VALUE_INTEGRATION_ID)
128 $this->_integrationMock->expects(
133 $this->returnValue($this->_integrationData)
135 $this->_integrationMock->expects(
140 self::VALUE_INTEGRATION_NAME,
143 $this->returnValue($this->_emptyIntegrationMock)
145 $this->_integrationMock->expects($this->any())->method(
'save')->will($this->returnSelf());
146 $this->_setValidIntegrationData();
147 $resultData = $this->_service->create($this->_integrationData)->getData();
148 $this->assertSame($this->_integrationData, $resultData);
157 $this->_integrationMock->expects(
162 $this->returnValue(self::VALUE_INTEGRATION_ID)
164 $this->_integrationMock->expects(
169 $this->returnValue($this->_integrationData)
171 $this->_integrationMock->expects(
176 self::VALUE_INTEGRATION_NAME,
179 $this->returnValue($this->_integrationMock)
181 $this->_integrationMock->expects($this->never())->method(
'save')->will($this->returnSelf());
182 $this->_service->create($this->_integrationData);
187 $this->_integrationMock->expects(
192 $this->returnValue(self::VALUE_INTEGRATION_ID)
194 $this->_integrationMock->expects(
199 $this->returnValue($this->_integrationData)
201 $this->_integrationMock->expects(
206 self::VALUE_INTEGRATION_ID
208 $this->returnValue($this->_integrationMock)
210 $this->_integrationMock->expects($this->once())->method(
'save')->will($this->returnSelf());
211 $this->_setValidIntegrationData();
212 $integrationData = $this->_service->update($this->_integrationData)->getData();
213 $this->assertEquals($this->_integrationData, $integrationData);
218 $this->_integrationMock->expects(
223 $this->returnValue(self::VALUE_INTEGRATION_ID)
225 $this->_integrationMock->expects(
230 $this->onConsecutiveCalls($this->_integrationMock, $this->_emptyIntegrationMock)
232 $this->_integrationMock->expects($this->once())->method(
'save')->will($this->returnSelf());
233 $this->_setValidIntegrationData();
240 $this->_integrationMock->expects($this->any())->method(
'getData')->will($this->returnValue($integrationData));
242 $updatedData = $this->_service->update($integrationData)->getData();
243 $this->assertEquals($integrationData, $updatedData);
252 $this->_integrationMock->expects(
257 $this->returnValue(self::VALUE_INTEGRATION_ID)
259 $this->_integrationMock->expects(
264 $this->onConsecutiveCalls($this->_integrationMock, $this->_getAnotherIntegrationMock())
266 $this->_integrationMock->expects($this->never())->method(
'save')->will($this->returnSelf());
267 $this->_setValidIntegrationData();
274 $this->_service->update($integrationData);
279 $this->_integrationMock->expects(
284 $this->returnValue(self::VALUE_INTEGRATION_ID)
286 $this->_integrationMock->expects(
291 $this->returnValue($this->_integrationData)
293 $this->_integrationMock->expects($this->once())->method(
'load')->will($this->returnSelf());
294 $this->_integrationMock->expects($this->never())->method(
'save');
295 $integrationData = $this->_service->get(self::VALUE_INTEGRATION_ID)->getData();
296 $this->assertEquals($this->_integrationData, $integrationData);
305 $this->_integrationMock->expects($this->any())->method(
'getId')->will($this->returnValue(
null));
306 $this->_integrationMock->expects($this->once())->method(
'load')->will($this->returnSelf());
307 $this->_integrationMock->expects($this->never())->method(
'save');
308 $this->_service->get(self::VALUE_INTEGRATION_ID)->getData();
313 $this->_integrationMock->expects(
318 self::VALUE_INTEGRATION_NAME,
321 $this->returnValue($this->_integrationMock)
323 $this->_integrationMock->expects(
328 $this->returnValue($this->_integrationData)
330 $integration = $this->_service->findByName(self::VALUE_INTEGRATION_NAME);
336 $this->_integrationMock->expects(
341 self::VALUE_INTEGRATION_NAME,
344 $this->returnValue($this->_emptyIntegrationMock)
346 $this->_emptyIntegrationMock->expects($this->any())->method(
'getData')->will($this->returnValue(
null));
347 $integration = $this->_service->findByName(self::VALUE_INTEGRATION_NAME);
353 $this->_integrationMock->expects(
358 $this->returnValue(self::VALUE_INTEGRATION_ID)
360 $this->_integrationMock->expects(
365 self::VALUE_INTEGRATION_ID
367 $this->returnValue($this->_integrationMock)
369 $this->_integrationMock->expects(
374 $this->returnValue($this->_integrationMock)
376 $this->_integrationMock->expects(
381 $this->returnValue($this->_integrationData)
383 $integrationData = $this->_service->delete(self::VALUE_INTEGRATION_ID);
393 $this->_integrationMock->expects($this->any())->method(
'getId')->will($this->returnValue(
null));
394 $this->_integrationMock->expects($this->once())->method(
'load')->will($this->returnSelf());
395 $this->_integrationMock->expects($this->never())->method(
'delete');
396 $this->_service->delete(self::VALUE_INTEGRATION_ID);
401 $this->_integrationMock->expects(
406 $this->returnValue($this->_integrationData)
409 $this->_integrationMock->expects(
414 self::VALUE_INTEGRATION_CONSUMER_ID,
417 $this->returnValue($this->_integrationMock)
420 $integration = $this->_service->findByConsumerId(self::VALUE_INTEGRATION_CONSUMER_ID);
426 $this->_emptyIntegrationMock->expects($this->any())->method(
'getData')->will($this->returnValue(
null));
428 $this->_integrationMock->expects(
433 self::VALUE_INTEGRATION_CONSUMER_ID,
436 $this->returnValue($this->_emptyIntegrationMock)
446 private function _setValidIntegrationData()
448 $this->_integrationMock->expects(
453 $this->returnValue(self::VALUE_INTEGRATION_NAME)
455 $this->_integrationMock->expects(
460 $this->returnValue(self::VALUE_INTEGRATION_EMAIL)
462 $this->_integrationMock->expects(
467 $this->returnValue(self::VALUE_INTEGRATION_ENDPOINT)
478 private function _getAnotherIntegrationMock(
479 $name = self::VALUE_INTEGRATION_NAME,
480 $integrationId = self::VALUE_INTEGRATION_ID
482 $integrationMock = $this->getMockBuilder(
483 \
Magento\Integration\Model\Integration::class
484 )->disableOriginalConstructor()->setMethods(
498 $integrationMock->expects($this->any())->method(
'getId')->will($this->returnValue($integrationId));
499 $integrationMock->expects($this->any())->method(
'getName')->will($this->returnValue(
$name));
500 $integrationMock->expects(
505 $this->returnValue(self::VALUE_INTEGRATION_EMAIL)
507 $integrationMock->expects(
512 $this->returnValue(self::VALUE_INTEGRATION_ENDPOINT)
514 return $integrationMock;
testCreateIntegrationAlreadyExistsException()
const VALUE_INTEGRATION_ANOTHER_NAME
const VALUE_INTEGRATION_CONSUMER_ID
testUpdateSuccessNameChanged()
testFindByConsumerIdNotFound()
const VALUE_INTEGRATION_NAME
const VALUE_INTEGRATION_ID
const VALUE_INTEGRATION_EMAIL
const VALUE_INTEGRATION_ENDPOINT
const VALUE_INTEGRATION_SETUP_BACKEND
if(!isset($_GET['name'])) $name