123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Theme\Test\Unit\Model\Theme;
- class ResolverTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Theme\Model\Theme\Resolver
- */
- protected $model;
- /**
- * @var \Magento\Framework\View\DesignInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $designMock;
- /**
- * @var \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $themeCollectionFactoryMock;
- /**
- * @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $appStateMock;
- /**
- * @var \Magento\Theme\Model\ResourceModel\Theme\Collection|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $themeCollectionMock;
- /**
- * @var \Magento\Framework\View\Design\ThemeInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $themeMock;
- protected function setUp()
- {
- $this->designMock = $this->getMockForAbstractClass(\Magento\Framework\View\DesignInterface::class);
- $this->themeCollectionFactoryMock = $this->createPartialMock(
- \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory::class,
- ['create']
- );
- $this->themeCollectionMock = $this->createMock(\Magento\Theme\Model\ResourceModel\Theme\Collection::class);
- $this->appStateMock = $this->createMock(\Magento\Framework\App\State::class);
- $this->themeMock = $this->getMockForAbstractClass(\Magento\Framework\View\Design\ThemeInterface::class);
- $this->model = new \Magento\Theme\Model\Theme\Resolver(
- $this->appStateMock,
- $this->designMock,
- $this->themeCollectionFactoryMock
- );
- }
- public function testGetByAreaWithThemeDefaultArea()
- {
- $this->designMock->expects(
- $this->exactly(2)
- )->method(
- 'getDesignTheme'
- )->will(
- $this->returnValue($this->themeMock)
- );
- $this->designMock->expects($this->never())->method('getArea');
- $this->designMock->expects($this->never())->method('getConfigurationDesignTheme');
- $this->themeMock->expects(
- $this->once()
- )->method(
- 'getArea'
- )->will(
- $this->returnValue('theme_area')
- );
- $this->themeCollectionFactoryMock->expects($this->never())->method('create');
- $this->appStateMock->expects(
- $this->once()
- )->method(
- 'getAreaCode'
- )->will(
- $this->returnValue('theme_area')
- );
- $this->assertEquals($this->themeMock, $this->model->get());
- }
- public function testGetByAreaWithDesignDefaultArea()
- {
- $this->designMock->expects(
- $this->exactly(2)
- )->method(
- 'getDesignTheme'
- )->will(
- $this->returnValue($this->themeMock)
- );
- $this->designMock->expects(
- $this->once()
- )->method(
- 'getArea'
- )->will(
- $this->returnValue('design_area')
- );
- $this->designMock->expects($this->never())->method('getConfigurationDesignTheme');
- $this->themeMock->expects(
- $this->once()
- )->method(
- 'getArea'
- )->will(
- $this->returnValue('theme_area')
- );
- $this->themeCollectionFactoryMock->expects($this->never())->method('create');
- $this->appStateMock->expects(
- $this->once()
- )->method(
- 'getAreaCode'
- )->will(
- $this->returnValue('design_area')
- );
- $this->assertEquals($this->themeMock, $this->model->get());
- }
- public function testGetByAreaWithOtherAreaAndStringThemeId()
- {
- $this->designMock->expects(
- $this->once()
- )->method(
- 'getDesignTheme'
- )->will(
- $this->returnValue($this->themeMock)
- );
- $this->designMock->expects(
- $this->once()
- )->method(
- 'getArea'
- )->will(
- $this->returnValue('design_area')
- );
- $this->designMock->expects(
- $this->once()
- )->method(
- 'getConfigurationDesignTheme'
- )->will(
- $this->returnValue('other_theme')
- );
- $this->themeMock->expects(
- $this->once()
- )->method(
- 'getArea'
- )->will(
- $this->returnValue('theme_area')
- );
- $this->themeCollectionFactoryMock->expects(
- $this->once()
- )->method(
- 'create'
- )->will(
- $this->returnValue($this->themeCollectionMock)
- );
- $this->themeCollectionMock->expects(
- $this->once()
- )->method(
- 'getThemeByFullPath'
- )->with(
- 'other_area' . \Magento\Framework\View\Design\ThemeInterface::PATH_SEPARATOR . 'other_theme'
- )->will(
- $this->returnValue($this->themeMock)
- );
- $this->appStateMock->expects(
- $this->once()
- )->method(
- 'getAreaCode'
- )->will(
- $this->returnValue('other_area')
- );
- $this->assertEquals($this->themeMock, $this->model->get());
- }
- public function testGetByAreaWithOtherAreaAndNumericThemeId()
- {
- $this->designMock->expects(
- $this->once()
- )->method(
- 'getDesignTheme'
- )->will(
- $this->returnValue($this->themeMock)
- );
- $this->designMock->expects(
- $this->once()
- )->method(
- 'getArea'
- )->will(
- $this->returnValue('design_area')
- );
- $this->designMock->expects(
- $this->once()
- )->method(
- 'getConfigurationDesignTheme'
- )->will(
- $this->returnValue(12)
- );
- $this->themeMock->expects(
- $this->once()
- )->method(
- 'getArea'
- )->will(
- $this->returnValue('theme_area')
- );
- $this->themeCollectionFactoryMock->expects(
- $this->once()
- )->method(
- 'create'
- )->will(
- $this->returnValue($this->themeCollectionMock)
- );
- $this->themeCollectionMock->expects(
- $this->once()
- )->method(
- 'getItemById'
- )->with(
- 12
- )->will(
- $this->returnValue($this->themeMock)
- );
- $this->appStateMock->expects(
- $this->once()
- )->method(
- 'getAreaCode'
- )->will(
- $this->returnValue('other_area')
- );
- $this->assertEquals($this->themeMock, $this->model->get());
- }
- }
|