AllowedCountriesTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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\Directory\Model\AllowedCountries;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Magento\Store\Api\Data\WebsiteInterface;
  10. use Magento\Store\Model\ScopeInterface;
  11. use Magento\Store\Model\StoreManagerInterface;
  12. class AllowedCountriesTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var \PHPUnit_Framework_MockObject_MockObject | ScopeConfigInterface
  16. */
  17. private $scopeConfigMock;
  18. /**
  19. * @var \PHPUnit_Framework_MockObject_MockObject | StoreManagerInterface
  20. */
  21. private $storeManagerMock;
  22. /**
  23. * @var AllowedCountries
  24. */
  25. private $allowedCountriesReader;
  26. /**
  27. * Test setUp
  28. */
  29. public function setUp()
  30. {
  31. $this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
  32. $this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
  33. $this->allowedCountriesReader = new AllowedCountries(
  34. $this->scopeConfigMock,
  35. $this->storeManagerMock
  36. );
  37. }
  38. /**
  39. * Test for getAllowedCountries
  40. */
  41. public function testGetAllowedCountriesWithEmptyFilter()
  42. {
  43. $website1 = $this->createMock(WebsiteInterface::class);
  44. $website1->expects($this->once())
  45. ->method('getId')
  46. ->willReturn(1);
  47. $this->storeManagerMock->expects($this->once())
  48. ->method('getWebsite')
  49. ->willReturn($website1);
  50. $this->scopeConfigMock->expects($this->once())
  51. ->method('getValue')
  52. ->with(AllowedCountries::ALLOWED_COUNTRIES_PATH, 'website', 1)
  53. ->willReturn('AM');
  54. $this->assertEquals(['AM' => 'AM'], $this->allowedCountriesReader->getAllowedCountries());
  55. }
  56. /**
  57. * Test for getAllowedCountries
  58. */
  59. public function testGetAllowedCountries()
  60. {
  61. $this->scopeConfigMock->expects($this->once())
  62. ->method('getValue')
  63. ->with(AllowedCountries::ALLOWED_COUNTRIES_PATH, 'website', 1)
  64. ->willReturn('AM');
  65. $this->assertEquals(
  66. ['AM' => 'AM'],
  67. $this->allowedCountriesReader->getAllowedCountries(ScopeInterface::SCOPE_WEBSITE, true)
  68. );
  69. }
  70. /**
  71. * Test for getAllowedCountries
  72. */
  73. public function testGetAllowedCountriesDefaultScope()
  74. {
  75. $this->storeManagerMock->expects($this->never())
  76. ->method('getStore');
  77. $this->scopeConfigMock->expects($this->once())
  78. ->method('getValue')
  79. ->with(AllowedCountries::ALLOWED_COUNTRIES_PATH, ScopeInterface::SCOPE_STORE, 0)
  80. ->willReturn('AM');
  81. $this->assertEquals(
  82. ['AM' => 'AM'],
  83. $this->allowedCountriesReader->getAllowedCountries(ScopeInterface::SCOPE_STORE, 0)
  84. );
  85. }
  86. }