diff options
author | ArthurHoaro <arthur@hoa.ro> | 2016-10-12 13:58:35 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2016-10-12 13:58:35 +0200 |
commit | bc22c9a0acb095970e9494cbe8954f0612e05dc0 (patch) | |
tree | 4e3a94b7469f5b2e3eaf946756235730429bf9d4 /tests | |
parent | 890afc32f744859d11b97eb26ed5c030af9b4145 (diff) | |
parent | ebd67c6e1b40aebdd3a52285ce9ff9412b2a3038 (diff) | |
download | Shaarli-bc22c9a0acb095970e9494cbe8954f0612e05dc0.tar.gz Shaarli-bc22c9a0acb095970e9494cbe8954f0612e05dc0.tar.zst Shaarli-bc22c9a0acb095970e9494cbe8954f0612e05dc0.zip |
Merge tag 'v0.7.0' of github.com:shaarli/Shaarli into stable
Release v0.7.0
Diffstat (limited to 'tests')
-rw-r--r-- | tests/FeedBuilderTest.php | 212 | ||||
-rw-r--r-- | tests/HttpUtils/GetHttpUrlTest.php | 27 | ||||
-rw-r--r-- | tests/LinkDBTest.php | 63 | ||||
-rw-r--r-- | tests/LinkFilterTest.php | 17 | ||||
-rw-r--r-- | tests/LinkUtilsTest.php | 11 | ||||
-rw-r--r-- | tests/NetscapeBookmarkUtilsTest.php | 134 | ||||
-rw-r--r-- | tests/TimeZoneTest.php | 2 | ||||
-rw-r--r-- | tests/Updater/UpdaterTest.php | 4 | ||||
-rw-r--r-- | tests/Url/UrlTest.php | 22 | ||||
-rw-r--r-- | tests/plugins/PluginMarkdownTest.php | 37 | ||||
-rw-r--r-- | tests/utils/ReferenceLinkDB.php | 20 |
11 files changed, 522 insertions, 27 deletions
diff --git a/tests/FeedBuilderTest.php b/tests/FeedBuilderTest.php new file mode 100644 index 00000000..069b1581 --- /dev/null +++ b/tests/FeedBuilderTest.php | |||
@@ -0,0 +1,212 @@ | |||
1 | <?php | ||
2 | |||
3 | require_once 'application/FeedBuilder.php'; | ||
4 | require_once 'application/LinkDB.php'; | ||
5 | |||
6 | /** | ||
7 | * FeedBuilderTest class. | ||
8 | * | ||
9 | * Unit tests for FeedBuilder. | ||
10 | */ | ||
11 | class FeedBuilderTest extends PHPUnit_Framework_TestCase | ||
12 | { | ||
13 | /** | ||
14 | * @var string locale Basque (Spain). | ||
15 | */ | ||
16 | public static $LOCALE = 'eu_ES'; | ||
17 | |||
18 | /** | ||
19 | * @var string language in RSS format. | ||
20 | */ | ||
21 | public static $RSS_LANGUAGE = 'eu-es'; | ||
22 | |||
23 | /** | ||
24 | * @var string language in ATOM format. | ||
25 | */ | ||
26 | public static $ATOM_LANGUAGUE = 'eu'; | ||
27 | |||
28 | protected static $testDatastore = 'sandbox/datastore.php'; | ||
29 | |||
30 | public static $linkDB; | ||
31 | |||
32 | public static $serverInfo; | ||
33 | |||
34 | /** | ||
35 | * Called before every test method. | ||
36 | */ | ||
37 | public static function setUpBeforeClass() | ||
38 | { | ||
39 | $refLinkDB = new ReferenceLinkDB(); | ||
40 | $refLinkDB->write(self::$testDatastore); | ||
41 | self::$linkDB = new LinkDB(self::$testDatastore, true, false); | ||
42 | self::$serverInfo = array( | ||
43 | 'HTTPS' => 'Off', | ||
44 | 'SERVER_NAME' => 'host.tld', | ||
45 | 'SERVER_PORT' => '80', | ||
46 | 'SCRIPT_NAME' => '/index.php', | ||
47 | 'REQUEST_URI' => '/index.php?do=feed', | ||
48 | ); | ||
49 | } | ||
50 | |||
51 | /** | ||
52 | * Test GetTypeLanguage(). | ||
53 | */ | ||
54 | public function testGetTypeLanguage() | ||
55 | { | ||
56 | $feedBuilder = new FeedBuilder(null, FeedBuilder::$FEED_ATOM, null, null, false); | ||
57 | $feedBuilder->setLocale(self::$LOCALE); | ||
58 | $this->assertEquals(self::$ATOM_LANGUAGUE, $feedBuilder->getTypeLanguage()); | ||
59 | $feedBuilder = new FeedBuilder(null, FeedBuilder::$FEED_RSS, null, null, false); | ||
60 | $feedBuilder->setLocale(self::$LOCALE); | ||
61 | $this->assertEquals(self::$RSS_LANGUAGE, $feedBuilder->getTypeLanguage()); | ||
62 | $feedBuilder = new FeedBuilder(null, FeedBuilder::$FEED_ATOM, null, null, false); | ||
63 | $this->assertEquals('en', $feedBuilder->getTypeLanguage()); | ||
64 | $feedBuilder = new FeedBuilder(null, FeedBuilder::$FEED_RSS, null, null, false); | ||
65 | $this->assertEquals('en-en', $feedBuilder->getTypeLanguage()); | ||
66 | } | ||
67 | |||
68 | /** | ||
69 | * Test buildData with RSS feed. | ||
70 | */ | ||
71 | public function testRSSBuildData() | ||
72 | { | ||
73 | $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_RSS, self::$serverInfo, null, false); | ||
74 | $feedBuilder->setLocale(self::$LOCALE); | ||
75 | $data = $feedBuilder->buildData(); | ||
76 | // Test headers (RSS) | ||
77 | $this->assertEquals(self::$RSS_LANGUAGE, $data['language']); | ||
78 | $this->assertEmpty($data['pubsubhub_url']); | ||
79 | $this->assertEquals('Tue, 10 Mar 2015 11:46:51 +0100', $data['last_update']); | ||
80 | $this->assertEquals(true, $data['show_dates']); | ||
81 | $this->assertEquals('http://host.tld/index.php?do=feed', $data['self_link']); | ||
82 | $this->assertEquals('http://host.tld/', $data['index_url']); | ||
83 | $this->assertFalse($data['usepermalinks']); | ||
84 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); | ||
85 | |||
86 | // Test first link (note link) | ||
87 | $link = array_shift($data['links']); | ||
88 | $this->assertEquals('20150310_114651', $link['linkdate']); | ||
89 | $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); | ||
90 | $this->assertEquals('http://host.tld/?WDWyig', $link['url']); | ||
91 | $this->assertEquals('Tue, 10 Mar 2015 11:46:51 +0100', $link['iso_date']); | ||
92 | $this->assertContains('Stallman has a beard', $link['description']); | ||
93 | $this->assertContains('Permalink', $link['description']); | ||
94 | $this->assertContains('http://host.tld/?WDWyig', $link['description']); | ||
95 | $this->assertEquals(1, count($link['taglist'])); | ||
96 | $this->assertEquals('stuff', $link['taglist'][0]); | ||
97 | |||
98 | // Test URL with external link. | ||
99 | $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $data['links']['20150310_114633']['url']); | ||
100 | |||
101 | // Test multitags. | ||
102 | $this->assertEquals(5, count($data['links']['20141125_084734']['taglist'])); | ||
103 | $this->assertEquals('css', $data['links']['20141125_084734']['taglist'][0]); | ||
104 | } | ||
105 | |||
106 | /** | ||
107 | * Test buildData with ATOM feed (test only specific to ATOM). | ||
108 | */ | ||
109 | public function testAtomBuildData() | ||
110 | { | ||
111 | $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, null, false); | ||
112 | $feedBuilder->setLocale(self::$LOCALE); | ||
113 | $data = $feedBuilder->buildData(); | ||
114 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); | ||
115 | $link = array_shift($data['links']); | ||
116 | $this->assertEquals('2015-03-10T11:46:51+01:00', $link['iso_date']); | ||
117 | } | ||
118 | |||
119 | /** | ||
120 | * Test buildData with search criteria. | ||
121 | */ | ||
122 | public function testBuildDataFiltered() | ||
123 | { | ||
124 | $criteria = array( | ||
125 | 'searchtags' => 'stuff', | ||
126 | 'searchterm' => 'beard', | ||
127 | ); | ||
128 | $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, $criteria, false); | ||
129 | $feedBuilder->setLocale(self::$LOCALE); | ||
130 | $data = $feedBuilder->buildData(); | ||
131 | $this->assertEquals(1, count($data['links'])); | ||
132 | $link = array_shift($data['links']); | ||
133 | $this->assertEquals('20150310_114651', $link['linkdate']); | ||
134 | } | ||
135 | |||
136 | /** | ||
137 | * Test buildData with nb limit. | ||
138 | */ | ||
139 | public function testBuildDataCount() | ||
140 | { | ||
141 | $criteria = array( | ||
142 | 'nb' => '1', | ||
143 | ); | ||
144 | $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, $criteria, false); | ||
145 | $feedBuilder->setLocale(self::$LOCALE); | ||
146 | $data = $feedBuilder->buildData(); | ||
147 | $this->assertEquals(1, count($data['links'])); | ||
148 | $link = array_shift($data['links']); | ||
149 | $this->assertEquals('20150310_114651', $link['linkdate']); | ||
150 | } | ||
151 | |||
152 | /** | ||
153 | * Test buildData with permalinks on. | ||
154 | */ | ||
155 | public function testBuildDataPermalinks() | ||
156 | { | ||
157 | $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, null, false); | ||
158 | $feedBuilder->setLocale(self::$LOCALE); | ||
159 | $feedBuilder->setUsePermalinks(true); | ||
160 | $data = $feedBuilder->buildData(); | ||
161 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); | ||
162 | $this->assertTrue($data['usepermalinks']); | ||
163 | // First link is a permalink | ||
164 | $link = array_shift($data['links']); | ||
165 | $this->assertEquals('20150310_114651', $link['linkdate']); | ||
166 | $this->assertEquals('http://host.tld/?WDWyig', $link['guid']); | ||
167 | $this->assertEquals('http://host.tld/?WDWyig', $link['url']); | ||
168 | $this->assertContains('Direct link', $link['description']); | ||
169 | $this->assertContains('http://host.tld/?WDWyig', $link['description']); | ||
170 | // Second link is a direct link | ||
171 | $link = array_shift($data['links']); | ||
172 | $this->assertEquals('20150310_114633', $link['linkdate']); | ||
173 | $this->assertEquals('http://host.tld/?kLHmZg', $link['guid']); | ||
174 | $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']); | ||
175 | $this->assertContains('Direct link', $link['description']); | ||
176 | $this->assertContains('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']); | ||
177 | } | ||
178 | |||
179 | /** | ||
180 | * Test buildData with hide dates settings. | ||
181 | */ | ||
182 | public function testBuildDataHideDates() | ||
183 | { | ||
184 | $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, null, false); | ||
185 | $feedBuilder->setLocale(self::$LOCALE); | ||
186 | $feedBuilder->setHideDates(true); | ||
187 | $data = $feedBuilder->buildData(); | ||
188 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); | ||
189 | $this->assertFalse($data['show_dates']); | ||
190 | |||
191 | // Show dates while logged in | ||
192 | $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, null, true); | ||
193 | $feedBuilder->setLocale(self::$LOCALE); | ||
194 | $feedBuilder->setHideDates(true); | ||
195 | $data = $feedBuilder->buildData(); | ||
196 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); | ||
197 | $this->assertTrue($data['show_dates']); | ||
198 | } | ||
199 | |||
200 | /** | ||
201 | * Test buildData with hide dates settings. | ||
202 | */ | ||
203 | public function testBuildDataPubsubhub() | ||
204 | { | ||
205 | $feedBuilder = new FeedBuilder(self::$linkDB, FeedBuilder::$FEED_ATOM, self::$serverInfo, null, false); | ||
206 | $feedBuilder->setLocale(self::$LOCALE); | ||
207 | $feedBuilder->setPubsubhubUrl('http://pubsubhub.io'); | ||
208 | $data = $feedBuilder->buildData(); | ||
209 | $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); | ||
210 | $this->assertEquals('http://pubsubhub.io', $data['pubsubhub_url']); | ||
211 | } | ||
212 | } | ||
diff --git a/tests/HttpUtils/GetHttpUrlTest.php b/tests/HttpUtils/GetHttpUrlTest.php index fd293505..ea53de5f 100644 --- a/tests/HttpUtils/GetHttpUrlTest.php +++ b/tests/HttpUtils/GetHttpUrlTest.php | |||
@@ -35,4 +35,31 @@ class GetHttpUrlTest extends PHPUnit_Framework_TestCase | |||
35 | $this->assertFalse($headers); | 35 | $this->assertFalse($headers); |
36 | $this->assertFalse($content); | 36 | $this->assertFalse($content); |
37 | } | 37 | } |
38 | |||
39 | /** | ||
40 | * Test getAbsoluteUrl with relative target URL. | ||
41 | */ | ||
42 | public function testGetAbsoluteUrlWithRelative() | ||
43 | { | ||
44 | $origin = 'http://non.existent/blabla/?test'; | ||
45 | $target = '/stuff.php'; | ||
46 | |||
47 | $expected = 'http://non.existent/stuff.php'; | ||
48 | $this->assertEquals($expected, getAbsoluteUrl($origin, $target)); | ||
49 | |||
50 | $target = 'stuff.php'; | ||
51 | $expected = 'http://non.existent/blabla/stuff.php'; | ||
52 | $this->assertEquals($expected, getAbsoluteUrl($origin, $target)); | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * Test getAbsoluteUrl with absolute target URL. | ||
57 | */ | ||
58 | public function testGetAbsoluteUrlWithAbsolute() | ||
59 | { | ||
60 | $origin = 'http://non.existent/blabla/?test'; | ||
61 | $target = 'http://other.url/stuff.php'; | ||
62 | |||
63 | $this->assertEquals($target, getAbsoluteUrl($origin, $target)); | ||
64 | } | ||
38 | } | 65 | } |
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index b6a273b3..b055fe91 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php | |||
@@ -17,8 +17,20 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
17 | { | 17 | { |
18 | // datastore to test write operations | 18 | // datastore to test write operations |
19 | protected static $testDatastore = 'sandbox/datastore.php'; | 19 | protected static $testDatastore = 'sandbox/datastore.php'; |
20 | |||
21 | /** | ||
22 | * @var ReferenceLinkDB instance. | ||
23 | */ | ||
20 | protected static $refDB = null; | 24 | protected static $refDB = null; |
25 | |||
26 | /** | ||
27 | * @var LinkDB public LinkDB instance. | ||
28 | */ | ||
21 | protected static $publicLinkDB = null; | 29 | protected static $publicLinkDB = null; |
30 | |||
31 | /** | ||
32 | * @var LinkDB private LinkDB instance. | ||
33 | */ | ||
22 | protected static $privateLinkDB = null; | 34 | protected static $privateLinkDB = null; |
23 | 35 | ||
24 | /** | 36 | /** |
@@ -326,6 +338,13 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
326 | $db = new LinkDB(self::$testDatastore, false, false, $redirector); | 338 | $db = new LinkDB(self::$testDatastore, false, false, $redirector); |
327 | foreach($db as $link) { | 339 | foreach($db as $link) { |
328 | $this->assertStringStartsWith($redirector, $link['real_url']); | 340 | $this->assertStringStartsWith($redirector, $link['real_url']); |
341 | $this->assertNotFalse(strpos($link['real_url'], urlencode('://'))); | ||
342 | } | ||
343 | |||
344 | $db = new LinkDB(self::$testDatastore, false, false, $redirector, false); | ||
345 | foreach($db as $link) { | ||
346 | $this->assertStringStartsWith($redirector, $link['real_url']); | ||
347 | $this->assertFalse(strpos($link['real_url'], urlencode('://'))); | ||
329 | } | 348 | } |
330 | } | 349 | } |
331 | 350 | ||
@@ -335,9 +354,10 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
335 | public function testFilterString() | 354 | public function testFilterString() |
336 | { | 355 | { |
337 | $tags = 'dev cartoon'; | 356 | $tags = 'dev cartoon'; |
357 | $request = array('searchtags' => $tags); | ||
338 | $this->assertEquals( | 358 | $this->assertEquals( |
339 | 2, | 359 | 2, |
340 | count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) | 360 | count(self::$privateLinkDB->filterSearch($request, true, false)) |
341 | ); | 361 | ); |
342 | } | 362 | } |
343 | 363 | ||
@@ -347,9 +367,10 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
347 | public function testFilterArray() | 367 | public function testFilterArray() |
348 | { | 368 | { |
349 | $tags = array('dev', 'cartoon'); | 369 | $tags = array('dev', 'cartoon'); |
370 | $request = array('searchtags' => $tags); | ||
350 | $this->assertEquals( | 371 | $this->assertEquals( |
351 | 2, | 372 | 2, |
352 | count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) | 373 | count(self::$privateLinkDB->filterSearch($request, true, false)) |
353 | ); | 374 | ); |
354 | } | 375 | } |
355 | 376 | ||
@@ -360,14 +381,48 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
360 | public function testHiddenTags() | 381 | public function testHiddenTags() |
361 | { | 382 | { |
362 | $tags = '.hidden'; | 383 | $tags = '.hidden'; |
384 | $request = array('searchtags' => $tags); | ||
363 | $this->assertEquals( | 385 | $this->assertEquals( |
364 | 1, | 386 | 1, |
365 | count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) | 387 | count(self::$privateLinkDB->filterSearch($request, true, false)) |
366 | ); | 388 | ); |
367 | 389 | ||
368 | $this->assertEquals( | 390 | $this->assertEquals( |
369 | 0, | 391 | 0, |
370 | count(self::$publicLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) | 392 | count(self::$publicLinkDB->filterSearch($request, true, false)) |
371 | ); | 393 | ); |
372 | } | 394 | } |
395 | |||
396 | /** | ||
397 | * Test filterHash() with a valid smallhash. | ||
398 | */ | ||
399 | public function testFilterHashValid() | ||
400 | { | ||
401 | $request = smallHash('20150310_114651'); | ||
402 | $this->assertEquals( | ||
403 | 1, | ||
404 | count(self::$publicLinkDB->filterHash($request)) | ||
405 | ); | ||
406 | } | ||
407 | |||
408 | /** | ||
409 | * Test filterHash() with an invalid smallhash. | ||
410 | * | ||
411 | * @expectedException LinkNotFoundException | ||
412 | */ | ||
413 | public function testFilterHashInValid1() | ||
414 | { | ||
415 | $request = 'blabla'; | ||
416 | self::$publicLinkDB->filterHash($request); | ||
417 | } | ||
418 | |||
419 | /** | ||
420 | * Test filterHash() with an empty smallhash. | ||
421 | * | ||
422 | * @expectedException LinkNotFoundException | ||
423 | */ | ||
424 | public function testFilterHashInValid() | ||
425 | { | ||
426 | self::$publicLinkDB->filterHash(''); | ||
427 | } | ||
373 | } | 428 | } |
diff --git a/tests/LinkFilterTest.php b/tests/LinkFilterTest.php index ef1cc10a..1620bb78 100644 --- a/tests/LinkFilterTest.php +++ b/tests/LinkFilterTest.php | |||
@@ -12,8 +12,6 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase | |||
12 | */ | 12 | */ |
13 | protected static $linkFilter; | 13 | protected static $linkFilter; |
14 | 14 | ||
15 | protected static $NB_LINKS_REFDB = 7; | ||
16 | |||
17 | /** | 15 | /** |
18 | * Instanciate linkFilter with ReferenceLinkDB data. | 16 | * Instanciate linkFilter with ReferenceLinkDB data. |
19 | */ | 17 | */ |
@@ -29,7 +27,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase | |||
29 | public function testFilter() | 27 | public function testFilter() |
30 | { | 28 | { |
31 | $this->assertEquals( | 29 | $this->assertEquals( |
32 | self::$NB_LINKS_REFDB, | 30 | ReferenceLinkDB::$NB_LINKS_TOTAL, |
33 | count(self::$linkFilter->filter('', '')) | 31 | count(self::$linkFilter->filter('', '')) |
34 | ); | 32 | ); |
35 | 33 | ||
@@ -40,12 +38,12 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase | |||
40 | ); | 38 | ); |
41 | 39 | ||
42 | $this->assertEquals( | 40 | $this->assertEquals( |
43 | self::$NB_LINKS_REFDB, | 41 | ReferenceLinkDB::$NB_LINKS_TOTAL, |
44 | count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, '')) | 42 | count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, '')) |
45 | ); | 43 | ); |
46 | 44 | ||
47 | $this->assertEquals( | 45 | $this->assertEquals( |
48 | self::$NB_LINKS_REFDB, | 46 | ReferenceLinkDB::$NB_LINKS_TOTAL, |
49 | count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '')) | 47 | count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '')) |
50 | ); | 48 | ); |
51 | } | 49 | } |
@@ -167,13 +165,12 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase | |||
167 | 165 | ||
168 | /** | 166 | /** |
169 | * No link for this hash | 167 | * No link for this hash |
168 | * | ||
169 | * @expectedException LinkNotFoundException | ||
170 | */ | 170 | */ |
171 | public function testFilterUnknownSmallHash() | 171 | public function testFilterUnknownSmallHash() |
172 | { | 172 | { |
173 | $this->assertEquals( | 173 | self::$linkFilter->filter(LinkFilter::$FILTER_HASH, 'Iblaah'); |
174 | 0, | ||
175 | count(self::$linkFilter->filter(LinkFilter::$FILTER_HASH, 'Iblaah')) | ||
176 | ); | ||
177 | } | 174 | } |
178 | 175 | ||
179 | /** | 176 | /** |
@@ -383,7 +380,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase | |||
383 | )) | 380 | )) |
384 | ); | 381 | ); |
385 | $this->assertEquals( | 382 | $this->assertEquals( |
386 | self::$NB_LINKS_REFDB, | 383 | ReferenceLinkDB::$NB_LINKS_TOTAL, |
387 | count(self::$linkFilter->filter( | 384 | count(self::$linkFilter->filter( |
388 | LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT, | 385 | LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT, |
389 | '' | 386 | '' |
diff --git a/tests/LinkUtilsTest.php b/tests/LinkUtilsTest.php index c2257590..d1b022fd 100644 --- a/tests/LinkUtilsTest.php +++ b/tests/LinkUtilsTest.php | |||
@@ -15,6 +15,8 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
15 | $title = 'Read me please.'; | 15 | $title = 'Read me please.'; |
16 | $html = '<html><meta>stuff</meta><title>'. $title .'</title></html>'; | 16 | $html = '<html><meta>stuff</meta><title>'. $title .'</title></html>'; |
17 | $this->assertEquals($title, html_extract_title($html)); | 17 | $this->assertEquals($title, html_extract_title($html)); |
18 | $html = '<html><title>'. $title .'</title>blabla<title>another</title></html>'; | ||
19 | $this->assertEquals($title, html_extract_title($html)); | ||
18 | } | 20 | } |
19 | 21 | ||
20 | /** | 22 | /** |
@@ -82,4 +84,13 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
82 | $html = '<html><meta>stuff</meta><meta charset=""/></html>'; | 84 | $html = '<html><meta>stuff</meta><meta charset=""/></html>'; |
83 | $this->assertFalse(html_extract_charset($html)); | 85 | $this->assertFalse(html_extract_charset($html)); |
84 | } | 86 | } |
87 | |||
88 | /** | ||
89 | * Test count_private. | ||
90 | */ | ||
91 | public function testCountPrivateLinks() | ||
92 | { | ||
93 | $refDB = new ReferenceLinkDB(); | ||
94 | $this->assertEquals($refDB->countPrivateLinks(), count_private($refDB->getLinks())); | ||
95 | } | ||
85 | } | 96 | } |
diff --git a/tests/NetscapeBookmarkUtilsTest.php b/tests/NetscapeBookmarkUtilsTest.php new file mode 100644 index 00000000..41e6d84c --- /dev/null +++ b/tests/NetscapeBookmarkUtilsTest.php | |||
@@ -0,0 +1,134 @@ | |||
1 | <?php | ||
2 | |||
3 | require_once 'application/NetscapeBookmarkUtils.php'; | ||
4 | |||
5 | /** | ||
6 | * Netscape bookmark import and export | ||
7 | */ | ||
8 | class NetscapeBookmarkUtilsTest extends PHPUnit_Framework_TestCase | ||
9 | { | ||
10 | /** | ||
11 | * @var string datastore to test write operations | ||
12 | */ | ||
13 | protected static $testDatastore = 'sandbox/datastore.php'; | ||
14 | |||
15 | /** | ||
16 | * @var ReferenceLinkDB instance. | ||
17 | */ | ||
18 | protected static $refDb = null; | ||
19 | |||
20 | /** | ||
21 | * @var LinkDB private LinkDB instance. | ||
22 | */ | ||
23 | protected static $linkDb = null; | ||
24 | |||
25 | /** | ||
26 | * Instantiate reference data | ||
27 | */ | ||
28 | public static function setUpBeforeClass() | ||
29 | { | ||
30 | self::$refDb = new ReferenceLinkDB(); | ||
31 | self::$refDb->write(self::$testDatastore); | ||
32 | self::$linkDb = new LinkDB(self::$testDatastore, true, false); | ||
33 | } | ||
34 | |||
35 | /** | ||
36 | * Attempt to export an invalid link selection | ||
37 | * @expectedException Exception | ||
38 | * @expectedExceptionMessageRegExp /Invalid export selection/ | ||
39 | */ | ||
40 | public function testFilterAndFormatInvalid() | ||
41 | { | ||
42 | NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'derp', false, ''); | ||
43 | } | ||
44 | |||
45 | /** | ||
46 | * Prepare all links for export | ||
47 | */ | ||
48 | public function testFilterAndFormatAll() | ||
49 | { | ||
50 | $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'all', false, ''); | ||
51 | $this->assertEquals(self::$refDb->countLinks(), sizeof($links)); | ||
52 | foreach ($links as $link) { | ||
53 | $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); | ||
54 | $this->assertEquals( | ||
55 | $date->getTimestamp(), | ||
56 | $link['timestamp'] | ||
57 | ); | ||
58 | $this->assertEquals( | ||
59 | str_replace(' ', ',', $link['tags']), | ||
60 | $link['taglist'] | ||
61 | ); | ||
62 | } | ||
63 | } | ||
64 | |||
65 | /** | ||
66 | * Prepare private links for export | ||
67 | */ | ||
68 | public function testFilterAndFormatPrivate() | ||
69 | { | ||
70 | $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'private', false, ''); | ||
71 | $this->assertEquals(self::$refDb->countPrivateLinks(), sizeof($links)); | ||
72 | foreach ($links as $link) { | ||
73 | $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); | ||
74 | $this->assertEquals( | ||
75 | $date->getTimestamp(), | ||
76 | $link['timestamp'] | ||
77 | ); | ||
78 | $this->assertEquals( | ||
79 | str_replace(' ', ',', $link['tags']), | ||
80 | $link['taglist'] | ||
81 | ); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | /** | ||
86 | * Prepare public links for export | ||
87 | */ | ||
88 | public function testFilterAndFormatPublic() | ||
89 | { | ||
90 | $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, ''); | ||
91 | $this->assertEquals(self::$refDb->countPublicLinks(), sizeof($links)); | ||
92 | foreach ($links as $link) { | ||
93 | $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); | ||
94 | $this->assertEquals( | ||
95 | $date->getTimestamp(), | ||
96 | $link['timestamp'] | ||
97 | ); | ||
98 | $this->assertEquals( | ||
99 | str_replace(' ', ',', $link['tags']), | ||
100 | $link['taglist'] | ||
101 | ); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | /** | ||
106 | * Do not prepend notes with the Shaarli index's URL | ||
107 | */ | ||
108 | public function testFilterAndFormatDoNotPrependNoteUrl() | ||
109 | { | ||
110 | $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, ''); | ||
111 | $this->assertEquals( | ||
112 | '?WDWyig', | ||
113 | $links[0]['url'] | ||
114 | ); | ||
115 | } | ||
116 | |||
117 | /** | ||
118 | * Prepend notes with the Shaarli index's URL | ||
119 | */ | ||
120 | public function testFilterAndFormatPrependNoteUrl() | ||
121 | { | ||
122 | $indexUrl = 'http://localhost:7469/shaarli/'; | ||
123 | $links = NetscapeBookmarkUtils::filterAndFormat( | ||
124 | self::$linkDb, | ||
125 | 'public', | ||
126 | true, | ||
127 | $indexUrl | ||
128 | ); | ||
129 | $this->assertEquals( | ||
130 | $indexUrl . '?WDWyig', | ||
131 | $links[0]['url'] | ||
132 | ); | ||
133 | } | ||
134 | } | ||
diff --git a/tests/TimeZoneTest.php b/tests/TimeZoneTest.php index b219030a..2976d116 100644 --- a/tests/TimeZoneTest.php +++ b/tests/TimeZoneTest.php | |||
@@ -67,7 +67,6 @@ class TimeZoneTest extends PHPUnit_Framework_TestCase | |||
67 | { | 67 | { |
68 | $this->assertTrue(isTimeZoneValid('America', 'Argentina/Ushuaia')); | 68 | $this->assertTrue(isTimeZoneValid('America', 'Argentina/Ushuaia')); |
69 | $this->assertTrue(isTimeZoneValid('Europe', 'Oslo')); | 69 | $this->assertTrue(isTimeZoneValid('Europe', 'Oslo')); |
70 | $this->assertTrue(isTimeZoneValid('UTC', 'UTC')); | ||
71 | } | 70 | } |
72 | 71 | ||
73 | /** | 72 | /** |
@@ -78,5 +77,6 @@ class TimeZoneTest extends PHPUnit_Framework_TestCase | |||
78 | $this->assertFalse(isTimeZoneValid('CEST', 'CEST')); | 77 | $this->assertFalse(isTimeZoneValid('CEST', 'CEST')); |
79 | $this->assertFalse(isTimeZoneValid('Europe', 'Atlantis')); | 78 | $this->assertFalse(isTimeZoneValid('Europe', 'Atlantis')); |
80 | $this->assertFalse(isTimeZoneValid('Middle_Earth', 'Moria')); | 79 | $this->assertFalse(isTimeZoneValid('Middle_Earth', 'Moria')); |
80 | $this->assertFalse(isTimeZoneValid('UTC', 'UTC')); | ||
81 | } | 81 | } |
82 | } | 82 | } |
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index d865066b..a29d9067 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php | |||
@@ -236,9 +236,9 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
236 | $refDB = new ReferenceLinkDB(); | 236 | $refDB = new ReferenceLinkDB(); |
237 | $refDB->write(self::$testDatastore); | 237 | $refDB->write(self::$testDatastore); |
238 | $linkDB = new LinkDB(self::$testDatastore, true, false); | 238 | $linkDB = new LinkDB(self::$testDatastore, true, false); |
239 | $this->assertEmpty($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude')); | 239 | $this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); |
240 | $updater = new Updater(array(), self::$configFields, $linkDB, true); | 240 | $updater = new Updater(array(), self::$configFields, $linkDB, true); |
241 | $updater->updateMethodRenameDashTags(); | 241 | $updater->updateMethodRenameDashTags(); |
242 | $this->assertNotEmpty($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude')); | 242 | $this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); |
243 | } | 243 | } |
244 | } | 244 | } |
diff --git a/tests/Url/UrlTest.php b/tests/Url/UrlTest.php index 425327ed..ce82265e 100644 --- a/tests/Url/UrlTest.php +++ b/tests/Url/UrlTest.php | |||
@@ -128,6 +128,13 @@ class UrlTest extends PHPUnit_Framework_TestCase | |||
128 | self::$baseUrl.'?my=stuff&is=kept#again', | 128 | self::$baseUrl.'?my=stuff&is=kept#again', |
129 | $url->cleanup() | 129 | $url->cleanup() |
130 | ); | 130 | ); |
131 | |||
132 | // test firefox reader url | ||
133 | $url = new Url( | ||
134 | 'about://reader?url=' . urlencode(self::$baseUrl .'?my=stuff&is=kept') | ||
135 | ); | ||
136 | $this->assertEquals(self::$baseUrl.'?my=stuff&is=kept', $url->cleanup()); | ||
137 | |||
131 | } | 138 | } |
132 | 139 | ||
133 | /** | 140 | /** |
@@ -174,4 +181,19 @@ class UrlTest extends PHPUnit_Framework_TestCase | |||
174 | $url = new Url('ftp://save.tld/mysave'); | 181 | $url = new Url('ftp://save.tld/mysave'); |
175 | $this->assertFalse($url->isHttp()); | 182 | $this->assertFalse($url->isHttp()); |
176 | } | 183 | } |
184 | |||
185 | /** | ||
186 | * Test IndToAscii. | ||
187 | */ | ||
188 | function testIndToAscii() | ||
189 | { | ||
190 | $ind = 'http://www.académie-française.fr/'; | ||
191 | $expected = 'http://www.xn--acadmie-franaise-npb1a.fr/'; | ||
192 | $url = new Url($ind); | ||
193 | $this->assertEquals($expected, $url->idnToAscii()); | ||
194 | |||
195 | $notInd = 'http://www.academie-francaise.fr/'; | ||
196 | $url = new Url($notInd); | ||
197 | $this->assertEquals($notInd, $url->idnToAscii()); | ||
198 | } | ||
177 | } | 199 | } |
diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php index 8e1a128a..fa7e1d52 100644 --- a/tests/plugins/PluginMarkdownTest.php +++ b/tests/plugins/PluginMarkdownTest.php | |||
@@ -102,7 +102,8 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase | |||
102 | /** | 102 | /** |
103 | * Test sanitize_html(). | 103 | * Test sanitize_html(). |
104 | */ | 104 | */ |
105 | function testSanitizeHtml() { | 105 | function testSanitizeHtml() |
106 | { | ||
106 | $input = '< script src="js.js"/>'; | 107 | $input = '< script src="js.js"/>'; |
107 | $input .= '< script attr>alert(\'xss\');</script>'; | 108 | $input .= '< script attr>alert(\'xss\');</script>'; |
108 | $input .= '<style> * { display: none }</style>'; | 109 | $input .= '<style> * { display: none }</style>'; |
@@ -114,4 +115,38 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase | |||
114 | $input = escape($input); | 115 | $input = escape($input); |
115 | $this->assertEquals($input, sanitize_html($input)); | 116 | $this->assertEquals($input, sanitize_html($input)); |
116 | } | 117 | } |
118 | |||
119 | /** | ||
120 | * Test the no markdown tag. | ||
121 | */ | ||
122 | function testNoMarkdownTag() | ||
123 | { | ||
124 | $str = 'All _work_ and `no play` makes Jack a *dull* boy.'; | ||
125 | $data = array( | ||
126 | 'links' => array(array( | ||
127 | 'description' => $str, | ||
128 | 'tags' => NO_MD_TAG | ||
129 | )) | ||
130 | ); | ||
131 | |||
132 | $data = hook_markdown_render_linklist($data); | ||
133 | $this->assertEquals($str, $data['links'][0]['description']); | ||
134 | |||
135 | $data = array( | ||
136 | // Columns data | ||
137 | 'cols' => array( | ||
138 | // First, second, third. | ||
139 | 0 => array( | ||
140 | // nth link | ||
141 | 0 => array( | ||
142 | 'formatedDescription' => $str, | ||
143 | 'tags' => NO_MD_TAG | ||
144 | ), | ||
145 | ), | ||
146 | ), | ||
147 | ); | ||
148 | |||
149 | $data = hook_markdown_render_daily($data); | ||
150 | $this->assertEquals($str, $data['cols'][0][0]['formatedDescription']); | ||
151 | } | ||
117 | } | 152 | } |
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php index 61faef05..dc4f5dfa 100644 --- a/tests/utils/ReferenceLinkDB.php +++ b/tests/utils/ReferenceLinkDB.php | |||
@@ -4,6 +4,8 @@ | |||
4 | */ | 4 | */ |
5 | class ReferenceLinkDB | 5 | class ReferenceLinkDB |
6 | { | 6 | { |
7 | public static $NB_LINKS_TOTAL = 7; | ||
8 | |||
7 | private $_links = array(); | 9 | private $_links = array(); |
8 | private $_publicCount = 0; | 10 | private $_publicCount = 0; |
9 | private $_privateCount = 0; | 11 | private $_privateCount = 0; |
@@ -14,6 +16,15 @@ class ReferenceLinkDB | |||
14 | function __construct() | 16 | function __construct() |
15 | { | 17 | { |
16 | $this->addLink( | 18 | $this->addLink( |
19 | 'Link title: @website', | ||
20 | '?WDWyig', | ||
21 | 'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this.', | ||
22 | 0, | ||
23 | '20150310_114651', | ||
24 | 'stuff' | ||
25 | ); | ||
26 | |||
27 | $this->addLink( | ||
17 | 'Free as in Freedom 2.0 @website', | 28 | 'Free as in Freedom 2.0 @website', |
18 | 'https://static.fsf.org/nosvn/faif-2.0.pdf', | 29 | 'https://static.fsf.org/nosvn/faif-2.0.pdf', |
19 | 'Richard Stallman and the Free Software Revolution. Read this.', | 30 | 'Richard Stallman and the Free Software Revolution. Read this.', |
@@ -23,15 +34,6 @@ class ReferenceLinkDB | |||
23 | ); | 34 | ); |
24 | 35 | ||
25 | $this->addLink( | 36 | $this->addLink( |
26 | 'Link title: @website', | ||
27 | 'local', | ||
28 | 'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this.', | ||
29 | 0, | ||
30 | '20150310_114651', | ||
31 | 'stuff' | ||
32 | ); | ||
33 | |||
34 | $this->addLink( | ||
35 | 'MediaGoblin', | 37 | 'MediaGoblin', |
36 | 'http://mediagoblin.org/', | 38 | 'http://mediagoblin.org/', |
37 | 'A free software media publishing platform', | 39 | 'A free software media publishing platform', |