ConfigTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Test theme config model
  8. */
  9. namespace Magento\Theme\Test\Unit\Model;
  10. class ConfigTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \PHPUnit_Framework_MockObject_MockObject
  14. */
  15. protected $_themeMock;
  16. /**
  17. * @var \PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $_configData;
  20. /**
  21. * @var \PHPUnit_Framework_MockObject_MockObject
  22. */
  23. protected $_storeManagerMock;
  24. /**
  25. * @var \PHPUnit_Framework_MockObject_MockObject
  26. */
  27. protected $_configCacheMock;
  28. /**
  29. * @var \PHPUnit_Framework_MockObject_MockObject
  30. */
  31. protected $_layoutCacheMock;
  32. /**
  33. * @var \Magento\Framework\App\Config\Storage\WriterInterface
  34. */
  35. protected $_scopeConfigWriter;
  36. /**
  37. * @var \Magento\Theme\Model\Config
  38. */
  39. protected $_model;
  40. protected function setUp()
  41. {
  42. /** @var $this->_themeMock \Magento\Theme\Model\Theme */
  43. $this->_themeMock = $this->createMock(\Magento\Theme\Model\Theme::class);
  44. $this->_storeManagerMock = $this->getMockForAbstractClass(
  45. \Magento\Store\Model\StoreManagerInterface::class,
  46. [],
  47. '',
  48. true,
  49. true,
  50. true,
  51. ['getStores', 'isSingleStoreMode']
  52. );
  53. $this->_configData = $this->createPartialMock(
  54. \Magento\Framework\App\Config\Value::class,
  55. ['getCollection', 'addFieldToFilter', '__wakeup']
  56. );
  57. $this->_configCacheMock = $this->getMockForAbstractClass(\Magento\Framework\Cache\FrontendInterface::class);
  58. $this->_layoutCacheMock = $this->getMockForAbstractClass(\Magento\Framework\Cache\FrontendInterface::class);
  59. $this->_scopeConfigWriter = $this->createPartialMock(
  60. \Magento\Framework\App\Config\Storage\WriterInterface::class,
  61. ['save', 'delete']
  62. );
  63. $this->_model = new \Magento\Theme\Model\Config(
  64. $this->_configData,
  65. $this->_scopeConfigWriter,
  66. $this->_storeManagerMock,
  67. $this->createMock(\Magento\Framework\Event\ManagerInterface::class),
  68. $this->_configCacheMock,
  69. $this->_layoutCacheMock
  70. );
  71. }
  72. protected function tearDown()
  73. {
  74. $this->_themeMock = null;
  75. $this->_configData = null;
  76. $this->_themeFactoryMock = null;
  77. $this->_configCacheMock = null;
  78. $this->_layoutCacheMock = null;
  79. $this->_model = null;
  80. }
  81. /**
  82. * cover \Magento\Theme\Model\Config::assignToStore
  83. */
  84. public function testAssignToStoreInSingleStoreMode()
  85. {
  86. $this->_storeManagerMock->expects($this->once())->method('isSingleStoreMode')->will($this->returnValue(true));
  87. $themePath = 'Magento/blank';
  88. /** Unassign themes from store */
  89. $configEntity = new \Magento\Framework\DataObject(['value' => 6, 'scope_id' => 8]);
  90. $this->_configData->expects(
  91. $this->once()
  92. )->method(
  93. 'getCollection'
  94. )->will(
  95. $this->returnValue($this->_configData)
  96. );
  97. $this->_configData->expects(
  98. $this->at(1)
  99. )->method(
  100. 'addFieldToFilter'
  101. )->with(
  102. 'scope',
  103. \Magento\Store\Model\ScopeInterface::SCOPE_STORES
  104. )->will(
  105. $this->returnValue($this->_configData)
  106. );
  107. $this->_configData->expects(
  108. $this->at(2)
  109. )->method(
  110. 'addFieldToFilter'
  111. )->with(
  112. 'path',
  113. \Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID
  114. )->will(
  115. $this->returnValue([$configEntity])
  116. );
  117. $this->_themeMock->expects($this->any())->method('getId')->will($this->returnValue(6));
  118. $this->_themeMock->expects($this->any())->method('getThemePath')->will($this->returnValue($themePath));
  119. $this->_scopeConfigWriter->expects($this->once())->method('delete');
  120. $this->_scopeConfigWriter->expects($this->once())->method('save');
  121. $this->_model->assignToStore($this->_themeMock, [2, 3, 5]);
  122. }
  123. /**
  124. * cover \Magento\Theme\Model\Config::assignToStore
  125. */
  126. public function testAssignToStoreNonSingleStoreMode()
  127. {
  128. $this->_storeManagerMock->expects($this->once())->method('isSingleStoreMode')->will($this->returnValue(false));
  129. $themePath = 'Magento/blank';
  130. /** Unassign themes from store */
  131. $configEntity = new \Magento\Framework\DataObject(['value' => 6, 'scope_id' => 8]);
  132. $this->_configData->expects(
  133. $this->once()
  134. )->method(
  135. 'getCollection'
  136. )->will(
  137. $this->returnValue($this->_configData)
  138. );
  139. $this->_configData->expects(
  140. $this->at(1)
  141. )->method(
  142. 'addFieldToFilter'
  143. )->with(
  144. 'scope',
  145. \Magento\Store\Model\ScopeInterface::SCOPE_STORES
  146. )->will(
  147. $this->returnValue($this->_configData)
  148. );
  149. $this->_configData->expects(
  150. $this->at(2)
  151. )->method(
  152. 'addFieldToFilter'
  153. )->with(
  154. 'path',
  155. \Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID
  156. )->will(
  157. $this->returnValue([$configEntity])
  158. );
  159. $this->_themeMock->expects($this->any())->method('getId')->will($this->returnValue(6));
  160. $this->_themeMock->expects($this->any())->method('getThemePath')->will($this->returnValue($themePath));
  161. $this->_scopeConfigWriter->expects($this->once())->method('delete');
  162. $this->_scopeConfigWriter->expects($this->exactly(3))->method('save');
  163. $this->_model->assignToStore($this->_themeMock, [2, 3, 5]);
  164. }
  165. }