CanUseForCurrencyTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Test\Unit\Model\Checks;
  7. use \Magento\Payment\Model\Checks\CanUseForCurrency;
  8. class CanUseForCurrencyTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * Expected currency code
  12. */
  13. const EXPECTED_CURRENCY_CODE = 'US';
  14. /**
  15. * @var CanUseForCurrency
  16. */
  17. protected $_model;
  18. protected function setUp()
  19. {
  20. $this->_model = new CanUseForCurrency();
  21. }
  22. /**
  23. * @dataProvider paymentMethodDataProvider
  24. * @param bool $expectation
  25. */
  26. public function testIsApplicable($expectation)
  27. {
  28. $paymentMethod = $this->getMockBuilder(
  29. \Magento\Payment\Model\MethodInterface::class
  30. )->disableOriginalConstructor()->setMethods([])->getMock();
  31. $paymentMethod->expects($this->once())->method('canUseForCurrency')->with(
  32. self::EXPECTED_CURRENCY_CODE
  33. )->will($this->returnValue($expectation));
  34. $quoteMock = $this->getMockBuilder(\Magento\Quote\Model\Quote::class)->disableOriginalConstructor()->setMethods(
  35. []
  36. )->getMock();
  37. $store = $this->getMockBuilder(
  38. \Magento\Store\Model\Store::class
  39. )->disableOriginalConstructor()->setMethods([])->getMock();
  40. $store->expects($this->once())->method('getBaseCurrencyCode')->will(
  41. $this->returnValue(self::EXPECTED_CURRENCY_CODE)
  42. );
  43. $quoteMock->expects($this->once())->method('getStore')->will($this->returnValue($store));
  44. $this->assertEquals($expectation, $this->_model->isApplicable($paymentMethod, $quoteMock));
  45. }
  46. /**
  47. * @return array
  48. */
  49. public function paymentMethodDataProvider()
  50. {
  51. return [[true], [false]];
  52. }
  53. }