diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/LinkDBTest.php | 4 | ||||
-rw-r--r-- | tests/LinkFilterTest.php | 26 | ||||
-rw-r--r-- | tests/LinkUtilsTest.php | 88 | ||||
-rw-r--r-- | tests/UtilsTest.php | 37 | ||||
-rw-r--r-- | tests/utils/ReferenceLinkDB.php | 14 |
5 files changed, 124 insertions, 45 deletions
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 9c64188f..46956f20 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php | |||
@@ -256,7 +256,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
256 | $link = self::$publicLinkDB->getLinkFromUrl('http://mediagoblin.org/'); | 256 | $link = self::$publicLinkDB->getLinkFromUrl('http://mediagoblin.org/'); |
257 | 257 | ||
258 | $this->assertNotEquals(false, $link); | 258 | $this->assertNotEquals(false, $link); |
259 | $this->assertEquals( | 259 | $this->assertContains( |
260 | 'A free software media publishing platform', | 260 | 'A free software media publishing platform', |
261 | $link['description'] | 261 | $link['description'] |
262 | ); | 262 | ); |
@@ -293,6 +293,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
293 | // The DB contains a link with `sTuff` and another one with `stuff` tag. | 293 | // The DB contains a link with `sTuff` and another one with `stuff` tag. |
294 | // They need to be grouped with the first case found (`sTuff`). | 294 | // They need to be grouped with the first case found (`sTuff`). |
295 | 'sTuff' => 2, | 295 | 'sTuff' => 2, |
296 | 'hashtag' => 2, | ||
296 | ), | 297 | ), |
297 | self::$publicLinkDB->allTags() | 298 | self::$publicLinkDB->allTags() |
298 | ); | 299 | ); |
@@ -315,6 +316,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
315 | 'sTuff' => 2, | 316 | 'sTuff' => 2, |
316 | '-exclude' => 1, | 317 | '-exclude' => 1, |
317 | '.hidden' => 1, | 318 | '.hidden' => 1, |
319 | 'hashtag' => 2, | ||
318 | ), | 320 | ), |
319 | self::$privateLinkDB->allTags() | 321 | self::$privateLinkDB->allTags() |
320 | ); | 322 | ); |
diff --git a/tests/LinkFilterTest.php b/tests/LinkFilterTest.php index 1620bb78..7d45fc59 100644 --- a/tests/LinkFilterTest.php +++ b/tests/LinkFilterTest.php | |||
@@ -387,4 +387,30 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase | |||
387 | )) | 387 | )) |
388 | ); | 388 | ); |
389 | } | 389 | } |
390 | |||
391 | /** | ||
392 | * Filter links by #hashtag. | ||
393 | */ | ||
394 | public function testFilterByHashtag() | ||
395 | { | ||
396 | $hashtag = 'hashtag'; | ||
397 | $this->assertEquals( | ||
398 | 3, | ||
399 | count(self::$linkFilter->filter( | ||
400 | LinkFilter::$FILTER_TAG, | ||
401 | $hashtag | ||
402 | )) | ||
403 | ); | ||
404 | |||
405 | $hashtag = 'private'; | ||
406 | $this->assertEquals( | ||
407 | 1, | ||
408 | count(self::$linkFilter->filter( | ||
409 | LinkFilter::$FILTER_TAG, | ||
410 | $hashtag, | ||
411 | false, | ||
412 | true | ||
413 | )) | ||
414 | ); | ||
415 | } | ||
390 | } | 416 | } |
diff --git a/tests/LinkUtilsTest.php b/tests/LinkUtilsTest.php index d1b022fd..7c0d4b0b 100644 --- a/tests/LinkUtilsTest.php +++ b/tests/LinkUtilsTest.php | |||
@@ -93,4 +93,92 @@ class LinkUtilsTest extends PHPUnit_Framework_TestCase | |||
93 | $refDB = new ReferenceLinkDB(); | 93 | $refDB = new ReferenceLinkDB(); |
94 | $this->assertEquals($refDB->countPrivateLinks(), count_private($refDB->getLinks())); | 94 | $this->assertEquals($refDB->countPrivateLinks(), count_private($refDB->getLinks())); |
95 | } | 95 | } |
96 | |||
97 | /** | ||
98 | * Test text2clickable without a redirector being set. | ||
99 | */ | ||
100 | public function testText2clickableWithoutRedirector() | ||
101 | { | ||
102 | $text = 'stuff http://hello.there/is=someone#here otherstuff'; | ||
103 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here">http://hello.there/is=someone#here</a> otherstuff'; | ||
104 | $processedText = text2clickable($text, ''); | ||
105 | $this->assertEquals($expectedText, $processedText); | ||
106 | } | ||
107 | |||
108 | /** | ||
109 | * Test text2clickable a redirector set. | ||
110 | */ | ||
111 | public function testText2clickableWithRedirector() | ||
112 | { | ||
113 | $text = 'stuff http://hello.there/is=someone#here otherstuff'; | ||
114 | $redirector = 'http://redirector.to'; | ||
115 | $expectedText = 'stuff <a href="'. | ||
116 | $redirector . | ||
117 | urlencode('http://hello.there/is=someone#here') . | ||
118 | '">http://hello.there/is=someone#here</a> otherstuff'; | ||
119 | $processedText = text2clickable($text, $redirector); | ||
120 | $this->assertEquals($expectedText, $processedText); | ||
121 | } | ||
122 | |||
123 | /** | ||
124 | * Test testSpace2nbsp. | ||
125 | */ | ||
126 | public function testSpace2nbsp() | ||
127 | { | ||
128 | $text = ' Are you thrilled by flags ?'. PHP_EOL .' Really?'; | ||
129 | $expectedText = ' Are you thrilled by flags ?'. PHP_EOL .' Really?'; | ||
130 | $processedText = space2nbsp($text); | ||
131 | $this->assertEquals($expectedText, $processedText); | ||
132 | } | ||
133 | |||
134 | /** | ||
135 | * Test hashtags auto-link. | ||
136 | */ | ||
137 | public function testHashtagAutolink() | ||
138 | { | ||
139 | $index = 'http://domain.tld/'; | ||
140 | $rawDescription = '#hashtag\n | ||
141 | # nothashtag\n | ||
142 | test#nothashtag #hashtag \#nothashtag\n | ||
143 | test #hashtag #hashtag test #hashtag.test\n | ||
144 | #hashtag #hashtag-nothashtag #hashtag_hashtag\n | ||
145 | What is #ашок anyway?\n | ||
146 | カタカナ #カタカナ」カタカナ\n'; | ||
147 | $autolinkedDescription = hashtag_autolink($rawDescription, $index); | ||
148 | |||
149 | $this->assertContains($this->getHashtagLink('hashtag', $index), $autolinkedDescription); | ||
150 | $this->assertNotContains(' #hashtag', $autolinkedDescription); | ||
151 | $this->assertNotContains('>#nothashtag', $autolinkedDescription); | ||
152 | $this->assertContains($this->getHashtagLink('ашок', $index), $autolinkedDescription); | ||
153 | $this->assertContains($this->getHashtagLink('カタカナ', $index), $autolinkedDescription); | ||
154 | $this->assertContains($this->getHashtagLink('hashtag_hashtag', $index), $autolinkedDescription); | ||
155 | $this->assertNotContains($this->getHashtagLink('hashtag-nothashtag', $index), $autolinkedDescription); | ||
156 | } | ||
157 | |||
158 | /** | ||
159 | * Test hashtags auto-link without index URL. | ||
160 | */ | ||
161 | public function testHashtagAutolinkNoIndex() | ||
162 | { | ||
163 | $rawDescription = 'blabla #hashtag x#nothashtag'; | ||
164 | $autolinkedDescription = hashtag_autolink($rawDescription); | ||
165 | |||
166 | $this->assertContains($this->getHashtagLink('hashtag'), $autolinkedDescription); | ||
167 | $this->assertNotContains(' #hashtag', $autolinkedDescription); | ||
168 | $this->assertNotContains('>#nothashtag', $autolinkedDescription); | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * Util function to build an hashtag link. | ||
173 | * | ||
174 | * @param string $hashtag Hashtag name. | ||
175 | * @param string $index Index URL. | ||
176 | * | ||
177 | * @return string HTML hashtag link. | ||
178 | */ | ||
179 | private function getHashtagLink($hashtag, $index = '') | ||
180 | { | ||
181 | $hashtagLink = '<a href="'. $index .'?addtag=$1" title="Hashtag $1">#$1</a>'; | ||
182 | return str_replace('$1', $hashtag, $hashtagLink); | ||
183 | } | ||
96 | } | 184 | } |
diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 3073b5eb..6a7870c4 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php | |||
@@ -253,41 +253,4 @@ class UtilsTest extends PHPUnit_Framework_TestCase | |||
253 | is_session_id_valid('c0ZqcWF3VFE2NmJBdm1HMVQ0ZHJ3UmZPbTFsNGhkNHI=') | 253 | is_session_id_valid('c0ZqcWF3VFE2NmJBdm1HMVQ0ZHJ3UmZPbTFsNGhkNHI=') |
254 | ); | 254 | ); |
255 | } | 255 | } |
256 | |||
257 | /** | ||
258 | * Test text2clickable without a redirector being set. | ||
259 | */ | ||
260 | public function testText2clickableWithoutRedirector() | ||
261 | { | ||
262 | $text = 'stuff http://hello.there/is=someone#here otherstuff'; | ||
263 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here">http://hello.there/is=someone#here</a> otherstuff'; | ||
264 | $processedText = text2clickable($text, ''); | ||
265 | $this->assertEquals($expectedText, $processedText); | ||
266 | } | ||
267 | |||
268 | /** | ||
269 | * Test text2clickable a redirector set. | ||
270 | */ | ||
271 | public function testText2clickableWithRedirector() | ||
272 | { | ||
273 | $text = 'stuff http://hello.there/is=someone#here otherstuff'; | ||
274 | $redirector = 'http://redirector.to'; | ||
275 | $expectedText = 'stuff <a href="'. | ||
276 | $redirector . | ||
277 | urlencode('http://hello.there/is=someone#here') . | ||
278 | '">http://hello.there/is=someone#here</a> otherstuff'; | ||
279 | $processedText = text2clickable($text, $redirector); | ||
280 | $this->assertEquals($expectedText, $processedText); | ||
281 | } | ||
282 | |||
283 | /** | ||
284 | * Test testSpace2nbsp. | ||
285 | */ | ||
286 | public function testSpace2nbsp() | ||
287 | { | ||
288 | $text = ' Are you thrilled by flags ?'. PHP_EOL .' Really?'; | ||
289 | $expectedText = ' Are you thrilled by flags ?'. PHP_EOL .' Really?'; | ||
290 | $processedText = space2nbsp($text); | ||
291 | $this->assertEquals($expectedText, $processedText); | ||
292 | } | ||
293 | } | 256 | } |
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php index 46165b4d..fe16baac 100644 --- a/tests/utils/ReferenceLinkDB.php +++ b/tests/utils/ReferenceLinkDB.php | |||
@@ -18,7 +18,7 @@ class ReferenceLinkDB | |||
18 | $this->addLink( | 18 | $this->addLink( |
19 | 'Link title: @website', | 19 | 'Link title: @website', |
20 | '?WDWyig', | 20 | '?WDWyig', |
21 | 'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this.', | 21 | 'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this. #hashtag', |
22 | 0, | 22 | 0, |
23 | '20150310_114651', | 23 | '20150310_114651', |
24 | 'sTuff' | 24 | 'sTuff' |
@@ -27,25 +27,25 @@ class ReferenceLinkDB | |||
27 | $this->addLink( | 27 | $this->addLink( |
28 | 'Free as in Freedom 2.0 @website', | 28 | 'Free as in Freedom 2.0 @website', |
29 | 'https://static.fsf.org/nosvn/faif-2.0.pdf', | 29 | 'https://static.fsf.org/nosvn/faif-2.0.pdf', |
30 | 'Richard Stallman and the Free Software Revolution. Read this.', | 30 | 'Richard Stallman and the Free Software Revolution. Read this. #hashtag', |
31 | 0, | 31 | 0, |
32 | '20150310_114633', | 32 | '20150310_114633', |
33 | 'free gnu software stallman -exclude stuff' | 33 | 'free gnu software stallman -exclude stuff hashtag' |
34 | ); | 34 | ); |
35 | 35 | ||
36 | $this->addLink( | 36 | $this->addLink( |
37 | 'MediaGoblin', | 37 | 'MediaGoblin', |
38 | 'http://mediagoblin.org/', | 38 | 'http://mediagoblin.org/', |
39 | 'A free software media publishing platform', | 39 | 'A free software media publishing platform #hashtagOther', |
40 | 0, | 40 | 0, |
41 | '20130614_184135', | 41 | '20130614_184135', |
42 | 'gnu media web .hidden' | 42 | 'gnu media web .hidden hashtag' |
43 | ); | 43 | ); |
44 | 44 | ||
45 | $this->addLink( | 45 | $this->addLink( |
46 | 'w3c-markup-validator', | 46 | 'w3c-markup-validator', |
47 | 'https://dvcs.w3.org/hg/markup-validator/summary', | 47 | 'https://dvcs.w3.org/hg/markup-validator/summary', |
48 | 'Mercurial repository for the W3C Validator', | 48 | 'Mercurial repository for the W3C Validator #private', |
49 | 1, | 49 | 1, |
50 | '20141125_084734', | 50 | '20141125_084734', |
51 | 'css html w3c web Mercurial' | 51 | 'css html w3c web Mercurial' |
@@ -54,7 +54,7 @@ class ReferenceLinkDB | |||
54 | $this->addLink( | 54 | $this->addLink( |
55 | 'UserFriendly - Web Designer', | 55 | 'UserFriendly - Web Designer', |
56 | 'http://ars.userfriendly.org/cartoons/?id=20121206', | 56 | 'http://ars.userfriendly.org/cartoons/?id=20121206', |
57 | 'Naming conventions...', | 57 | 'Naming conventions... #private', |
58 | 0, | 58 | 0, |
59 | '20121206_142300', | 59 | '20121206_142300', |
60 | 'dev cartoon web' | 60 | 'dev cartoon web' |