diff options
Diffstat (limited to 'tests/Updater/UpdaterTest.php')
-rw-r--r-- | tests/Updater/UpdaterTest.php | 97 |
1 files changed, 25 insertions, 72 deletions
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'; | |||
10 | class UpdaterTest extends PHPUnit_Framework_TestCase | 10 | class 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 | } |