aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/HttpUtils/GetHttpUrlTest.php26
-rw-r--r--tests/LinkDBTest.php229
-rw-r--r--tests/LinkFilterTest.php242
-rw-r--r--tests/LinkUtilsTest.php85
-rw-r--r--tests/Url/UrlTest.php29
-rw-r--r--tests/UtilsTest.php66
-rw-r--r--tests/plugins/PlugQrcodeTest.php4
-rw-r--r--tests/plugins/PluginWallabagTest.php4
-rw-r--r--tests/plugins/WallabagInstanceTest.php60
-rw-r--r--tests/utils/ReferenceLinkDB.php5
10 files changed, 526 insertions, 224 deletions
diff --git a/tests/HttpUtils/GetHttpUrlTest.php b/tests/HttpUtils/GetHttpUrlTest.php
index 76092b80..fd293505 100644
--- a/tests/HttpUtils/GetHttpUrlTest.php
+++ b/tests/HttpUtils/GetHttpUrlTest.php
@@ -6,7 +6,7 @@
6require_once 'application/HttpUtils.php'; 6require_once 'application/HttpUtils.php';
7 7
8/** 8/**
9 * Unitary tests for get_http_url() 9 * Unitary tests for get_http_response()
10 */ 10 */
11class GetHttpUrlTest extends PHPUnit_Framework_TestCase 11class GetHttpUrlTest extends PHPUnit_Framework_TestCase
12{ 12{
@@ -15,12 +15,15 @@ class GetHttpUrlTest extends PHPUnit_Framework_TestCase
15 */ 15 */
16 public function testGetInvalidLocalUrl() 16 public function testGetInvalidLocalUrl()
17 { 17 {
18 list($headers, $content) = get_http_url('/non/existent', 1); 18 // Local
19 $this->assertEquals('HTTP Error', $headers[0]); 19 list($headers, $content) = get_http_response('/non/existent', 1);
20 $this->assertRegexp( 20 $this->assertEquals('Invalid HTTP Url', $headers[0]);
21 '/failed to open stream: No such file or directory/', 21 $this->assertFalse($content);
22 $content 22
23 ); 23 // Non HTTP
24 list($headers, $content) = get_http_response('ftp://save.tld/mysave', 1);
25 $this->assertEquals('Invalid HTTP Url', $headers[0]);
26 $this->assertFalse($content);
24 } 27 }
25 28
26 /** 29 /**
@@ -28,11 +31,8 @@ class GetHttpUrlTest extends PHPUnit_Framework_TestCase
28 */ 31 */
29 public function testGetInvalidRemoteUrl() 32 public function testGetInvalidRemoteUrl()
30 { 33 {
31 list($headers, $content) = get_http_url('http://non.existent', 1); 34 list($headers, $content) = @get_http_response('http://non.existent', 1);
32 $this->assertEquals('HTTP Error', $headers[0]); 35 $this->assertFalse($headers);
33 $this->assertRegexp( 36 $this->assertFalse($content);
34 '/Name or service not known/',
35 $content
36 );
37 } 37 }
38} 38}
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php
index 7b22b270..3b1a2057 100644
--- a/tests/LinkDBTest.php
+++ b/tests/LinkDBTest.php
@@ -302,236 +302,49 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
302 } 302 }
303 303
304 /** 304 /**
305 * Filter links using a tag 305 * Test real_url without redirector.
306 */
307 public function testFilterOneTag()
308 {
309 $this->assertEquals(
310 3,
311 sizeof(self::$publicLinkDB->filterTags('web', false))
312 );
313
314 $this->assertEquals(
315 4,
316 sizeof(self::$privateLinkDB->filterTags('web', false))
317 );
318 }
319
320 /**
321 * Filter links using a tag - case-sensitive
322 */
323 public function testFilterCaseSensitiveTag()
324 {
325 $this->assertEquals(
326 0,
327 sizeof(self::$privateLinkDB->filterTags('mercurial', true))
328 );
329
330 $this->assertEquals(
331 1,
332 sizeof(self::$privateLinkDB->filterTags('Mercurial', true))
333 );
334 }
335
336 /**
337 * Filter links using a tag combination
338 */
339 public function testFilterMultipleTags()
340 {
341 $this->assertEquals(
342 1,
343 sizeof(self::$publicLinkDB->filterTags('dev cartoon', false))
344 );
345
346 $this->assertEquals(
347 2,
348 sizeof(self::$privateLinkDB->filterTags('dev cartoon', false))
349 );
350 }
351
352 /**
353 * Filter links using a non-existent tag
354 */
355 public function testFilterUnknownTag()
356 {
357 $this->assertEquals(
358 0,
359 sizeof(self::$publicLinkDB->filterTags('null', false))
360 );
361 }
362
363 /**
364 * Return links for a given day
365 */
366 public function testFilterDay()
367 {
368 $this->assertEquals(
369 2,
370 sizeof(self::$publicLinkDB->filterDay('20121206'))
371 );
372
373 $this->assertEquals(
374 3,
375 sizeof(self::$privateLinkDB->filterDay('20121206'))
376 );
377 }
378
379 /**
380 * 404 - day not found
381 */
382 public function testFilterUnknownDay()
383 {
384 $this->assertEquals(
385 0,
386 sizeof(self::$publicLinkDB->filterDay('19700101'))
387 );
388
389 $this->assertEquals(
390 0,
391 sizeof(self::$privateLinkDB->filterDay('19700101'))
392 );
393 }
394
395 /**
396 * Use an invalid date format
397 * @expectedException Exception
398 * @expectedExceptionMessageRegExp /Invalid date format/
399 */
400 public function testFilterInvalidDayWithChars()
401 {
402 self::$privateLinkDB->filterDay('Rainy day, dream away');
403 }
404
405 /**
406 * Use an invalid date format
407 * @expectedException Exception
408 * @expectedExceptionMessageRegExp /Invalid date format/
409 */
410 public function testFilterInvalidDayDigits()
411 {
412 self::$privateLinkDB->filterDay('20');
413 }
414
415 /**
416 * Retrieve a link entry with its hash
417 */
418 public function testFilterSmallHash()
419 {
420 $links = self::$privateLinkDB->filterSmallHash('IuWvgA');
421
422 $this->assertEquals(
423 1,
424 sizeof($links)
425 );
426
427 $this->assertEquals(
428 'MediaGoblin',
429 $links['20130614_184135']['title']
430 );
431
432 }
433
434 /**
435 * No link for this hash
436 */
437 public function testFilterUnknownSmallHash()
438 {
439 $this->assertEquals(
440 0,
441 sizeof(self::$privateLinkDB->filterSmallHash('Iblaah'))
442 );
443 }
444
445 /**
446 * Full-text search - result from a link's URL
447 */
448 public function testFilterFullTextURL()
449 {
450 $this->assertEquals(
451 2,
452 sizeof(self::$publicLinkDB->filterFullText('ars.userfriendly.org'))
453 );
454 }
455
456 /**
457 * Full-text search - result from a link's title only
458 */ 306 */
459 public function testFilterFullTextTitle() 307 public function testLinkRealUrlWithoutRedirector()
460 { 308 {
461 // use miscellaneous cases 309 $db = new LinkDB(self::$testDatastore, false, false);
462 $this->assertEquals( 310 foreach($db as $link) {
463 2, 311 $this->assertEquals($link['url'], $link['real_url']);
464 sizeof(self::$publicLinkDB->filterFullText('userfriendly -')) 312 }
465 );
466 $this->assertEquals(
467 2,
468 sizeof(self::$publicLinkDB->filterFullText('UserFriendly -'))
469 );
470 $this->assertEquals(
471 2,
472 sizeof(self::$publicLinkDB->filterFullText('uSeRFrIendlY -'))
473 );
474
475 // use miscellaneous case and offset
476 $this->assertEquals(
477 2,
478 sizeof(self::$publicLinkDB->filterFullText('RFrIendL'))
479 );
480 } 313 }
481 314
482 /** 315 /**
483 * Full-text search - result from the link's description only 316 * Test real_url with redirector.
484 */ 317 */
485 public function testFilterFullTextDescription() 318 public function testLinkRealUrlWithRedirector()
486 { 319 {
487 $this->assertEquals( 320 $redirector = 'http://redirector.to?';
488 1, 321 $db = new LinkDB(self::$testDatastore, false, false, $redirector);
489 sizeof(self::$publicLinkDB->filterFullText('media publishing')) 322 foreach($db as $link) {
490 ); 323 $this->assertStringStartsWith($redirector, $link['real_url']);
324 }
491 } 325 }
492 326
493 /** 327 /**
494 * Full-text search - result from the link's tags only 328 * Test filter with string.
495 */ 329 */
496 public function testFilterFullTextTags() 330 public function testFilterString()
497 { 331 {
332 $tags = 'dev cartoon';
498 $this->assertEquals( 333 $this->assertEquals(
499 2, 334 2,
500 sizeof(self::$publicLinkDB->filterFullText('gnu')) 335 count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false))
501 ); 336 );
502 } 337 }
503 338
504 /** 339 /**
505 * Full-text search - result set from mixed sources 340 * Test filter with string.
506 */ 341 */
507 public function testFilterFullTextMixed() 342 public function testFilterArray()
508 { 343 {
344 $tags = array('dev', 'cartoon');
509 $this->assertEquals( 345 $this->assertEquals(
510 2, 346 2,
511 sizeof(self::$publicLinkDB->filterFullText('free software')) 347 count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false))
512 ); 348 );
513 } 349 }
514
515 /**
516 * Test real_url without redirector.
517 */
518 public function testLinkRealUrlWithoutRedirector()
519 {
520 $db = new LinkDB(self::$testDatastore, false, false);
521 foreach($db as $link) {
522 $this->assertEquals($link['url'], $link['real_url']);
523 }
524 }
525
526 /**
527 * Test real_url with redirector.
528 */
529 public function testLinkRealUrlWithRedirector()
530 {
531 $redirector = 'http://redirector.to?';
532 $db = new LinkDB(self::$testDatastore, false, false, $redirector);
533 foreach($db as $link) {
534 $this->assertStringStartsWith($redirector, $link['real_url']);
535 }
536 }
537} 350}
diff --git a/tests/LinkFilterTest.php b/tests/LinkFilterTest.php
new file mode 100644
index 00000000..5107ab72
--- /dev/null
+++ b/tests/LinkFilterTest.php
@@ -0,0 +1,242 @@
1<?php
2
3require_once 'application/LinkFilter.php';
4
5/**
6 * Class LinkFilterTest.
7 */
8class LinkFilterTest extends PHPUnit_Framework_TestCase
9{
10 /**
11 * @var LinkFilter instance.
12 */
13 protected static $linkFilter;
14
15 /**
16 * Instanciate linkFilter with ReferenceLinkDB data.
17 */
18 public static function setUpBeforeClass()
19 {
20 $refDB = new ReferenceLinkDB();
21 self::$linkFilter = new LinkFilter($refDB->getLinks());
22 }
23
24 /**
25 * Blank filter.
26 */
27 public function testFilter()
28 {
29 $this->assertEquals(
30 6,
31 count(self::$linkFilter->filter('', ''))
32 );
33
34 // Private only.
35 $this->assertEquals(
36 2,
37 count(self::$linkFilter->filter('', '', false, true))
38 );
39 }
40
41 /**
42 * Filter links using a tag
43 */
44 public function testFilterOneTag()
45 {
46 $this->assertEquals(
47 4,
48 count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, 'web', false))
49 );
50
51 // Private only.
52 $this->assertEquals(
53 1,
54 count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, 'web', false, true))
55 );
56 }
57
58 /**
59 * Filter links using a tag - case-sensitive
60 */
61 public function testFilterCaseSensitiveTag()
62 {
63 $this->assertEquals(
64 0,
65 count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, 'mercurial', true))
66 );
67
68 $this->assertEquals(
69 1,
70 count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, 'Mercurial', true))
71 );
72 }
73
74 /**
75 * Filter links using a tag combination
76 */
77 public function testFilterMultipleTags()
78 {
79 $this->assertEquals(
80 2,
81 count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, 'dev cartoon', false))
82 );
83 }
84
85 /**
86 * Filter links using a non-existent tag
87 */
88 public function testFilterUnknownTag()
89 {
90 $this->assertEquals(
91 0,
92 count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, 'null', false))
93 );
94 }
95
96 /**
97 * Return links for a given day
98 */
99 public function testFilterDay()
100 {
101 $this->assertEquals(
102 3,
103 count(self::$linkFilter->filter(LinkFilter::$FILTER_DAY, '20121206'))
104 );
105 }
106
107 /**
108 * 404 - day not found
109 */
110 public function testFilterUnknownDay()
111 {
112 $this->assertEquals(
113 0,
114 count(self::$linkFilter->filter(LinkFilter::$FILTER_DAY, '19700101'))
115 );
116 }
117
118 /**
119 * Use an invalid date format
120 * @expectedException Exception
121 * @expectedExceptionMessageRegExp /Invalid date format/
122 */
123 public function testFilterInvalidDayWithChars()
124 {
125 self::$linkFilter->filter(LinkFilter::$FILTER_DAY, 'Rainy day, dream away');
126 }
127
128 /**
129 * Use an invalid date format
130 * @expectedException Exception
131 * @expectedExceptionMessageRegExp /Invalid date format/
132 */
133 public function testFilterInvalidDayDigits()
134 {
135 self::$linkFilter->filter(LinkFilter::$FILTER_DAY, '20');
136 }
137
138 /**
139 * Retrieve a link entry with its hash
140 */
141 public function testFilterSmallHash()
142 {
143 $links = self::$linkFilter->filter(LinkFilter::$FILTER_HASH, 'IuWvgA');
144
145 $this->assertEquals(
146 1,
147 count($links)
148 );
149
150 $this->assertEquals(
151 'MediaGoblin',
152 $links['20130614_184135']['title']
153 );
154 }
155
156 /**
157 * No link for this hash
158 */
159 public function testFilterUnknownSmallHash()
160 {
161 $this->assertEquals(
162 0,
163 count(self::$linkFilter->filter(LinkFilter::$FILTER_HASH, 'Iblaah'))
164 );
165 }
166
167 /**
168 * Full-text search - result from a link's URL
169 */
170 public function testFilterFullTextURL()
171 {
172 $this->assertEquals(
173 2,
174 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'ars.userfriendly.org'))
175 );
176 }
177
178 /**
179 * Full-text search - result from a link's title only
180 */
181 public function testFilterFullTextTitle()
182 {
183 // use miscellaneous cases
184 $this->assertEquals(
185 2,
186 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'userfriendly -'))
187 );
188 $this->assertEquals(
189 2,
190 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'UserFriendly -'))
191 );
192 $this->assertEquals(
193 2,
194 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'uSeRFrIendlY -'))
195 );
196
197 // use miscellaneous case and offset
198 $this->assertEquals(
199 2,
200 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'RFrIendL'))
201 );
202 }
203
204 /**
205 * Full-text search - result from the link's description only
206 */
207 public function testFilterFullTextDescription()
208 {
209 $this->assertEquals(
210 1,
211 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'media publishing'))
212 );
213 }
214
215 /**
216 * Full-text search - result from the link's tags only
217 */
218 public function testFilterFullTextTags()
219 {
220 $this->assertEquals(
221 2,
222 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'gnu'))
223 );
224
225 // Private only.
226 $this->assertEquals(
227 1,
228 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'web', false, true))
229 );
230 }
231
232 /**
233 * Full-text search - result set from mixed sources
234 */
235 public function testFilterFullTextMixed()
236 {
237 $this->assertEquals(
238 2,
239 count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'free software'))
240 );
241 }
242}
diff --git a/tests/LinkUtilsTest.php b/tests/LinkUtilsTest.php
new file mode 100644
index 00000000..c2257590
--- /dev/null
+++ b/tests/LinkUtilsTest.php
@@ -0,0 +1,85 @@
1<?php
2
3require_once 'application/LinkUtils.php';
4
5/**
6* Class LinkUtilsTest.
7*/
8class LinkUtilsTest extends PHPUnit_Framework_TestCase
9{
10 /**
11 * Test html_extract_title() when the title is found.
12 */
13 public function testHtmlExtractExistentTitle()
14 {
15 $title = 'Read me please.';
16 $html = '<html><meta>stuff</meta><title>'. $title .'</title></html>';
17 $this->assertEquals($title, html_extract_title($html));
18 }
19
20 /**
21 * Test html_extract_title() when the title is not found.
22 */
23 public function testHtmlExtractNonExistentTitle()
24 {
25 $html = '<html><meta>stuff</meta></html>';
26 $this->assertFalse(html_extract_title($html));
27 }
28
29 /**
30 * Test get_charset() with all priorities.
31 */
32 public function testGetCharset()
33 {
34 $headers = array('Content-Type' => 'text/html; charset=Headers');
35 $html = '<html><meta>stuff</meta><meta charset="Html"/></html>';
36 $default = 'default';
37 $this->assertEquals('headers', get_charset($headers, $html, $default));
38 $this->assertEquals('html', get_charset(array(), $html, $default));
39 $this->assertEquals($default, get_charset(array(), '', $default));
40 $this->assertEquals('utf-8', get_charset(array(), ''));
41 }
42
43 /**
44 * Test headers_extract_charset() when the charset is found.
45 */
46 public function testHeadersExtractExistentCharset()
47 {
48 $charset = 'x-MacCroatian';
49 $headers = array('Content-Type' => 'text/html; charset='. $charset);
50 $this->assertEquals(strtolower($charset), headers_extract_charset($headers));
51 }
52
53 /**
54 * Test headers_extract_charset() when the charset is not found.
55 */
56 public function testHeadersExtractNonExistentCharset()
57 {
58 $headers = array();
59 $this->assertFalse(headers_extract_charset($headers));
60
61 $headers = array('Content-Type' => 'text/html');
62 $this->assertFalse(headers_extract_charset($headers));
63 }
64
65 /**
66 * Test html_extract_charset() when the charset is found.
67 */
68 public function testHtmlExtractExistentCharset()
69 {
70 $charset = 'x-MacCroatian';
71 $html = '<html><meta>stuff2</meta><meta charset="'. $charset .'"/></html>';
72 $this->assertEquals(strtolower($charset), html_extract_charset($html));
73 }
74
75 /**
76 * Test html_extract_charset() when the charset is not found.
77 */
78 public function testHtmlExtractNonExistentCharset()
79 {
80 $html = '<html><meta>stuff</meta></html>';
81 $this->assertFalse(html_extract_charset($html));
82 $html = '<html><meta>stuff</meta><meta charset=""/></html>';
83 $this->assertFalse(html_extract_charset($html));
84 }
85}
diff --git a/tests/Url/UrlTest.php b/tests/Url/UrlTest.php
index e498d79e..425327ed 100644
--- a/tests/Url/UrlTest.php
+++ b/tests/Url/UrlTest.php
@@ -145,4 +145,33 @@ class UrlTest extends PHPUnit_Framework_TestCase
145 $url = new Url('git://domain.tld/push?pull=clone#checkout'); 145 $url = new Url('git://domain.tld/push?pull=clone#checkout');
146 $this->assertEquals('git', $url->getScheme()); 146 $this->assertEquals('git', $url->getScheme());
147 } 147 }
148
149 /**
150 * Test add trailing slash.
151 */
152 function testAddTrailingSlash()
153 {
154 $strOn = 'http://randomstr.com/test/';
155 $strOff = 'http://randomstr.com/test';
156 $this->assertEquals($strOn, add_trailing_slash($strOn));
157 $this->assertEquals($strOn, add_trailing_slash($strOff));
158 }
159
160 /**
161 * Test valid HTTP url.
162 */
163 function testUrlIsHttp()
164 {
165 $url = new Url(self::$baseUrl);
166 $this->assertTrue($url->isHttp());
167 }
168
169 /**
170 * Test non HTTP url.
171 */
172 function testUrlIsNotHttp()
173 {
174 $url = new Url('ftp://save.tld/mysave');
175 $this->assertFalse($url->isHttp());
176 }
148} 177}
diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php
index 02eecda2..3073b5eb 100644
--- a/tests/UtilsTest.php
+++ b/tests/UtilsTest.php
@@ -18,6 +18,13 @@ class UtilsTest extends PHPUnit_Framework_TestCase
18 // Session ID hashes 18 // Session ID hashes
19 protected static $sidHashes = null; 19 protected static $sidHashes = null;
20 20
21 // Log file
22 protected static $testLogFile = 'tests.log';
23
24 // Expected log date format
25 protected static $dateFormat = 'Y/m/d H:i:s';
26
27
21 /** 28 /**
22 * Assign reference data 29 * Assign reference data
23 */ 30 */
@@ -27,6 +34,65 @@ class UtilsTest extends PHPUnit_Framework_TestCase
27 } 34 }
28 35
29 /** 36 /**
37 * Resets test data before each test
38 */
39 protected function setUp()
40 {
41 if (file_exists(self::$testLogFile)) {
42 unlink(self::$testLogFile);
43 }
44 }
45
46 /**
47 * Returns a list of the elements from the last logged entry
48 *
49 * @return list (date, ip address, message)
50 */
51 protected function getLastLogEntry()
52 {
53 $logFile = file(self::$testLogFile);
54 return explode(' - ', trim(array_pop($logFile), PHP_EOL));
55 }
56
57 /**
58 * Log a message to a file - IPv4 client address
59 */
60 public function testLogmIp4()
61 {
62 $logMessage = 'IPv4 client connected';
63 logm(self::$testLogFile, '127.0.0.1', $logMessage);
64 list($date, $ip, $message) = $this->getLastLogEntry();
65
66 $this->assertInstanceOf(
67 'DateTime',
68 DateTime::createFromFormat(self::$dateFormat, $date)
69 );
70 $this->assertTrue(
71 filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false
72 );
73 $this->assertEquals($logMessage, $message);
74 }
75
76 /**
77 * Log a message to a file - IPv6 client address
78 */
79 public function testLogmIp6()
80 {
81 $logMessage = 'IPv6 client connected';
82 logm(self::$testLogFile, '2001:db8::ff00:42:8329', $logMessage);
83 list($date, $ip, $message) = $this->getLastLogEntry();
84
85 $this->assertInstanceOf(
86 'DateTime',
87 DateTime::createFromFormat(self::$dateFormat, $date)
88 );
89 $this->assertTrue(
90 filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false
91 );
92 $this->assertEquals($logMessage, $message);
93 }
94
95 /**
30 * Represent a link by its hash 96 * Represent a link by its hash
31 */ 97 */
32 public function testSmallHash() 98 public function testSmallHash()
diff --git a/tests/plugins/PlugQrcodeTest.php b/tests/plugins/PlugQrcodeTest.php
index c749fa86..86dc7f29 100644
--- a/tests/plugins/PlugQrcodeTest.php
+++ b/tests/plugins/PlugQrcodeTest.php
@@ -30,7 +30,7 @@ class PlugQrcodeTest extends PHPUnit_Framework_TestCase
30 'title' => $str, 30 'title' => $str,
31 'links' => array( 31 'links' => array(
32 array( 32 array(
33 'real_url' => $str, 33 'url' => $str,
34 ) 34 )
35 ) 35 )
36 ); 36 );
@@ -39,7 +39,7 @@ class PlugQrcodeTest extends PHPUnit_Framework_TestCase
39 $link = $data['links'][0]; 39 $link = $data['links'][0];
40 // data shouldn't be altered 40 // data shouldn't be altered
41 $this->assertEquals($str, $data['title']); 41 $this->assertEquals($str, $data['title']);
42 $this->assertEquals($str, $link['real_url']); 42 $this->assertEquals($str, $link['url']);
43 43
44 // plugin data 44 // plugin data
45 $this->assertEquals(1, count($link['link_plugin'])); 45 $this->assertEquals(1, count($link['link_plugin']));
diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php
index 7cc83f4f..5d3a60e0 100644
--- a/tests/plugins/PluginWallabagTest.php
+++ b/tests/plugins/PluginWallabagTest.php
@@ -44,6 +44,8 @@ class PluginWallabagTest extends PHPUnit_Framework_TestCase
44 44
45 // plugin data 45 // plugin data
46 $this->assertEquals(1, count($link['link_plugin'])); 46 $this->assertEquals(1, count($link['link_plugin']));
47 $this->assertNotFalse(strpos($link['link_plugin'][0], $str)); 47 $this->assertNotFalse(strpos($link['link_plugin'][0], urlencode($str)));
48 $this->assertNotFalse(strpos($link['link_plugin'][0], $GLOBALS['plugins']['WALLABAG_URL']));
48 } 49 }
49} 50}
51
diff --git a/tests/plugins/WallabagInstanceTest.php b/tests/plugins/WallabagInstanceTest.php
new file mode 100644
index 00000000..7c14c1df
--- /dev/null
+++ b/tests/plugins/WallabagInstanceTest.php
@@ -0,0 +1,60 @@
1<?php
2
3require_once 'plugins/wallabag/WallabagInstance.php';
4
5/**
6 * Class WallabagInstanceTest
7 */
8class WallabagInstanceTest extends PHPUnit_Framework_TestCase
9{
10 /**
11 * @var string wallabag url.
12 */
13 private $instance;
14
15 /**
16 * Reset plugin path
17 */
18 function setUp()
19 {
20 $this->instance = 'http://some.url';
21 }
22
23 /**
24 * Test WallabagInstance with API V1.
25 */
26 function testWallabagInstanceV1()
27 {
28 $instance = new WallabagInstance($this->instance, 1);
29 $expected = $this->instance . '/?plainurl=';
30 $result = $instance->getWallabagUrl();
31 $this->assertEquals($expected, $result);
32 }
33
34 /**
35 * Test WallabagInstance with API V2.
36 */
37 function testWallabagInstanceV2()
38 {
39 $instance = new WallabagInstance($this->instance, 2);
40 $expected = $this->instance . '/bookmarklet?url=';
41 $result = $instance->getWallabagUrl();
42 $this->assertEquals($expected, $result);
43 }
44
45 /**
46 * Test WallabagInstance with an invalid API version.
47 */
48 function testWallabagInstanceInvalidVersion()
49 {
50 $instance = new WallabagInstance($this->instance, false);
51 $expected = $this->instance . '/?plainurl=';
52 $result = $instance->getWallabagUrl();
53 $this->assertEquals($expected, $result);
54
55 $instance = new WallabagInstance($this->instance, 3);
56 $expected = $this->instance . '/?plainurl=';
57 $result = $instance->getWallabagUrl();
58 $this->assertEquals($expected, $result);
59 }
60}
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php
index 47b51829..011317ef 100644
--- a/tests/utils/ReferenceLinkDB.php
+++ b/tests/utils/ReferenceLinkDB.php
@@ -124,4 +124,9 @@ class ReferenceLinkDB
124 { 124 {
125 return $this->_privateCount; 125 return $this->_privateCount;
126 } 126 }
127
128 public function getLinks()
129 {
130 return $this->_links;
131 }
127} 132}