2016-05-18 21:43:59 +02:00
|
|
|
<?php
|
2017-03-03 23:06:12 +01:00
|
|
|
namespace Shaarli\Config;
|
2016-05-18 21:43:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ConfigPhpTest
|
|
|
|
*/
|
2017-03-03 23:06:12 +01:00
|
|
|
class ConfigPhpTest extends \PHPUnit_Framework_TestCase
|
2016-05-18 21:43:59 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var ConfigPhp
|
|
|
|
*/
|
|
|
|
protected $configIO;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->configIO = new ConfigPhp();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read a simple existing config file.
|
|
|
|
*/
|
|
|
|
public function testRead()
|
|
|
|
{
|
2016-05-18 21:48:24 +02:00
|
|
|
$conf = $this->configIO->read('tests/utils/config/configPhp.php');
|
2016-05-18 21:43:59 +02:00
|
|
|
$this->assertEquals('root', $conf['login']);
|
|
|
|
$this->assertEquals('lala', $conf['redirector']);
|
|
|
|
$this->assertEquals('data/datastore.php', $conf['config']['DATASTORE']);
|
|
|
|
$this->assertEquals('1', $conf['plugins']['WALLABAG_VERSION']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read a non existent config file -> empty array.
|
|
|
|
*/
|
|
|
|
public function testReadNonExistent()
|
|
|
|
{
|
|
|
|
$this->assertEquals(array(), $this->configIO->read('nope'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a new config file.
|
|
|
|
*/
|
|
|
|
public function testWriteNew()
|
|
|
|
{
|
2016-05-18 21:48:24 +02:00
|
|
|
$dataFile = 'tests/utils/config/configWrite.php';
|
2016-05-18 21:43:59 +02:00
|
|
|
$data = array(
|
|
|
|
'login' => 'root',
|
|
|
|
'redirector' => 'lala',
|
|
|
|
'config' => array(
|
|
|
|
'DATASTORE' => 'data/datastore.php',
|
|
|
|
),
|
|
|
|
'plugins' => array(
|
|
|
|
'WALLABAG_VERSION' => '1',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->configIO->write($dataFile, $data);
|
|
|
|
$expected = '<?php
|
|
|
|
$GLOBALS[\'login\'] = \'root\';
|
|
|
|
$GLOBALS[\'redirector\'] = \'lala\';
|
|
|
|
$GLOBALS[\'config\'][\'DATASTORE\'] = \'data/datastore.php\';
|
|
|
|
$GLOBALS[\'plugins\'][\'WALLABAG_VERSION\'] = \'1\';
|
|
|
|
';
|
2016-05-18 21:48:24 +02:00
|
|
|
$this->assertEquals($expected, file_get_contents($dataFile));
|
|
|
|
unlink($dataFile);
|
2016-05-18 21:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overwrite an existing setting.
|
|
|
|
*/
|
|
|
|
public function testOverwrite()
|
|
|
|
{
|
2016-05-18 21:48:24 +02:00
|
|
|
$source = 'tests/utils/config/configPhp.php';
|
|
|
|
$dest = 'tests/utils/config/configOverwrite.php';
|
|
|
|
copy($source, $dest);
|
2016-05-18 21:43:59 +02:00
|
|
|
$conf = $this->configIO->read($dest);
|
|
|
|
$conf['redirector'] = 'blabla';
|
|
|
|
$this->configIO->write($dest, $conf);
|
|
|
|
$conf = $this->configIO->read($dest);
|
|
|
|
$this->assertEquals('blabla', $conf['redirector']);
|
2016-05-18 21:48:24 +02:00
|
|
|
unlink($dest);
|
2016-05-18 21:43:59 +02:00
|
|
|
}
|
|
|
|
}
|