7
7
8
8
use \Magento \Framework \Setup \FilePermissions ;
9
9
use Magento \Framework \App \Filesystem \DirectoryList ;
10
+ use Magento \Framework \App \State ;
11
+ use function Magento \NonComposerComponentRegistration \main ;
10
12
11
13
class FilePermissionsTest extends \PHPUnit \Framework \TestCase
12
14
{
@@ -25,6 +27,11 @@ class FilePermissionsTest extends \PHPUnit\Framework\TestCase
25
27
*/
26
28
private $ directoryListMock ;
27
29
30
+ /**
31
+ * @var \PHPUnit_Framework_MockObject_MockObject|State
32
+ */
33
+ private $ stateMock ;
34
+
28
35
/**
29
36
* @var FilePermissions
30
37
*/
@@ -34,6 +41,7 @@ public function setUp()
34
41
{
35
42
$ this ->directoryWriteMock = $ this ->createMock (\Magento \Framework \Filesystem \Directory \Write::class);
36
43
$ this ->filesystemMock = $ this ->createMock (\Magento \Framework \Filesystem::class);
44
+ $ this ->stateMock = $ this ->createMock (State::class);
37
45
38
46
$ this ->filesystemMock
39
47
->expects ($ this ->any ())
@@ -43,13 +51,21 @@ public function setUp()
43
51
44
52
$ this ->filePermissions = new FilePermissions (
45
53
$ this ->filesystemMock ,
46
- $ this ->directoryListMock
54
+ $ this ->directoryListMock ,
55
+ $ this ->stateMock
47
56
);
48
57
}
49
58
50
- public function testGetInstallationWritableDirectories ()
59
+ /**
60
+ * @param string $mageMode
61
+ * @dataProvider modeDataProvider
62
+ */
63
+ public function testGetInstallationWritableDirectories ($ mageMode )
51
64
{
52
65
$ this ->setUpDirectoryListInstallation ();
66
+ $ this ->stateMock ->expects ($ this ->once ())
67
+ ->method ('getMode ' )
68
+ ->willReturn ($ mageMode );
53
69
54
70
$ expected = [
55
71
BP . '/app/etc ' ,
@@ -62,6 +78,23 @@ public function testGetInstallationWritableDirectories()
62
78
$ this ->assertEquals ($ expected , $ this ->filePermissions ->getInstallationWritableDirectories ());
63
79
}
64
80
81
+ public function testGetInstallationWritableDirectoriesInProduction ()
82
+ {
83
+ $ this ->setUpDirectoryListInstallationInProduction ();
84
+ $ this ->stateMock ->expects ($ this ->once ())
85
+ ->method ('getMode ' )
86
+ ->willReturn (State::MODE_PRODUCTION );
87
+
88
+ $ expected = [
89
+ BP . '/app/etc ' ,
90
+ BP . '/var ' ,
91
+ BP . '/pub/media ' ,
92
+ BP . '/pub/static '
93
+ ];
94
+
95
+ $ this ->assertEquals ($ expected , $ this ->filePermissions ->getInstallationWritableDirectories ());
96
+ }
97
+
65
98
public function testGetApplicationNonWritableDirectories ()
66
99
{
67
100
$ this ->directoryListMock
@@ -134,13 +167,18 @@ public function getApplicationCurrentNonWritableDirectoriesDataProvider()
134
167
}
135
168
136
169
/**
170
+ * @param string $mageMode
171
+ * @dataProvider modeDataProvider
137
172
* @covers \Magento\Framework\Setup\FilePermissions::getMissingWritableDirectoriesForInstallation
138
173
* @covers \Magento\Framework\Setup\FilePermissions::getMissingWritablePathsForInstallation
139
174
*/
140
- public function testGetMissingWritableDirectoriesAndPathsForInstallation ()
175
+ public function testGetMissingWritableDirectoriesAndPathsForInstallation ($ mageMode )
141
176
{
142
177
$ this ->setUpDirectoryListInstallation ();
143
178
$ this ->setUpDirectoryWriteInstallation ();
179
+ $ this ->stateMock ->expects ($ this ->once ())
180
+ ->method ('getMode ' )
181
+ ->willReturn ($ mageMode );
144
182
145
183
$ expected = [
146
184
BP . '/var ' ,
@@ -160,6 +198,31 @@ public function testGetMissingWritableDirectoriesAndPathsForInstallation()
160
198
);
161
199
}
162
200
201
+ public function testGetMissingWritableDirectoriesAndPathsForInstallationInProduction ()
202
+ {
203
+ $ this ->setUpDirectoryListInstallationInProduction ();
204
+ $ this ->setUpDirectoryWriteInstallation ();
205
+ $ this ->stateMock ->expects ($ this ->once ())
206
+ ->method ('getMode ' )
207
+ ->willReturn (State::MODE_PRODUCTION );
208
+
209
+ $ expected = [
210
+ BP . '/var ' ,
211
+ BP . '/pub/media ' ,
212
+ BP . '/pub/static '
213
+ ];
214
+
215
+ $ this ->assertEquals (
216
+ $ expected ,
217
+ array_values ($ this ->filePermissions ->getMissingWritableDirectoriesForInstallation ())
218
+ );
219
+
220
+ $ this ->assertEquals (
221
+ $ expected ,
222
+ array_values ($ this ->filePermissions ->getMissingWritablePathsForInstallation ())
223
+ );
224
+ }
225
+
163
226
public function testGetMissingWritableDirectoriesForDbUpgrade ()
164
227
{
165
228
$ directoryMethods = ['isExist ' , 'isDirectory ' , 'isReadable ' , 'isWritable ' ];
@@ -240,6 +303,30 @@ public function setUpDirectoryListInstallation()
240
303
->will ($ this ->returnValue (BP . '/generated ' ));
241
304
}
242
305
306
+ public function setUpDirectoryListInstallationInProduction ()
307
+ {
308
+ $ this ->directoryListMock
309
+ ->expects ($ this ->at (0 ))
310
+ ->method ('getPath ' )
311
+ ->with (DirectoryList::CONFIG )
312
+ ->will ($ this ->returnValue (BP . '/app/etc ' ));
313
+ $ this ->directoryListMock
314
+ ->expects ($ this ->at (1 ))
315
+ ->method ('getPath ' )
316
+ ->with (DirectoryList::VAR_DIR )
317
+ ->will ($ this ->returnValue (BP . '/var ' ));
318
+ $ this ->directoryListMock
319
+ ->expects ($ this ->at (2 ))
320
+ ->method ('getPath ' )
321
+ ->with (DirectoryList::MEDIA )
322
+ ->will ($ this ->returnValue (BP . '/pub/media ' ));
323
+ $ this ->directoryListMock
324
+ ->expects ($ this ->at (3 ))
325
+ ->method ('getPath ' )
326
+ ->with (DirectoryList::STATIC_VIEW )
327
+ ->will ($ this ->returnValue (BP . '/pub/static ' ));
328
+ }
329
+
243
330
public function setUpDirectoryWriteInstallation ()
244
331
{
245
332
// CONFIG
@@ -294,4 +381,15 @@ public function setUpDirectoryWriteInstallation()
294
381
->method ('isWritable ' )
295
382
->will ($ this ->returnValue (false ));
296
383
}
384
+
385
+ /**
386
+ * @return array
387
+ */
388
+ public function modeDataProvider ()
389
+ {
390
+ return [
391
+ [State::MODE_DEFAULT ],
392
+ [State::MODE_DEVELOPER ],
393
+ ];
394
+ }
297
395
}
0 commit comments