ResolverTest.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Theme\Test\Unit\Model\Theme;
  7. class ResolverTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Theme\Model\Theme\Resolver
  11. */
  12. protected $model;
  13. /**
  14. * @var \Magento\Framework\View\DesignInterface|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $designMock;
  17. /**
  18. * @var \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $themeCollectionFactoryMock;
  21. /**
  22. * @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $appStateMock;
  25. /**
  26. * @var \Magento\Theme\Model\ResourceModel\Theme\Collection|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $themeCollectionMock;
  29. /**
  30. * @var \Magento\Framework\View\Design\ThemeInterface|\PHPUnit_Framework_MockObject_MockObject
  31. */
  32. protected $themeMock;
  33. protected function setUp()
  34. {
  35. $this->designMock = $this->getMockForAbstractClass(\Magento\Framework\View\DesignInterface::class);
  36. $this->themeCollectionFactoryMock = $this->createPartialMock(
  37. \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory::class,
  38. ['create']
  39. );
  40. $this->themeCollectionMock = $this->createMock(\Magento\Theme\Model\ResourceModel\Theme\Collection::class);
  41. $this->appStateMock = $this->createMock(\Magento\Framework\App\State::class);
  42. $this->themeMock = $this->getMockForAbstractClass(\Magento\Framework\View\Design\ThemeInterface::class);
  43. $this->model = new \Magento\Theme\Model\Theme\Resolver(
  44. $this->appStateMock,
  45. $this->designMock,
  46. $this->themeCollectionFactoryMock
  47. );
  48. }
  49. public function testGetByAreaWithThemeDefaultArea()
  50. {
  51. $this->designMock->expects(
  52. $this->exactly(2)
  53. )->method(
  54. 'getDesignTheme'
  55. )->will(
  56. $this->returnValue($this->themeMock)
  57. );
  58. $this->designMock->expects($this->never())->method('getArea');
  59. $this->designMock->expects($this->never())->method('getConfigurationDesignTheme');
  60. $this->themeMock->expects(
  61. $this->once()
  62. )->method(
  63. 'getArea'
  64. )->will(
  65. $this->returnValue('theme_area')
  66. );
  67. $this->themeCollectionFactoryMock->expects($this->never())->method('create');
  68. $this->appStateMock->expects(
  69. $this->once()
  70. )->method(
  71. 'getAreaCode'
  72. )->will(
  73. $this->returnValue('theme_area')
  74. );
  75. $this->assertEquals($this->themeMock, $this->model->get());
  76. }
  77. public function testGetByAreaWithDesignDefaultArea()
  78. {
  79. $this->designMock->expects(
  80. $this->exactly(2)
  81. )->method(
  82. 'getDesignTheme'
  83. )->will(
  84. $this->returnValue($this->themeMock)
  85. );
  86. $this->designMock->expects(
  87. $this->once()
  88. )->method(
  89. 'getArea'
  90. )->will(
  91. $this->returnValue('design_area')
  92. );
  93. $this->designMock->expects($this->never())->method('getConfigurationDesignTheme');
  94. $this->themeMock->expects(
  95. $this->once()
  96. )->method(
  97. 'getArea'
  98. )->will(
  99. $this->returnValue('theme_area')
  100. );
  101. $this->themeCollectionFactoryMock->expects($this->never())->method('create');
  102. $this->appStateMock->expects(
  103. $this->once()
  104. )->method(
  105. 'getAreaCode'
  106. )->will(
  107. $this->returnValue('design_area')
  108. );
  109. $this->assertEquals($this->themeMock, $this->model->get());
  110. }
  111. public function testGetByAreaWithOtherAreaAndStringThemeId()
  112. {
  113. $this->designMock->expects(
  114. $this->once()
  115. )->method(
  116. 'getDesignTheme'
  117. )->will(
  118. $this->returnValue($this->themeMock)
  119. );
  120. $this->designMock->expects(
  121. $this->once()
  122. )->method(
  123. 'getArea'
  124. )->will(
  125. $this->returnValue('design_area')
  126. );
  127. $this->designMock->expects(
  128. $this->once()
  129. )->method(
  130. 'getConfigurationDesignTheme'
  131. )->will(
  132. $this->returnValue('other_theme')
  133. );
  134. $this->themeMock->expects(
  135. $this->once()
  136. )->method(
  137. 'getArea'
  138. )->will(
  139. $this->returnValue('theme_area')
  140. );
  141. $this->themeCollectionFactoryMock->expects(
  142. $this->once()
  143. )->method(
  144. 'create'
  145. )->will(
  146. $this->returnValue($this->themeCollectionMock)
  147. );
  148. $this->themeCollectionMock->expects(
  149. $this->once()
  150. )->method(
  151. 'getThemeByFullPath'
  152. )->with(
  153. 'other_area' . \Magento\Framework\View\Design\ThemeInterface::PATH_SEPARATOR . 'other_theme'
  154. )->will(
  155. $this->returnValue($this->themeMock)
  156. );
  157. $this->appStateMock->expects(
  158. $this->once()
  159. )->method(
  160. 'getAreaCode'
  161. )->will(
  162. $this->returnValue('other_area')
  163. );
  164. $this->assertEquals($this->themeMock, $this->model->get());
  165. }
  166. public function testGetByAreaWithOtherAreaAndNumericThemeId()
  167. {
  168. $this->designMock->expects(
  169. $this->once()
  170. )->method(
  171. 'getDesignTheme'
  172. )->will(
  173. $this->returnValue($this->themeMock)
  174. );
  175. $this->designMock->expects(
  176. $this->once()
  177. )->method(
  178. 'getArea'
  179. )->will(
  180. $this->returnValue('design_area')
  181. );
  182. $this->designMock->expects(
  183. $this->once()
  184. )->method(
  185. 'getConfigurationDesignTheme'
  186. )->will(
  187. $this->returnValue(12)
  188. );
  189. $this->themeMock->expects(
  190. $this->once()
  191. )->method(
  192. 'getArea'
  193. )->will(
  194. $this->returnValue('theme_area')
  195. );
  196. $this->themeCollectionFactoryMock->expects(
  197. $this->once()
  198. )->method(
  199. 'create'
  200. )->will(
  201. $this->returnValue($this->themeCollectionMock)
  202. );
  203. $this->themeCollectionMock->expects(
  204. $this->once()
  205. )->method(
  206. 'getItemById'
  207. )->with(
  208. 12
  209. )->will(
  210. $this->returnValue($this->themeMock)
  211. );
  212. $this->appStateMock->expects(
  213. $this->once()
  214. )->method(
  215. 'getAreaCode'
  216. )->will(
  217. $this->returnValue('other_area')
  218. );
  219. $this->assertEquals($this->themeMock, $this->model->get());
  220. }
  221. }