StoresConfigTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Test class for \Magento\Store\Model\Store\StoresConfig
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Store\Test\Unit\Model;
  9. class StoresConfigTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var \Magento\Store\Model\StoresConfig
  13. */
  14. protected $_model;
  15. /**
  16. * @var \PHPUnit_Framework_MockObject_MockObject
  17. */
  18. protected $_storeManager;
  19. /**
  20. * @var \PHPUnit_Framework_MockObject_MockObject
  21. */
  22. protected $_storeOne;
  23. /**
  24. * @var \PHPUnit_Framework_MockObject_MockObject
  25. */
  26. protected $_storeTwo;
  27. /**
  28. * @var \PHPUnit_Framework_MockObject_MockObject
  29. */
  30. protected $_config;
  31. protected function setUp()
  32. {
  33. $this->_storeOne = $this->createMock(\Magento\Store\Model\Store::class);
  34. $this->_storeTwo = $this->createMock(\Magento\Store\Model\Store::class);
  35. $this->_storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
  36. $this->_config = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
  37. $this->_model = new \Magento\Store\Model\StoresConfig(
  38. $this->_storeManager,
  39. $this->_config
  40. );
  41. }
  42. public function testGetStoresConfigByPath()
  43. {
  44. $path = 'config/path';
  45. $this->_storeOne
  46. ->expects($this->at(0))
  47. ->method('getCode')
  48. ->will($this->returnValue('code_0'));
  49. $this->_storeOne
  50. ->expects($this->at(1))
  51. ->method('getId')
  52. ->will($this->returnValue(0));
  53. $this->_storeTwo
  54. ->expects($this->at(0))
  55. ->method('getCode')
  56. ->will($this->returnValue('code_1'));
  57. $this->_storeTwo
  58. ->expects($this->at(1))
  59. ->method('getId')
  60. ->will($this->returnValue(1));
  61. $this->_storeManager
  62. ->expects($this->once())
  63. ->method('getStores')
  64. ->with(true)
  65. ->will($this->returnValue([0 => $this->_storeOne, 1 => $this->_storeTwo]));
  66. $this->_config
  67. ->expects($this->at(0))
  68. ->method('getValue')
  69. ->with($path, 'store', 'code_0')
  70. ->will($this->returnValue(0));
  71. $this->_config
  72. ->expects($this->at(1))
  73. ->method('getValue')
  74. ->with($path, 'store', 'code_1')
  75. ->will($this->returnValue(1));
  76. $this->assertEquals([0 => 0, 1 => 1], $this->_model->getStoresConfigByPath($path));
  77. }
  78. }