aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/bookmark/LinkUtilsTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-13 12:05:08 +0200
committerArthurHoaro <arthur@hoa.ro>2020-10-13 12:05:08 +0200
commitb6f678a5a1d15acf284ebcec16c905e976671ce1 (patch)
tree33c7da831482ed79c44896ef19c73c72ada84f2e /tests/bookmark/LinkUtilsTest.php
parentb14687036b9b800681197f51fdc47e62f0c88e2e (diff)
parent1c1520b6b98ab20201bfe15577782a52320339df (diff)
downloadShaarli-b6f678a5a1d15acf284ebcec16c905e976671ce1.tar.gz
Shaarli-b6f678a5a1d15acf284ebcec16c905e976671ce1.tar.zst
Shaarli-b6f678a5a1d15acf284ebcec16c905e976671ce1.zip
Merge branch 'v0.12' into latest
Diffstat (limited to 'tests/bookmark/LinkUtilsTest.php')
-rw-r--r--tests/bookmark/LinkUtilsTest.php48
1 files changed, 25 insertions, 23 deletions
diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php
index 78cb8f2a..ef00b92f 100644
--- a/tests/bookmark/LinkUtilsTest.php
+++ b/tests/bookmark/LinkUtilsTest.php
@@ -2,9 +2,7 @@
2 2
3namespace Shaarli\Bookmark; 3namespace Shaarli\Bookmark;
4 4
5use PHPUnit\Framework\TestCase; 5use Shaarli\TestCase;
6use ReferenceLinkDB;
7use Shaarli\Config\ConfigManager;
8 6
9require_once 'tests/utils/CurlUtils.php'; 7require_once 'tests/utils/CurlUtils.php';
10 8
@@ -45,6 +43,19 @@ class LinkUtilsTest extends TestCase
45 } 43 }
46 44
47 /** 45 /**
46 * Test headers_extract_charset() when the charset is found with odd quotes.
47 */
48 public function testHeadersExtractExistentCharsetWithQuotes()
49 {
50 $charset = 'x-MacCroatian';
51 $headers = 'text/html; charset="' . $charset . '"otherstuff="test"';
52 $this->assertEquals(strtolower($charset), header_extract_charset($headers));
53
54 $headers = 'text/html; charset=\'' . $charset . '\'otherstuff="test"';
55 $this->assertEquals(strtolower($charset), header_extract_charset($headers));
56 }
57
58 /**
48 * Test headers_extract_charset() when the charset is not found. 59 * Test headers_extract_charset() when the charset is not found.
49 */ 60 */
50 public function testHeadersExtractNonExistentCharset() 61 public function testHeadersExtractNonExistentCharset()
@@ -389,15 +400,6 @@ class LinkUtilsTest extends TestCase
389 } 400 }
390 401
391 /** 402 /**
392 * Test count_private.
393 */
394 public function testCountPrivateLinks()
395 {
396 $refDB = new ReferenceLinkDB();
397 $this->assertEquals($refDB->countPrivateLinks(), count_private($refDB->getLinks()));
398 }
399
400 /**
401 * Test text2clickable. 403 * Test text2clickable.
402 */ 404 */
403 public function testText2clickable() 405 public function testText2clickable()
@@ -448,13 +450,13 @@ class LinkUtilsTest extends TestCase
448 カタカナ #カタカナ」カタカナ\n'; 450 カタカナ #カタカナ」カタカナ\n';
449 $autolinkedDescription = hashtag_autolink($rawDescription, $index); 451 $autolinkedDescription = hashtag_autolink($rawDescription, $index);
450 452
451 $this->assertContains($this->getHashtagLink('hashtag', $index), $autolinkedDescription); 453 $this->assertContainsPolyfill($this->getHashtagLink('hashtag', $index), $autolinkedDescription);
452 $this->assertNotContains(' #hashtag', $autolinkedDescription); 454 $this->assertNotContainsPolyfill(' #hashtag', $autolinkedDescription);
453 $this->assertNotContains('>#nothashtag', $autolinkedDescription); 455 $this->assertNotContainsPolyfill('>#nothashtag', $autolinkedDescription);
454 $this->assertContains($this->getHashtagLink('ашок', $index), $autolinkedDescription); 456 $this->assertContainsPolyfill($this->getHashtagLink('ашок', $index), $autolinkedDescription);
455 $this->assertContains($this->getHashtagLink('カタカナ', $index), $autolinkedDescription); 457 $this->assertContainsPolyfill($this->getHashtagLink('カタカナ', $index), $autolinkedDescription);
456 $this->assertContains($this->getHashtagLink('hashtag_hashtag', $index), $autolinkedDescription); 458 $this->assertContainsPolyfill($this->getHashtagLink('hashtag_hashtag', $index), $autolinkedDescription);
457 $this->assertNotContains($this->getHashtagLink('hashtag-nothashtag', $index), $autolinkedDescription); 459 $this->assertNotContainsPolyfill($this->getHashtagLink('hashtag-nothashtag', $index), $autolinkedDescription);
458 } 460 }
459 461
460 /** 462 /**
@@ -465,9 +467,9 @@ class LinkUtilsTest extends TestCase
465 $rawDescription = 'blabla #hashtag x#nothashtag'; 467 $rawDescription = 'blabla #hashtag x#nothashtag';
466 $autolinkedDescription = hashtag_autolink($rawDescription); 468 $autolinkedDescription = hashtag_autolink($rawDescription);
467 469
468 $this->assertContains($this->getHashtagLink('hashtag'), $autolinkedDescription); 470 $this->assertContainsPolyfill($this->getHashtagLink('hashtag'), $autolinkedDescription);
469 $this->assertNotContains(' #hashtag', $autolinkedDescription); 471 $this->assertNotContainsPolyfill(' #hashtag', $autolinkedDescription);
470 $this->assertNotContains('>#nothashtag', $autolinkedDescription); 472 $this->assertNotContainsPolyfill('>#nothashtag', $autolinkedDescription);
471 } 473 }
472 474
473 /** 475 /**
@@ -500,7 +502,7 @@ class LinkUtilsTest extends TestCase
500 */ 502 */
501 private function getHashtagLink($hashtag, $index = '') 503 private function getHashtagLink($hashtag, $index = '')
502 { 504 {
503 $hashtagLink = '<a href="' . $index . '?addtag=$1" title="Hashtag $1">#$1</a>'; 505 $hashtagLink = '<a href="' . $index . './add-tag/$1" title="Hashtag $1">#$1</a>';
504 return str_replace('$1', $hashtag, $hashtagLink); 506 return str_replace('$1', $hashtag, $hashtagLink);
505 } 507 }
506} 508}