Replace $GLOBALS configuration with the configuration manager in the whole code base
This commit is contained in:
parent
59404d7909
commit
684e662a58
23 changed files with 421 additions and 855 deletions
|
@ -3,6 +3,7 @@
|
|||
* ApplicationUtils' tests
|
||||
*/
|
||||
|
||||
require_once 'application/config/ConfigManager.php';
|
||||
require_once 'application/ApplicationUtils.php';
|
||||
|
||||
/**
|
||||
|
@ -59,7 +60,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
|
|||
$testTimeout
|
||||
)
|
||||
);
|
||||
$this->assertRegexp(
|
||||
$this->assertRegExp(
|
||||
self::$versionPattern,
|
||||
ApplicationUtils::getLatestGitVersionCode(
|
||||
'https://raw.githubusercontent.com/shaarli/Shaarli/'
|
||||
|
@ -275,21 +276,21 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testCheckCurrentResourcePermissions()
|
||||
{
|
||||
$config = array(
|
||||
'CACHEDIR' => 'cache',
|
||||
'CONFIG_FILE' => 'data/config.php',
|
||||
'DATADIR' => 'data',
|
||||
'DATASTORE' => 'data/datastore.php',
|
||||
'IPBANS_FILENAME' => 'data/ipbans.php',
|
||||
'LOG_FILE' => 'data/log.txt',
|
||||
'PAGECACHE' => 'pagecache',
|
||||
'RAINTPL_TMP' => 'tmp',
|
||||
'RAINTPL_TPL' => 'tpl',
|
||||
'UPDATECHECK_FILENAME' => 'data/lastupdatecheck.txt'
|
||||
);
|
||||
$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');
|
||||
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
ApplicationUtils::checkResourcePermissions($config)
|
||||
ApplicationUtils::checkResourcePermissions()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -298,18 +299,17 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testCheckCurrentResourcePermissionsErrors()
|
||||
{
|
||||
$config = array(
|
||||
'CACHEDIR' => 'null/cache',
|
||||
'CONFIG_FILE' => 'null/data/config.php',
|
||||
'DATADIR' => 'null/data',
|
||||
'DATASTORE' => 'null/data/store.php',
|
||||
'IPBANS_FILENAME' => 'null/data/ipbans.php',
|
||||
'LOG_FILE' => 'null/data/log.txt',
|
||||
'PAGECACHE' => 'null/pagecache',
|
||||
'RAINTPL_TMP' => 'null/tmp',
|
||||
'RAINTPL_TPL' => 'null/tpl',
|
||||
'UPDATECHECK_FILENAME' => 'null/data/lastupdatecheck.txt'
|
||||
);
|
||||
$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');
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'"null/tpl" directory is not readable',
|
||||
|
@ -322,7 +322,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
|
|||
'"null/tmp" directory is not readable',
|
||||
'"null/tmp" directory is not writable'
|
||||
),
|
||||
ApplicationUtils::checkResourcePermissions($config)
|
||||
ApplicationUtils::checkResourcePermissions()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,244 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Config' tests
|
||||
*/
|
||||
|
||||
require_once 'application/Config.php';
|
||||
|
||||
/**
|
||||
* Unitary tests for Shaarli config related functions
|
||||
*/
|
||||
class ConfigTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
// Configuration input set.
|
||||
private static $configFields;
|
||||
|
||||
/**
|
||||
* Executed before each test.
|
||||
*/
|
||||
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(
|
||||
'CONFIG_FILE' => 'tests/config.php',
|
||||
'DATADIR' => 'tests',
|
||||
'config1' => 'config1data',
|
||||
'config2' => 'config2data',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executed after each test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
if (is_file(self::$configFields['config']['CONFIG_FILE'])) {
|
||||
unlink(self::$configFields['config']['CONFIG_FILE']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test writeConfig function, valid use case, while being logged in.
|
||||
*/
|
||||
public function testWriteConfig()
|
||||
{
|
||||
writeConfig(self::$configFields, true);
|
||||
|
||||
include self::$configFields['config']['CONFIG_FILE'];
|
||||
$this->assertEquals(self::$configFields['login'], $GLOBALS['login']);
|
||||
$this->assertEquals(self::$configFields['hash'], $GLOBALS['hash']);
|
||||
$this->assertEquals(self::$configFields['salt'], $GLOBALS['salt']);
|
||||
$this->assertEquals(self::$configFields['timezone'], $GLOBALS['timezone']);
|
||||
$this->assertEquals(self::$configFields['title'], $GLOBALS['title']);
|
||||
$this->assertEquals(self::$configFields['titleLink'], $GLOBALS['titleLink']);
|
||||
$this->assertEquals(self::$configFields['redirector'], $GLOBALS['redirector']);
|
||||
$this->assertEquals(self::$configFields['disablesessionprotection'], $GLOBALS['disablesessionprotection']);
|
||||
$this->assertEquals(self::$configFields['privateLinkByDefault'], $GLOBALS['privateLinkByDefault']);
|
||||
$this->assertEquals(self::$configFields['config']['config1'], $GLOBALS['config']['config1']);
|
||||
$this->assertEquals(self::$configFields['config']['config2'], $GLOBALS['config']['config2']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test writeConfig option while logged in:
|
||||
* 1. init fields.
|
||||
* 2. update fields, add new sub config, add new root config.
|
||||
* 3. rewrite config.
|
||||
* 4. check result.
|
||||
*/
|
||||
public function testWriteConfigFieldUpdate()
|
||||
{
|
||||
writeConfig(self::$configFields, true);
|
||||
self::$configFields['title'] = 'ok';
|
||||
self::$configFields['config']['config1'] = 'ok';
|
||||
self::$configFields['config']['config_new'] = 'ok';
|
||||
self::$configFields['new'] = 'should not be saved';
|
||||
writeConfig(self::$configFields, true);
|
||||
|
||||
include self::$configFields['config']['CONFIG_FILE'];
|
||||
$this->assertEquals('ok', $GLOBALS['title']);
|
||||
$this->assertEquals('ok', $GLOBALS['config']['config1']);
|
||||
$this->assertEquals('ok', $GLOBALS['config']['config_new']);
|
||||
$this->assertFalse(isset($GLOBALS['new']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test writeConfig function with an empty array.
|
||||
*
|
||||
* @expectedException MissingFieldConfigException
|
||||
*/
|
||||
public function testWriteConfigEmpty()
|
||||
{
|
||||
writeConfig(array(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test writeConfig function with a missing mandatory field.
|
||||
*
|
||||
* @expectedException MissingFieldConfigException
|
||||
*/
|
||||
public function testWriteConfigMissingField()
|
||||
{
|
||||
unset(self::$configFields['login']);
|
||||
writeConfig(self::$configFields, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test writeConfig function while being logged out, and there is no config file existing.
|
||||
*/
|
||||
public function testWriteConfigLoggedOutNoFile()
|
||||
{
|
||||
writeConfig(self::$configFields, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test writeConfig function while being logged out, and a config file already exists.
|
||||
*
|
||||
* @expectedException UnauthorizedConfigException
|
||||
*/
|
||||
public function testWriteConfigLoggedOutWithFile()
|
||||
{
|
||||
file_put_contents(self::$configFields['config']['CONFIG_FILE'], '');
|
||||
writeConfig(self::$configFields, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test save_plugin_config with valid data.
|
||||
*
|
||||
* @throws PluginConfigOrderException
|
||||
*/
|
||||
public function testSavePluginConfigValid()
|
||||
{
|
||||
$data = array(
|
||||
'order_plugin1' => 2, // no plugin related
|
||||
'plugin2' => 0, // new - at the end
|
||||
'plugin3' => 0, // 2nd
|
||||
'order_plugin3' => 8,
|
||||
'plugin4' => 0, // 1st
|
||||
'order_plugin4' => 5,
|
||||
);
|
||||
|
||||
$expected = array(
|
||||
'plugin3',
|
||||
'plugin4',
|
||||
'plugin2',
|
||||
);
|
||||
|
||||
$out = save_plugin_config($data);
|
||||
$this->assertEquals($expected, $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test save_plugin_config with invalid data.
|
||||
*
|
||||
* @expectedException PluginConfigOrderException
|
||||
*/
|
||||
public function testSavePluginConfigInvalid()
|
||||
{
|
||||
$data = array(
|
||||
'plugin2' => 0,
|
||||
'plugin3' => 0,
|
||||
'order_plugin3' => 0,
|
||||
'plugin4' => 0,
|
||||
'order_plugin4' => 0,
|
||||
);
|
||||
|
||||
save_plugin_config($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test save_plugin_config without data.
|
||||
*/
|
||||
public function testSavePluginConfigEmpty()
|
||||
{
|
||||
$this->assertEquals(array(), save_plugin_config(array()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validate_plugin_order with valid data.
|
||||
*/
|
||||
public function testValidatePluginOrderValid()
|
||||
{
|
||||
$data = array(
|
||||
'order_plugin1' => 2,
|
||||
'plugin2' => 0,
|
||||
'plugin3' => 0,
|
||||
'order_plugin3' => 1,
|
||||
'plugin4' => 0,
|
||||
'order_plugin4' => 5,
|
||||
);
|
||||
|
||||
$this->assertTrue(validate_plugin_order($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validate_plugin_order with invalid data.
|
||||
*/
|
||||
public function testValidatePluginOrderInvalid()
|
||||
{
|
||||
$data = array(
|
||||
'order_plugin1' => 2,
|
||||
'order_plugin3' => 1,
|
||||
'order_plugin4' => 1,
|
||||
);
|
||||
|
||||
$this->assertFalse(validate_plugin_order($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test load_plugin_parameter_values.
|
||||
*/
|
||||
public function testLoadPluginParameterValues()
|
||||
{
|
||||
$plugins = array(
|
||||
'plugin_name' => array(
|
||||
'parameters' => array(
|
||||
'param1' => true,
|
||||
'param2' => false,
|
||||
'param3' => '',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$parameters = array(
|
||||
'param1' => 'value1',
|
||||
'param2' => 'value2',
|
||||
);
|
||||
|
||||
$result = load_plugin_parameter_values($plugins, $parameters);
|
||||
$this->assertEquals('value1', $result['plugin_name']['parameters']['param1']);
|
||||
$this->assertEquals('value2', $result['plugin_name']['parameters']['param2']);
|
||||
$this->assertEquals('', $result['plugin_name']['parameters']['param3']);
|
||||
}
|
||||
}
|
|
@ -76,7 +76,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
|
|||
// Test headers (RSS)
|
||||
$this->assertEquals(self::$RSS_LANGUAGE, $data['language']);
|
||||
$this->assertEmpty($data['pubsubhub_url']);
|
||||
$this->assertEquals('Tue, 10 Mar 2015 11:46:51 +0100', $data['last_update']);
|
||||
$this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $data['last_update']);
|
||||
$this->assertEquals(true, $data['show_dates']);
|
||||
$this->assertEquals('http://host.tld/index.php?do=feed', $data['self_link']);
|
||||
$this->assertEquals('http://host.tld/', $data['index_url']);
|
||||
|
@ -88,7 +88,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertEquals('20150310_114651', $link['linkdate']);
|
||||
$this->assertEquals('http://host.tld/?WDWyig', $link['guid']);
|
||||
$this->assertEquals('http://host.tld/?WDWyig', $link['url']);
|
||||
$this->assertEquals('Tue, 10 Mar 2015 11:46:51 +0100', $link['iso_date']);
|
||||
$this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['iso_date']);
|
||||
$this->assertContains('Stallman has a beard', $link['description']);
|
||||
$this->assertContains('Permalink', $link['description']);
|
||||
$this->assertContains('http://host.tld/?WDWyig', $link['description']);
|
||||
|
@ -113,7 +113,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
|
|||
$data = $feedBuilder->buildData();
|
||||
$this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
|
||||
$link = array_shift($data['links']);
|
||||
$this->assertEquals('2015-03-10T11:46:51+01:00', $link['iso_date']);
|
||||
$this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:+\d{2}/', $link['iso_date']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -101,7 +101,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
|
|||
* Attempt to instantiate a LinkDB whereas the datastore is not writable
|
||||
*
|
||||
* @expectedException IOException
|
||||
* @expectedExceptionMessageRegExp /Error accessing null/
|
||||
* @expectedExceptionMessageRegExp /Error accessing\nnull/
|
||||
*/
|
||||
public function testConstructDatastoreNotWriteable()
|
||||
{
|
||||
|
|
|
@ -12,13 +12,12 @@ class DummyUpdater extends Updater
|
|||
* Object constructor.
|
||||
*
|
||||
* @param array $doneUpdates Updates which are already done.
|
||||
* @param array $config Shaarli's configuration array.
|
||||
* @param LinkDB $linkDB LinkDB instance.
|
||||
* @param boolean $isLoggedIn True if the user is logged in.
|
||||
*/
|
||||
public function __construct($doneUpdates, $config, $linkDB, $isLoggedIn)
|
||||
public function __construct($doneUpdates, $linkDB, $isLoggedIn)
|
||||
{
|
||||
parent::__construct($doneUpdates, $config, $linkDB, $isLoggedIn);
|
||||
parent::__construct($doneUpdates, $linkDB, $isLoggedIn);
|
||||
|
||||
// Retrieve all update methods.
|
||||
// For unit test, only retrieve final methods,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
require_once 'application/config/ConfigManager.php';
|
||||
require_once 'tests/Updater/DummyUpdater.php';
|
||||
|
||||
/**
|
||||
|
@ -18,6 +19,16 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
protected static $testDatastore = 'sandbox/datastore.php';
|
||||
|
||||
/**
|
||||
* @var string Config file path.
|
||||
*/
|
||||
protected static $configFile = 'tests/Updater/config.php';
|
||||
|
||||
/**
|
||||
* @var ConfigManager
|
||||
*/
|
||||
protected $conf;
|
||||
|
||||
/**
|
||||
* Executed before each test.
|
||||
*/
|
||||
|
@ -34,13 +45,19 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
'disablesessionprotection' => false,
|
||||
'privateLinkByDefault' => false,
|
||||
'config' => array(
|
||||
'CONFIG_FILE' => 'tests/Updater/config.php',
|
||||
'DATADIR' => 'tests/Updater',
|
||||
'PAGECACHE' => 'sandbox/pagecache',
|
||||
'config1' => 'config1data',
|
||||
'config2' => 'config2data',
|
||||
)
|
||||
);
|
||||
|
||||
ConfigManager::$CONFIG_FILE = 'tests/Updater/config';
|
||||
$this->conf = ConfigManager::getInstance();
|
||||
foreach (self::$configFields as $key => $value) {
|
||||
$this->conf->set($key, $value);
|
||||
}
|
||||
$this->conf->write(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,16 +67,16 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
if (is_file(self::$configFields['config']['CONFIG_FILE'])) {
|
||||
unlink(self::$configFields['config']['CONFIG_FILE']);
|
||||
if (is_file(self::$configFile)) {
|
||||
unlink(self::$configFile);
|
||||
}
|
||||
|
||||
if (is_file(self::$configFields['config']['DATADIR'] . '/options.php')) {
|
||||
unlink(self::$configFields['config']['DATADIR'] . '/options.php');
|
||||
}
|
||||
|
||||
if (is_file(self::$configFields['config']['DATADIR'] . '/updates.json')) {
|
||||
unlink(self::$configFields['config']['DATADIR'] . '/updates.json');
|
||||
if (is_file(self::$configFields['config']['DATADIR'] . '/updates.txt')) {
|
||||
unlink(self::$configFields['config']['DATADIR'] . '/updates.txt');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +86,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
public function testReadEmptyUpdatesFile()
|
||||
{
|
||||
$this->assertEquals(array(), read_updates_file(''));
|
||||
$updatesFile = self::$configFields['config']['DATADIR'] . '/updates.json';
|
||||
$updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt';
|
||||
touch($updatesFile);
|
||||
$this->assertEquals(array(), read_updates_file($updatesFile));
|
||||
}
|
||||
|
@ -79,7 +96,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testReadWriteUpdatesFile()
|
||||
{
|
||||
$updatesFile = self::$configFields['config']['DATADIR'] . '/updates.json';
|
||||
$updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt';
|
||||
$updatesMethods = array('m1', 'm2', 'm3');
|
||||
|
||||
write_updates_file($updatesFile, $updatesMethods);
|
||||
|
@ -112,7 +129,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testWriteUpdatesFileNotWritable()
|
||||
{
|
||||
$updatesFile = self::$configFields['config']['DATADIR'] . '/updates.json';
|
||||
$updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt';
|
||||
touch($updatesFile);
|
||||
chmod($updatesFile, 0444);
|
||||
@write_updates_file($updatesFile, array('test'));
|
||||
|
@ -131,10 +148,10 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
'updateMethodDummy3',
|
||||
'updateMethodException',
|
||||
);
|
||||
$updater = new DummyUpdater($updates, array(), array(), true);
|
||||
$updater = new DummyUpdater($updates, array(), true);
|
||||
$this->assertEquals(array(), $updater->update());
|
||||
|
||||
$updater = new DummyUpdater(array(), array(), array(), false);
|
||||
$updater = new DummyUpdater(array(), array(), false);
|
||||
$this->assertEquals(array(), $updater->update());
|
||||
}
|
||||
|
||||
|
@ -149,7 +166,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
'updateMethodDummy2',
|
||||
'updateMethodDummy3',
|
||||
);
|
||||
$updater = new DummyUpdater($updates, array(), array(), true);
|
||||
$updater = new DummyUpdater($updates, array(), true);
|
||||
$this->assertEquals($expectedUpdates, $updater->update());
|
||||
}
|
||||
|
||||
|
@ -165,7 +182,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
);
|
||||
$expectedUpdate = array('updateMethodDummy2');
|
||||
|
||||
$updater = new DummyUpdater($updates, array(), array(), true);
|
||||
$updater = new DummyUpdater($updates, array(), true);
|
||||
$this->assertEquals($expectedUpdate, $updater->update());
|
||||
}
|
||||
|
||||
|
@ -182,7 +199,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
'updateMethodDummy3',
|
||||
);
|
||||
|
||||
$updater = new DummyUpdater($updates, array(), array(), true);
|
||||
$updater = new DummyUpdater($updates, array(), true);
|
||||
$updater->update();
|
||||
}
|
||||
|
||||
|
@ -195,26 +212,25 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testUpdateMergeDeprecatedConfig()
|
||||
{
|
||||
// init
|
||||
writeConfig(self::$configFields, true);
|
||||
$configCopy = self::$configFields;
|
||||
$invert = !$configCopy['privateLinkByDefault'];
|
||||
$configCopy['privateLinkByDefault'] = $invert;
|
||||
|
||||
// Use writeConfig to create a options.php
|
||||
$configCopy['config']['CONFIG_FILE'] = 'tests/Updater/options.php';
|
||||
writeConfig($configCopy, true);
|
||||
ConfigManager::$CONFIG_FILE = 'tests/Updater/options';
|
||||
$invert = !$this->conf->get('privateLinkByDefault');
|
||||
$this->conf->set('privateLinkByDefault', $invert);
|
||||
$this->conf->write(true);
|
||||
|
||||
$this->assertTrue(is_file($configCopy['config']['CONFIG_FILE']));
|
||||
$optionsFile = 'tests/Updater/options.php';
|
||||
$this->assertTrue(is_file($optionsFile));
|
||||
|
||||
ConfigManager::$CONFIG_FILE = 'tests/Updater/config';
|
||||
|
||||
// merge configs
|
||||
$updater = new Updater(array(), self::$configFields, array(), true);
|
||||
$updater = new Updater(array(), array(), true);
|
||||
$updater->updateMethodMergeDeprecatedConfigFile();
|
||||
|
||||
// make sure updated field is changed
|
||||
include self::$configFields['config']['CONFIG_FILE'];
|
||||
$this->assertEquals($invert, $GLOBALS['privateLinkByDefault']);
|
||||
$this->assertFalse(is_file($configCopy['config']['CONFIG_FILE']));
|
||||
$this->conf->reload();
|
||||
$this->assertEquals($invert, $this->conf->get('privateLinkByDefault'));
|
||||
$this->assertFalse(is_file($optionsFile));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -222,22 +238,22 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testMergeDeprecatedConfigNoFile()
|
||||
{
|
||||
writeConfig(self::$configFields, true);
|
||||
|
||||
$updater = new Updater(array(), self::$configFields, array(), true);
|
||||
$updater = new Updater(array(), array(), true);
|
||||
$updater->updateMethodMergeDeprecatedConfigFile();
|
||||
|
||||
include self::$configFields['config']['CONFIG_FILE'];
|
||||
$this->assertEquals(self::$configFields['login'], $GLOBALS['login']);
|
||||
$this->assertEquals(self::$configFields['login'], $this->conf->get('login'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test renameDashTags update method.
|
||||
*/
|
||||
public function testRenameDashTags()
|
||||
{
|
||||
$refDB = new ReferenceLinkDB();
|
||||
$refDB->write(self::$testDatastore);
|
||||
$linkDB = new LinkDB(self::$testDatastore, true, false);
|
||||
$this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude')));
|
||||
$updater = new Updater(array(), self::$configFields, $linkDB, true);
|
||||
$updater = new Updater(array(), $linkDB, true);
|
||||
$updater->updateMethodRenameDashTags();
|
||||
$this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude')));
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class ConfigPhpTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testRead()
|
||||
{
|
||||
$conf = $this->configIO->read('tests/config/php/configOK');
|
||||
$conf = $this->configIO->read('tests/utils/config/configPhp.php');
|
||||
$this->assertEquals('root', $conf['login']);
|
||||
$this->assertEquals('lala', $conf['redirector']);
|
||||
$this->assertEquals('data/datastore.php', $conf['config']['DATASTORE']);
|
||||
|
@ -42,7 +42,7 @@ class ConfigPhpTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testWriteNew()
|
||||
{
|
||||
$dataFile = 'tests/config/php/configWrite';
|
||||
$dataFile = 'tests/utils/config/configWrite.php';
|
||||
$data = array(
|
||||
'login' => 'root',
|
||||
'redirector' => 'lala',
|
||||
|
@ -60,8 +60,8 @@ $GLOBALS[\'redirector\'] = \'lala\';
|
|||
$GLOBALS[\'config\'][\'DATASTORE\'] = \'data/datastore.php\';
|
||||
$GLOBALS[\'plugins\'][\'WALLABAG_VERSION\'] = \'1\';
|
||||
';
|
||||
$this->assertEquals($expected, file_get_contents($dataFile .'.php'));
|
||||
unlink($dataFile .'.php');
|
||||
$this->assertEquals($expected, file_get_contents($dataFile));
|
||||
unlink($dataFile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,14 +69,14 @@ $GLOBALS[\'plugins\'][\'WALLABAG_VERSION\'] = \'1\';
|
|||
*/
|
||||
public function testOverwrite()
|
||||
{
|
||||
$source = 'tests/config/php/configOK.php';
|
||||
$dest = 'tests/config/php/configOverwrite';
|
||||
copy($source, $dest . '.php');
|
||||
$source = 'tests/utils/config/configPhp.php';
|
||||
$dest = 'tests/utils/config/configOverwrite.php';
|
||||
copy($source, $dest);
|
||||
$conf = $this->configIO->read($dest);
|
||||
$conf['redirector'] = 'blabla';
|
||||
$this->configIO->write($dest, $conf);
|
||||
$conf = $this->configIO->read($dest);
|
||||
$this->assertEquals('blabla', $conf['redirector']);
|
||||
unlink($dest .'.php');
|
||||
unlink($dest);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
<?php
|
||||
$GLOBALS['login'] = 'root';
|
||||
$GLOBALS['hash'] = 'hash';
|
||||
$GLOBALS['salt'] = 'salt';
|
||||
$GLOBALS['timezone'] = 'Europe/Paris';
|
||||
$GLOBALS['title'] = 'BIGBANG';
|
||||
$GLOBALS['titleLink'] = '?';
|
||||
$GLOBALS['redirector'] = 'lala';
|
||||
$GLOBALS['disablesessionprotection'] = false;
|
||||
$GLOBALS['privateLinkByDefault'] = true;
|
||||
$GLOBALS['config']['DATADIR'] = 'data';
|
||||
$GLOBALS['config']['DATASTORE'] = 'data/datastore.php';
|
||||
$GLOBALS['plugins']['WALLABAG_URL'] = 'ghf';
|
||||
$GLOBALS['plugins']['WALLABAG_VERSION'] = '1';
|
14
tests/utils/config/configPhp.php
Normal file
14
tests/utils/config/configPhp.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
$GLOBALS['login'] = 'root';
|
||||
$GLOBALS['hash'] = 'hash';
|
||||
$GLOBALS['salt'] = 'salt';
|
||||
$GLOBALS['timezone'] = 'Europe/Paris';
|
||||
$GLOBALS['title'] = 'title';
|
||||
$GLOBALS['titleLink'] = 'titleLink';
|
||||
$GLOBALS['redirector'] = 'lala';
|
||||
$GLOBALS['disablesessionprotection'] = false;
|
||||
$GLOBALS['privateLinkByDefault'] = false;
|
||||
$GLOBALS['config']['DATADIR'] = 'tests/Updater';
|
||||
$GLOBALS['config']['PAGECACHE'] = 'sandbox/pagecache';
|
||||
$GLOBALS['config']['DATASTORE'] = 'data/datastore.php';
|
||||
$GLOBALS['plugins']['WALLABAG_VERSION'] = '1';
|
15
tests/utils/config/configUpdater.php
Normal file
15
tests/utils/config/configUpdater.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?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