ScopeFallbackResolverTest.php 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Store\Test\Unit\Model;
  7. use Magento\Store\Api\Data\GroupInterface;
  8. use Magento\Store\Api\Data\StoreInterface;
  9. use Magento\Store\Model\ScopeFallbackResolver;
  10. use Magento\Store\Model\StoreManagerInterface;
  11. use Magento\Store\Model\ScopeInterface;
  12. use Magento\Framework\App\Config\ScopeConfigInterface;
  13. class ScopeFallbackResolverTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /** @var ScopeFallbackResolver */
  16. protected $model;
  17. /** @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
  18. protected $storeManagerMock;
  19. protected function setUp()
  20. {
  21. $this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
  22. ->getMockForAbstractClass();
  23. $this->model = new ScopeFallbackResolver($this->storeManagerMock);
  24. }
  25. /**
  26. * @param string $scope
  27. * @param int $scopeId
  28. * @param bool $forConfig
  29. * @param int $websiteId
  30. * @param int $groupId
  31. * @param array $result
  32. *
  33. * @dataProvider dataProviderGetFallbackScope
  34. */
  35. public function testGetFallbackScope($scope, $scopeId, $forConfig, $websiteId, $groupId, $result)
  36. {
  37. /** @var GroupInterface|\PHPUnit_Framework_MockObject_MockObject $groupMock */
  38. $groupMock = $this->getMockBuilder(\Magento\Store\Api\Data\GroupInterface::class)
  39. ->getMockForAbstractClass();
  40. $groupMock->expects($this->any())
  41. ->method('getWebsiteId')
  42. ->willReturn($websiteId);
  43. /** @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject $storeMock */
  44. $storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
  45. ->getMockForAbstractClass();
  46. $storeMock->expects($this->any())
  47. ->method('getWebsiteId')
  48. ->willReturn($websiteId);
  49. $storeMock->expects($this->any())
  50. ->method('getStoreGroupId')
  51. ->willReturn($groupId);
  52. $this->storeManagerMock->expects($this->any())
  53. ->method('getGroup')
  54. ->with($scopeId)
  55. ->willReturn($groupMock);
  56. $this->storeManagerMock->expects($this->any())
  57. ->method('getStore')
  58. ->with($scopeId)
  59. ->willReturn($storeMock);
  60. $this->assertEquals($result, $this->model->getFallbackScope($scope, $scopeId, $forConfig));
  61. }
  62. /**
  63. * @return array
  64. */
  65. public function dataProviderGetFallbackScope()
  66. {
  67. return [
  68. [ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, true, null, null, [null, null]],
  69. [ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0, false, 1, 2, [null, null]],
  70. [ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 1, false, 0, 0, [null, null]],
  71. [ScopeInterface::SCOPE_WEBSITE, 1, true, 0, 0, [ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null]],
  72. [ScopeInterface::SCOPE_WEBSITE, 2, false, null, null, [ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null]],
  73. [ScopeInterface::SCOPE_WEBSITES, 3, true, 1, null, [ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null]],
  74. [ScopeInterface::SCOPE_WEBSITES, 4, false, 0, null, [ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null]],
  75. [ScopeInterface::SCOPE_GROUP, 1, true, 1, null, [ScopeInterface::SCOPE_WEBSITES, 1]],
  76. [ScopeInterface::SCOPE_GROUP, 2, false, 2, 3, [ScopeInterface::SCOPE_WEBSITES, 2]],
  77. [ScopeInterface::SCOPE_STORE, 1, true, 1, null, [ScopeInterface::SCOPE_WEBSITES, 1]],
  78. [ScopeInterface::SCOPE_STORE, 3, true, 1, 2, [ScopeInterface::SCOPE_WEBSITES, 1]],
  79. [ScopeInterface::SCOPE_STORE, 2, false, null, 1, [ScopeInterface::SCOPE_GROUP, 1]],
  80. [ScopeInterface::SCOPE_STORE, 4, false, 3, 2, [ScopeInterface::SCOPE_GROUP, 2]],
  81. [ScopeInterface::SCOPE_STORES, 1, true, 5, null, [ScopeInterface::SCOPE_WEBSITES, 5]],
  82. [ScopeInterface::SCOPE_STORES, 3, true, 6, 0, [ScopeInterface::SCOPE_WEBSITES, 6]],
  83. [ScopeInterface::SCOPE_STORES, 2, false, null, 7, [ScopeInterface::SCOPE_GROUP, 7]],
  84. [ScopeInterface::SCOPE_STORES, 4, false, 0, 8, [ScopeInterface::SCOPE_GROUP, 8]],
  85. ];
  86. }
  87. }