7
7
8
8
use \Magento \Framework \Setup \FilePermissions ;
9
9
use Magento \Framework \App \Filesystem \DirectoryList ;
10
+ use Magento \Framework \App \State ;
10
11
11
12
class FilePermissionsTest extends \PHPUnit \Framework \TestCase
12
13
{
@@ -25,6 +26,11 @@ class FilePermissionsTest extends \PHPUnit\Framework\TestCase
25
26
*/
26
27
private $ directoryListMock ;
27
28
29
+ /**
30
+ * @var \PHPUnit_Framework_MockObject_MockObject|State
31
+ */
32
+ private $ stateMock ;
33
+
28
34
/**
29
35
* @var FilePermissions
30
36
*/
@@ -34,6 +40,7 @@ public function setUp()
34
40
{
35
41
$ this ->directoryWriteMock = $ this ->createMock (\Magento \Framework \Filesystem \Directory \Write::class);
36
42
$ this ->filesystemMock = $ this ->createMock (\Magento \Framework \Filesystem::class);
43
+ $ this ->stateMock = $ this ->createMock (State::class);
37
44
38
45
$ this ->filesystemMock
39
46
->expects ($ this ->any ())
@@ -43,13 +50,21 @@ public function setUp()
43
50
44
51
$ this ->filePermissions = new FilePermissions (
45
52
$ this ->filesystemMock ,
46
- $ this ->directoryListMock
53
+ $ this ->directoryListMock ,
54
+ $ this ->stateMock
47
55
);
48
56
}
49
57
50
- public function testGetInstallationWritableDirectories ()
58
+ /**
59
+ * @param string $mageMode
60
+ * @dataProvider modeDataProvider
61
+ */
62
+ public function testGetInstallationWritableDirectories ($ mageMode )
51
63
{
52
64
$ this ->setUpDirectoryListInstallation ();
65
+ $ this ->stateMock ->expects ($ this ->once ())
66
+ ->method ('getMode ' )
67
+ ->willReturn ($ mageMode );
53
68
54
69
$ expected = [
55
70
BP . '/app/etc ' ,
@@ -62,6 +77,23 @@ public function testGetInstallationWritableDirectories()
62
77
$ this ->assertEquals ($ expected , $ this ->filePermissions ->getInstallationWritableDirectories ());
63
78
}
64
79
80
+ public function testGetInstallationWritableDirectoriesInProduction ()
81
+ {
82
+ $ this ->setUpDirectoryListInstallationInProduction ();
83
+ $ this ->stateMock ->expects ($ this ->once ())
84
+ ->method ('getMode ' )
85
+ ->willReturn (State::MODE_PRODUCTION );
86
+
87
+ $ expected = [
88
+ BP . '/app/etc ' ,
89
+ BP . '/var ' ,
90
+ BP . '/pub/media ' ,
91
+ BP . '/pub/static '
92
+ ];
93
+
94
+ $ this ->assertEquals ($ expected , $ this ->filePermissions ->getInstallationWritableDirectories ());
95
+ }
96
+
65
97
public function testGetApplicationNonWritableDirectories ()
66
98
{
67
99
$ this ->directoryListMock
@@ -134,13 +166,18 @@ public function getApplicationCurrentNonWritableDirectoriesDataProvider()
134
166
}
135
167
136
168
/**
169
+ * @param string $mageMode
170
+ * @dataProvider modeDataProvider
137
171
* @covers \Magento\Framework\Setup\FilePermissions::getMissingWritableDirectoriesForInstallation
138
172
* @covers \Magento\Framework\Setup\FilePermissions::getMissingWritablePathsForInstallation
139
173
*/
140
- public function testGetMissingWritableDirectoriesAndPathsForInstallation ()
174
+ public function testGetMissingWritableDirectoriesAndPathsForInstallation ($ mageMode )
141
175
{
142
176
$ this ->setUpDirectoryListInstallation ();
143
177
$ this ->setUpDirectoryWriteInstallation ();
178
+ $ this ->stateMock ->expects ($ this ->once ())
179
+ ->method ('getMode ' )
180
+ ->willReturn ($ mageMode );
144
181
145
182
$ expected = [
146
183
BP . '/var ' ,
@@ -160,6 +197,31 @@ public function testGetMissingWritableDirectoriesAndPathsForInstallation()
160
197
);
161
198
}
162
199
200
+ public function testGetMissingWritableDirectoriesAndPathsForInstallationInProduction ()
201
+ {
202
+ $ this ->setUpDirectoryListInstallationInProduction ();
203
+ $ this ->setUpDirectoryWriteInstallation ();
204
+ $ this ->stateMock ->expects ($ this ->once ())
205
+ ->method ('getMode ' )
206
+ ->willReturn (State::MODE_PRODUCTION );
207
+
208
+ $ expected = [
209
+ BP . '/var ' ,
210
+ BP . '/pub/media ' ,
211
+ BP . '/pub/static '
212
+ ];
213
+
214
+ $ this ->assertEquals (
215
+ $ expected ,
216
+ array_values ($ this ->filePermissions ->getMissingWritableDirectoriesForInstallation ())
217
+ );
218
+
219
+ $ this ->assertEquals (
220
+ $ expected ,
221
+ array_values ($ this ->filePermissions ->getMissingWritablePathsForInstallation ())
222
+ );
223
+ }
224
+
163
225
public function testGetMissingWritableDirectoriesForDbUpgrade ()
164
226
{
165
227
$ directoryMethods = ['isExist ' , 'isDirectory ' , 'isReadable ' , 'isWritable ' ];
@@ -212,6 +274,16 @@ public function getUnnecessaryWritableDirectoriesForApplicationDataProvider()
212
274
}
213
275
214
276
public function setUpDirectoryListInstallation ()
277
+ {
278
+ $ this ->setUpDirectoryListInstallationInProduction ();
279
+ $ this ->directoryListMock
280
+ ->expects ($ this ->at (4 ))
281
+ ->method ('getPath ' )
282
+ ->with (DirectoryList::GENERATED )
283
+ ->will ($ this ->returnValue (BP . '/generated ' ));
284
+ }
285
+
286
+ public function setUpDirectoryListInstallationInProduction ()
215
287
{
216
288
$ this ->directoryListMock
217
289
->expects ($ this ->at (0 ))
@@ -233,11 +305,6 @@ public function setUpDirectoryListInstallation()
233
305
->method ('getPath ' )
234
306
->with (DirectoryList::STATIC_VIEW )
235
307
->will ($ this ->returnValue (BP . '/pub/static ' ));
236
- $ this ->directoryListMock
237
- ->expects ($ this ->at (4 ))
238
- ->method ('getPath ' )
239
- ->with (DirectoryList::GENERATED )
240
- ->will ($ this ->returnValue (BP . '/generated ' ));
241
308
}
242
309
243
310
public function setUpDirectoryWriteInstallation ()
@@ -294,4 +361,15 @@ public function setUpDirectoryWriteInstallation()
294
361
->method ('isWritable ' )
295
362
->will ($ this ->returnValue (false ));
296
363
}
364
+
365
+ /**
366
+ * @return array
367
+ */
368
+ public function modeDataProvider ()
369
+ {
370
+ return [
371
+ [State::MODE_DEFAULT ],
372
+ [State::MODE_DEVELOPER ],
373
+ ];
374
+ }
297
375
}
0 commit comments