_event = new DataObject(); $this->_observer = new \Magento\Framework\Event\Observer(); $this->_observer->setEvent($this->_event); $this->_authorization = $this->getMockForAbstractClass(\Magento\Framework\AuthorizationInterface::class); $this->_model = new \Magento\Paypal\Observer\RestrictAdminBillingAgreementUsageObserver($this->_authorization); } /** * @return array */ public function restrictAdminBillingAgreementUsageDataProvider() { return [ [new \stdClass(), false, true], [ $this->getMockForAbstractClass( \Magento\Paypal\Model\Payment\Method\Billing\AbstractAgreement::class, [], '', false ), true, true ], [ $this->getMockForAbstractClass( \Magento\Paypal\Model\Payment\Method\Billing\AbstractAgreement::class, [], '', false ), false, false ] ]; } /** * @param object $methodInstance * @param bool $isAllowed * @param bool $isAvailable * @dataProvider restrictAdminBillingAgreementUsageDataProvider */ public function testExecute($methodInstance, $isAllowed, $isAvailable) { $this->_event->setMethodInstance($methodInstance); $this->_authorization->expects( $this->any() )->method( 'isAllowed' )->with( 'Magento_Paypal::use' )->will( $this->returnValue($isAllowed) ); $result = new DataObject(); $result->setData('is_available', true); $this->_event->setResult($result); $this->_model->execute($this->_observer); $this->assertEquals($isAvailable, $result->getData('is_available')); } }