Rename configuration keys and fix GLOBALS in templates
This commit is contained in:
parent
eeea1c3daa
commit
da10377b3c
18 changed files with 350 additions and 323 deletions
|
@ -277,16 +277,16 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
|
|||
public function testCheckCurrentResourcePermissions()
|
||||
{
|
||||
$conf = ConfigManager::getInstance();
|
||||
$conf->set('config.CACHEDIR', 'cache');
|
||||
$conf->set('config.CONFIG_FILE', 'data/config.php');
|
||||
$conf->set('config.DATADIR', 'data');
|
||||
$conf->set('config.DATASTORE', 'data/datastore.php');
|
||||
$conf->set('config.IPBANS_FILENAME', 'data/ipbans.php');
|
||||
$conf->set('config.LOG_FILE', 'data/log.txt');
|
||||
$conf->set('config.PAGECACHE', 'pagecache');
|
||||
$conf->set('config.RAINTPL_TMP', 'tmp');
|
||||
$conf->set('config.RAINTPL_TPL', 'tpl');
|
||||
$conf->set('config.UPDATECHECK_FILENAME', 'data/lastupdatecheck.txt');
|
||||
$conf->set('path.thumbnails_cache', 'cache');
|
||||
$conf->set('path.config', 'data/config.php');
|
||||
$conf->set('path.data_dir', 'data');
|
||||
$conf->set('path.datastore', 'data/datastore.php');
|
||||
$conf->set('path.ban_file', 'data/ipbans.php');
|
||||
$conf->set('path.log', 'data/log.txt');
|
||||
$conf->set('path.page_cache', 'pagecache');
|
||||
$conf->set('path.raintpl_tmp', 'tmp');
|
||||
$conf->set('path.raintpl_tpl', 'tpl');
|
||||
$conf->set('path.update_check', 'data/lastupdatecheck.txt');
|
||||
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
|
@ -300,16 +300,16 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
|
|||
public function testCheckCurrentResourcePermissionsErrors()
|
||||
{
|
||||
$conf = ConfigManager::getInstance();
|
||||
$conf->set('config.CACHEDIR', 'null/cache');
|
||||
$conf->set('config.CONFIG_FILE', 'null/data/config.php');
|
||||
$conf->set('config.DATADIR', 'null/data');
|
||||
$conf->set('config.DATASTORE', 'null/data/store.php');
|
||||
$conf->set('config.IPBANS_FILENAME', 'null/data/ipbans.php');
|
||||
$conf->set('config.LOG_FILE', 'null/data/log.txt');
|
||||
$conf->set('config.PAGECACHE', 'null/pagecache');
|
||||
$conf->set('config.RAINTPL_TMP', 'null/tmp');
|
||||
$conf->set('config.RAINTPL_TPL', 'null/tpl');
|
||||
$conf->set('config.UPDATECHECK_FILENAME', 'null/data/lastupdatecheck.txt');
|
||||
$conf->set('path.thumbnails_cache', 'null/cache');
|
||||
$conf->set('path.config', 'null/data/config.php');
|
||||
$conf->set('path.data_dir', 'null/data');
|
||||
$conf->set('path.datastore', 'null/data/store.php');
|
||||
$conf->set('path.ban_file', 'null/data/ipbans.php');
|
||||
$conf->set('path.log', 'null/data/log.txt');
|
||||
$conf->set('path.page_cache', 'null/pagecache');
|
||||
$conf->set('path.raintpl_tmp', 'null/tmp');
|
||||
$conf->set('path.raintpl_tpl', 'null/tpl');
|
||||
$conf->set('path.update_check', 'null/data/lastupdatecheck.txt');
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'"null/tpl" directory is not readable',
|
||||
|
|
|
@ -9,11 +9,6 @@ require_once 'tests/Updater/DummyUpdater.php';
|
|||
*/
|
||||
class UpdaterTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var array Configuration input set.
|
||||
*/
|
||||
private static $configFields;
|
||||
|
||||
/**
|
||||
* @var string Path to test datastore.
|
||||
*/
|
||||
|
@ -22,7 +17,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* @var string Config file path (without extension).
|
||||
*/
|
||||
protected static $configFile = 'tests/utils/config/configUpdater';
|
||||
protected static $configFile = 'tests/utils/config/configJson';
|
||||
|
||||
/**
|
||||
* @var ConfigManager
|
||||
|
@ -34,51 +29,8 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function setUp()
|
||||
{
|
||||
self::$configFields = array(
|
||||
'login' => 'login',
|
||||
'hash' => 'hash',
|
||||
'salt' => 'salt',
|
||||
'timezone' => 'Europe/Paris',
|
||||
'title' => 'title',
|
||||
'titleLink' => 'titleLink',
|
||||
'redirector' => '',
|
||||
'disablesessionprotection' => false,
|
||||
'privateLinkByDefault' => false,
|
||||
'config' => array(
|
||||
'DATADIR' => 'tests/Updater',
|
||||
'PAGECACHE' => 'sandbox/pagecache',
|
||||
'config1' => 'config1data',
|
||||
'config2' => 'config2data',
|
||||
)
|
||||
);
|
||||
|
||||
ConfigManager::$CONFIG_FILE = self::$configFile;
|
||||
$this->conf = ConfigManager::reset();
|
||||
$this->conf->reload();
|
||||
foreach (self::$configFields as $key => $value) {
|
||||
$this->conf->set($key, $value);
|
||||
}
|
||||
$this->conf->write(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executed after each test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
if (is_file('tests/Updater/config.json')) {
|
||||
unlink('tests/Updater/config.json');
|
||||
}
|
||||
|
||||
if (is_file(self::$configFields['config']['DATADIR'] . '/options.php')) {
|
||||
unlink(self::$configFields['config']['DATADIR'] . '/options.php');
|
||||
}
|
||||
|
||||
if (is_file(self::$configFields['config']['DATADIR'] . '/updates.txt')) {
|
||||
unlink(self::$configFields['config']['DATADIR'] . '/updates.txt');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,9 +39,10 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
public function testReadEmptyUpdatesFile()
|
||||
{
|
||||
$this->assertEquals(array(), read_updates_file(''));
|
||||
$updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt';
|
||||
$updatesFile = $this->conf->get('path.data_dir') . '/updates.txt';
|
||||
touch($updatesFile);
|
||||
$this->assertEquals(array(), read_updates_file($updatesFile));
|
||||
unlink($updatesFile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,7 +50,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testReadWriteUpdatesFile()
|
||||
{
|
||||
$updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt';
|
||||
$updatesFile = $this->conf->get('path.data_dir') . '/updates.txt';
|
||||
$updatesMethods = array('m1', 'm2', 'm3');
|
||||
|
||||
write_updates_file($updatesFile, $updatesMethods);
|
||||
|
@ -109,6 +62,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
write_updates_file($updatesFile, $updatesMethods);
|
||||
$readMethods = read_updates_file($updatesFile);
|
||||
$this->assertEquals($readMethods, $updatesMethods);
|
||||
unlink($updatesFile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,10 +84,15 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testWriteUpdatesFileNotWritable()
|
||||
{
|
||||
$updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt';
|
||||
$updatesFile = $this->conf->get('path.data_dir') . '/updates.txt';
|
||||
touch($updatesFile);
|
||||
chmod($updatesFile, 0444);
|
||||
@write_updates_file($updatesFile, array('test'));
|
||||
try {
|
||||
@write_updates_file($updatesFile, array('test'));
|
||||
} catch (Exception $e) {
|
||||
unlink($updatesFile);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -213,17 +172,15 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testUpdateMergeDeprecatedConfig()
|
||||
{
|
||||
// Use writeConfig to create a options.php
|
||||
ConfigManager::$CONFIG_FILE = 'tests/Updater/options';
|
||||
$this->conf->setConfigIO(new ConfigPhp());
|
||||
|
||||
$invert = !$this->conf->get('privateLinkByDefault');
|
||||
$this->conf->set('privateLinkByDefault', $invert);
|
||||
$this->conf->write(true);
|
||||
ConfigManager::$CONFIG_FILE = 'tests/utils/config/configPhp';
|
||||
$this->conf = $this->conf->reset();
|
||||
|
||||
$optionsFile = 'tests/Updater/options.php';
|
||||
$this->assertTrue(is_file($optionsFile));
|
||||
$options = '<?php
|
||||
$GLOBALS[\'privateLinkByDefault\'] = true;';
|
||||
file_put_contents($optionsFile, $options);
|
||||
|
||||
// tmp config file.
|
||||
ConfigManager::$CONFIG_FILE = 'tests/Updater/config';
|
||||
|
||||
// merge configs
|
||||
|
@ -233,7 +190,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
// make sure updated field is changed
|
||||
$this->conf->reload();
|
||||
$this->assertEquals($invert, $this->conf->get('privateLinkByDefault'));
|
||||
$this->assertTrue($this->conf->get('general.default_private_links'));
|
||||
$this->assertFalse(is_file($optionsFile));
|
||||
// Delete the generated file.
|
||||
unlink($this->conf->getConfigFile());
|
||||
|
@ -247,7 +204,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
$updater = new Updater(array(), array(), true);
|
||||
$updater->updateMethodMergeDeprecatedConfigFile();
|
||||
|
||||
$this->assertEquals(self::$configFields['login'], $this->conf->get('login'));
|
||||
$this->assertEquals('root', $this->conf->get('credentials.login'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -286,9 +243,9 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
// Check JSON config data.
|
||||
$conf->reload();
|
||||
$this->assertEquals('root', $conf->get('login'));
|
||||
$this->assertEquals('lala', $conf->get('redirector'));
|
||||
$this->assertEquals('data/datastore.php', $conf->get('config.DATASTORE'));
|
||||
$this->assertEquals('root', $conf->get('credentials.login'));
|
||||
$this->assertEquals('lala', $conf->get('extras.redirector'));
|
||||
$this->assertEquals('data/datastore.php', $conf->get('path.datastore'));
|
||||
$this->assertEquals('1', $conf->get('plugins.WALLABAG_VERSION'));
|
||||
|
||||
rename($configFile . '.save.php', $configFile . '.php');
|
||||
|
@ -300,15 +257,11 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testConfigToJsonNothingToDo()
|
||||
{
|
||||
$configFile = 'tests/utils/config/configUpdateDone';
|
||||
ConfigManager::$CONFIG_FILE = $configFile;
|
||||
$conf = ConfigManager::reset();
|
||||
$conf->reload();
|
||||
$filetime = filemtime($conf->getConfigFile());
|
||||
$filetime = filemtime($this->conf->getConfigFile());
|
||||
$updater = new Updater(array(), array(), false);
|
||||
$done = $updater->updateMethodConfigToJson();
|
||||
$this->assertTrue($done);
|
||||
$expected = filemtime($conf->getConfigFile());
|
||||
$expected = filemtime($this->conf->getConfigFile());
|
||||
$this->assertEquals($expected, $filetime);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase
|
|||
public function testRead()
|
||||
{
|
||||
$conf = $this->configIO->read('tests/utils/config/configJson.json.php');
|
||||
$this->assertEquals('root', $conf['login']);
|
||||
$this->assertEquals('lala', $conf['redirector']);
|
||||
$this->assertEquals('data/datastore.php', $conf['config']['DATASTORE']);
|
||||
$this->assertEquals('root', $conf['credentials']['login']);
|
||||
$this->assertEquals('lala', $conf['extras']['redirector']);
|
||||
$this->assertEquals('tests/utils/config/datastore.php', $conf['path']['datastore']);
|
||||
$this->assertEquals('1', $conf['plugins']['WALLABAG_VERSION']);
|
||||
}
|
||||
|
||||
|
@ -55,10 +55,14 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase
|
|||
{
|
||||
$dataFile = 'tests/utils/config/configWrite.json.php';
|
||||
$data = array(
|
||||
'login' => 'root',
|
||||
'redirector' => 'lala',
|
||||
'config' => array(
|
||||
'DATASTORE' => 'data/datastore.php',
|
||||
'credentials' => array(
|
||||
'login' => 'root',
|
||||
),
|
||||
'path' => array(
|
||||
'datastore' => 'data/datastore.php',
|
||||
),
|
||||
'extras' => array(
|
||||
'redirector' => 'lala',
|
||||
),
|
||||
'plugins' => array(
|
||||
'WALLABAG_VERSION' => '1',
|
||||
|
@ -68,19 +72,23 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase
|
|||
// PHP 5.3 doesn't support json pretty print.
|
||||
if (defined('JSON_PRETTY_PRINT')) {
|
||||
$expected = '{
|
||||
"login": "root",
|
||||
"redirector": "lala",
|
||||
"config": {
|
||||
"DATASTORE": "data\/datastore.php"
|
||||
"credentials": {
|
||||
"login": "root"
|
||||
},
|
||||
"path": {
|
||||
"datastore": "data\/datastore.php"
|
||||
},
|
||||
"extras": {
|
||||
"redirector": "lala"
|
||||
},
|
||||
"plugins": {
|
||||
"WALLABAG_VERSION": "1"
|
||||
}
|
||||
}';
|
||||
} else {
|
||||
$expected = '{"login":"root","redirector":"lala","config":{"DATASTORE":"data\/datastore.php"},"plugins":{"WALLABAG_VERSION":"1"}}';
|
||||
$expected = '{"credentials":{"login":"root"},"path":{"datastore":"data\/datastore.php"},"extras":{"redirector":"lala"},"plugins":{"WALLABAG_VERSION":"1"}}';
|
||||
}
|
||||
$expected = ConfigJson::$PHP_HEADER . $expected;
|
||||
$expected = ConfigJson::getPhpHeaders() . $expected;
|
||||
$this->assertEquals($expected, file_get_contents($dataFile));
|
||||
unlink($dataFile);
|
||||
}
|
||||
|
@ -94,10 +102,10 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase
|
|||
$dest = 'tests/utils/config/configOverwrite.json.php';
|
||||
copy($source, $dest);
|
||||
$conf = $this->configIO->read($dest);
|
||||
$conf['redirector'] = 'blabla';
|
||||
$conf['extras']['redirector'] = 'blabla';
|
||||
$this->configIO->write($dest, $conf);
|
||||
$conf = $this->configIO->read($dest);
|
||||
$this->assertEquals('blabla', $conf['redirector']);
|
||||
$this->assertEquals('blabla', $conf['extras']['redirector']);
|
||||
unlink($dest);
|
||||
}
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testExistsOk()
|
||||
{
|
||||
$this->assertTrue($this->conf->exists('login'));
|
||||
$this->assertTrue($this->conf->exists('credentials.login'));
|
||||
$this->assertTrue($this->conf->exists('config.foo'));
|
||||
}
|
||||
|
||||
|
@ -163,12 +163,12 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase
|
|||
public function testReload()
|
||||
{
|
||||
ConfigManager::$CONFIG_FILE = 'tests/utils/config/configTmp';
|
||||
$newConf = ConfigJson::$PHP_HEADER . '{ "key": "value" }';
|
||||
$newConf = ConfigJson::getPhpHeaders() . '{ "key": "value" }';
|
||||
file_put_contents($this->conf->getConfigFile(), $newConf);
|
||||
$this->conf->reload();
|
||||
unlink($this->conf->getConfigFile());
|
||||
// Previous conf no longer exists, and new values have been loaded.
|
||||
$this->assertFalse($this->conf->exists('login'));
|
||||
$this->assertFalse($this->conf->exists('credentials.login'));
|
||||
$this->assertEquals('value', $this->conf->get('key'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,28 @@
|
|||
<?php /*
|
||||
{
|
||||
"redirector":"lala",
|
||||
"login":"root",
|
||||
"hash":"hash",
|
||||
"salt":"salt",
|
||||
"timezone":"Europe\/Paris",
|
||||
"disablesessionprotection":false,
|
||||
"privateLinkByDefault":true,
|
||||
"title": "Shaarli",
|
||||
"titleLink": "?",
|
||||
"credentials": {
|
||||
"login":"root",
|
||||
"hash":"hash",
|
||||
"salt":"salt"
|
||||
},
|
||||
"security": {
|
||||
"session_protection_disabled":false
|
||||
},
|
||||
"general": {
|
||||
"timezone":"Europe\/Paris",
|
||||
"default_private_linksheader_link":true,
|
||||
"title": "Shaarli",
|
||||
"header_link": "?"
|
||||
},
|
||||
"extras": {
|
||||
"redirector":"lala"
|
||||
},
|
||||
"config": {
|
||||
"foo": "bar",
|
||||
"DATASTORE": "data\/datastore.php"
|
||||
"foo": "bar"
|
||||
},
|
||||
"path": {
|
||||
"datastore": "tests\/utils\/config\/datastore.php",
|
||||
"data_dir": "tests\/utils\/config"
|
||||
},
|
||||
"plugins": {
|
||||
"WALLABAG_VERSION": 1
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
<?php /*
|
||||
{
|
||||
"login": "root"
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<?php
|
||||
$GLOBALS['login'] = 'login';
|
||||
$GLOBALS['hash'] = 'hash';
|
||||
$GLOBALS['salt'] = 'salt';
|
||||
$GLOBALS['timezone'] = 'Europe/Paris';
|
||||
$GLOBALS['title'] = 'title';
|
||||
$GLOBALS['titleLink'] = 'titleLink';
|
||||
$GLOBALS['redirector'] = '';
|
||||
$GLOBALS['disablesessionprotection'] = false;
|
||||
$GLOBALS['privateLinkByDefault'] = false;
|
||||
$GLOBALS['config']['DATADIR'] = 'tests/Updater';
|
||||
$GLOBALS['config']['PAGECACHE'] = 'sandbox/pagecache';
|
||||
$GLOBALS['config']['config1'] = 'config1data';
|
||||
$GLOBALS['config']['config2'] = 'config2data';
|
||||
$GLOBALS['plugins']['WALLABAG_VERSION'] = '2';
|
Loading…
Add table
Add a link
Reference in a new issue