diff options
Diffstat (limited to 'tests/bookmark')
-rw-r--r-- | tests/bookmark/LinkDBTest.php | 32 | ||||
-rw-r--r-- | tests/bookmark/LinkUtilsTest.php | 61 |
2 files changed, 27 insertions, 66 deletions
diff --git a/tests/bookmark/LinkDBTest.php b/tests/bookmark/LinkDBTest.php index ff5c0b97..2990a6b5 100644 --- a/tests/bookmark/LinkDBTest.php +++ b/tests/bookmark/LinkDBTest.php | |||
@@ -362,36 +362,6 @@ class LinkDBTest extends \PHPUnit\Framework\TestCase | |||
362 | } | 362 | } |
363 | 363 | ||
364 | /** | 364 | /** |
365 | * Test real_url without redirector. | ||
366 | */ | ||
367 | public function testLinkRealUrlWithoutRedirector() | ||
368 | { | ||
369 | $db = new LinkDB(self::$testDatastore, false, false); | ||
370 | foreach ($db as $link) { | ||
371 | $this->assertEquals($link['url'], $link['real_url']); | ||
372 | } | ||
373 | } | ||
374 | |||
375 | /** | ||
376 | * Test real_url with redirector. | ||
377 | */ | ||
378 | public function testLinkRealUrlWithRedirector() | ||
379 | { | ||
380 | $redirector = 'http://redirector.to?'; | ||
381 | $db = new LinkDB(self::$testDatastore, false, false, $redirector); | ||
382 | foreach ($db as $link) { | ||
383 | $this->assertStringStartsWith($redirector, $link['real_url']); | ||
384 | $this->assertNotFalse(strpos($link['real_url'], urlencode('://'))); | ||
385 | } | ||
386 | |||
387 | $db = new LinkDB(self::$testDatastore, false, false, $redirector, false); | ||
388 | foreach ($db as $link) { | ||
389 | $this->assertStringStartsWith($redirector, $link['real_url']); | ||
390 | $this->assertFalse(strpos($link['real_url'], urlencode('://'))); | ||
391 | } | ||
392 | } | ||
393 | |||
394 | /** | ||
395 | * Test filter with string. | 365 | * Test filter with string. |
396 | */ | 366 | */ |
397 | public function testFilterString() | 367 | public function testFilterString() |
@@ -516,7 +486,7 @@ class LinkDBTest extends \PHPUnit\Framework\TestCase | |||
516 | public function testRenameTagCaseSensitive() | 486 | public function testRenameTagCaseSensitive() |
517 | { | 487 | { |
518 | self::$refDB->write(self::$testDatastore); | 488 | self::$refDB->write(self::$testDatastore); |
519 | $linkDB = new LinkDB(self::$testDatastore, true, false, ''); | 489 | $linkDB = new LinkDB(self::$testDatastore, true, false); |
520 | 490 | ||
521 | $res = $linkDB->renameTag('sTuff', 'Taz'); | 491 | $res = $linkDB->renameTag('sTuff', 'Taz'); |
522 | $this->assertEquals(1, count($res)); | 492 | $this->assertEquals(1, count($res)); |
diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php index 1b8688e6..25fb3043 100644 --- a/tests/bookmark/LinkUtilsTest.php +++ b/tests/bookmark/LinkUtilsTest.php | |||
@@ -216,56 +216,27 @@ class LinkUtilsTest extends \PHPUnit\Framework\TestCase | |||
216 | } | 216 | } |
217 | 217 | ||
218 | /** | 218 | /** |
219 | * Test text2clickable without a redirector being set. | 219 | * Test text2clickable. |
220 | */ | 220 | */ |
221 | public function testText2clickableWithoutRedirector() | 221 | public function testText2clickable() |
222 | { | 222 | { |
223 | $text = 'stuff http://hello.there/is=someone#here otherstuff'; | 223 | $text = 'stuff http://hello.there/is=someone#here otherstuff'; |
224 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here">' | 224 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here">' |
225 | . 'http://hello.there/is=someone#here</a> otherstuff'; | 225 | . 'http://hello.there/is=someone#here</a> otherstuff'; |
226 | $processedText = text2clickable($text, ''); | 226 | $processedText = text2clickable($text); |
227 | $this->assertEquals($expectedText, $processedText); | 227 | $this->assertEquals($expectedText, $processedText); |
228 | 228 | ||
229 | $text = 'stuff http://hello.there/is=someone#here(please) otherstuff'; | 229 | $text = 'stuff http://hello.there/is=someone#here(please) otherstuff'; |
230 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">' | 230 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">' |
231 | . 'http://hello.there/is=someone#here(please)</a> otherstuff'; | 231 | . 'http://hello.there/is=someone#here(please)</a> otherstuff'; |
232 | $processedText = text2clickable($text, ''); | 232 | $processedText = text2clickable($text); |
233 | $this->assertEquals($expectedText, $processedText); | 233 | $this->assertEquals($expectedText, $processedText); |
234 | 234 | ||
235 | $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff'; | 235 | $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff'; |
236 | $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff'; | ||
236 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">' | 237 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">' |
237 | . 'http://hello.there/is=someone#here(please)&no</a> otherstuff'; | 238 | . 'http://hello.there/is=someone#here(please)&no</a> otherstuff'; |
238 | $processedText = text2clickable($text, ''); | 239 | $processedText = text2clickable($text); |
239 | $this->assertEquals($expectedText, $processedText); | ||
240 | } | ||
241 | |||
242 | /** | ||
243 | * Test text2clickable with a redirector set. | ||
244 | */ | ||
245 | public function testText2clickableWithRedirector() | ||
246 | { | ||
247 | $text = 'stuff http://hello.there/is=someone#here otherstuff'; | ||
248 | $redirector = 'http://redirector.to'; | ||
249 | $expectedText = 'stuff <a href="' . | ||
250 | $redirector . | ||
251 | urlencode('http://hello.there/is=someone#here') . | ||
252 | '">http://hello.there/is=someone#here</a> otherstuff'; | ||
253 | $processedText = text2clickable($text, $redirector); | ||
254 | $this->assertEquals($expectedText, $processedText); | ||
255 | } | ||
256 | |||
257 | /** | ||
258 | * Test text2clickable a redirector set and without URL encode. | ||
259 | */ | ||
260 | public function testText2clickableWithRedirectorDontEncode() | ||
261 | { | ||
262 | $text = 'stuff http://hello.there/?is=someone&or=something#here otherstuff'; | ||
263 | $redirector = 'http://redirector.to'; | ||
264 | $expectedText = 'stuff <a href="' . | ||
265 | $redirector . | ||
266 | 'http://hello.there/?is=someone&or=something#here' . | ||
267 | '">http://hello.there/?is=someone&or=something#here</a> otherstuff'; | ||
268 | $processedText = text2clickable($text, $redirector, false); | ||
269 | $this->assertEquals($expectedText, $processedText); | 240 | $this->assertEquals($expectedText, $processedText); |
270 | } | 241 | } |
271 | 242 | ||
@@ -318,6 +289,26 @@ class LinkUtilsTest extends \PHPUnit\Framework\TestCase | |||
318 | } | 289 | } |
319 | 290 | ||
320 | /** | 291 | /** |
292 | * Test is_note with note URLs. | ||
293 | */ | ||
294 | public function testIsNote() | ||
295 | { | ||
296 | $this->assertTrue(is_note('?')); | ||
297 | $this->assertTrue(is_note('?abcDEf')); | ||
298 | $this->assertTrue(is_note('?_abcDEf#123')); | ||
299 | } | ||
300 | |||
301 | /** | ||
302 | * Test is_note with non note URLs. | ||
303 | */ | ||
304 | public function testIsNotNote() | ||
305 | { | ||
306 | $this->assertFalse(is_note('')); | ||
307 | $this->assertFalse(is_note('nope')); | ||
308 | $this->assertFalse(is_note('https://github.com/shaarli/Shaarli/?hi')); | ||
309 | } | ||
310 | |||
311 | /** | ||
321 | * Util function to build an hashtag link. | 312 | * Util function to build an hashtag link. |
322 | * | 313 | * |
323 | * @param string $hashtag Hashtag name. | 314 | * @param string $hashtag Hashtag name. |