123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Theme\Test\Unit\Model\Config;
- use Magento\Theme\Model\Config\Importer;
- use Magento\Theme\Model\ResourceModel\Theme as ThemeResourceModel;
- use Magento\Theme\Model\ResourceModel\Theme\Data\Collection as ThemeDbCollection;
- use Magento\Theme\Model\ResourceModel\Theme\Data\CollectionFactory;
- use Magento\Theme\Model\Theme\Collection as ThemeFilesystemCollection;
- use Magento\Theme\Model\Theme\Data;
- use Magento\Theme\Model\Theme\Registration;
- class ImporterTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var ThemeFilesystemCollection|\PHPUnit_Framework_MockObject_MockObject
- */
- private $themeFilesystemCollectionMock;
- /**
- * @var ThemeDbCollection|\PHPUnit_Framework_MockObject_MockObject
- */
- private $themeDbCollectionMock;
- /**
- * @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
- */
- private $themecollectionFactoryMock;
- /**
- * @var Registration|\PHPUnit_Framework_MockObject_MockObject
- */
- private $themeRegistrationMock;
- /**
- * @var ThemeResourceModel|\PHPUnit_Framework_MockObject_MockObject
- */
- private $themeResourceModelMock;
- /**
- * @var Importer
- */
- private $importer;
- protected function setUp()
- {
- $this->themeFilesystemCollectionMock = $this->getMockBuilder(ThemeFilesystemCollection::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->themeDbCollectionMock = $this->getMockBuilder(ThemeDbCollection::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->themecollectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
- ->setMethods(['create'])
- ->disableOriginalConstructor()
- ->getMock();
- $this->themeRegistrationMock = $this->getMockBuilder(Registration::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->themeResourceModelMock = $this->getMockBuilder(ThemeResourceModel::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->importer = new Importer(
- $this->themeFilesystemCollectionMock,
- $this->themecollectionFactoryMock,
- $this->themeRegistrationMock,
- $this->themeResourceModelMock
- );
- }
- /**
- * @expectedException \Magento\Framework\Exception\State\InvalidTransitionException
- * @expectedExceptionMessage Some error
- */
- public function testImportWithException()
- {
- $this->themeRegistrationMock->expects($this->once())
- ->method('register')
- ->willThrowException(new \Exception('Some error'));
- $this->importer->import([]);
- }
- public function testImport()
- {
- /** @var Data|\PHPUnit_Framework_MockObject_MockObject $firstThemeMock */
- $firstThemeMock = $this->getMockBuilder(Data::class)
- ->disableOriginalConstructor()
- ->getMock();
- $firstThemeMock->expects($this->atLeastOnce())
- ->method('getFullPath')
- ->willReturn('frontend/Magento/luma');
- /** @var Data|\PHPUnit_Framework_MockObject_MockObject $secondThemeMock */
- $secondThemeMock = $this->getMockBuilder(Data::class)
- ->disableOriginalConstructor()
- ->getMock();
- $secondThemeMock->expects($this->once())
- ->method('getFullPath')
- ->willReturn('frontend/Magento/blank');
- /** @var Data|\PHPUnit_Framework_MockObject_MockObject $thirdThemeMock */
- $thirdThemeMock = $this->getMockBuilder(Data::class)
- ->disableOriginalConstructor()
- ->getMock();
- $thirdThemeMock->expects($this->once())
- ->method('getFullPath')
- ->willReturn('frontend/Magento/test');
- $this->themeRegistrationMock->expects($this->once())
- ->method('register')
- ->willReturnSelf();
- $this->themeDbCollectionMock->expects($this->once())
- ->method('getItems')
- ->willReturn([$firstThemeMock, $secondThemeMock, $thirdThemeMock]);
- $this->themecollectionFactoryMock->expects($this->once())
- ->method('create')
- ->willReturn($this->themeDbCollectionMock);
- $this->themeResourceModelMock->expects($this->once())
- ->method('delete')
- ->with($secondThemeMock)
- ->willReturnSelf();
- $this->themeRegistrationMock->expects($this->any())
- ->method('getThemeFromDb')
- ->willReturnMap([
- ['frontend/Magento/luma', $firstThemeMock],
- ['frontend/Magento/blank', $secondThemeMock],
- ]);
- $this->themeFilesystemCollectionMock->expects($this->once())
- ->method('getAllIds')
- ->willReturn(['frontend/Magento/luma']);
- $result = $this->importer->import([
- 'frontend/Magento/test' => [
- 'area' => 'frontend',
- 'parent_id' => 'Magento/blank',
- 'theme_path' => 'Magento/test',
- ],
- ]);
- $this->assertSame(
- [
- '<info>Theme import was started.</info>',
- '<info>Theme import finished.</info>'
- ],
- $result
- );
- }
- /**
- * @param array $inFile
- * @param array $inDb
- * @param array $inFs
- * @param array $expectedResult
- * @dataProvider getWarningMessagesDataProvider
- */
- public function testGetWarningMessages(array $inFile, array $inDb, array $inFs, array $expectedResult)
- {
- $themes = [];
- foreach ($inDb as $themePath) {
- /** @var Data|\PHPUnit_Framework_MockObject_MockObject $themeMock */
- $themeMock = $this->getMockBuilder(Data::class)
- ->disableOriginalConstructor()
- ->getMock();
- $themeMock->expects($this->any())
- ->method('getFullPath')
- ->willReturn($themePath);
- $themes[] = $themeMock;
- }
- $this->themeDbCollectionMock->expects($this->once())
- ->method('getItems')
- ->willReturn($themes);
- $this->themecollectionFactoryMock->expects($this->once())
- ->method('create')
- ->willReturn($this->themeDbCollectionMock);
- $this->themeFilesystemCollectionMock->expects($this->once())
- ->method('getAllIds')
- ->willReturn($inFs);
- $this->assertEquals($expectedResult, $this->importer->getWarningMessages($inFile));
- }
- /**
- * @return array
- */
- public function getWarningMessagesDataProvider()
- {
- return [
- [[], [], [], []],
- [
- ['frontend/Magento/luma' => ['Data of theme']],
- ['frontend/Magento/luma'],
- ['frontend/Magento/luma'],
- []
- ],
- [
- ['frontend/Magento/luma' => ['Data of theme']],
- ['frontend/Magento/luma'],
- [],
- []
- ],
- [
- [
- 'frontend/Magento/luma' => ['Data of theme'],
- 'frontend/Magento/blank' => ['Data of theme']
- ],
- [],
- ['frontend/Magento/luma', 'frontend/Magento/blank'],
- [
- '<info>The following themes will be registered:</info>'
- . ' frontend/Magento/luma, frontend/Magento/blank',
- ]
- ],
- [
- [
- 'frontend/Magento/luma' => ['Data of theme'],
- 'frontend/Magento/blank' => ['Data of theme']
- ],
- [],
- [],
- []
- ],
- [
- [],
- [],
- ['frontend/Magento/luma'],
- [
- '<info>The following themes will be registered:</info> frontend/Magento/luma',
- ]
- ],
- [
- [],
- ['frontend/Magento/luma', 'frontend/Magento/blank'],
- [],
- [
- '<info>The following themes will be removed:</info> frontend/Magento/luma, frontend/Magento/blank',
- ]
- ],
- [
- [],
- ['frontend/Magento/luma'],
- ['frontend/Magento/luma'],
- []
- ],
- ];
- }
- }
|