123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Theme\Test\Unit\Model\Theme;
- use \Magento\Theme\Model\Theme\SingleFile;
- class SingleFileTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var SingleFile
- */
- protected $object;
- /**
- * @var \Magento\Framework\View\Design\Theme\Customization\FileInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $file;
- /**
- * Initialize testable object
- */
- protected function setUp()
- {
- $this->file = $this->getMockBuilder(\Magento\Framework\View\Design\Theme\Customization\FileInterface::class)
- ->getMock();
- $this->object = new SingleFile($this->file);
- }
- /**
- * cover update method
- */
- public function testUpdate()
- {
- $fileContent = 'file content';
- $customFiles = [];
- $fileType = 'png';
- $customCss = $this->getMockBuilder(\Magento\Framework\View\Design\Theme\FileInterface::class)
- ->disableOriginalConstructor()
- ->setMethods(
- [
- 'delete',
- 'save',
- 'getContent',
- 'getFileInfo',
- 'getFullPath',
- 'getFileName',
- 'setFileName',
- 'getTheme',
- 'setTheme',
- 'getCustomizationService',
- 'setCustomizationService',
- 'setData',
- 'getType',
- 'prepareFile',
- ]
- )
- ->getMock();
- $theme = $this->getMockBuilder(\Magento\Framework\View\Design\ThemeInterface::class)
- ->setMethods(
- [
- 'getArea',
- 'getThemePath',
- 'getFullPath',
- 'getParentTheme',
- 'getCode',
- 'isPhysical',
- 'getInheritedThemes',
- 'getId',
- 'getCustomization',
- ]
- )
- ->getMock();
- $customization = $this->getMockBuilder(\Magento\Framework\View\Design\Theme\CustomizationInterface::class)
- ->getMock();
- $customCss->expects($this->once())
- ->method('setData')
- ->with('content', $fileContent);
- $customCss->expects($this->once())
- ->method('setTheme')
- ->with($theme);
- $customCss->expects($this->once())
- ->method('save');
- $this->file->expects($this->once())
- ->method('create')
- ->willReturn($customCss);
- $this->file->expects($this->once())
- ->method('getType')
- ->willReturn($fileType);
- $customization->expects($this->once())
- ->method('getFilesByType')
- ->with($fileType)
- ->willReturn($customFiles);
- $theme->expects($this->once())
- ->method('getCustomization')
- ->willReturn($customization);
- /** @var \Magento\Framework\View\Design\ThemeInterface $theme */
- $this->assertInstanceOf(
- \Magento\Framework\View\Design\Theme\FileInterface::class,
- $this->object->update($theme, $fileContent)
- );
- }
- /**
- * cover update method when fileContent is empty
- */
- public function testUpdateWhenFileDelete()
- {
- $customCss = $this->getMockBuilder(\Magento\Framework\View\Design\Theme\FileInterface::class)
- ->disableOriginalConstructor()
- ->setMethods(
- [
- 'delete',
- 'save',
- 'getContent',
- 'getFileInfo',
- 'getFullPath',
- 'getFileName',
- 'setFileName',
- 'getTheme',
- 'setTheme',
- 'getCustomizationService',
- 'setCustomizationService',
- 'setData',
- 'getType',
- 'prepareFile',
- ]
- )
- ->getMock();
- $fileContent = '';
- $customFiles = [$customCss];
- $fileType = 'png';
- $theme = $this->getMockBuilder(\Magento\Framework\View\Design\ThemeInterface::class)
- ->setMethods(
- [
- 'getArea',
- 'getThemePath',
- 'getFullPath',
- 'getParentTheme',
- 'getCode',
- 'isPhysical',
- 'getInheritedThemes',
- 'getId',
- 'getCustomization',
- ]
- )
- ->getMock();
- $customization = $this->getMockBuilder(\Magento\Framework\View\Design\Theme\CustomizationInterface::class)
- ->getMock();
- $customCss->expects($this->once())
- ->method('delete');
- $this->file->expects($this->once())
- ->method('getType')
- ->willReturn($fileType);
- $customization->expects($this->once())
- ->method('getFilesByType')
- ->with($fileType)
- ->willReturn($customFiles);
- $theme->expects($this->once())
- ->method('getCustomization')
- ->willReturn($customization);
- /** @var \Magento\Framework\View\Design\ThemeInterface $theme */
- $this->assertInstanceOf(
- \Magento\Framework\View\Design\Theme\FileInterface::class,
- $this->object->update($theme, $fileContent)
- );
- }
- }
|