CurrencyConfigTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Directory\Test\Unit\Model;
  7. use Magento\Config\App\Config\Type\System;
  8. use Magento\Directory\Model\CurrencyConfig;
  9. use Magento\Framework\App\Area;
  10. use Magento\Framework\App\Config\ScopeConfigInterface;
  11. use Magento\Framework\App\State;
  12. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  13. use Magento\Store\Api\Data\StoreInterface;
  14. use Magento\Store\Model\StoreManagerInterface;
  15. use PHPUnit\Framework\TestCase;
  16. /**
  17. * Provide tests for CurrencyConfig model.
  18. */
  19. class CurrencyConfigTest extends TestCase
  20. {
  21. /**
  22. * @var CurrencyConfig
  23. */
  24. private $testSubject;
  25. /**
  26. * @var System|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. private $config;
  29. /**
  30. * @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  31. */
  32. private $storeManager;
  33. /**
  34. * @var State|\PHPUnit_Framework_MockObject_MockObject
  35. */
  36. private $appState;
  37. /**
  38. * @inheritdoc
  39. */
  40. protected function setUp()
  41. {
  42. $this->config = $this->getMockBuilder(ScopeConfigInterface::class)
  43. ->disableOriginalConstructor()
  44. ->getMock();
  45. $this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)
  46. ->setMethods(['getStores', 'getWebsites'])
  47. ->disableOriginalConstructor()
  48. ->getMockForAbstractClass();
  49. $this->appState = $this->getMockBuilder(State::class)
  50. ->disableOriginalConstructor()
  51. ->getMock();
  52. $objectManager = new ObjectManager($this);
  53. $this->testSubject = $objectManager->getObject(
  54. CurrencyConfig::class,
  55. [
  56. 'storeManager' => $this->storeManager,
  57. 'appState' => $this->appState,
  58. 'config' => $this->config,
  59. ]
  60. );
  61. }
  62. /**
  63. * Test get currency config for admin, crontab and storefront areas.
  64. *
  65. * @dataProvider getConfigCurrenciesDataProvider
  66. * @return void
  67. */
  68. public function testGetConfigCurrencies(string $areCode)
  69. {
  70. $path = 'test/path';
  71. $expected = ['ARS', 'AUD', 'BZD'];
  72. $this->appState->expects(self::once())
  73. ->method('getAreaCode')
  74. ->willReturn($areCode);
  75. /** @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject $store */
  76. $store = $this->getMockBuilder(StoreInterface::class)
  77. ->setMethods(['getCode'])
  78. ->disableOriginalConstructor()
  79. ->getMockForAbstractClass();
  80. $store->expects(self::once())
  81. ->method('getCode')
  82. ->willReturn('testCode');
  83. if (in_array($areCode, [Area::AREA_ADMINHTML, Area::AREA_CRONTAB])) {
  84. $this->storeManager->expects(self::once())
  85. ->method('getStores')
  86. ->willReturn([$store]);
  87. } else {
  88. $this->storeManager->expects(self::once())
  89. ->method('getStore')
  90. ->willReturn($store);
  91. }
  92. $this->config->expects(self::once())
  93. ->method('getValue')
  94. ->with(
  95. self::identicalTo($path)
  96. )->willReturn('ARS,AUD,BZD');
  97. $result = $this->testSubject->getConfigCurrencies($path);
  98. self::assertEquals($expected, $result);
  99. }
  100. /**
  101. * Provide test data for getConfigCurrencies test.
  102. *
  103. * @return array
  104. */
  105. public function getConfigCurrenciesDataProvider()
  106. {
  107. return [
  108. ['areaCode' => Area::AREA_ADMINHTML],
  109. ['areaCode' => Area::AREA_CRONTAB],
  110. ['areaCode' => Area::AREA_FRONTEND],
  111. ];
  112. }
  113. }