Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomCssTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Theme\Model\Theme\Customization\File\CustomCss;
9 
10 class CustomCssTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $customizationPath;
16 
20  protected $fileFactory;
21 
25  protected $filesystem;
26 
30  protected $object;
31 
35  protected function setUp()
36  {
37  $this->customizationPath = $this->getMockBuilder(\Magento\Framework\View\Design\Theme\Customization\Path::class)
38  ->disableOriginalConstructor()
39  ->getMock();
40  $this->fileFactory = $this->getMockBuilder(\Magento\Framework\View\Design\Theme\FileFactory::class)
41  ->setMethods(['create'])
42  ->disableOriginalConstructor()
43  ->getMock();
44  $this->filesystem = $this->getMockBuilder(\Magento\Framework\Filesystem::class)
45  ->disableOriginalConstructor()
46  ->getMock();
47 
48  $this->object = new CustomCss(
49  $this->customizationPath,
50  $this->fileFactory,
51  $this->filesystem
52  );
53  }
54 
59  public function testPrepareFile()
60  {
61  $file = $this->getMockBuilder(\Magento\Framework\View\Design\Theme\FileInterface::class)
62  ->setMethods(
63  [
64  'delete',
65  'save',
66  'getContent',
67  'getFileInfo',
68  'getFullPath',
69  'getFileName',
70  'setFileName',
71  'getTheme',
72  'setTheme',
73  'getCustomizationService',
74  'setCustomizationService',
75  'getId',
76  'setData',
77  ]
78  )
79  ->getMock();
80  $file->expects($this->any())
81  ->method('setData')
82  ->willReturnMap(
83  [
84  ['file_type', CustomCss::TYPE, $this->returnSelf()],
85  ['file_path', CustomCss::TYPE . '/' . CustomCss::FILE_NAME, $this->returnSelf()],
86  ['sort_order', CustomCss::SORT_ORDER, $this->returnSelf()],
87  ]
88  );
89  $file->expects($this->once())
90  ->method('getId')
91  ->willReturn(null);
92  $file->expects($this->at(0))
93  ->method('getFileName')
94  ->willReturn(null);
95  $file->expects($this->at(1))
96  ->method('getFileName')
97  ->willReturn(CustomCss::FILE_NAME);
98  $file->expects($this->once())
99  ->method('setFileName')
100  ->with(CustomCss::FILE_NAME);
101 
103  $this->assertInstanceOf(
104  \Magento\Theme\Model\Theme\Customization\File\CustomCss::class,
105  $this->object->prepareFile($file)
106  );
107  }
108 }