46 $this->contextMock = $this->createPartialMock(\
Magento\Framework\Model\Context::class, [
'getEventDispatcher']);
47 $eventManagerMock = $this->getMockForAbstractClass(
48 \
Magento\Framework\Event\ManagerInterface::class,
56 $this->contextMock->expects($this->once())
57 ->method(
'getEventDispatcher')
58 ->will($this->returnValue($eventManagerMock));
59 $this->registryMock = $this->createMock(\
Magento\Framework\Registry::class);
60 $this->oauthDataMock = $this->createMock(\
Magento\
Integration\Helper\Oauth\Data::class);
61 $this->resourceMock = $this->getMockForAbstractClass(
68 [
'getIdFieldName',
'selectByCompositeKey',
'deleteOldEntries']
70 $this->resourceCollectionMock = $this->createMock(\
Magento\Framework\Data\
Collection\AbstractDb::class);
71 $this->nonceModel = new \Magento\Integration\Model\Oauth\Nonce(
76 $this->resourceCollectionMock
82 $this->oauthDataMock->expects($this->once())
83 ->method(
'isCleanupProbability')
84 ->will($this->returnValue(
true));
86 $this->oauthDataMock->expects($this->once())
87 ->method(
'getCleanupExpirationPeriod')
88 ->will($this->returnValue(30));
90 $this->resourceMock->expects($this->once())
91 ->method(
'deleteOldEntries')
93 ->will($this->returnValue(1));
95 $this->assertEquals($this->nonceModel, $this->nonceModel->afterSave());
100 $this->oauthDataMock->expects($this->once())
101 ->method(
'isCleanupProbability')
102 ->will($this->returnValue(
false));
104 $this->oauthDataMock->expects($this->never())
105 ->method(
'getCleanupExpirationPeriod');
107 $this->resourceMock->expects($this->never())
108 ->method(
'deleteOldEntries');
110 $this->assertEquals($this->nonceModel, $this->nonceModel->afterSave());
115 $expectedData = [
'testData'];
116 $nonce =
'testNonce';
119 $this->resourceMock->expects($this->once())
120 ->method(
'selectByCompositeKey')
121 ->with($nonce, $consumerId)
122 ->will($this->returnValue($expectedData));
123 $this->nonceModel->loadByCompositeKey($nonce, $consumerId);
125 $this->assertEquals($expectedData, $this->nonceModel->getData());
testAfterSaveNoCleanupProbability()