aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ApplicationUtilsTest.php40
-rw-r--r--tests/Updater/UpdaterTest.php97
-rw-r--r--tests/config/ConfigJsonTest.php38
-rw-r--r--tests/config/ConfigManagerTest.php6
-rw-r--r--tests/utils/config/configJson.json.php33
-rw-r--r--tests/utils/config/configUpdateDone.json.php4
-rw-r--r--tests/utils/config/configUpdater.php15
7 files changed, 93 insertions, 140 deletions
diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php
index cf82b655..f92412ba 100644
--- a/tests/ApplicationUtilsTest.php
+++ b/tests/ApplicationUtilsTest.php
@@ -277,16 +277,16 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
277 public function testCheckCurrentResourcePermissions() 277 public function testCheckCurrentResourcePermissions()
278 { 278 {
279 $conf = ConfigManager::getInstance(); 279 $conf = ConfigManager::getInstance();
280 $conf->set('config.CACHEDIR', 'cache'); 280 $conf->set('path.thumbnails_cache', 'cache');
281 $conf->set('config.CONFIG_FILE', 'data/config.php'); 281 $conf->set('path.config', 'data/config.php');
282 $conf->set('config.DATADIR', 'data'); 282 $conf->set('path.data_dir', 'data');
283 $conf->set('config.DATASTORE', 'data/datastore.php'); 283 $conf->set('path.datastore', 'data/datastore.php');
284 $conf->set('config.IPBANS_FILENAME', 'data/ipbans.php'); 284 $conf->set('path.ban_file', 'data/ipbans.php');
285 $conf->set('config.LOG_FILE', 'data/log.txt'); 285 $conf->set('path.log', 'data/log.txt');
286 $conf->set('config.PAGECACHE', 'pagecache'); 286 $conf->set('path.page_cache', 'pagecache');
287 $conf->set('config.RAINTPL_TMP', 'tmp'); 287 $conf->set('path.raintpl_tmp', 'tmp');
288 $conf->set('config.RAINTPL_TPL', 'tpl'); 288 $conf->set('path.raintpl_tpl', 'tpl');
289 $conf->set('config.UPDATECHECK_FILENAME', 'data/lastupdatecheck.txt'); 289 $conf->set('path.update_check', 'data/lastupdatecheck.txt');
290 290
291 $this->assertEquals( 291 $this->assertEquals(
292 array(), 292 array(),
@@ -300,16 +300,16 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase
300 public function testCheckCurrentResourcePermissionsErrors() 300 public function testCheckCurrentResourcePermissionsErrors()
301 { 301 {
302 $conf = ConfigManager::getInstance(); 302 $conf = ConfigManager::getInstance();
303 $conf->set('config.CACHEDIR', 'null/cache'); 303 $conf->set('path.thumbnails_cache', 'null/cache');
304 $conf->set('config.CONFIG_FILE', 'null/data/config.php'); 304 $conf->set('path.config', 'null/data/config.php');
305 $conf->set('config.DATADIR', 'null/data'); 305 $conf->set('path.data_dir', 'null/data');
306 $conf->set('config.DATASTORE', 'null/data/store.php'); 306 $conf->set('path.datastore', 'null/data/store.php');
307 $conf->set('config.IPBANS_FILENAME', 'null/data/ipbans.php'); 307 $conf->set('path.ban_file', 'null/data/ipbans.php');
308 $conf->set('config.LOG_FILE', 'null/data/log.txt'); 308 $conf->set('path.log', 'null/data/log.txt');
309 $conf->set('config.PAGECACHE', 'null/pagecache'); 309 $conf->set('path.page_cache', 'null/pagecache');
310 $conf->set('config.RAINTPL_TMP', 'null/tmp'); 310 $conf->set('path.raintpl_tmp', 'null/tmp');
311 $conf->set('config.RAINTPL_TPL', 'null/tpl'); 311 $conf->set('path.raintpl_tpl', 'null/tpl');
312 $conf->set('config.UPDATECHECK_FILENAME', 'null/data/lastupdatecheck.txt'); 312 $conf->set('path.update_check', 'null/data/lastupdatecheck.txt');
313 $this->assertEquals( 313 $this->assertEquals(
314 array( 314 array(
315 '"null/tpl" directory is not readable', 315 '"null/tpl" directory is not readable',
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php
index f8de2f70..04883a46 100644
--- a/tests/Updater/UpdaterTest.php
+++ b/tests/Updater/UpdaterTest.php
@@ -10,11 +10,6 @@ require_once 'tests/Updater/DummyUpdater.php';
10class UpdaterTest extends PHPUnit_Framework_TestCase 10class UpdaterTest extends PHPUnit_Framework_TestCase
11{ 11{
12 /** 12 /**
13 * @var array Configuration input set.
14 */
15 private static $configFields;
16
17 /**
18 * @var string Path to test datastore. 13 * @var string Path to test datastore.
19 */ 14 */
20 protected static $testDatastore = 'sandbox/datastore.php'; 15 protected static $testDatastore = 'sandbox/datastore.php';
@@ -22,7 +17,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
22 /** 17 /**
23 * @var string Config file path (without extension). 18 * @var string Config file path (without extension).
24 */ 19 */
25 protected static $configFile = 'tests/utils/config/configUpdater'; 20 protected static $configFile = 'tests/utils/config/configJson';
26 21
27 /** 22 /**
28 * @var ConfigManager 23 * @var ConfigManager
@@ -34,51 +29,8 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
34 */ 29 */
35 public function setUp() 30 public function setUp()
36 { 31 {
37 self::$configFields = array(
38 'login' => 'login',
39 'hash' => 'hash',
40 'salt' => 'salt',
41 'timezone' => 'Europe/Paris',
42 'title' => 'title',
43 'titleLink' => 'titleLink',
44 'redirector' => '',
45 'disablesessionprotection' => false,
46 'privateLinkByDefault' => false,
47 'config' => array(
48 'DATADIR' => 'tests/Updater',
49 'PAGECACHE' => 'sandbox/pagecache',
50 'config1' => 'config1data',
51 'config2' => 'config2data',
52 )
53 );
54
55 ConfigManager::$CONFIG_FILE = self::$configFile; 32 ConfigManager::$CONFIG_FILE = self::$configFile;
56 $this->conf = ConfigManager::reset(); 33 $this->conf = ConfigManager::reset();
57 $this->conf->reload();
58 foreach (self::$configFields as $key => $value) {
59 $this->conf->set($key, $value);
60 }
61 $this->conf->write(true);
62 }
63
64 /**
65 * Executed after each test.
66 *
67 * @return void
68 */
69 public function tearDown()
70 {
71 if (is_file('tests/Updater/config.json')) {
72 unlink('tests/Updater/config.json');
73 }
74
75 if (is_file(self::$configFields['config']['DATADIR'] . '/options.php')) {
76 unlink(self::$configFields['config']['DATADIR'] . '/options.php');
77 }
78
79 if (is_file(self::$configFields['config']['DATADIR'] . '/updates.txt')) {
80 unlink(self::$configFields['config']['DATADIR'] . '/updates.txt');
81 }
82 } 34 }
83 35
84 /** 36 /**
@@ -87,9 +39,10 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
87 public function testReadEmptyUpdatesFile() 39 public function testReadEmptyUpdatesFile()
88 { 40 {
89 $this->assertEquals(array(), read_updates_file('')); 41 $this->assertEquals(array(), read_updates_file(''));
90 $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt'; 42 $updatesFile = $this->conf->get('path.data_dir') . '/updates.txt';
91 touch($updatesFile); 43 touch($updatesFile);
92 $this->assertEquals(array(), read_updates_file($updatesFile)); 44 $this->assertEquals(array(), read_updates_file($updatesFile));
45 unlink($updatesFile);
93 } 46 }
94 47
95 /** 48 /**
@@ -97,7 +50,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
97 */ 50 */
98 public function testReadWriteUpdatesFile() 51 public function testReadWriteUpdatesFile()
99 { 52 {
100 $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt'; 53 $updatesFile = $this->conf->get('path.data_dir') . '/updates.txt';
101 $updatesMethods = array('m1', 'm2', 'm3'); 54 $updatesMethods = array('m1', 'm2', 'm3');
102 55
103 write_updates_file($updatesFile, $updatesMethods); 56 write_updates_file($updatesFile, $updatesMethods);
@@ -109,6 +62,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
109 write_updates_file($updatesFile, $updatesMethods); 62 write_updates_file($updatesFile, $updatesMethods);
110 $readMethods = read_updates_file($updatesFile); 63 $readMethods = read_updates_file($updatesFile);
111 $this->assertEquals($readMethods, $updatesMethods); 64 $this->assertEquals($readMethods, $updatesMethods);
65 unlink($updatesFile);
112 } 66 }
113 67
114 /** 68 /**
@@ -130,10 +84,15 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
130 */ 84 */
131 public function testWriteUpdatesFileNotWritable() 85 public function testWriteUpdatesFileNotWritable()
132 { 86 {
133 $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt'; 87 $updatesFile = $this->conf->get('path.data_dir') . '/updates.txt';
134 touch($updatesFile); 88 touch($updatesFile);
135 chmod($updatesFile, 0444); 89 chmod($updatesFile, 0444);
136 @write_updates_file($updatesFile, array('test')); 90 try {
91 @write_updates_file($updatesFile, array('test'));
92 } catch (Exception $e) {
93 unlink($updatesFile);
94 throw $e;
95 }
137 } 96 }
138 97
139 /** 98 /**
@@ -213,17 +172,15 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
213 */ 172 */
214 public function testUpdateMergeDeprecatedConfig() 173 public function testUpdateMergeDeprecatedConfig()
215 { 174 {
216 // Use writeConfig to create a options.php 175 ConfigManager::$CONFIG_FILE = 'tests/utils/config/configPhp';
217 ConfigManager::$CONFIG_FILE = 'tests/Updater/options'; 176 $this->conf = $this->conf->reset();
218 $this->conf->setConfigIO(new ConfigPhp());
219
220 $invert = !$this->conf->get('privateLinkByDefault');
221 $this->conf->set('privateLinkByDefault', $invert);
222 $this->conf->write(true);
223 177
224 $optionsFile = 'tests/Updater/options.php'; 178 $optionsFile = 'tests/Updater/options.php';
225 $this->assertTrue(is_file($optionsFile)); 179 $options = '<?php
180$GLOBALS[\'privateLinkByDefault\'] = true;';
181 file_put_contents($optionsFile, $options);
226 182
183 // tmp config file.
227 ConfigManager::$CONFIG_FILE = 'tests/Updater/config'; 184 ConfigManager::$CONFIG_FILE = 'tests/Updater/config';
228 185
229 // merge configs 186 // merge configs
@@ -233,7 +190,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
233 190
234 // make sure updated field is changed 191 // make sure updated field is changed
235 $this->conf->reload(); 192 $this->conf->reload();
236 $this->assertEquals($invert, $this->conf->get('privateLinkByDefault')); 193 $this->assertTrue($this->conf->get('general.default_private_links'));
237 $this->assertFalse(is_file($optionsFile)); 194 $this->assertFalse(is_file($optionsFile));
238 // Delete the generated file. 195 // Delete the generated file.
239 unlink($this->conf->getConfigFile()); 196 unlink($this->conf->getConfigFile());
@@ -247,7 +204,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
247 $updater = new Updater(array(), array(), true); 204 $updater = new Updater(array(), array(), true);
248 $updater->updateMethodMergeDeprecatedConfigFile(); 205 $updater->updateMethodMergeDeprecatedConfigFile();
249 206
250 $this->assertEquals(self::$configFields['login'], $this->conf->get('login')); 207 $this->assertEquals('root', $this->conf->get('credentials.login'));
251 } 208 }
252 209
253 /** 210 /**
@@ -286,9 +243,9 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
286 243
287 // Check JSON config data. 244 // Check JSON config data.
288 $conf->reload(); 245 $conf->reload();
289 $this->assertEquals('root', $conf->get('login')); 246 $this->assertEquals('root', $conf->get('credentials.login'));
290 $this->assertEquals('lala', $conf->get('redirector')); 247 $this->assertEquals('lala', $conf->get('extras.redirector'));
291 $this->assertEquals('data/datastore.php', $conf->get('config.DATASTORE')); 248 $this->assertEquals('data/datastore.php', $conf->get('path.datastore'));
292 $this->assertEquals('1', $conf->get('plugins.WALLABAG_VERSION')); 249 $this->assertEquals('1', $conf->get('plugins.WALLABAG_VERSION'));
293 250
294 rename($configFile . '.save.php', $configFile . '.php'); 251 rename($configFile . '.save.php', $configFile . '.php');
@@ -300,15 +257,11 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
300 */ 257 */
301 public function testConfigToJsonNothingToDo() 258 public function testConfigToJsonNothingToDo()
302 { 259 {
303 $configFile = 'tests/utils/config/configUpdateDone'; 260 $filetime = filemtime($this->conf->getConfigFile());
304 ConfigManager::$CONFIG_FILE = $configFile;
305 $conf = ConfigManager::reset();
306 $conf->reload();
307 $filetime = filemtime($conf->getConfigFile());
308 $updater = new Updater(array(), array(), false); 261 $updater = new Updater(array(), array(), false);
309 $done = $updater->updateMethodConfigToJson(); 262 $done = $updater->updateMethodConfigToJson();
310 $this->assertTrue($done); 263 $this->assertTrue($done);
311 $expected = filemtime($conf->getConfigFile()); 264 $expected = filemtime($this->conf->getConfigFile());
312 $this->assertEquals($expected, $filetime); 265 $this->assertEquals($expected, $filetime);
313 } 266 }
314} 267}
diff --git a/tests/config/ConfigJsonTest.php b/tests/config/ConfigJsonTest.php
index 5b3bce46..0960c729 100644
--- a/tests/config/ConfigJsonTest.php
+++ b/tests/config/ConfigJsonTest.php
@@ -23,9 +23,9 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase
23 public function testRead() 23 public function testRead()
24 { 24 {
25 $conf = $this->configIO->read('tests/utils/config/configJson.json.php'); 25 $conf = $this->configIO->read('tests/utils/config/configJson.json.php');
26 $this->assertEquals('root', $conf['login']); 26 $this->assertEquals('root', $conf['credentials']['login']);
27 $this->assertEquals('lala', $conf['redirector']); 27 $this->assertEquals('lala', $conf['extras']['redirector']);
28 $this->assertEquals('data/datastore.php', $conf['config']['DATASTORE']); 28 $this->assertEquals('tests/utils/config/datastore.php', $conf['path']['datastore']);
29 $this->assertEquals('1', $conf['plugins']['WALLABAG_VERSION']); 29 $this->assertEquals('1', $conf['plugins']['WALLABAG_VERSION']);
30 } 30 }
31 31
@@ -55,10 +55,14 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase
55 { 55 {
56 $dataFile = 'tests/utils/config/configWrite.json.php'; 56 $dataFile = 'tests/utils/config/configWrite.json.php';
57 $data = array( 57 $data = array(
58 'login' => 'root', 58 'credentials' => array(
59 'redirector' => 'lala', 59 'login' => 'root',
60 'config' => array( 60 ),
61 'DATASTORE' => 'data/datastore.php', 61 'path' => array(
62 'datastore' => 'data/datastore.php',
63 ),
64 'extras' => array(
65 'redirector' => 'lala',
62 ), 66 ),
63 'plugins' => array( 67 'plugins' => array(
64 'WALLABAG_VERSION' => '1', 68 'WALLABAG_VERSION' => '1',
@@ -68,19 +72,23 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase
68 // PHP 5.3 doesn't support json pretty print. 72 // PHP 5.3 doesn't support json pretty print.
69 if (defined('JSON_PRETTY_PRINT')) { 73 if (defined('JSON_PRETTY_PRINT')) {
70 $expected = '{ 74 $expected = '{
71 "login": "root", 75 "credentials": {
72 "redirector": "lala", 76 "login": "root"
73 "config": { 77 },
74 "DATASTORE": "data\/datastore.php" 78 "path": {
79 "datastore": "data\/datastore.php"
80 },
81 "extras": {
82 "redirector": "lala"
75 }, 83 },
76 "plugins": { 84 "plugins": {
77 "WALLABAG_VERSION": "1" 85 "WALLABAG_VERSION": "1"
78 } 86 }
79}'; 87}';
80 } else { 88 } else {
81 $expected = '{"login":"root","redirector":"lala","config":{"DATASTORE":"data\/datastore.php"},"plugins":{"WALLABAG_VERSION":"1"}}'; 89 $expected = '{"credentials":{"login":"root"},"path":{"datastore":"data\/datastore.php"},"extras":{"redirector":"lala"},"plugins":{"WALLABAG_VERSION":"1"}}';
82 } 90 }
83 $expected = ConfigJson::$PHP_HEADER . $expected; 91 $expected = ConfigJson::getPhpHeaders() . $expected;
84 $this->assertEquals($expected, file_get_contents($dataFile)); 92 $this->assertEquals($expected, file_get_contents($dataFile));
85 unlink($dataFile); 93 unlink($dataFile);
86 } 94 }
@@ -94,10 +102,10 @@ class ConfigJsonTest extends PHPUnit_Framework_TestCase
94 $dest = 'tests/utils/config/configOverwrite.json.php'; 102 $dest = 'tests/utils/config/configOverwrite.json.php';
95 copy($source, $dest); 103 copy($source, $dest);
96 $conf = $this->configIO->read($dest); 104 $conf = $this->configIO->read($dest);
97 $conf['redirector'] = 'blabla'; 105 $conf['extras']['redirector'] = 'blabla';
98 $this->configIO->write($dest, $conf); 106 $this->configIO->write($dest, $conf);
99 $conf = $this->configIO->read($dest); 107 $conf = $this->configIO->read($dest);
100 $this->assertEquals('blabla', $conf['redirector']); 108 $this->assertEquals('blabla', $conf['extras']['redirector']);
101 unlink($dest); 109 unlink($dest);
102 } 110 }
103 111
diff --git a/tests/config/ConfigManagerTest.php b/tests/config/ConfigManagerTest.php
index 7390699c..9ff0f473 100644
--- a/tests/config/ConfigManagerTest.php
+++ b/tests/config/ConfigManagerTest.php
@@ -131,7 +131,7 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase
131 */ 131 */
132 public function testExistsOk() 132 public function testExistsOk()
133 { 133 {
134 $this->assertTrue($this->conf->exists('login')); 134 $this->assertTrue($this->conf->exists('credentials.login'));
135 $this->assertTrue($this->conf->exists('config.foo')); 135 $this->assertTrue($this->conf->exists('config.foo'));
136 } 136 }
137 137
@@ -163,12 +163,12 @@ class ConfigManagerTest extends PHPUnit_Framework_TestCase
163 public function testReload() 163 public function testReload()
164 { 164 {
165 ConfigManager::$CONFIG_FILE = 'tests/utils/config/configTmp'; 165 ConfigManager::$CONFIG_FILE = 'tests/utils/config/configTmp';
166 $newConf = ConfigJson::$PHP_HEADER . '{ "key": "value" }'; 166 $newConf = ConfigJson::getPhpHeaders() . '{ "key": "value" }';
167 file_put_contents($this->conf->getConfigFile(), $newConf); 167 file_put_contents($this->conf->getConfigFile(), $newConf);
168 $this->conf->reload(); 168 $this->conf->reload();
169 unlink($this->conf->getConfigFile()); 169 unlink($this->conf->getConfigFile());
170 // Previous conf no longer exists, and new values have been loaded. 170 // Previous conf no longer exists, and new values have been loaded.
171 $this->assertFalse($this->conf->exists('login')); 171 $this->assertFalse($this->conf->exists('credentials.login'));
172 $this->assertEquals('value', $this->conf->get('key')); 172 $this->assertEquals('value', $this->conf->get('key'));
173 } 173 }
174} 174}
diff --git a/tests/utils/config/configJson.json.php b/tests/utils/config/configJson.json.php
index 71b59edd..6a841f8a 100644
--- a/tests/utils/config/configJson.json.php
+++ b/tests/utils/config/configJson.json.php
@@ -1,17 +1,28 @@
1<?php /* 1<?php /*
2{ 2{
3 "redirector":"lala", 3 "credentials": {
4 "login":"root", 4 "login":"root",
5 "hash":"hash", 5 "hash":"hash",
6 "salt":"salt", 6 "salt":"salt"
7 "timezone":"Europe\/Paris", 7 },
8 "disablesessionprotection":false, 8 "security": {
9 "privateLinkByDefault":true, 9 "session_protection_disabled":false
10 "title": "Shaarli", 10 },
11 "titleLink": "?", 11 "general": {
12 "timezone":"Europe\/Paris",
13 "default_private_linksheader_link":true,
14 "title": "Shaarli",
15 "header_link": "?"
16 },
17 "extras": {
18 "redirector":"lala"
19 },
12 "config": { 20 "config": {
13 "foo": "bar", 21 "foo": "bar"
14 "DATASTORE": "data\/datastore.php" 22 },
23 "path": {
24 "datastore": "tests\/utils\/config\/datastore.php",
25 "data_dir": "tests\/utils\/config"
15 }, 26 },
16 "plugins": { 27 "plugins": {
17 "WALLABAG_VERSION": 1 28 "WALLABAG_VERSION": 1
diff --git a/tests/utils/config/configUpdateDone.json.php b/tests/utils/config/configUpdateDone.json.php
deleted file mode 100644
index a4e460d1..00000000
--- a/tests/utils/config/configUpdateDone.json.php
+++ /dev/null
@@ -1,4 +0,0 @@
1<?php /*
2{
3 "login": "root"
4}
diff --git a/tests/utils/config/configUpdater.php b/tests/utils/config/configUpdater.php
deleted file mode 100644
index ee4a56b5..00000000
--- a/tests/utils/config/configUpdater.php
+++ /dev/null
@@ -1,15 +0,0 @@
1<?php
2$GLOBALS['login'] = 'login';
3$GLOBALS['hash'] = 'hash';
4$GLOBALS['salt'] = 'salt';
5$GLOBALS['timezone'] = 'Europe/Paris';
6$GLOBALS['title'] = 'title';
7$GLOBALS['titleLink'] = 'titleLink';
8$GLOBALS['redirector'] = '';
9$GLOBALS['disablesessionprotection'] = false;
10$GLOBALS['privateLinkByDefault'] = false;
11$GLOBALS['config']['DATADIR'] = 'tests/Updater';
12$GLOBALS['config']['PAGECACHE'] = 'sandbox/pagecache';
13$GLOBALS['config']['config1'] = 'config1data';
14$GLOBALS['config']['config2'] = 'config2data';
15$GLOBALS['plugins']['WALLABAG_VERSION'] = '2';