diff options
Diffstat (limited to 'tests/Updater')
-rw-r--r-- | tests/Updater/DummyUpdater.php | 5 | ||||
-rw-r--r-- | tests/Updater/UpdaterTest.php | 80 |
2 files changed, 50 insertions, 35 deletions
diff --git a/tests/Updater/DummyUpdater.php b/tests/Updater/DummyUpdater.php index e9ef2aaa..6724b203 100644 --- a/tests/Updater/DummyUpdater.php +++ b/tests/Updater/DummyUpdater.php | |||
@@ -12,13 +12,12 @@ class DummyUpdater extends Updater | |||
12 | * Object constructor. | 12 | * Object constructor. |
13 | * | 13 | * |
14 | * @param array $doneUpdates Updates which are already done. | 14 | * @param array $doneUpdates Updates which are already done. |
15 | * @param array $config Shaarli's configuration array. | ||
16 | * @param LinkDB $linkDB LinkDB instance. | 15 | * @param LinkDB $linkDB LinkDB instance. |
17 | * @param boolean $isLoggedIn True if the user is logged in. | 16 | * @param boolean $isLoggedIn True if the user is logged in. |
18 | */ | 17 | */ |
19 | public function __construct($doneUpdates, $config, $linkDB, $isLoggedIn) | 18 | public function __construct($doneUpdates, $linkDB, $isLoggedIn) |
20 | { | 19 | { |
21 | parent::__construct($doneUpdates, $config, $linkDB, $isLoggedIn); | 20 | parent::__construct($doneUpdates, $linkDB, $isLoggedIn); |
22 | 21 | ||
23 | // Retrieve all update methods. | 22 | // Retrieve all update methods. |
24 | // For unit test, only retrieve final methods, | 23 | // For unit test, only retrieve final methods, |
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index a29d9067..8bfb4ba3 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php | |||
@@ -1,5 +1,6 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | require_once 'application/config/ConfigManager.php'; | ||
3 | require_once 'tests/Updater/DummyUpdater.php'; | 4 | require_once 'tests/Updater/DummyUpdater.php'; |
4 | 5 | ||
5 | /** | 6 | /** |
@@ -19,6 +20,16 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
19 | protected static $testDatastore = 'sandbox/datastore.php'; | 20 | protected static $testDatastore = 'sandbox/datastore.php'; |
20 | 21 | ||
21 | /** | 22 | /** |
23 | * @var string Config file path. | ||
24 | */ | ||
25 | protected static $configFile = 'tests/Updater/config.php'; | ||
26 | |||
27 | /** | ||
28 | * @var ConfigManager | ||
29 | */ | ||
30 | protected $conf; | ||
31 | |||
32 | /** | ||
22 | * Executed before each test. | 33 | * Executed before each test. |
23 | */ | 34 | */ |
24 | public function setUp() | 35 | public function setUp() |
@@ -34,13 +45,19 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
34 | 'disablesessionprotection' => false, | 45 | 'disablesessionprotection' => false, |
35 | 'privateLinkByDefault' => false, | 46 | 'privateLinkByDefault' => false, |
36 | 'config' => array( | 47 | 'config' => array( |
37 | 'CONFIG_FILE' => 'tests/Updater/config.php', | ||
38 | 'DATADIR' => 'tests/Updater', | 48 | 'DATADIR' => 'tests/Updater', |
39 | 'PAGECACHE' => 'sandbox/pagecache', | 49 | 'PAGECACHE' => 'sandbox/pagecache', |
40 | 'config1' => 'config1data', | 50 | 'config1' => 'config1data', |
41 | 'config2' => 'config2data', | 51 | 'config2' => 'config2data', |
42 | ) | 52 | ) |
43 | ); | 53 | ); |
54 | |||
55 | ConfigManager::$CONFIG_FILE = 'tests/Updater/config'; | ||
56 | $this->conf = ConfigManager::getInstance(); | ||
57 | foreach (self::$configFields as $key => $value) { | ||
58 | $this->conf->set($key, $value); | ||
59 | } | ||
60 | $this->conf->write(true); | ||
44 | } | 61 | } |
45 | 62 | ||
46 | /** | 63 | /** |
@@ -50,16 +67,16 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
50 | */ | 67 | */ |
51 | public function tearDown() | 68 | public function tearDown() |
52 | { | 69 | { |
53 | if (is_file(self::$configFields['config']['CONFIG_FILE'])) { | 70 | if (is_file(self::$configFile)) { |
54 | unlink(self::$configFields['config']['CONFIG_FILE']); | 71 | unlink(self::$configFile); |
55 | } | 72 | } |
56 | 73 | ||
57 | if (is_file(self::$configFields['config']['DATADIR'] . '/options.php')) { | 74 | if (is_file(self::$configFields['config']['DATADIR'] . '/options.php')) { |
58 | unlink(self::$configFields['config']['DATADIR'] . '/options.php'); | 75 | unlink(self::$configFields['config']['DATADIR'] . '/options.php'); |
59 | } | 76 | } |
60 | 77 | ||
61 | if (is_file(self::$configFields['config']['DATADIR'] . '/updates.json')) { | 78 | if (is_file(self::$configFields['config']['DATADIR'] . '/updates.txt')) { |
62 | unlink(self::$configFields['config']['DATADIR'] . '/updates.json'); | 79 | unlink(self::$configFields['config']['DATADIR'] . '/updates.txt'); |
63 | } | 80 | } |
64 | } | 81 | } |
65 | 82 | ||
@@ -69,7 +86,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
69 | public function testReadEmptyUpdatesFile() | 86 | public function testReadEmptyUpdatesFile() |
70 | { | 87 | { |
71 | $this->assertEquals(array(), read_updates_file('')); | 88 | $this->assertEquals(array(), read_updates_file('')); |
72 | $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.json'; | 89 | $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt'; |
73 | touch($updatesFile); | 90 | touch($updatesFile); |
74 | $this->assertEquals(array(), read_updates_file($updatesFile)); | 91 | $this->assertEquals(array(), read_updates_file($updatesFile)); |
75 | } | 92 | } |
@@ -79,7 +96,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
79 | */ | 96 | */ |
80 | public function testReadWriteUpdatesFile() | 97 | public function testReadWriteUpdatesFile() |
81 | { | 98 | { |
82 | $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.json'; | 99 | $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt'; |
83 | $updatesMethods = array('m1', 'm2', 'm3'); | 100 | $updatesMethods = array('m1', 'm2', 'm3'); |
84 | 101 | ||
85 | write_updates_file($updatesFile, $updatesMethods); | 102 | write_updates_file($updatesFile, $updatesMethods); |
@@ -112,7 +129,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
112 | */ | 129 | */ |
113 | public function testWriteUpdatesFileNotWritable() | 130 | public function testWriteUpdatesFileNotWritable() |
114 | { | 131 | { |
115 | $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.json'; | 132 | $updatesFile = self::$configFields['config']['DATADIR'] . '/updates.txt'; |
116 | touch($updatesFile); | 133 | touch($updatesFile); |
117 | chmod($updatesFile, 0444); | 134 | chmod($updatesFile, 0444); |
118 | @write_updates_file($updatesFile, array('test')); | 135 | @write_updates_file($updatesFile, array('test')); |
@@ -131,10 +148,10 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
131 | 'updateMethodDummy3', | 148 | 'updateMethodDummy3', |
132 | 'updateMethodException', | 149 | 'updateMethodException', |
133 | ); | 150 | ); |
134 | $updater = new DummyUpdater($updates, array(), array(), true); | 151 | $updater = new DummyUpdater($updates, array(), true); |
135 | $this->assertEquals(array(), $updater->update()); | 152 | $this->assertEquals(array(), $updater->update()); |
136 | 153 | ||
137 | $updater = new DummyUpdater(array(), array(), array(), false); | 154 | $updater = new DummyUpdater(array(), array(), false); |
138 | $this->assertEquals(array(), $updater->update()); | 155 | $this->assertEquals(array(), $updater->update()); |
139 | } | 156 | } |
140 | 157 | ||
@@ -149,7 +166,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
149 | 'updateMethodDummy2', | 166 | 'updateMethodDummy2', |
150 | 'updateMethodDummy3', | 167 | 'updateMethodDummy3', |
151 | ); | 168 | ); |
152 | $updater = new DummyUpdater($updates, array(), array(), true); | 169 | $updater = new DummyUpdater($updates, array(), true); |
153 | $this->assertEquals($expectedUpdates, $updater->update()); | 170 | $this->assertEquals($expectedUpdates, $updater->update()); |
154 | } | 171 | } |
155 | 172 | ||
@@ -165,7 +182,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
165 | ); | 182 | ); |
166 | $expectedUpdate = array('updateMethodDummy2'); | 183 | $expectedUpdate = array('updateMethodDummy2'); |
167 | 184 | ||
168 | $updater = new DummyUpdater($updates, array(), array(), true); | 185 | $updater = new DummyUpdater($updates, array(), true); |
169 | $this->assertEquals($expectedUpdate, $updater->update()); | 186 | $this->assertEquals($expectedUpdate, $updater->update()); |
170 | } | 187 | } |
171 | 188 | ||
@@ -182,7 +199,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
182 | 'updateMethodDummy3', | 199 | 'updateMethodDummy3', |
183 | ); | 200 | ); |
184 | 201 | ||
185 | $updater = new DummyUpdater($updates, array(), array(), true); | 202 | $updater = new DummyUpdater($updates, array(), true); |
186 | $updater->update(); | 203 | $updater->update(); |
187 | } | 204 | } |
188 | 205 | ||
@@ -195,26 +212,25 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
195 | */ | 212 | */ |
196 | public function testUpdateMergeDeprecatedConfig() | 213 | public function testUpdateMergeDeprecatedConfig() |
197 | { | 214 | { |
198 | // init | ||
199 | writeConfig(self::$configFields, true); | ||
200 | $configCopy = self::$configFields; | ||
201 | $invert = !$configCopy['privateLinkByDefault']; | ||
202 | $configCopy['privateLinkByDefault'] = $invert; | ||
203 | |||
204 | // Use writeConfig to create a options.php | 215 | // Use writeConfig to create a options.php |
205 | $configCopy['config']['CONFIG_FILE'] = 'tests/Updater/options.php'; | 216 | ConfigManager::$CONFIG_FILE = 'tests/Updater/options'; |
206 | writeConfig($configCopy, true); | 217 | $invert = !$this->conf->get('privateLinkByDefault'); |
218 | $this->conf->set('privateLinkByDefault', $invert); | ||
219 | $this->conf->write(true); | ||
220 | |||
221 | $optionsFile = 'tests/Updater/options.php'; | ||
222 | $this->assertTrue(is_file($optionsFile)); | ||
207 | 223 | ||
208 | $this->assertTrue(is_file($configCopy['config']['CONFIG_FILE'])); | 224 | ConfigManager::$CONFIG_FILE = 'tests/Updater/config'; |
209 | 225 | ||
210 | // merge configs | 226 | // merge configs |
211 | $updater = new Updater(array(), self::$configFields, array(), true); | 227 | $updater = new Updater(array(), array(), true); |
212 | $updater->updateMethodMergeDeprecatedConfigFile(); | 228 | $updater->updateMethodMergeDeprecatedConfigFile(); |
213 | 229 | ||
214 | // make sure updated field is changed | 230 | // make sure updated field is changed |
215 | include self::$configFields['config']['CONFIG_FILE']; | 231 | $this->conf->reload(); |
216 | $this->assertEquals($invert, $GLOBALS['privateLinkByDefault']); | 232 | $this->assertEquals($invert, $this->conf->get('privateLinkByDefault')); |
217 | $this->assertFalse(is_file($configCopy['config']['CONFIG_FILE'])); | 233 | $this->assertFalse(is_file($optionsFile)); |
218 | } | 234 | } |
219 | 235 | ||
220 | /** | 236 | /** |
@@ -222,22 +238,22 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
222 | */ | 238 | */ |
223 | public function testMergeDeprecatedConfigNoFile() | 239 | public function testMergeDeprecatedConfigNoFile() |
224 | { | 240 | { |
225 | writeConfig(self::$configFields, true); | 241 | $updater = new Updater(array(), array(), true); |
226 | |||
227 | $updater = new Updater(array(), self::$configFields, array(), true); | ||
228 | $updater->updateMethodMergeDeprecatedConfigFile(); | 242 | $updater->updateMethodMergeDeprecatedConfigFile(); |
229 | 243 | ||
230 | include self::$configFields['config']['CONFIG_FILE']; | 244 | $this->assertEquals(self::$configFields['login'], $this->conf->get('login')); |
231 | $this->assertEquals(self::$configFields['login'], $GLOBALS['login']); | ||
232 | } | 245 | } |
233 | 246 | ||
247 | /** | ||
248 | * Test renameDashTags update method. | ||
249 | */ | ||
234 | public function testRenameDashTags() | 250 | public function testRenameDashTags() |
235 | { | 251 | { |
236 | $refDB = new ReferenceLinkDB(); | 252 | $refDB = new ReferenceLinkDB(); |
237 | $refDB->write(self::$testDatastore); | 253 | $refDB->write(self::$testDatastore); |
238 | $linkDB = new LinkDB(self::$testDatastore, true, false); | 254 | $linkDB = new LinkDB(self::$testDatastore, true, false); |
239 | $this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); | 255 | $this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); |
240 | $updater = new Updater(array(), self::$configFields, $linkDB, true); | 256 | $updater = new Updater(array(), $linkDB, true); |
241 | $updater->updateMethodRenameDashTags(); | 257 | $updater->updateMethodRenameDashTags(); |
242 | $this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); | 258 | $this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); |
243 | } | 259 | } |