*/
class UpdaterTest extends PHPUnit_Framework_TestCase
{
- /**
- * @var array Configuration input set.
- */
- private static $configFields;
-
/**
* @var string Path to test datastore.
*/
/**
* @var string Config file path (without extension).
*/
- protected static $configFile = 'tests/utils/config/configUpdater';
+ protected static $configFile = 'tests/utils/config/configJson';
/**
* @var ConfigManager
*/
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');
- }
+ $this->conf = new ConfigManager(self::$configFile);
}
/**
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);
}
/**
*/
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);
write_updates_file($updatesFile, $updatesMethods);
$readMethods = read_updates_file($updatesFile);
$this->assertEquals($readMethods, $updatesMethods);
+ unlink($updatesFile);
}
/**
*/
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;
+ }
}
/**
'updateMethodDummy3',
'updateMethodException',
);
- $updater = new DummyUpdater($updates, array(), true);
+ $updater = new DummyUpdater($updates, array(), $this->conf, true);
$this->assertEquals(array(), $updater->update());
- $updater = new DummyUpdater(array(), array(), false);
+ $updater = new DummyUpdater(array(), array(), $this->conf, false);
$this->assertEquals(array(), $updater->update());
}
'updateMethodDummy2',
'updateMethodDummy3',
);
- $updater = new DummyUpdater($updates, array(), true);
+ $updater = new DummyUpdater($updates, array(), $this->conf, true);
$this->assertEquals($expectedUpdates, $updater->update());
}
);
$expectedUpdate = array('updateMethodDummy2');
- $updater = new DummyUpdater($updates, array(), true);
+ $updater = new DummyUpdater($updates, array(), $this->conf, true);
$this->assertEquals($expectedUpdate, $updater->update());
}
'updateMethodDummy3',
);
- $updater = new DummyUpdater($updates, array(), true);
+ $updater = new DummyUpdater($updates, array(), $this->conf, true);
$updater->update();
}
*/
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);
+ $this->conf->setConfigFile('tests/utils/config/configPhp');
+ $this->conf->reset();
$optionsFile = 'tests/Updater/options.php';
- $this->assertTrue(is_file($optionsFile));
+ $options = '<?php
+$GLOBALS[\'privateLinkByDefault\'] = true;';
+ file_put_contents($optionsFile, $options);
- ConfigManager::$CONFIG_FILE = 'tests/Updater/config';
+ // tmp config file.
+ $this->conf->setConfigFile('tests/Updater/config');
// merge configs
- $updater = new Updater(array(), array(), true);
+ $updater = new Updater(array(), array(), $this->conf, true);
// This writes a new config file in tests/Updater/config.php
$updater->updateMethodMergeDeprecatedConfigFile();
// 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());
+ unlink($this->conf->getConfigFileExt());
}
/**
*/
public function testMergeDeprecatedConfigNoFile()
{
- $updater = new Updater(array(), array(), true);
+ $updater = new Updater(array(), array(), $this->conf, true);
$updater->updateMethodMergeDeprecatedConfigFile();
- $this->assertEquals(self::$configFields['login'], $this->conf->get('login'));
+ $this->assertEquals('root', $this->conf->get('credentials.login'));
}
/**
$refDB->write(self::$testDatastore);
$linkDB = new LinkDB(self::$testDatastore, true, false);
$this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude')));
- $updater = new Updater(array(), $linkDB, true);
+ $updater = new Updater(array(), $linkDB, $this->conf, true);
$updater->updateMethodRenameDashTags();
$this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude')));
}
public function testConfigToJson()
{
$configFile = 'tests/utils/config/configPhp';
- ConfigManager::$CONFIG_FILE = $configFile;
- $conf = ConfigManager::reset();
+ $this->conf->setConfigFile($configFile);
+ $this->conf->reset();
// The ConfigIO is initialized with ConfigPhp.
- $this->assertTrue($conf->getConfigIO() instanceof ConfigPhp);
+ $this->assertTrue($this->conf->getConfigIO() instanceof ConfigPhp);
- $updater = new Updater(array(), array(), false);
+ $updater = new Updater(array(), array(), $this->conf, false);
$done = $updater->updateMethodConfigToJson();
$this->assertTrue($done);
// The ConfigIO has been updated to ConfigJson.
- $this->assertTrue($conf->getConfigIO() instanceof ConfigJson);
- $this->assertTrue(file_exists($conf->getConfigFile()));
+ $this->assertTrue($this->conf->getConfigIO() instanceof ConfigJson);
+ $this->assertTrue(file_exists($this->conf->getConfigFileExt()));
// 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('1', $conf->get('plugins.WALLABAG_VERSION'));
+ $this->conf->reload();
+ $this->assertEquals('root', $this->conf->get('credentials.login'));
+ $this->assertEquals('lala', $this->conf->get('extras.redirector'));
+ $this->assertEquals('data/datastore.php', $this->conf->get('path.datastore'));
+ $this->assertEquals('1', $this->conf->get('plugins.WALLABAG_VERSION'));
rename($configFile . '.save.php', $configFile . '.php');
- unlink($conf->getConfigFile());
+ unlink($this->conf->getConfigFileExt());
}
/**
*/
public function testConfigToJsonNothingToDo()
{
- $configFile = 'tests/utils/config/configUpdateDone';
- ConfigManager::$CONFIG_FILE = $configFile;
- $conf = ConfigManager::reset();
- $conf->reload();
- $filetime = filemtime($conf->getConfigFile());
- $updater = new Updater(array(), array(), false);
+ $filetime = filemtime($this->conf->getConfigFileExt());
+ $updater = new Updater(array(), array(), $this->conf, false);
$done = $updater->updateMethodConfigToJson();
$this->assertTrue($done);
- $expected = filemtime($conf->getConfigFile());
+ $expected = filemtime($this->conf->getConfigFileExt());
$this->assertEquals($expected, $filetime);
}
}