diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ApplicationUtilsTest.php | 54 | ||||
-rw-r--r-- | tests/ConfigTest.php | 244 | ||||
-rw-r--r-- | tests/FeedBuilderTest.php | 6 | ||||
-rw-r--r-- | tests/LinkDBTest.php | 2 | ||||
-rw-r--r-- | tests/Updater/DummyUpdater.php | 5 | ||||
-rw-r--r-- | tests/Updater/UpdaterTest.php | 80 | ||||
-rw-r--r-- | tests/config/ConfigPhpTest.php | 16 | ||||
-rw-r--r-- | tests/config/php/configOK.php | 14 | ||||
-rw-r--r-- | tests/utils/config/configPhp.php | 14 | ||||
-rw-r--r-- | tests/utils/config/configUpdater.php | 15 |
10 files changed, 118 insertions, 332 deletions
diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php index 6064357d..cf82b655 100644 --- a/tests/ApplicationUtilsTest.php +++ b/tests/ApplicationUtilsTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | * ApplicationUtils' tests | 3 | * ApplicationUtils' tests |
4 | */ | 4 | */ |
5 | 5 | ||
6 | require_once 'application/config/ConfigManager.php'; | ||
6 | require_once 'application/ApplicationUtils.php'; | 7 | require_once 'application/ApplicationUtils.php'; |
7 | 8 | ||
8 | /** | 9 | /** |
@@ -59,7 +60,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase | |||
59 | $testTimeout | 60 | $testTimeout |
60 | ) | 61 | ) |
61 | ); | 62 | ); |
62 | $this->assertRegexp( | 63 | $this->assertRegExp( |
63 | self::$versionPattern, | 64 | self::$versionPattern, |
64 | ApplicationUtils::getLatestGitVersionCode( | 65 | ApplicationUtils::getLatestGitVersionCode( |
65 | 'https://raw.githubusercontent.com/shaarli/Shaarli/' | 66 | 'https://raw.githubusercontent.com/shaarli/Shaarli/' |
@@ -275,21 +276,21 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase | |||
275 | */ | 276 | */ |
276 | public function testCheckCurrentResourcePermissions() | 277 | public function testCheckCurrentResourcePermissions() |
277 | { | 278 | { |
278 | $config = array( | 279 | $conf = ConfigManager::getInstance(); |
279 | 'CACHEDIR' => 'cache', | 280 | $conf->set('config.CACHEDIR', 'cache'); |
280 | 'CONFIG_FILE' => 'data/config.php', | 281 | $conf->set('config.CONFIG_FILE', 'data/config.php'); |
281 | 'DATADIR' => 'data', | 282 | $conf->set('config.DATADIR', 'data'); |
282 | 'DATASTORE' => 'data/datastore.php', | 283 | $conf->set('config.DATASTORE', 'data/datastore.php'); |
283 | 'IPBANS_FILENAME' => 'data/ipbans.php', | 284 | $conf->set('config.IPBANS_FILENAME', 'data/ipbans.php'); |
284 | 'LOG_FILE' => 'data/log.txt', | 285 | $conf->set('config.LOG_FILE', 'data/log.txt'); |
285 | 'PAGECACHE' => 'pagecache', | 286 | $conf->set('config.PAGECACHE', 'pagecache'); |
286 | 'RAINTPL_TMP' => 'tmp', | 287 | $conf->set('config.RAINTPL_TMP', 'tmp'); |
287 | 'RAINTPL_TPL' => 'tpl', | 288 | $conf->set('config.RAINTPL_TPL', 'tpl'); |
288 | 'UPDATECHECK_FILENAME' => 'data/lastupdatecheck.txt' | 289 | $conf->set('config.UPDATECHECK_FILENAME', 'data/lastupdatecheck.txt'); |
289 | ); | 290 | |
290 | $this->assertEquals( | 291 | $this->assertEquals( |
291 | array(), | 292 | array(), |
292 | ApplicationUtils::checkResourcePermissions($config) | 293 | ApplicationUtils::checkResourcePermissions() |
293 | ); | 294 | ); |
294 | } | 295 | } |
295 | 296 | ||
@@ -298,18 +299,17 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase | |||
298 | */ | 299 | */ |
299 | public function testCheckCurrentResourcePermissionsErrors() | 300 | public function testCheckCurrentResourcePermissionsErrors() |
300 | { | 301 | { |
301 | $config = array( | 302 | $conf = ConfigManager::getInstance(); |
302 | 'CACHEDIR' => 'null/cache', | 303 | $conf->set('config.CACHEDIR', 'null/cache'); |
303 | 'CONFIG_FILE' => 'null/data/config.php', | 304 | $conf->set('config.CONFIG_FILE', 'null/data/config.php'); |
304 | 'DATADIR' => 'null/data', | 305 | $conf->set('config.DATADIR', 'null/data'); |
305 | 'DATASTORE' => 'null/data/store.php', | 306 | $conf->set('config.DATASTORE', 'null/data/store.php'); |
306 | 'IPBANS_FILENAME' => 'null/data/ipbans.php', | 307 | $conf->set('config.IPBANS_FILENAME', 'null/data/ipbans.php'); |
307 | 'LOG_FILE' => 'null/data/log.txt', | 308 | $conf->set('config.LOG_FILE', 'null/data/log.txt'); |
308 | 'PAGECACHE' => 'null/pagecache', | 309 | $conf->set('config.PAGECACHE', 'null/pagecache'); |
309 | 'RAINTPL_TMP' => 'null/tmp', | 310 | $conf->set('config.RAINTPL_TMP', 'null/tmp'); |
310 | 'RAINTPL_TPL' => 'null/tpl', | 311 | $conf->set('config.RAINTPL_TPL', 'null/tpl'); |
311 | 'UPDATECHECK_FILENAME' => 'null/data/lastupdatecheck.txt' | 312 | $conf->set('config.UPDATECHECK_FILENAME', 'null/data/lastupdatecheck.txt'); |
312 | ); | ||
313 | $this->assertEquals( | 313 | $this->assertEquals( |
314 | array( | 314 | array( |
315 | '"null/tpl" directory is not readable', | 315 | '"null/tpl" directory is not readable', |
@@ -322,7 +322,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase | |||
322 | '"null/tmp" directory is not readable', | 322 | '"null/tmp" directory is not readable', |
323 | '"null/tmp" directory is not writable' | 323 | '"null/tmp" directory is not writable' |
324 | ), | 324 | ), |
325 | ApplicationUtils::checkResourcePermissions($config) | 325 | ApplicationUtils::checkResourcePermissions() |
326 | ); | 326 | ); |
327 | } | 327 | } |
328 | } | 328 | } |
diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php deleted file mode 100644 index 7200aae6..00000000 --- a/tests/ConfigTest.php +++ /dev/null | |||
@@ -1,244 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * Config' tests | ||
4 | */ | ||
5 | |||
6 | require_once 'application/Config.php'; | ||
7 | |||
8 | /** | ||
9 | * Unitary tests for Shaarli config related functions | ||
10 | */ | ||
11 | class ConfigTest extends PHPUnit_Framework_TestCase | ||
12 | { | ||
13 | // Configuration input set. | ||
14 | private static $configFields; | ||
15 | |||
16 | /** | ||
17 | * Executed before each test. | ||
18 | */ | ||
19 | public function setUp() | ||
20 | { | ||
21 | self::$configFields = array( | ||
22 | 'login' => 'login', | ||
23 | 'hash' => 'hash', | ||
24 | 'salt' => 'salt', | ||
25 | 'timezone' => 'Europe/Paris', | ||
26 | 'title' => 'title', | ||
27 | 'titleLink' => 'titleLink', | ||
28 | 'redirector' => '', | ||
29 | 'disablesessionprotection' => false, | ||
30 | 'privateLinkByDefault' => false, | ||
31 | 'config' => array( | ||
32 | 'CONFIG_FILE' => 'tests/config.php', | ||
33 | 'DATADIR' => 'tests', | ||
34 | 'config1' => 'config1data', | ||
35 | 'config2' => 'config2data', | ||
36 | ) | ||
37 | ); | ||
38 | } | ||
39 | |||
40 | /** | ||
41 | * Executed after each test. | ||
42 | * | ||
43 | * @return void | ||
44 | */ | ||
45 | public function tearDown() | ||
46 | { | ||
47 | if (is_file(self::$configFields['config']['CONFIG_FILE'])) { | ||
48 | unlink(self::$configFields['config']['CONFIG_FILE']); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | /** | ||
53 | * Test writeConfig function, valid use case, while being logged in. | ||
54 | */ | ||
55 | public function testWriteConfig() | ||
56 | { | ||
57 | writeConfig(self::$configFields, true); | ||
58 | |||
59 | include self::$configFields['config']['CONFIG_FILE']; | ||
60 | $this->assertEquals(self::$configFields['login'], $GLOBALS['login']); | ||
61 | $this->assertEquals(self::$configFields['hash'], $GLOBALS['hash']); | ||
62 | $this->assertEquals(self::$configFields['salt'], $GLOBALS['salt']); | ||
63 | $this->assertEquals(self::$configFields['timezone'], $GLOBALS['timezone']); | ||
64 | $this->assertEquals(self::$configFields['title'], $GLOBALS['title']); | ||
65 | $this->assertEquals(self::$configFields['titleLink'], $GLOBALS['titleLink']); | ||
66 | $this->assertEquals(self::$configFields['redirector'], $GLOBALS['redirector']); | ||
67 | $this->assertEquals(self::$configFields['disablesessionprotection'], $GLOBALS['disablesessionprotection']); | ||
68 | $this->assertEquals(self::$configFields['privateLinkByDefault'], $GLOBALS['privateLinkByDefault']); | ||
69 | $this->assertEquals(self::$configFields['config']['config1'], $GLOBALS['config']['config1']); | ||
70 | $this->assertEquals(self::$configFields['config']['config2'], $GLOBALS['config']['config2']); | ||
71 | } | ||
72 | |||
73 | /** | ||
74 | * Test writeConfig option while logged in: | ||
75 | * 1. init fields. | ||
76 | * 2. update fields, add new sub config, add new root config. | ||
77 | * 3. rewrite config. | ||
78 | * 4. check result. | ||
79 | */ | ||
80 | public function testWriteConfigFieldUpdate() | ||
81 | { | ||
82 | writeConfig(self::$configFields, true); | ||
83 | self::$configFields['title'] = 'ok'; | ||
84 | self::$configFields['config']['config1'] = 'ok'; | ||
85 | self::$configFields['config']['config_new'] = 'ok'; | ||
86 | self::$configFields['new'] = 'should not be saved'; | ||
87 | writeConfig(self::$configFields, true); | ||
88 | |||
89 | include self::$configFields['config']['CONFIG_FILE']; | ||
90 | $this->assertEquals('ok', $GLOBALS['title']); | ||
91 | $this->assertEquals('ok', $GLOBALS['config']['config1']); | ||
92 | $this->assertEquals('ok', $GLOBALS['config']['config_new']); | ||
93 | $this->assertFalse(isset($GLOBALS['new'])); | ||
94 | } | ||
95 | |||
96 | /** | ||
97 | * Test writeConfig function with an empty array. | ||
98 | * | ||
99 | * @expectedException MissingFieldConfigException | ||
100 | */ | ||
101 | public function testWriteConfigEmpty() | ||
102 | { | ||
103 | writeConfig(array(), true); | ||
104 | } | ||
105 | |||
106 | /** | ||
107 | * Test writeConfig function with a missing mandatory field. | ||
108 | * | ||
109 | * @expectedException MissingFieldConfigException | ||
110 | */ | ||
111 | public function testWriteConfigMissingField() | ||
112 | { | ||
113 | unset(self::$configFields['login']); | ||
114 | writeConfig(self::$configFields, true); | ||
115 | } | ||
116 | |||
117 | /** | ||
118 | * Test writeConfig function while being logged out, and there is no config file existing. | ||
119 | */ | ||
120 | public function testWriteConfigLoggedOutNoFile() | ||
121 | { | ||
122 | writeConfig(self::$configFields, false); | ||
123 | } | ||
124 | |||
125 | /** | ||
126 | * Test writeConfig function while being logged out, and a config file already exists. | ||
127 | * | ||
128 | * @expectedException UnauthorizedConfigException | ||
129 | */ | ||
130 | public function testWriteConfigLoggedOutWithFile() | ||
131 | { | ||
132 | file_put_contents(self::$configFields['config']['CONFIG_FILE'], ''); | ||
133 | writeConfig(self::$configFields, false); | ||
134 | } | ||
135 | |||
136 | /** | ||
137 | * Test save_plugin_config with valid data. | ||
138 | * | ||
139 | * @throws PluginConfigOrderException | ||
140 | */ | ||
141 | public function testSavePluginConfigValid() | ||
142 | { | ||
143 | $data = array( | ||
144 | 'order_plugin1' => 2, // no plugin related | ||
145 | 'plugin2' => 0, // new - at the end | ||
146 | 'plugin3' => 0, // 2nd | ||
147 | 'order_plugin3' => 8, | ||
148 | 'plugin4' => 0, // 1st | ||
149 | 'order_plugin4' => 5, | ||
150 | ); | ||
151 | |||
152 | $expected = array( | ||
153 | 'plugin3', | ||
154 | 'plugin4', | ||
155 | 'plugin2', | ||
156 | ); | ||
157 | |||
158 | $out = save_plugin_config($data); | ||
159 | $this->assertEquals($expected, $out); | ||
160 | } | ||
161 | |||
162 | /** | ||
163 | * Test save_plugin_config with invalid data. | ||
164 | * | ||
165 | * @expectedException PluginConfigOrderException | ||
166 | */ | ||
167 | public function testSavePluginConfigInvalid() | ||
168 | { | ||
169 | $data = array( | ||
170 | 'plugin2' => 0, | ||
171 | 'plugin3' => 0, | ||
172 | 'order_plugin3' => 0, | ||
173 | 'plugin4' => 0, | ||
174 | 'order_plugin4' => 0, | ||
175 | ); | ||
176 | |||
177 | save_plugin_config($data); | ||
178 | } | ||
179 | |||
180 | /** | ||
181 | * Test save_plugin_config without data. | ||
182 | */ | ||
183 | public function testSavePluginConfigEmpty() | ||
184 | { | ||
185 | $this->assertEquals(array(), save_plugin_config(array())); | ||
186 | } | ||
187 | |||
188 | /** | ||
189 | * Test validate_plugin_order with valid data. | ||
190 | */ | ||
191 | public function testValidatePluginOrderValid() | ||
192 | { | ||
193 | $data = array( | ||
194 | 'order_plugin1' => 2, | ||
195 | 'plugin2' => 0, | ||
196 | 'plugin3' => 0, | ||
197 | 'order_plugin3' => 1, | ||
198 | 'plugin4' => 0, | ||
199 | 'order_plugin4' => 5, | ||
200 | ); | ||
201 | |||
202 | $this->assertTrue(validate_plugin_order($data)); | ||
203 | } | ||
204 | |||
205 | /** | ||
206 | * Test validate_plugin_order with invalid data. | ||
207 | */ | ||
208 | public function testValidatePluginOrderInvalid() | ||
209 | { | ||
210 | $data = array( | ||
211 | 'order_plugin1' => 2, | ||
212 | 'order_plugin3' => 1, | ||
213 | 'order_plugin4' => 1, | ||
214 | ); | ||
215 | |||
216 | $this->assertFalse(validate_plugin_order($data)); | ||
217 | } | ||
218 | |||
219 | /** | ||
220 | * Test load_plugin_parameter_values. | ||
221 | */ | ||
222 | public function testLoadPluginParameterValues() | ||
223 | { | ||
224 | $plugins = array( | ||
225 | 'plugin_name' => array( | ||
226 | 'parameters' => array( | ||
227 | 'param1' => true, | ||
228 | 'param2' => false, | ||
229 | 'param3' => '', | ||
230 | ) | ||
231 | ) | ||
232 | ); | ||
233 | |||
234 | $parameters = array( | ||
235 | 'param1' => 'value1', | ||
236 | 'param2' => 'value2', | ||
237 | ); | ||
238 | |||
239 | $result = load_plugin_parameter_values($plugins, $parameters); | ||
240 | $this->assertEquals('value1', $result['plugin_name']['parameters']['param1']); | ||
241 | $this->assertEquals('value2', $result['plugin_name']['parameters']['param2']); | ||
242 | $this->assertEquals('', $result['plugin_name']['parameters']['param3']); | ||
243 | } | ||
244 | } | ||
diff --git a/tests/FeedBuilderTest.php b/tests/FeedBuilderTest.php index 069b1581..a4d6960c 100644 --- a/tests/FeedBuilderTest.php +++ b/tests/FeedBuilderTest.php | |||
@@ -76,7 +76,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase | |||
76 | // Test headers (RSS) | 76 | // Test headers (RSS) |
77 | $this->assertEquals(self::$RSS_LANGUAGE, $data['language']); | 77 | $this->assertEquals(self::$RSS_LANGUAGE, $data['language']); |
78 | $this->assertEmpty($data['pubsubhub_url']); | 78 | $this->assertEmpty($data['pubsubhub_url']); |
79 | $this->assertEquals('Tue, 10 Mar 2015 11:46:51 +0100', $data['last_update']); | 79 | $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $data['last_update']); |
80 | $this->assertEquals(true, $data['show_dates']); | 80 | $this->assertEquals(true, $data['show_dates']); |
81 | $this->assertEquals('http://host.tld/index.php?do=feed', $data['self_link']); | 81 | $this->assertEquals('http://host.tld/index.php?do=feed', $data['self_link']); |
82 | $this->assertEquals('http://host.tld/', $data['index_url']); | 82 | $this->assertEquals('http://host.tld/', $data['index_url']); |
@@ -88,7 +88,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase | |||
88 | $this->assertEquals('20150310_114651', $link['linkdate']); | 88 | $this->assertEquals('20150310_114651', $link['linkdate']); |
89 | $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); | 89 | $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); |
90 | $this->assertEquals('http://host.tld/?WDWyig', $link['url']); | 90 | $this->assertEquals('http://host.tld/?WDWyig', $link['url']); |
91 | $this->assertEquals('Tue, 10 Mar 2015 11:46:51 +0100', $link['iso_date']); | 91 | $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['iso_date']); |
92 | $this->assertContains('Stallman has a beard', $link['description']); | 92 | $this->assertContains('Stallman has a beard', $link['description']); |
93 | $this->assertContains('Permalink', $link['description']); | 93 | $this->assertContains('Permalink', $link['description']); |
94 | $this->assertContains('http://host.tld/?WDWyig', $link['description']); | 94 | $this->assertContains('http://host.tld/?WDWyig', $link['description']); |
@@ -113,7 +113,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase | |||
113 | $data = $feedBuilder->buildData(); | 113 | $data = $feedBuilder->buildData(); |
114 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); | 114 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); |
115 | $link = array_shift($data['links']); | 115 | $link = array_shift($data['links']); |
116 | $this->assertEquals('2015-03-10T11:46:51+01:00', $link['iso_date']); | 116 | $this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:+\d{2}/', $link['iso_date']); |
117 | } | 117 | } |
118 | 118 | ||
119 | /** | 119 | /** |
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index b055fe91..956be3b4 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php | |||
@@ -101,7 +101,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
101 | * Attempt to instantiate a LinkDB whereas the datastore is not writable | 101 | * Attempt to instantiate a LinkDB whereas the datastore is not writable |
102 | * | 102 | * |
103 | * @expectedException IOException | 103 | * @expectedException IOException |
104 | * @expectedExceptionMessageRegExp /Error accessing null/ | 104 | * @expectedExceptionMessageRegExp /Error accessing\nnull/ |
105 | */ | 105 | */ |
106 | public function testConstructDatastoreNotWriteable() | 106 | public function testConstructDatastoreNotWriteable() |
107 | { | 107 | { |
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 | } |
diff --git a/tests/config/ConfigPhpTest.php b/tests/config/ConfigPhpTest.php index 0f849bd5..58cd8d2a 100644 --- a/tests/config/ConfigPhpTest.php +++ b/tests/config/ConfigPhpTest.php | |||
@@ -22,7 +22,7 @@ class ConfigPhpTest extends PHPUnit_Framework_TestCase | |||
22 | */ | 22 | */ |
23 | public function testRead() | 23 | public function testRead() |
24 | { | 24 | { |
25 | $conf = $this->configIO->read('tests/config/php/configOK'); | 25 | $conf = $this->configIO->read('tests/utils/config/configPhp.php'); |
26 | $this->assertEquals('root', $conf['login']); | 26 | $this->assertEquals('root', $conf['login']); |
27 | $this->assertEquals('lala', $conf['redirector']); | 27 | $this->assertEquals('lala', $conf['redirector']); |
28 | $this->assertEquals('data/datastore.php', $conf['config']['DATASTORE']); | 28 | $this->assertEquals('data/datastore.php', $conf['config']['DATASTORE']); |
@@ -42,7 +42,7 @@ class ConfigPhpTest extends PHPUnit_Framework_TestCase | |||
42 | */ | 42 | */ |
43 | public function testWriteNew() | 43 | public function testWriteNew() |
44 | { | 44 | { |
45 | $dataFile = 'tests/config/php/configWrite'; | 45 | $dataFile = 'tests/utils/config/configWrite.php'; |
46 | $data = array( | 46 | $data = array( |
47 | 'login' => 'root', | 47 | 'login' => 'root', |
48 | 'redirector' => 'lala', | 48 | 'redirector' => 'lala', |
@@ -60,8 +60,8 @@ $GLOBALS[\'redirector\'] = \'lala\'; | |||
60 | $GLOBALS[\'config\'][\'DATASTORE\'] = \'data/datastore.php\'; | 60 | $GLOBALS[\'config\'][\'DATASTORE\'] = \'data/datastore.php\'; |
61 | $GLOBALS[\'plugins\'][\'WALLABAG_VERSION\'] = \'1\'; | 61 | $GLOBALS[\'plugins\'][\'WALLABAG_VERSION\'] = \'1\'; |
62 | '; | 62 | '; |
63 | $this->assertEquals($expected, file_get_contents($dataFile .'.php')); | 63 | $this->assertEquals($expected, file_get_contents($dataFile)); |
64 | unlink($dataFile .'.php'); | 64 | unlink($dataFile); |
65 | } | 65 | } |
66 | 66 | ||
67 | /** | 67 | /** |
@@ -69,14 +69,14 @@ $GLOBALS[\'plugins\'][\'WALLABAG_VERSION\'] = \'1\'; | |||
69 | */ | 69 | */ |
70 | public function testOverwrite() | 70 | public function testOverwrite() |
71 | { | 71 | { |
72 | $source = 'tests/config/php/configOK.php'; | 72 | $source = 'tests/utils/config/configPhp.php'; |
73 | $dest = 'tests/config/php/configOverwrite'; | 73 | $dest = 'tests/utils/config/configOverwrite.php'; |
74 | copy($source, $dest . '.php'); | 74 | copy($source, $dest); |
75 | $conf = $this->configIO->read($dest); | 75 | $conf = $this->configIO->read($dest); |
76 | $conf['redirector'] = 'blabla'; | 76 | $conf['redirector'] = 'blabla'; |
77 | $this->configIO->write($dest, $conf); | 77 | $this->configIO->write($dest, $conf); |
78 | $conf = $this->configIO->read($dest); | 78 | $conf = $this->configIO->read($dest); |
79 | $this->assertEquals('blabla', $conf['redirector']); | 79 | $this->assertEquals('blabla', $conf['redirector']); |
80 | unlink($dest .'.php'); | 80 | unlink($dest); |
81 | } | 81 | } |
82 | } | 82 | } |
diff --git a/tests/config/php/configOK.php b/tests/config/php/configOK.php deleted file mode 100644 index b91ad293..00000000 --- a/tests/config/php/configOK.php +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | <?php | ||
2 | $GLOBALS['login'] = 'root'; | ||
3 | $GLOBALS['hash'] = 'hash'; | ||
4 | $GLOBALS['salt'] = 'salt'; | ||
5 | $GLOBALS['timezone'] = 'Europe/Paris'; | ||
6 | $GLOBALS['title'] = 'BIGBANG'; | ||
7 | $GLOBALS['titleLink'] = '?'; | ||
8 | $GLOBALS['redirector'] = 'lala'; | ||
9 | $GLOBALS['disablesessionprotection'] = false; | ||
10 | $GLOBALS['privateLinkByDefault'] = true; | ||
11 | $GLOBALS['config']['DATADIR'] = 'data'; | ||
12 | $GLOBALS['config']['DATASTORE'] = 'data/datastore.php'; | ||
13 | $GLOBALS['plugins']['WALLABAG_URL'] = 'ghf'; | ||
14 | $GLOBALS['plugins']['WALLABAG_VERSION'] = '1'; \ No newline at end of file | ||
diff --git a/tests/utils/config/configPhp.php b/tests/utils/config/configPhp.php new file mode 100644 index 00000000..0e034175 --- /dev/null +++ b/tests/utils/config/configPhp.php | |||
@@ -0,0 +1,14 @@ | |||
1 | <?php | ||
2 | $GLOBALS['login'] = 'root'; | ||
3 | $GLOBALS['hash'] = 'hash'; | ||
4 | $GLOBALS['salt'] = 'salt'; | ||
5 | $GLOBALS['timezone'] = 'Europe/Paris'; | ||
6 | $GLOBALS['title'] = 'title'; | ||
7 | $GLOBALS['titleLink'] = 'titleLink'; | ||
8 | $GLOBALS['redirector'] = 'lala'; | ||
9 | $GLOBALS['disablesessionprotection'] = false; | ||
10 | $GLOBALS['privateLinkByDefault'] = false; | ||
11 | $GLOBALS['config']['DATADIR'] = 'tests/Updater'; | ||
12 | $GLOBALS['config']['PAGECACHE'] = 'sandbox/pagecache'; | ||
13 | $GLOBALS['config']['DATASTORE'] = 'data/datastore.php'; | ||
14 | $GLOBALS['plugins']['WALLABAG_VERSION'] = '1'; | ||
diff --git a/tests/utils/config/configUpdater.php b/tests/utils/config/configUpdater.php new file mode 100644 index 00000000..ee4a56b5 --- /dev/null +++ b/tests/utils/config/configUpdater.php | |||
@@ -0,0 +1,15 @@ | |||
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'; | ||