DesignTest.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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\View;
  7. use Magento\Store\Model\ScopeInterface;
  8. use Magento\Theme\Model\View\Design;
  9. class DesignTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject
  13. */
  14. protected $state;
  15. /**
  16. * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  17. */
  18. protected $storeManager;
  19. /**
  20. * @var \Magento\Framework\View\Design\Theme\FlyweightFactory|\PHPUnit_Framework_MockObject_MockObject
  21. */
  22. protected $flyweightThemeFactory;
  23. /**
  24. * @var \Magento\Theme\Model\ThemeFactory|\PHPUnit_Framework_MockObject_MockObject
  25. */
  26. protected $themeFactory;
  27. /**
  28. * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  29. */
  30. protected $config;
  31. /**
  32. * @var string|\PHPUnit_Framework_MockObject_MockObject
  33. */
  34. protected $defaultTheme = 'anyName4Theme';
  35. /**
  36. * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  37. */
  38. private $objectManager;
  39. /**
  40. * @var Design::__construct
  41. */
  42. private $model;
  43. protected function setUp()
  44. {
  45. $this->storeManager = $this->getMockForAbstractClass(\Magento\Store\Model\StoreManagerInterface::class);
  46. $this->flyweightThemeFactory = $this->createMock(\Magento\Framework\View\Design\Theme\FlyweightFactory::class);
  47. $this->config = $this->getMockForAbstractClass(\Magento\Framework\App\Config\ScopeConfigInterface::class);
  48. $this->themeFactory = $this->createPartialMock(\Magento\Theme\Model\ThemeFactory::class, ['create']);
  49. $this->objectManager = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class);
  50. $this->state = $this->createMock(\Magento\Framework\App\State::class);
  51. $themes = [Design::DEFAULT_AREA => $this->defaultTheme];
  52. $this->model = new Design(
  53. $this->storeManager,
  54. $this->flyweightThemeFactory,
  55. $this->config,
  56. $this->themeFactory,
  57. $this->objectManager,
  58. $this->state,
  59. $themes
  60. );
  61. }
  62. /**
  63. * @param string $themePath
  64. * @param string $themeId
  65. * @param string $expectedResult
  66. * @dataProvider getThemePathDataProvider
  67. */
  68. public function testGetThemePath($themePath, $themeId, $expectedResult)
  69. {
  70. $theme = $this->getMockForAbstractClass(\Magento\Framework\View\Design\ThemeInterface::class);
  71. $theme->expects($this->once())->method('getThemePath')->will($this->returnValue($themePath));
  72. $theme->expects($this->any())->method('getId')->will($this->returnValue($themeId));
  73. /** @var $theme \Magento\Framework\View\Design\ThemeInterface */
  74. $this->assertEquals($expectedResult, $this->model->getThemePath($theme));
  75. }
  76. /**
  77. * @return array
  78. */
  79. public function getThemePathDataProvider()
  80. {
  81. return [
  82. ['some_path', '', 'some_path'],
  83. ['', '2', \Magento\Framework\View\DesignInterface::PUBLIC_THEME_DIR . '2'],
  84. ['', '', \Magento\Framework\View\DesignInterface::PUBLIC_VIEW_DIR],
  85. ];
  86. }
  87. /**
  88. * @return array
  89. */
  90. public function designThemeDataProvider()
  91. {
  92. return [
  93. 'single' => [true, ScopeInterface::SCOPE_WEBSITES],
  94. 'multi' => [false, ScopeInterface::SCOPE_STORE],
  95. ];
  96. }
  97. /**
  98. * @test
  99. * @param bool $storeMode
  100. * @param string $scope
  101. * @dataProvider designThemeDataProvider
  102. * @return void
  103. */
  104. public function testSetDefaultDesignTheme($storeMode, $scope)
  105. {
  106. $area = Design::DEFAULT_AREA;
  107. $this->state->expects($this->any())
  108. ->method('getAreaCode')
  109. ->willReturn($area);
  110. $this->storeManager->expects($this->once())
  111. ->method('isSingleStoreMode')
  112. ->willReturn($storeMode);
  113. $this->config->expects($this->once())
  114. ->method('getValue')
  115. ->with(Design::XML_PATH_THEME_ID, $scope, null)
  116. ->willReturn(null);
  117. $this->flyweightThemeFactory->expects($this->once())
  118. ->method('create')
  119. ->with($this->defaultTheme, $area);
  120. $this->assertInstanceOf(get_class($this->model), $this->model->setDefaultDesignTheme());
  121. }
  122. /**
  123. * @test
  124. * @return void
  125. * @covers \Magento\Theme\Model\View\Design::getDesignParams
  126. * @covers \Magento\Theme\Model\View\Design::getLocale
  127. * @covers \Magento\Theme\Model\View\Design::getArea
  128. * @covers \Magento\Theme\Model\View\Design::getDesignTheme
  129. */
  130. public function testGetDesignParams()
  131. {
  132. $locale = 'locale';
  133. $area = Design::DEFAULT_AREA;
  134. $localeMock = $this->getMockForAbstractClass(\Magento\Framework\Locale\ResolverInterface::class);
  135. $localeMock->expects($this->once())
  136. ->method('getLocale')
  137. ->will($this->returnValue($locale));
  138. $this->objectManager->expects($this->once())
  139. ->method('get')
  140. ->will($this->returnValue($localeMock));
  141. $this->state->expects($this->any())
  142. ->method('getAreaCode')
  143. ->willReturn($area);
  144. $this->themeFactory->expects($this->once())
  145. ->method('create')
  146. ->willReturn($this->getMockBuilder(\Magento\Framework\View\Design\ThemeInterface::class)->getMock());
  147. $params = $this->model->getDesignParams();
  148. $this->assertInstanceOf(\Magento\Framework\View\Design\ThemeInterface::class, $params['themeModel']);
  149. $this->assertEquals($area, $params['area']);
  150. $this->assertEquals($locale, $params['locale']);
  151. }
  152. /**
  153. * @test
  154. * @return void
  155. * @covers \Magento\Theme\Model\View\Design::setDesignTheme
  156. * @covers \Magento\Theme\Model\View\Design::setArea
  157. */
  158. public function testSetDesignTheme()
  159. {
  160. $area = 'adminhtml';
  161. $theme = $this->getMockBuilder(\Magento\Framework\View\Design\ThemeInterface::class)->getMock();
  162. $this->assertInstanceOf(get_class($this->model), $this->model->setDesignTheme($theme, $area));
  163. }
  164. }