Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SingleFileTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Theme\Model\Theme\SingleFile;
9 
10 class SingleFileTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $object;
16 
20  protected $file;
21 
25  protected function setUp()
26  {
27  $this->file = $this->getMockBuilder(\Magento\Framework\View\Design\Theme\Customization\FileInterface::class)
28  ->getMock();
29 
30  $this->object = new SingleFile($this->file);
31  }
32 
36  public function testUpdate()
37  {
38  $fileContent = 'file content';
39  $customFiles = [];
40  $fileType = 'png';
41  $customCss = $this->getMockBuilder(\Magento\Framework\View\Design\Theme\FileInterface::class)
42  ->disableOriginalConstructor()
43  ->setMethods(
44  [
45  'delete',
46  'save',
47  'getContent',
48  'getFileInfo',
49  'getFullPath',
50  'getFileName',
51  'setFileName',
52  'getTheme',
53  'setTheme',
54  'getCustomizationService',
55  'setCustomizationService',
56  'setData',
57  'getType',
58  'prepareFile',
59  ]
60  )
61  ->getMock();
62  $theme = $this->getMockBuilder(\Magento\Framework\View\Design\ThemeInterface::class)
63  ->setMethods(
64  [
65  'getArea',
66  'getThemePath',
67  'getFullPath',
68  'getParentTheme',
69  'getCode',
70  'isPhysical',
71  'getInheritedThemes',
72  'getId',
73  'getCustomization',
74  ]
75  )
76  ->getMock();
77  $customization = $this->getMockBuilder(\Magento\Framework\View\Design\Theme\CustomizationInterface::class)
78  ->getMock();
79 
80  $customCss->expects($this->once())
81  ->method('setData')
82  ->with('content', $fileContent);
83  $customCss->expects($this->once())
84  ->method('setTheme')
85  ->with($theme);
86  $customCss->expects($this->once())
87  ->method('save');
88  $this->file->expects($this->once())
89  ->method('create')
90  ->willReturn($customCss);
91  $this->file->expects($this->once())
92  ->method('getType')
93  ->willReturn($fileType);
94  $customization->expects($this->once())
95  ->method('getFilesByType')
96  ->with($fileType)
97  ->willReturn($customFiles);
98  $theme->expects($this->once())
99  ->method('getCustomization')
100  ->willReturn($customization);
101 
103  $this->assertInstanceOf(
104  \Magento\Framework\View\Design\Theme\FileInterface::class,
105  $this->object->update($theme, $fileContent)
106  );
107  }
108 
112  public function testUpdateWhenFileDelete()
113  {
114  $customCss = $this->getMockBuilder(\Magento\Framework\View\Design\Theme\FileInterface::class)
115  ->disableOriginalConstructor()
116  ->setMethods(
117  [
118  'delete',
119  'save',
120  'getContent',
121  'getFileInfo',
122  'getFullPath',
123  'getFileName',
124  'setFileName',
125  'getTheme',
126  'setTheme',
127  'getCustomizationService',
128  'setCustomizationService',
129  'setData',
130  'getType',
131  'prepareFile',
132  ]
133  )
134  ->getMock();
135  $fileContent = '';
136  $customFiles = [$customCss];
137  $fileType = 'png';
138 
139  $theme = $this->getMockBuilder(\Magento\Framework\View\Design\ThemeInterface::class)
140  ->setMethods(
141  [
142  'getArea',
143  'getThemePath',
144  'getFullPath',
145  'getParentTheme',
146  'getCode',
147  'isPhysical',
148  'getInheritedThemes',
149  'getId',
150  'getCustomization',
151  ]
152  )
153  ->getMock();
154  $customization = $this->getMockBuilder(\Magento\Framework\View\Design\Theme\CustomizationInterface::class)
155  ->getMock();
156 
157  $customCss->expects($this->once())
158  ->method('delete');
159  $this->file->expects($this->once())
160  ->method('getType')
161  ->willReturn($fileType);
162  $customization->expects($this->once())
163  ->method('getFilesByType')
164  ->with($fileType)
165  ->willReturn($customFiles);
166  $theme->expects($this->once())
167  ->method('getCustomization')
168  ->willReturn($customization);
169 
171  $this->assertInstanceOf(
172  \Magento\Framework\View\Design\Theme\FileInterface::class,
173  $this->object->update($theme, $fileContent)
174  );
175  }
176 }
$theme