diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/LanguagesTest.php | 41 | ||||
-rw-r--r-- | tests/LinkDBTest.php | 4 | ||||
-rw-r--r-- | tests/NetscapeBookmarkUtils/BookmarkExportTest.php (renamed from tests/NetscapeBookmarkUtilsTest.php) | 4 | ||||
-rw-r--r-- | tests/NetscapeBookmarkUtils/BookmarkImportTest.php | 546 | ||||
-rw-r--r-- | tests/NetscapeBookmarkUtils/input/empty.htm | 0 | ||||
-rw-r--r-- | tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm | 9 | ||||
-rw-r--r-- | tests/NetscapeBookmarkUtils/input/netscape_basic.htm | 11 | ||||
-rw-r--r-- | tests/NetscapeBookmarkUtils/input/netscape_nested.htm | 31 | ||||
-rw-r--r-- | tests/NetscapeBookmarkUtils/input/no_doctype.htm | 7 | ||||
-rw-r--r-- | tests/NetscapeBookmarkUtils/input/same_date.htm | 11 | ||||
-rw-r--r-- | tests/PluginManagerTest.php | 2 | ||||
-rw-r--r-- | tests/Updater/UpdaterTest.php | 24 | ||||
-rw-r--r-- | tests/utils/ReferenceLinkDB.php | 2 | ||||
-rw-r--r-- | tests/utils/config/configInvalid.json.php | 2 |
14 files changed, 689 insertions, 5 deletions
diff --git a/tests/LanguagesTest.php b/tests/LanguagesTest.php new file mode 100644 index 00000000..79c136c8 --- /dev/null +++ b/tests/LanguagesTest.php | |||
@@ -0,0 +1,41 @@ | |||
1 | <?php | ||
2 | |||
3 | require_once 'application/Languages.php'; | ||
4 | |||
5 | /** | ||
6 | * Class LanguagesTest. | ||
7 | */ | ||
8 | class LanguagesTest extends PHPUnit_Framework_TestCase | ||
9 | { | ||
10 | /** | ||
11 | * Test t() with a simple non identified value. | ||
12 | */ | ||
13 | public function testTranslateSingleNotID() | ||
14 | { | ||
15 | $text = 'abcdé 564 fgK'; | ||
16 | $this->assertEquals($text, t($text)); | ||
17 | } | ||
18 | |||
19 | /** | ||
20 | * Test t() with a non identified plural form. | ||
21 | */ | ||
22 | public function testTranslatePluralNotID() | ||
23 | { | ||
24 | $text = '%s sandwich'; | ||
25 | $nText = '%s sandwiches'; | ||
26 | $this->assertEquals('0 sandwich', t($text, $nText)); | ||
27 | $this->assertEquals('1 sandwich', t($text, $nText, 1)); | ||
28 | $this->assertEquals('2 sandwiches', t($text, $nText, 2)); | ||
29 | } | ||
30 | |||
31 | /** | ||
32 | * Test t() with a non identified invalid plural form. | ||
33 | */ | ||
34 | public function testTranslatePluralNotIDInvalid() | ||
35 | { | ||
36 | $text = 'sandwich'; | ||
37 | $nText = 'sandwiches'; | ||
38 | $this->assertEquals('sandwich', t($text, $nText, 1)); | ||
39 | $this->assertEquals('sandwiches', t($text, $nText, 2)); | ||
40 | } | ||
41 | } | ||
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 46956f20..31306069 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php | |||
@@ -317,6 +317,10 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
317 | '-exclude' => 1, | 317 | '-exclude' => 1, |
318 | '.hidden' => 1, | 318 | '.hidden' => 1, |
319 | 'hashtag' => 2, | 319 | 'hashtag' => 2, |
320 | 'tag1' => 1, | ||
321 | 'tag2' => 1, | ||
322 | 'tag3' => 1, | ||
323 | 'tag4' => 1, | ||
320 | ), | 324 | ), |
321 | self::$privateLinkDB->allTags() | 325 | self::$privateLinkDB->allTags() |
322 | ); | 326 | ); |
diff --git a/tests/NetscapeBookmarkUtilsTest.php b/tests/NetscapeBookmarkUtils/BookmarkExportTest.php index 41e6d84c..cc54ab9f 100644 --- a/tests/NetscapeBookmarkUtilsTest.php +++ b/tests/NetscapeBookmarkUtils/BookmarkExportTest.php | |||
@@ -3,9 +3,9 @@ | |||
3 | require_once 'application/NetscapeBookmarkUtils.php'; | 3 | require_once 'application/NetscapeBookmarkUtils.php'; |
4 | 4 | ||
5 | /** | 5 | /** |
6 | * Netscape bookmark import and export | 6 | * Netscape bookmark export |
7 | */ | 7 | */ |
8 | class NetscapeBookmarkUtilsTest extends PHPUnit_Framework_TestCase | 8 | class BookmarkExportTest extends PHPUnit_Framework_TestCase |
9 | { | 9 | { |
10 | /** | 10 | /** |
11 | * @var string datastore to test write operations | 11 | * @var string datastore to test write operations |
diff --git a/tests/NetscapeBookmarkUtils/BookmarkImportTest.php b/tests/NetscapeBookmarkUtils/BookmarkImportTest.php new file mode 100644 index 00000000..f0ad500f --- /dev/null +++ b/tests/NetscapeBookmarkUtils/BookmarkImportTest.php | |||
@@ -0,0 +1,546 @@ | |||
1 | <?php | ||
2 | |||
3 | require_once 'application/NetscapeBookmarkUtils.php'; | ||
4 | |||
5 | |||
6 | /** | ||
7 | * Utility function to load a file's metadata in a $_FILES-like array | ||
8 | * | ||
9 | * @param string $filename Basename of the file | ||
10 | * | ||
11 | * @return array A $_FILES-like array | ||
12 | */ | ||
13 | function file2array($filename) | ||
14 | { | ||
15 | return array( | ||
16 | 'filetoupload' => array( | ||
17 | 'name' => $filename, | ||
18 | 'tmp_name' => __DIR__ . '/input/' . $filename, | ||
19 | 'size' => filesize(__DIR__ . '/input/' . $filename) | ||
20 | ) | ||
21 | ); | ||
22 | } | ||
23 | |||
24 | |||
25 | /** | ||
26 | * Netscape bookmark import | ||
27 | */ | ||
28 | class BookmarkImportTest extends PHPUnit_Framework_TestCase | ||
29 | { | ||
30 | /** | ||
31 | * @var string datastore to test write operations | ||
32 | */ | ||
33 | protected static $testDatastore = 'sandbox/datastore.php'; | ||
34 | |||
35 | /** | ||
36 | * @var LinkDB private LinkDB instance | ||
37 | */ | ||
38 | protected $linkDb = null; | ||
39 | |||
40 | /** | ||
41 | * @var string Dummy page cache | ||
42 | */ | ||
43 | protected $pagecache = 'tests'; | ||
44 | |||
45 | /** | ||
46 | * Resets test data before each test | ||
47 | */ | ||
48 | protected function setUp() | ||
49 | { | ||
50 | if (file_exists(self::$testDatastore)) { | ||
51 | unlink(self::$testDatastore); | ||
52 | } | ||
53 | // start with an empty datastore | ||
54 | file_put_contents(self::$testDatastore, '<?php /* S7QysKquBQA= */ ?>'); | ||
55 | $this->linkDb = new LinkDB(self::$testDatastore, true, false); | ||
56 | } | ||
57 | |||
58 | /** | ||
59 | * Attempt to import bookmarks from an empty file | ||
60 | */ | ||
61 | public function testImportEmptyData() | ||
62 | { | ||
63 | $files = file2array('empty.htm'); | ||
64 | $this->assertEquals( | ||
65 | 'File empty.htm (0 bytes) has an unknown file format.' | ||
66 | .' Nothing was imported.', | ||
67 | NetscapeBookmarkUtils::import(NULL, $files, NULL, NULL) | ||
68 | ); | ||
69 | $this->assertEquals(0, count($this->linkDb)); | ||
70 | } | ||
71 | |||
72 | /** | ||
73 | * Attempt to import bookmarks from a file with no Doctype | ||
74 | */ | ||
75 | public function testImportNoDoctype() | ||
76 | { | ||
77 | $files = file2array('no_doctype.htm'); | ||
78 | $this->assertEquals( | ||
79 | 'File no_doctype.htm (350 bytes) has an unknown file format. Nothing was imported.', | ||
80 | NetscapeBookmarkUtils::import(NULL, $files, NULL, NULL) | ||
81 | ); | ||
82 | $this->assertEquals(0, count($this->linkDb)); | ||
83 | } | ||
84 | |||
85 | /** | ||
86 | * Ensure IE dumps are supported | ||
87 | */ | ||
88 | public function testImportInternetExplorerEncoding() | ||
89 | { | ||
90 | $files = file2array('internet_explorer_encoding.htm'); | ||
91 | $this->assertEquals( | ||
92 | 'File internet_explorer_encoding.htm (356 bytes) was successfully processed:' | ||
93 | .' 1 links imported, 0 links overwritten, 0 links skipped.', | ||
94 | NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache) | ||
95 | ); | ||
96 | $this->assertEquals(1, count($this->linkDb)); | ||
97 | $this->assertEquals(0, count_private($this->linkDb)); | ||
98 | |||
99 | $this->assertEquals( | ||
100 | array( | ||
101 | 'linkdate' => '20160618_173944', | ||
102 | 'title' => 'Hg Init a Mercurial tutorial by Joel Spolsky', | ||
103 | 'url' => 'http://hginit.com/', | ||
104 | 'description' => '', | ||
105 | 'private' => 0, | ||
106 | 'tags' => '' | ||
107 | ), | ||
108 | $this->linkDb->getLinkFromUrl('http://hginit.com/') | ||
109 | ); | ||
110 | } | ||
111 | |||
112 | |||
113 | /** | ||
114 | * Import bookmarks nested in a folder hierarchy | ||
115 | */ | ||
116 | public function testImportNested() | ||
117 | { | ||
118 | $files = file2array('netscape_nested.htm'); | ||
119 | $this->assertEquals( | ||
120 | 'File netscape_nested.htm (1337 bytes) was successfully processed:' | ||
121 | .' 8 links imported, 0 links overwritten, 0 links skipped.', | ||
122 | NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache) | ||
123 | ); | ||
124 | $this->assertEquals(8, count($this->linkDb)); | ||
125 | $this->assertEquals(2, count_private($this->linkDb)); | ||
126 | |||
127 | $this->assertEquals( | ||
128 | array( | ||
129 | 'linkdate' => '20160225_205541', | ||
130 | 'title' => 'Nested 1', | ||
131 | 'url' => 'http://nest.ed/1', | ||
132 | 'description' => '', | ||
133 | 'private' => 0, | ||
134 | 'tags' => 'tag1 tag2' | ||
135 | ), | ||
136 | $this->linkDb->getLinkFromUrl('http://nest.ed/1') | ||
137 | ); | ||
138 | $this->assertEquals( | ||
139 | array( | ||
140 | 'linkdate' => '20160225_205542', | ||
141 | 'title' => 'Nested 1-1', | ||
142 | 'url' => 'http://nest.ed/1-1', | ||
143 | 'description' => '', | ||
144 | 'private' => 0, | ||
145 | 'tags' => 'folder1 tag1 tag2' | ||
146 | ), | ||
147 | $this->linkDb->getLinkFromUrl('http://nest.ed/1-1') | ||
148 | ); | ||
149 | $this->assertEquals( | ||
150 | array( | ||
151 | 'linkdate' => '20160225_205547', | ||
152 | 'title' => 'Nested 1-2', | ||
153 | 'url' => 'http://nest.ed/1-2', | ||
154 | 'description' => '', | ||
155 | 'private' => 0, | ||
156 | 'tags' => 'folder1 tag3 tag4' | ||
157 | ), | ||
158 | $this->linkDb->getLinkFromUrl('http://nest.ed/1-2') | ||
159 | ); | ||
160 | $this->assertEquals( | ||
161 | array( | ||
162 | 'linkdate' => '20160202_172222', | ||
163 | 'title' => 'Nested 2-1', | ||
164 | 'url' => 'http://nest.ed/2-1', | ||
165 | 'description' => 'First link of the second section', | ||
166 | 'private' => 1, | ||
167 | 'tags' => 'folder2' | ||
168 | ), | ||
169 | $this->linkDb->getLinkFromUrl('http://nest.ed/2-1') | ||
170 | ); | ||
171 | $this->assertEquals( | ||
172 | array( | ||
173 | 'linkdate' => '20160119_200227', | ||
174 | 'title' => 'Nested 2-2', | ||
175 | 'url' => 'http://nest.ed/2-2', | ||
176 | 'description' => 'Second link of the second section', | ||
177 | 'private' => 1, | ||
178 | 'tags' => 'folder2' | ||
179 | ), | ||
180 | $this->linkDb->getLinkFromUrl('http://nest.ed/2-2') | ||
181 | ); | ||
182 | $this->assertEquals( | ||
183 | array( | ||
184 | 'linkdate' => '20160202_172223', | ||
185 | 'title' => 'Nested 3-1', | ||
186 | 'url' => 'http://nest.ed/3-1', | ||
187 | 'description' => '', | ||
188 | 'private' => 0, | ||
189 | 'tags' => 'folder3 folder3-1 tag3' | ||
190 | ), | ||
191 | $this->linkDb->getLinkFromUrl('http://nest.ed/3-1') | ||
192 | ); | ||
193 | $this->assertEquals( | ||
194 | array( | ||
195 | 'linkdate' => '20160119_200228', | ||
196 | 'title' => 'Nested 3-2', | ||
197 | 'url' => 'http://nest.ed/3-2', | ||
198 | 'description' => '', | ||
199 | 'private' => 0, | ||
200 | 'tags' => 'folder3 folder3-1' | ||
201 | ), | ||
202 | $this->linkDb->getLinkFromUrl('http://nest.ed/3-2') | ||
203 | ); | ||
204 | $this->assertEquals( | ||
205 | array( | ||
206 | 'linkdate' => '20160229_081541', | ||
207 | 'title' => 'Nested 2', | ||
208 | 'url' => 'http://nest.ed/2', | ||
209 | 'description' => '', | ||
210 | 'private' => 0, | ||
211 | 'tags' => 'tag4' | ||
212 | ), | ||
213 | $this->linkDb->getLinkFromUrl('http://nest.ed/2') | ||
214 | ); | ||
215 | } | ||
216 | |||
217 | /** | ||
218 | * Import bookmarks with the default privacy setting (reuse from file) | ||
219 | * | ||
220 | * The $_POST array is not set. | ||
221 | */ | ||
222 | public function testImportDefaultPrivacyNoPost() | ||
223 | { | ||
224 | $files = file2array('netscape_basic.htm'); | ||
225 | $this->assertEquals( | ||
226 | 'File netscape_basic.htm (482 bytes) was successfully processed:' | ||
227 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | ||
228 | NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache) | ||
229 | ); | ||
230 | $this->assertEquals(2, count($this->linkDb)); | ||
231 | $this->assertEquals(1, count_private($this->linkDb)); | ||
232 | |||
233 | $this->assertEquals( | ||
234 | array( | ||
235 | 'linkdate' => '20001010_105536', | ||
236 | 'title' => 'Secret stuff', | ||
237 | 'url' => 'https://private.tld', | ||
238 | 'description' => "Super-secret stuff you're not supposed to know about", | ||
239 | 'private' => 1, | ||
240 | 'tags' => 'private secret' | ||
241 | ), | ||
242 | $this->linkDb->getLinkFromUrl('https://private.tld') | ||
243 | ); | ||
244 | $this->assertEquals( | ||
245 | array( | ||
246 | 'linkdate' => '20160225_205548', | ||
247 | 'title' => 'Public stuff', | ||
248 | 'url' => 'http://public.tld', | ||
249 | 'description' => '', | ||
250 | 'private' => 0, | ||
251 | 'tags' => 'public hello world' | ||
252 | ), | ||
253 | $this->linkDb->getLinkFromUrl('http://public.tld') | ||
254 | ); | ||
255 | } | ||
256 | |||
257 | /** | ||
258 | * Import bookmarks with the default privacy setting (reuse from file) | ||
259 | */ | ||
260 | public function testImportKeepPrivacy() | ||
261 | { | ||
262 | $post = array('privacy' => 'default'); | ||
263 | $files = file2array('netscape_basic.htm'); | ||
264 | $this->assertEquals( | ||
265 | 'File netscape_basic.htm (482 bytes) was successfully processed:' | ||
266 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | ||
267 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) | ||
268 | ); | ||
269 | $this->assertEquals(2, count($this->linkDb)); | ||
270 | $this->assertEquals(1, count_private($this->linkDb)); | ||
271 | |||
272 | $this->assertEquals( | ||
273 | array( | ||
274 | 'linkdate' => '20001010_105536', | ||
275 | 'title' => 'Secret stuff', | ||
276 | 'url' => 'https://private.tld', | ||
277 | 'description' => "Super-secret stuff you're not supposed to know about", | ||
278 | 'private' => 1, | ||
279 | 'tags' => 'private secret' | ||
280 | ), | ||
281 | $this->linkDb->getLinkFromUrl('https://private.tld') | ||
282 | ); | ||
283 | $this->assertEquals( | ||
284 | array( | ||
285 | 'linkdate' => '20160225_205548', | ||
286 | 'title' => 'Public stuff', | ||
287 | 'url' => 'http://public.tld', | ||
288 | 'description' => '', | ||
289 | 'private' => 0, | ||
290 | 'tags' => 'public hello world' | ||
291 | ), | ||
292 | $this->linkDb->getLinkFromUrl('http://public.tld') | ||
293 | ); | ||
294 | } | ||
295 | |||
296 | /** | ||
297 | * Import links as public | ||
298 | */ | ||
299 | public function testImportAsPublic() | ||
300 | { | ||
301 | $post = array('privacy' => 'public'); | ||
302 | $files = file2array('netscape_basic.htm'); | ||
303 | $this->assertEquals( | ||
304 | 'File netscape_basic.htm (482 bytes) was successfully processed:' | ||
305 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | ||
306 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) | ||
307 | ); | ||
308 | $this->assertEquals(2, count($this->linkDb)); | ||
309 | $this->assertEquals(0, count_private($this->linkDb)); | ||
310 | $this->assertEquals( | ||
311 | 0, | ||
312 | $this->linkDb['20001010_105536']['private'] | ||
313 | ); | ||
314 | $this->assertEquals( | ||
315 | 0, | ||
316 | $this->linkDb['20160225_205548']['private'] | ||
317 | ); | ||
318 | } | ||
319 | |||
320 | /** | ||
321 | * Import links as private | ||
322 | */ | ||
323 | public function testImportAsPrivate() | ||
324 | { | ||
325 | $post = array('privacy' => 'private'); | ||
326 | $files = file2array('netscape_basic.htm'); | ||
327 | $this->assertEquals( | ||
328 | 'File netscape_basic.htm (482 bytes) was successfully processed:' | ||
329 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | ||
330 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) | ||
331 | ); | ||
332 | $this->assertEquals(2, count($this->linkDb)); | ||
333 | $this->assertEquals(2, count_private($this->linkDb)); | ||
334 | $this->assertEquals( | ||
335 | 1, | ||
336 | $this->linkDb['20001010_105536']['private'] | ||
337 | ); | ||
338 | $this->assertEquals( | ||
339 | 1, | ||
340 | $this->linkDb['20160225_205548']['private'] | ||
341 | ); | ||
342 | } | ||
343 | |||
344 | /** | ||
345 | * Overwrite private links so they become public | ||
346 | */ | ||
347 | public function testOverwriteAsPublic() | ||
348 | { | ||
349 | $files = file2array('netscape_basic.htm'); | ||
350 | |||
351 | // import links as private | ||
352 | $post = array('privacy' => 'private'); | ||
353 | $this->assertEquals( | ||
354 | 'File netscape_basic.htm (482 bytes) was successfully processed:' | ||
355 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | ||
356 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) | ||
357 | ); | ||
358 | $this->assertEquals(2, count($this->linkDb)); | ||
359 | $this->assertEquals(2, count_private($this->linkDb)); | ||
360 | $this->assertEquals( | ||
361 | 1, | ||
362 | $this->linkDb['20001010_105536']['private'] | ||
363 | ); | ||
364 | $this->assertEquals( | ||
365 | 1, | ||
366 | $this->linkDb['20160225_205548']['private'] | ||
367 | ); | ||
368 | |||
369 | // re-import as public, enable overwriting | ||
370 | $post = array( | ||
371 | 'privacy' => 'public', | ||
372 | 'overwrite' => 'true' | ||
373 | ); | ||
374 | $this->assertEquals( | ||
375 | 'File netscape_basic.htm (482 bytes) was successfully processed:' | ||
376 | .' 2 links imported, 2 links overwritten, 0 links skipped.', | ||
377 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) | ||
378 | ); | ||
379 | $this->assertEquals(2, count($this->linkDb)); | ||
380 | $this->assertEquals(0, count_private($this->linkDb)); | ||
381 | $this->assertEquals( | ||
382 | 0, | ||
383 | $this->linkDb['20001010_105536']['private'] | ||
384 | ); | ||
385 | $this->assertEquals( | ||
386 | 0, | ||
387 | $this->linkDb['20160225_205548']['private'] | ||
388 | ); | ||
389 | } | ||
390 | |||
391 | /** | ||
392 | * Overwrite public links so they become private | ||
393 | */ | ||
394 | public function testOverwriteAsPrivate() | ||
395 | { | ||
396 | $files = file2array('netscape_basic.htm'); | ||
397 | |||
398 | // import links as public | ||
399 | $post = array('privacy' => 'public'); | ||
400 | $this->assertEquals( | ||
401 | 'File netscape_basic.htm (482 bytes) was successfully processed:' | ||
402 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | ||
403 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) | ||
404 | ); | ||
405 | $this->assertEquals(2, count($this->linkDb)); | ||
406 | $this->assertEquals(0, count_private($this->linkDb)); | ||
407 | $this->assertEquals( | ||
408 | 0, | ||
409 | $this->linkDb['20001010_105536']['private'] | ||
410 | ); | ||
411 | $this->assertEquals( | ||
412 | 0, | ||
413 | $this->linkDb['20160225_205548']['private'] | ||
414 | ); | ||
415 | |||
416 | // re-import as private, enable overwriting | ||
417 | $post = array( | ||
418 | 'privacy' => 'private', | ||
419 | 'overwrite' => 'true' | ||
420 | ); | ||
421 | $this->assertEquals( | ||
422 | 'File netscape_basic.htm (482 bytes) was successfully processed:' | ||
423 | .' 2 links imported, 2 links overwritten, 0 links skipped.', | ||
424 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) | ||
425 | ); | ||
426 | $this->assertEquals(2, count($this->linkDb)); | ||
427 | $this->assertEquals(2, count_private($this->linkDb)); | ||
428 | $this->assertEquals( | ||
429 | 1, | ||
430 | $this->linkDb['20001010_105536']['private'] | ||
431 | ); | ||
432 | $this->assertEquals( | ||
433 | 1, | ||
434 | $this->linkDb['20160225_205548']['private'] | ||
435 | ); | ||
436 | } | ||
437 | |||
438 | /** | ||
439 | * Attept to import the same links twice without enabling overwriting | ||
440 | */ | ||
441 | public function testSkipOverwrite() | ||
442 | { | ||
443 | $post = array('privacy' => 'public'); | ||
444 | $files = file2array('netscape_basic.htm'); | ||
445 | $this->assertEquals( | ||
446 | 'File netscape_basic.htm (482 bytes) was successfully processed:' | ||
447 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | ||
448 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) | ||
449 | ); | ||
450 | $this->assertEquals(2, count($this->linkDb)); | ||
451 | $this->assertEquals(0, count_private($this->linkDb)); | ||
452 | |||
453 | // re-import as private, DO NOT enable overwriting | ||
454 | $post = array('privacy' => 'private'); | ||
455 | $this->assertEquals( | ||
456 | 'File netscape_basic.htm (482 bytes) was successfully processed:' | ||
457 | .' 0 links imported, 0 links overwritten, 2 links skipped.', | ||
458 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) | ||
459 | ); | ||
460 | $this->assertEquals(2, count($this->linkDb)); | ||
461 | $this->assertEquals(0, count_private($this->linkDb)); | ||
462 | } | ||
463 | |||
464 | /** | ||
465 | * Add user-specified tags to all imported bookmarks | ||
466 | */ | ||
467 | public function testSetDefaultTags() | ||
468 | { | ||
469 | $post = array( | ||
470 | 'privacy' => 'public', | ||
471 | 'default_tags' => 'tag1,tag2 tag3' | ||
472 | ); | ||
473 | $files = file2array('netscape_basic.htm'); | ||
474 | $this->assertEquals( | ||
475 | 'File netscape_basic.htm (482 bytes) was successfully processed:' | ||
476 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | ||
477 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) | ||
478 | ); | ||
479 | $this->assertEquals(2, count($this->linkDb)); | ||
480 | $this->assertEquals(0, count_private($this->linkDb)); | ||
481 | $this->assertEquals( | ||
482 | 'tag1 tag2 tag3 private secret', | ||
483 | $this->linkDb['20001010_105536']['tags'] | ||
484 | ); | ||
485 | $this->assertEquals( | ||
486 | 'tag1 tag2 tag3 public hello world', | ||
487 | $this->linkDb['20160225_205548']['tags'] | ||
488 | ); | ||
489 | } | ||
490 | |||
491 | /** | ||
492 | * The user-specified tags contain characters to be escaped | ||
493 | */ | ||
494 | public function testSanitizeDefaultTags() | ||
495 | { | ||
496 | $post = array( | ||
497 | 'privacy' => 'public', | ||
498 | 'default_tags' => 'tag1&,tag2 "tag3"' | ||
499 | ); | ||
500 | $files = file2array('netscape_basic.htm'); | ||
501 | $this->assertEquals( | ||
502 | 'File netscape_basic.htm (482 bytes) was successfully processed:' | ||
503 | .' 2 links imported, 0 links overwritten, 0 links skipped.', | ||
504 | NetscapeBookmarkUtils::import($post, $files, $this->linkDb, $this->pagecache) | ||
505 | ); | ||
506 | $this->assertEquals(2, count($this->linkDb)); | ||
507 | $this->assertEquals(0, count_private($this->linkDb)); | ||
508 | $this->assertEquals( | ||
509 | 'tag1& tag2 "tag3" private secret', | ||
510 | $this->linkDb['20001010_105536']['tags'] | ||
511 | ); | ||
512 | $this->assertEquals( | ||
513 | 'tag1& tag2 "tag3" public hello world', | ||
514 | $this->linkDb['20160225_205548']['tags'] | ||
515 | ); | ||
516 | } | ||
517 | |||
518 | /** | ||
519 | * Ensure each imported bookmark has a unique linkdate | ||
520 | * | ||
521 | * See https://github.com/shaarli/Shaarli/issues/351 | ||
522 | */ | ||
523 | public function testImportSameDate() | ||
524 | { | ||
525 | $files = file2array('same_date.htm'); | ||
526 | $this->assertEquals( | ||
527 | 'File same_date.htm (453 bytes) was successfully processed:' | ||
528 | .' 3 links imported, 0 links overwritten, 0 links skipped.', | ||
529 | NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache) | ||
530 | ); | ||
531 | $this->assertEquals(3, count($this->linkDb)); | ||
532 | $this->assertEquals(0, count_private($this->linkDb)); | ||
533 | $this->assertEquals( | ||
534 | '20160225_205548', | ||
535 | $this->linkDb['20160225_205548']['linkdate'] | ||
536 | ); | ||
537 | $this->assertEquals( | ||
538 | '20160225_205549', | ||
539 | $this->linkDb['20160225_205549']['linkdate'] | ||
540 | ); | ||
541 | $this->assertEquals( | ||
542 | '20160225_205550', | ||
543 | $this->linkDb['20160225_205550']['linkdate'] | ||
544 | ); | ||
545 | } | ||
546 | } | ||
diff --git a/tests/NetscapeBookmarkUtils/input/empty.htm b/tests/NetscapeBookmarkUtils/input/empty.htm new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/NetscapeBookmarkUtils/input/empty.htm | |||
diff --git a/tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm b/tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm new file mode 100644 index 00000000..18703cf6 --- /dev/null +++ b/tests/NetscapeBookmarkUtils/input/internet_explorer_encoding.htm | |||
@@ -0,0 +1,9 @@ | |||
1 | <!DOCTYPE NETSCAPE-Bookmark-file-1> | ||
2 | <!-- This is an automatically generated file. | ||
3 | It will be read and overwritten. | ||
4 | Do Not Edit! --> | ||
5 | <TITLE>Bookmarks</TITLE> | ||
6 | <H1>Bookmarks</H1> | ||
7 | <DL><p> | ||
8 | <DT><A HREF="http://hginit.com/" ADD_DATE="1466271584" LAST_VISIT="1466271584" LAST_MODIFIED="1466271584" >Hg Init a Mercurial tutorial by Joel Spolsky</A> | ||
9 | </DL><p> | ||
diff --git a/tests/NetscapeBookmarkUtils/input/netscape_basic.htm b/tests/NetscapeBookmarkUtils/input/netscape_basic.htm new file mode 100644 index 00000000..affe0cf8 --- /dev/null +++ b/tests/NetscapeBookmarkUtils/input/netscape_basic.htm | |||
@@ -0,0 +1,11 @@ | |||
1 | <!DOCTYPE NETSCAPE-Bookmark-file-1> | ||
2 | <!-- This is an automatically generated file. | ||
3 | It will be read and overwritten. | ||
4 | Do Not Edit! --> | ||
5 | <TITLE>Bookmarks</TITLE> | ||
6 | <H1>Bookmarks</H1> | ||
7 | <DL><p> | ||
8 | <DT><A HREF="https://private.tld" ADD_DATE="10/Oct/2000:13:55:36 +0300" PRIVATE="1" TAGS="private secret">Secret stuff</A> | ||
9 | <DD>Super-secret stuff you're not supposed to know about | ||
10 | <DT><A HREF="http://public.tld" ADD_DATE="1456433748" PRIVATE="0" TAGS="public hello world">Public stuff</A> | ||
11 | </DL><p> | ||
diff --git a/tests/NetscapeBookmarkUtils/input/netscape_nested.htm b/tests/NetscapeBookmarkUtils/input/netscape_nested.htm new file mode 100644 index 00000000..b486fe18 --- /dev/null +++ b/tests/NetscapeBookmarkUtils/input/netscape_nested.htm | |||
@@ -0,0 +1,31 @@ | |||
1 | <!DOCTYPE NETSCAPE-Bookmark-file-1> | ||
2 | <!-- This is an automatically generated file. | ||
3 | It will be read and overwritten. | ||
4 | Do Not Edit! --> | ||
5 | <TITLE>Bookmarks</TITLE> | ||
6 | <H1>Bookmarks</H1> | ||
7 | <DL><p> | ||
8 | <DT><A HREF="http://nest.ed/1" ADD_DATE="1456433741" PRIVATE="0" TAGS="tag1,tag2">Nested 1</A> | ||
9 | <DT><H3 ADD_DATE="1456433722" LAST_MODIFIED="1456433739">Folder1</H3> | ||
10 | <DL><p> | ||
11 | <DT><A HREF="http://nest.ed/1-1" ADD_DATE="1456433742" PRIVATE="0" TAGS="tag1,tag2">Nested 1-1</A> | ||
12 | <DT><A HREF="http://nest.ed/1-2" ADD_DATE="1456433747" PRIVATE="0" TAGS="tag3,tag4">Nested 1-2</A> | ||
13 | </DL><p> | ||
14 | <DT><H3 ADD_DATE="1456433722">Folder2</H3> | ||
15 | <DD>This second folder contains wonderful links! | ||
16 | <DL><p> | ||
17 | <DT><A HREF="http://nest.ed/2-1" ADD_DATE="1454433742" PRIVATE="1">Nested 2-1</A> | ||
18 | <DD>First link of the second section | ||
19 | <DT><A HREF="http://nest.ed/2-2" ADD_DATE="1453233747" PRIVATE="1">Nested 2-2</A> | ||
20 | <DD>Second link of the second section | ||
21 | </DL><p> | ||
22 | <DT><H3>Folder3</H3> | ||
23 | <DL><p> | ||
24 | <DT><H3>Folder3-1</H3> | ||
25 | <DL><p> | ||
26 | <DT><A HREF="http://nest.ed/3-1" ADD_DATE="1454433742" PRIVATE="0" TAGS="tag3">Nested 3-1</A> | ||
27 | <DT><A HREF="http://nest.ed/3-2" ADD_DATE="1453233747" PRIVATE="0">Nested 3-2</A> | ||
28 | </DL><p> | ||
29 | </DL><p> | ||
30 | <DT><A HREF="http://nest.ed/2" ADD_DATE="1456733741" PRIVATE="0" TAGS="tag4">Nested 2</A> | ||
31 | </DL><p> | ||
diff --git a/tests/NetscapeBookmarkUtils/input/no_doctype.htm b/tests/NetscapeBookmarkUtils/input/no_doctype.htm new file mode 100644 index 00000000..766d398b --- /dev/null +++ b/tests/NetscapeBookmarkUtils/input/no_doctype.htm | |||
@@ -0,0 +1,7 @@ | |||
1 | <TITLE>Bookmarks</TITLE> | ||
2 | <H1>Bookmarks</H1> | ||
3 | <DL><p> | ||
4 | <DT><A HREF="https://private.tld" ADD_DATE="10/Oct/2000:13:55:36 +0300" PRIVATE="1" TAGS="private secret">Secret stuff</A> | ||
5 | <DD>Super-secret stuff you're not supposed to know about | ||
6 | <DT><A HREF="http://public.tld" ADD_DATE="1456433748" PRIVATE="0" TAGS="public hello world">Public stuff</A> | ||
7 | </DL><p> | ||
diff --git a/tests/NetscapeBookmarkUtils/input/same_date.htm b/tests/NetscapeBookmarkUtils/input/same_date.htm new file mode 100644 index 00000000..9d58a582 --- /dev/null +++ b/tests/NetscapeBookmarkUtils/input/same_date.htm | |||
@@ -0,0 +1,11 @@ | |||
1 | <!DOCTYPE NETSCAPE-Bookmark-file-1> | ||
2 | <!-- This is an automatically generated file. | ||
3 | It will be read and overwritten. | ||
4 | Do Not Edit! --> | ||
5 | <TITLE>Bookmarks</TITLE> | ||
6 | <H1>Bookmarks</H1> | ||
7 | <DL><p> | ||
8 | <DT><A HREF="https://fir.st" ADD_DATE="1456433748" PRIVATE="0">Today's first link</A> | ||
9 | <DT><A HREF="https://seco.nd" ADD_DATE="1456433748" PRIVATE="0">Today's second link</A> | ||
10 | <DT><A HREF="https://thi.rd" ADD_DATE="1456433748" PRIVATE="0">Today's third link</A> | ||
11 | </DL><p> | ||
diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php index f4826e2e..ddf48185 100644 --- a/tests/PluginManagerTest.php +++ b/tests/PluginManagerTest.php | |||
@@ -92,4 +92,4 @@ class PluginManagerTest extends PHPUnit_Framework_TestCase | |||
92 | $this->assertEquals('test plugin', $meta[self::$pluginName]['description']); | 92 | $this->assertEquals('test plugin', $meta[self::$pluginName]['description']); |
93 | $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']); | 93 | $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']); |
94 | } | 94 | } |
95 | } \ No newline at end of file | 95 | } |
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 6bdce08b..0d0ad922 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php | |||
@@ -263,4 +263,28 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; | |||
263 | $expected = filemtime($this->conf->getConfigFileExt()); | 263 | $expected = filemtime($this->conf->getConfigFileExt()); |
264 | $this->assertEquals($expected, $filetime); | 264 | $this->assertEquals($expected, $filetime); |
265 | } | 265 | } |
266 | |||
267 | /** | ||
268 | * Test escapeUnescapedConfig with valid data. | ||
269 | */ | ||
270 | public function testEscapeConfig() | ||
271 | { | ||
272 | $sandbox = 'sandbox/config'; | ||
273 | copy(self::$configFile .'.json.php', $sandbox .'.json.php'); | ||
274 | $this->conf = new ConfigManager($sandbox); | ||
275 | $title = '<script>alert("title");</script>'; | ||
276 | $headerLink = '<script>alert("header_link");</script>'; | ||
277 | $redirectorUrl = '<script>alert("redirector");</script>'; | ||
278 | $this->conf->set('general.title', $title); | ||
279 | $this->conf->set('general.header_link', $headerLink); | ||
280 | $this->conf->set('redirector.url', $redirectorUrl); | ||
281 | $updater = new Updater(array(), array(), $this->conf, true); | ||
282 | $done = $updater->updateMethodEscapeUnescapedConfig(); | ||
283 | $this->assertTrue($done); | ||
284 | $this->conf->reload(); | ||
285 | $this->assertEquals(escape($title), $this->conf->get('general.title')); | ||
286 | $this->assertEquals(escape($headerLink), $this->conf->get('general.header_link')); | ||
287 | $this->assertEquals(escape($redirectorUrl), $this->conf->get('redirector.url')); | ||
288 | unlink($sandbox .'.json.php'); | ||
289 | } | ||
266 | } | 290 | } |
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php index fe16baac..fcc7a4f9 100644 --- a/tests/utils/ReferenceLinkDB.php +++ b/tests/utils/ReferenceLinkDB.php | |||
@@ -75,7 +75,7 @@ class ReferenceLinkDB | |||
75 | '', | 75 | '', |
76 | 1, | 76 | 1, |
77 | '20121206_182539', | 77 | '20121206_182539', |
78 | 'dev cartoon' | 78 | 'dev cartoon tag1 tag2 tag3 tag4 ' |
79 | ); | 79 | ); |
80 | } | 80 | } |
81 | 81 | ||
diff --git a/tests/utils/config/configInvalid.json.php b/tests/utils/config/configInvalid.json.php index 167f2168..e39d640a 100644 --- a/tests/utils/config/configInvalid.json.php +++ b/tests/utils/config/configInvalid.json.php | |||
@@ -2,4 +2,4 @@ | |||
2 | { | 2 | { |
3 | bad: bad, | 3 | bad: bad, |
4 | } | 4 | } |
5 | */ ?> \ No newline at end of file | 5 | */ ?> |