StoreConfigurationProviderTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Analytics\Test\Unit\Model;
  7. use Magento\Analytics\Model\StoreConfigurationProvider;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Magento\Store\Api\Data\StoreInterface;
  10. use Magento\Store\Api\Data\WebsiteInterface;
  11. use Magento\Store\Model\StoreManagerInterface;
  12. class StoreConfigurationProviderTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. private $scopeConfigMock;
  18. /**
  19. * @var string[]
  20. */
  21. private $configPaths;
  22. /**
  23. * @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. private $storeManagerMock;
  26. /**
  27. * @var WebsiteInterface|\PHPUnit_Framework_MockObject_MockObject
  28. */
  29. private $websiteMock;
  30. /**
  31. * @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject
  32. */
  33. private $storeMock;
  34. /**
  35. * @var StoreConfigurationProvider|\PHPUnit_Framework_MockObject_MockObject
  36. */
  37. private $storeConfigurationProvider;
  38. /**
  39. * @return void
  40. */
  41. protected function setUp()
  42. {
  43. $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
  44. ->disableOriginalConstructor()
  45. ->getMock();
  46. $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
  47. ->disableOriginalConstructor()
  48. ->getMock();
  49. $this->websiteMock = $this->getMockBuilder(WebsiteInterface::class)
  50. ->disableOriginalConstructor()
  51. ->getMock();
  52. $this->storeMock = $this->getMockBuilder(StoreInterface::class)
  53. ->disableOriginalConstructor()
  54. ->getMock();
  55. $this->configPaths = [
  56. 'web/unsecure/base_url',
  57. 'currency/options/base',
  58. 'general/locale/timezone'
  59. ];
  60. $this->storeConfigurationProvider = new StoreConfigurationProvider(
  61. $this->scopeConfigMock,
  62. $this->storeManagerMock,
  63. $this->configPaths
  64. );
  65. }
  66. public function testGetReport()
  67. {
  68. $map = [
  69. ['web/unsecure/base_url', 'default', 0, '127.0.0.1'],
  70. ['currency/options/base', 'default', 0, 'USD'],
  71. ['general/locale/timezone', 'default', 0, 'America/Dawson'],
  72. ['web/unsecure/base_url', 'websites', 1, '127.0.0.2'],
  73. ['currency/options/base', 'websites', 1, 'USD'],
  74. ['general/locale/timezone', 'websites', 1, 'America/Belem'],
  75. ['web/unsecure/base_url', 'stores', 2, '127.0.0.3'],
  76. ['currency/options/base', 'stores', 2, 'USD'],
  77. ['general/locale/timezone', 'stores', 2, 'America/Phoenix'],
  78. ];
  79. $this->scopeConfigMock
  80. ->method('getValue')
  81. ->will($this->returnValueMap($map));
  82. $this->storeManagerMock->expects($this->once())
  83. ->method('getWebsites')
  84. ->willReturn([$this->websiteMock]);
  85. $this->storeManagerMock->expects($this->once())
  86. ->method('getStores')
  87. ->willReturn([$this->storeMock]);
  88. $this->websiteMock->expects($this->once())
  89. ->method('getId')
  90. ->willReturn(1);
  91. $this->storeMock->expects($this->once())
  92. ->method('getId')
  93. ->willReturn(2);
  94. $result = iterator_to_array($this->storeConfigurationProvider->getReport());
  95. $resultValues = [];
  96. foreach ($result as $item) {
  97. $resultValues[] = array_values($item);
  98. }
  99. array_multisort($resultValues);
  100. array_multisort($map);
  101. $this->assertEquals($resultValues, $map);
  102. }
  103. }