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