RestrictAdminBillingAgreementUsageObserverTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Paypal\Test\Unit\Observer;
  8. use Magento\Framework\DataObject;
  9. /**
  10. * Class RestrictAdminBillingAgreementUsageObserverTest
  11. */
  12. class RestrictAdminBillingAgreementUsageObserverTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var \Magento\Paypal\Observer\RestrictAdminBillingAgreementUsageObserver
  16. */
  17. protected $_model;
  18. /**
  19. * @var \Magento\Framework\Event\Observer
  20. */
  21. protected $_observer;
  22. /**
  23. * @var DataObject
  24. */
  25. protected $_event;
  26. /**
  27. * @var \Magento\Framework\AuthorizationInterface|\PHPUnit_Framework_MockObject_MockObject
  28. */
  29. protected $_authorization;
  30. protected function setUp()
  31. {
  32. $this->_event = new DataObject();
  33. $this->_observer = new \Magento\Framework\Event\Observer();
  34. $this->_observer->setEvent($this->_event);
  35. $this->_authorization = $this->getMockForAbstractClass(\Magento\Framework\AuthorizationInterface::class);
  36. $this->_model = new \Magento\Paypal\Observer\RestrictAdminBillingAgreementUsageObserver($this->_authorization);
  37. }
  38. /**
  39. * @return array
  40. */
  41. public function restrictAdminBillingAgreementUsageDataProvider()
  42. {
  43. return [
  44. [new \stdClass(), false, true],
  45. [
  46. $this->getMockForAbstractClass(
  47. \Magento\Paypal\Model\Payment\Method\Billing\AbstractAgreement::class,
  48. [],
  49. '',
  50. false
  51. ),
  52. true,
  53. true
  54. ],
  55. [
  56. $this->getMockForAbstractClass(
  57. \Magento\Paypal\Model\Payment\Method\Billing\AbstractAgreement::class,
  58. [],
  59. '',
  60. false
  61. ),
  62. false,
  63. false
  64. ]
  65. ];
  66. }
  67. /**
  68. * @param object $methodInstance
  69. * @param bool $isAllowed
  70. * @param bool $isAvailable
  71. * @dataProvider restrictAdminBillingAgreementUsageDataProvider
  72. */
  73. public function testExecute($methodInstance, $isAllowed, $isAvailable)
  74. {
  75. $this->_event->setMethodInstance($methodInstance);
  76. $this->_authorization->expects(
  77. $this->any()
  78. )->method(
  79. 'isAllowed'
  80. )->with(
  81. 'Magento_Paypal::use'
  82. )->will(
  83. $this->returnValue($isAllowed)
  84. );
  85. $result = new DataObject();
  86. $result->setData('is_available', true);
  87. $this->_event->setResult($result);
  88. $this->_model->execute($this->_observer);
  89. $this->assertEquals($isAvailable, $result->getData('is_available'));
  90. }
  91. }