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( [ 'Theme import was started.', 'Theme import finished.' ], $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'], [ 'The following themes will be registered:' . ' frontend/Magento/luma, frontend/Magento/blank', ] ], [ [ 'frontend/Magento/luma' => ['Data of theme'], 'frontend/Magento/blank' => ['Data of theme'] ], [], [], [] ], [ [], [], ['frontend/Magento/luma'], [ 'The following themes will be registered: frontend/Magento/luma', ] ], [ [], ['frontend/Magento/luma', 'frontend/Magento/blank'], [], [ 'The following themes will be removed: frontend/Magento/luma, frontend/Magento/blank', ] ], [ [], ['frontend/Magento/luma'], ['frontend/Magento/luma'], [] ], ]; } }