DwstreeTest.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Config\Test\Unit\Block\System\Config;
  7. class DwstreeTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Config\Block\System\Config\Dwstree
  11. */
  12. protected $object;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $requestMock;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $storeManagerMock;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $websiteMock;
  25. /**
  26. * @var \PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $storeMock;
  29. /**
  30. * @var \PHPUnit_Framework_MockObject_MockObject
  31. */
  32. protected $context;
  33. protected function setUp()
  34. {
  35. $this->requestMock = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
  36. ->disableOriginalConstructor()
  37. ->getMock();
  38. $this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
  39. ->disableOriginalConstructor()
  40. ->getMock();
  41. $this->websiteMock = $this->getMockBuilder(\Magento\Store\Model\Website::class)
  42. ->disableOriginalConstructor()
  43. ->getMock();
  44. $this->storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
  45. ->disableOriginalConstructor()
  46. ->getMock();
  47. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  48. $this->context = $objectManager->getObject(
  49. \Magento\Backend\Block\Template\Context::class,
  50. [
  51. 'request' => $this->requestMock,
  52. 'storeManager' => $this->storeManagerMock,
  53. ]
  54. );
  55. $this->object = $objectManager->getObject(
  56. \Magento\Config\Block\System\Config\Dwstree::class,
  57. ['context' => $this->context]
  58. );
  59. }
  60. /**
  61. * @param $section
  62. * @param $website
  63. * @param $store
  64. * @dataProvider initTabsDataProvider
  65. */
  66. public function testInitTabs($section, $website, $store)
  67. {
  68. $this->requestMock->expects($this->any())
  69. ->method('getParam')
  70. ->will(
  71. $this->returnValueMap(
  72. [
  73. ['section', $section],
  74. ['website', $website['expected']['code']],
  75. ['store', $store['expected']['code']],
  76. ]
  77. )
  78. );
  79. $this->storeManagerMock->expects($this->once())
  80. ->method('getWebsites')
  81. ->willReturn([$this->websiteMock]);
  82. $this->websiteMock->expects($this->any())
  83. ->method('getCode')
  84. ->willReturn($website['actual']['code']);
  85. $this->websiteMock->expects($this->any())
  86. ->method('getName')
  87. ->willReturn($website['expected']['name']);
  88. $this->websiteMock->expects($this->once())
  89. ->method('getStores')
  90. ->willReturn([$this->storeMock]);
  91. $this->storeMock->expects($this->any())
  92. ->method('getCode')
  93. ->willReturn($store['actual']['code']);
  94. $this->storeMock->expects($this->any())
  95. ->method('getName')
  96. ->willReturn($store['actual']['name']);
  97. $this->assertEquals($this->object, $this->object->initTabs());
  98. $this->assertEquals(
  99. [
  100. 'default',
  101. 'website_' . $website['actual']['code'],
  102. 'store_' . $store['actual']['code']
  103. ],
  104. $this->object->getTabsIds()
  105. );
  106. }
  107. /**
  108. * @return array
  109. */
  110. public function initTabsDataProvider()
  111. {
  112. return [
  113. 'matchAll' => [
  114. 'scope' => 'Test Scope',
  115. 'website' => [
  116. 'expected' => ['name' => 'Test Website Name', 'code' => 'Test Website Code'],
  117. 'actual' => ['name' => 'Test Website Name', 'code' => 'Test Website Code'],
  118. ],
  119. 'store' => [
  120. 'expected' => ['name' => 'Test Store Name', 'code' => 'Test Store Code'],
  121. 'actual' => ['name' => 'Test Store Name', 'code' => 'Test Store Code'],
  122. ],
  123. ],
  124. 'matchStore' => [
  125. 'scope' => 'Test Scope',
  126. 'website' => [
  127. 'expected' => ['name' => 'Test Website Name', 'code' => 'Test Website Code'],
  128. 'actual' => ['name' => false, 'code' => false],
  129. ],
  130. 'store' => [
  131. 'expected' => ['name' => 'Test Store Name', 'code' => 'Test Store Code'],
  132. 'actual' => ['name' => 'Test Store Name', 'code' => 'Test Store Code'],
  133. ],
  134. ],
  135. 'matchWebsite' => [
  136. 'scope' => 'Test Scope',
  137. 'website' => [
  138. 'expected' => ['name' => 'Test Website Name', 'code' => 'Test Website Code'],
  139. 'actual' => ['name' => 'Test Website Name', 'code' => 'Test Website Code'],
  140. ],
  141. 'store' => [
  142. 'expected' => ['name' => 'Test Store Name', 'code' => 'Test Store Code'],
  143. 'actual' => ['name' => false, 'code' => false],
  144. ],
  145. ],
  146. 'noMatch' => [
  147. 'scope' => 'Test Scope',
  148. 'website' => [
  149. 'expected' => ['name' => 'Test Website Name', 'code' => 'Test Website Code'],
  150. 'actual' => ['name' => false, 'code' => false],
  151. ],
  152. 'store' => [
  153. 'expected' => ['name' => 'Test Store Name', 'code' => 'Test Store Code'],
  154. 'actual' => ['name' => false, 'code' => false],
  155. ],
  156. ],
  157. ];
  158. }
  159. }