AllowedCountriesTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Model\Plugin;
  7. use Magento\Customer\Model\Config\Share;
  8. use Magento\Customer\Model\Plugin\AllowedCountries;
  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 \Magento\Customer\Model\Config\Share | \PHPUnit_Framework_MockObject_MockObject
  16. */
  17. private $shareConfig;
  18. /**
  19. * @var StoreManagerInterface | \PHPUnit_Framework_MockObject_MockObject
  20. */
  21. private $storeManager;
  22. /** @var AllowedCountries */
  23. private $plugin;
  24. public function setUp()
  25. {
  26. $this->shareConfig = $this->getMockBuilder(Share::class)
  27. ->disableOriginalConstructor()
  28. ->getMock();
  29. $this->storeManager = $this->createMock(StoreManagerInterface::class);
  30. $this->plugin = new AllowedCountries($this->shareConfig, $this->storeManager);
  31. }
  32. public function testGetAllowedCountriesWithGlobalScope()
  33. {
  34. $expectedFilter = 1;
  35. $expectedScope = ScopeInterface::SCOPE_WEBSITES;
  36. $this->shareConfig->expects($this->once())
  37. ->method('isGlobalScope')
  38. ->willReturn(true);
  39. $originalAllowedCountriesMock = $this->getMockBuilder(\Magento\Directory\Model\AllowedCountries::class)
  40. ->disableOriginalConstructor()
  41. ->getMock();
  42. $websiteMock = $this->createMock(WebsiteInterface::class);
  43. $websiteMock->expects($this->once())
  44. ->method('getId')
  45. ->willReturn($expectedFilter);
  46. $this->storeManager->expects($this->once())
  47. ->method('getWebsites')
  48. ->willReturn([$websiteMock]);
  49. $this->assertEquals(
  50. [$expectedScope, [$expectedFilter]],
  51. $this->plugin->beforeGetAllowedCountries($originalAllowedCountriesMock)
  52. );
  53. }
  54. }