@@ -27,6 +27,16 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
27
27
*/
28
28
protected $ _objectManager ;
29
29
30
+ /**
31
+ * @var string Default value for session.save_path setting
32
+ */
33
+ protected $ defaultSavePath ;
34
+
35
+ /**
36
+ * @var \Magento\Framework\App\DeploymentConfig | \PHPUnit_Framework_MockObject_MockObject
37
+ */
38
+ protected $ deploymentConfigMock ;
39
+
30
40
protected function setUp ()
31
41
{
32
42
$ this ->_objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
@@ -35,24 +45,27 @@ protected function setUp()
35
45
if ($ sessionManager ->isSessionExists ()) {
36
46
$ sessionManager ->writeClose ();
37
47
}
38
- $ deploymentConfigMock = $ this ->getMock ('Magento\Framework\App\DeploymentConfig ' , [], [], '' , false );
39
- $ deploymentConfigMock ->expects ($ this ->at (0 ))
48
+ $ this -> deploymentConfigMock = $ this ->getMock ('Magento\Framework\App\DeploymentConfig ' , [], [], '' , false );
49
+ $ this -> deploymentConfigMock ->expects ($ this ->at (0 ))
40
50
->method ('get ' )
41
51
->with (Config::PARAM_SESSION_SAVE_METHOD , 'files ' )
42
52
->will ($ this ->returnValue ('files ' ));
43
- $ deploymentConfigMock ->expects ($ this ->at (1 ))
53
+ $ this -> deploymentConfigMock ->expects ($ this ->at (1 ))
44
54
->method ('get ' )
45
55
->with (Config::PARAM_SESSION_SAVE_PATH )
46
56
->will ($ this ->returnValue (null ));
47
- $ deploymentConfigMock ->expects ($ this ->at (2 ))
57
+ $ this -> deploymentConfigMock ->expects ($ this ->at (2 ))
48
58
->method ('get ' )
49
59
->with (Config::PARAM_SESSION_CACHE_LIMITER )
50
60
->will ($ this ->returnValue ($ this ->_cacheLimiter ));
51
61
52
62
$ this ->_model = $ this ->_objectManager ->create (
53
63
'Magento\Framework\Session\Config ' ,
54
- ['deploymentConfig ' => $ deploymentConfigMock ]
64
+ ['deploymentConfig ' => $ this -> deploymentConfigMock ]
55
65
);
66
+ $ this ->defaultSavePath = $ this ->_objectManager
67
+ ->get ('Magento\Framework\Filesystem\DirectoryList ' )
68
+ ->getPath (DirectoryList::SESSION );
56
69
}
57
70
58
71
protected function tearDown ()
@@ -283,4 +296,47 @@ public function testSetSavePath()
283
296
$ this ->_model ->setSavePath ('some_save_path ' );
284
297
$ this ->assertEquals ($ this ->_model ->getOption ('save_path ' ), 'some_save_path ' );
285
298
}
299
+
300
+ /**
301
+ * @dataProvider savePathDataProvider
302
+ */
303
+ public function testConstructorSavePath ($ existing , $ given , $ expected )
304
+ {
305
+ $ sessionSavePath = ini_get ('session.save_path ' );
306
+ if ($ expected === 'default ' ) {
307
+ $ expected = $ this ->defaultSavePath . '/ ' ;
308
+ }
309
+ $ setup = ini_set ('session.save_path ' , $ existing );
310
+ if ($ setup === false ) {
311
+ $ this ->markTestSkipped ('Cannot set session.save_path with ini_set ' );
312
+ }
313
+
314
+ $ this ->deploymentConfigMock ->expects ($ this ->at (1 ))
315
+ ->method ('get ' )
316
+ ->with (Config::PARAM_SESSION_SAVE_PATH )
317
+ ->will ($ this ->returnValue ($ given ));
318
+
319
+ $ this ->_model = $ this ->_objectManager ->create (
320
+ 'Magento\Framework\Session\Config ' ,
321
+ ['deploymentConfig ' => $ this ->deploymentConfigMock ]
322
+ );
323
+ $ this ->assertEquals ($ expected , $ this ->_model ->getOption ('save_path ' ));
324
+
325
+ if ($ sessionSavePath != ini_get ('session.save_path ' )) {
326
+ ini_set ('session.save_path ' , $ sessionSavePath );
327
+ }
328
+ }
329
+
330
+ public function savePathDataProvider ()
331
+ {
332
+ // preset value (null = not set), input value (null = not set), expected value
333
+ $ savePathGiven = 'explicit_save_path ' ;
334
+ $ presetPath = 'preset_save_path ' ;
335
+ return [
336
+ [null , $ savePathGiven , $ savePathGiven ],
337
+ [null , null , 'default ' ],
338
+ [$ presetPath , $ savePathGiven , $ savePathGiven ],
339
+ [$ presetPath , null , $ presetPath ],
340
+ ];
341
+ }
286
342
}
0 commit comments