X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fbookmark%2FLinkUtilsTest.php;h=29941c8cd0ed32307faa0eea5bde9b99b3d77967;hb=458b6b9918ec27154dd45416947bb93bedb97109;hp=591976f2c30b1a293ec7f845972147a02c3420c4;hpb=3fb29fdda04ca86e04422d49b86cf646d53c4f9d;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php index 591976f2..29941c8c 100644 --- a/tests/bookmark/LinkUtilsTest.php +++ b/tests/bookmark/LinkUtilsTest.php @@ -2,9 +2,7 @@ namespace Shaarli\Bookmark; -use PHPUnit\Framework\TestCase; -use ReferenceLinkDB; -use Shaarli\Config\ConfigManager; +use Shaarli\TestCase; require_once 'tests/utils/CurlUtils.php'; @@ -44,6 +42,19 @@ class LinkUtilsTest extends TestCase $this->assertEquals(strtolower($charset), header_extract_charset($headers)); } + /** + * Test headers_extract_charset() when the charset is found with odd quotes. + */ + public function testHeadersExtractExistentCharsetWithQuotes() + { + $charset = 'x-MacCroatian'; + $headers = 'text/html; charset="' . $charset . '"otherstuff="test"'; + $this->assertEquals(strtolower($charset), header_extract_charset($headers)); + + $headers = 'text/html; charset=\'' . $charset . '\'otherstuff="test"'; + $this->assertEquals(strtolower($charset), header_extract_charset($headers)); + } + /** * Test headers_extract_charset() when the charset is not found. */ @@ -83,8 +94,78 @@ class LinkUtilsTest extends TestCase public function testHtmlExtractExistentNameTag() { $description = 'Bob and Alice share cookies.'; + + // Simple one line $html = 'stuff2'; $this->assertEquals($description, html_extract_tag('description', $html)); + + // Simple OpenGraph + $html = ''; + $this->assertEquals($description, html_extract_tag('description', $html)); + + // Simple reversed OpenGraph + $html = ''; + $this->assertEquals($description, html_extract_tag('description', $html)); + + // ItemProp OpenGraph + $html = ''; + $this->assertEquals($description, html_extract_tag('description', $html)); + + // OpenGraph without quotes + $html = ''; + $this->assertEquals($description, html_extract_tag('description', $html)); + + // OpenGraph reversed without quotes + $html = ''; + $this->assertEquals($description, html_extract_tag('description', $html)); + + // OpenGraph with noise + $html = ''; + $this->assertEquals($description, html_extract_tag('description', $html)); + + // OpenGraph reversed with noise + $html = ''; + $this->assertEquals($description, html_extract_tag('description', $html)); + + // OpenGraph multiple properties start + $html = ''; + $this->assertEquals($description, html_extract_tag('description', $html)); + + // OpenGraph multiple properties end + $html = ''; + $this->assertEquals($description, html_extract_tag('description', $html)); + + // OpenGraph multiple properties both end + $html = ''; + $this->assertEquals($description, html_extract_tag('description', $html)); + + // OpenGraph multiple properties both end with noise + $html = ''; + $this->assertEquals($description, html_extract_tag('description', $html)); + + // OpenGraph reversed multiple properties start + $html = ''; + $this->assertEquals($description, html_extract_tag('description', $html)); + + // OpenGraph reversed multiple properties end + $html = ''; + $this->assertEquals($description, html_extract_tag('description', $html)); + + // OpenGraph reversed multiple properties both end + $html = ''; + $this->assertEquals($description, html_extract_tag('description', $html)); + + // OpenGraph reversed multiple properties both end with noise + $html = ''; + $this->assertEquals($description, html_extract_tag('description', $html)); + + // Suggestion from #1375 + $html = ''; + $this->assertEquals($description, html_extract_tag('description', $html)); } /** @@ -94,6 +175,25 @@ class LinkUtilsTest extends TestCase { $html = 'stuff2'; $this->assertFalse(html_extract_tag('description', $html)); + + // Partial meta tag + $html = ''; + $this->assertFalse(html_extract_tag('description', $html)); + + $html = ''; + $this->assertFalse(html_extract_tag('description', $html)); + + $html = ''; + $this->assertFalse(html_extract_tag('description', $html)); + + $html = ''; + $this->assertFalse(html_extract_tag('description', $html)); + + $html = ''; + $this->assertFalse(html_extract_tag('description', $html)); + + $html = ''; + $this->assertFalse(html_extract_tag('description', $html)); } /** @@ -439,13 +539,13 @@ class LinkUtilsTest extends TestCase カタカナ #カタカナ」カタカナ\n'; $autolinkedDescription = hashtag_autolink($rawDescription, $index); - $this->assertContains($this->getHashtagLink('hashtag', $index), $autolinkedDescription); - $this->assertNotContains(' #hashtag', $autolinkedDescription); - $this->assertNotContains('>#nothashtag', $autolinkedDescription); - $this->assertContains($this->getHashtagLink('ашок', $index), $autolinkedDescription); - $this->assertContains($this->getHashtagLink('カタカナ', $index), $autolinkedDescription); - $this->assertContains($this->getHashtagLink('hashtag_hashtag', $index), $autolinkedDescription); - $this->assertNotContains($this->getHashtagLink('hashtag-nothashtag', $index), $autolinkedDescription); + $this->assertContainsPolyfill($this->getHashtagLink('hashtag', $index), $autolinkedDescription); + $this->assertNotContainsPolyfill(' #hashtag', $autolinkedDescription); + $this->assertNotContainsPolyfill('>#nothashtag', $autolinkedDescription); + $this->assertContainsPolyfill($this->getHashtagLink('ашок', $index), $autolinkedDescription); + $this->assertContainsPolyfill($this->getHashtagLink('カタカナ', $index), $autolinkedDescription); + $this->assertContainsPolyfill($this->getHashtagLink('hashtag_hashtag', $index), $autolinkedDescription); + $this->assertNotContainsPolyfill($this->getHashtagLink('hashtag-nothashtag', $index), $autolinkedDescription); } /** @@ -456,9 +556,9 @@ class LinkUtilsTest extends TestCase $rawDescription = 'blabla #hashtag x#nothashtag'; $autolinkedDescription = hashtag_autolink($rawDescription); - $this->assertContains($this->getHashtagLink('hashtag'), $autolinkedDescription); - $this->assertNotContains(' #hashtag', $autolinkedDescription); - $this->assertNotContains('>#nothashtag', $autolinkedDescription); + $this->assertContainsPolyfill($this->getHashtagLink('hashtag'), $autolinkedDescription); + $this->assertNotContainsPolyfill(' #hashtag', $autolinkedDescription); + $this->assertNotContainsPolyfill('>#nothashtag', $autolinkedDescription); } /** @@ -491,7 +591,7 @@ class LinkUtilsTest extends TestCase */ private function getHashtagLink($hashtag, $index = '') { - $hashtagLink = '#$1'; + $hashtagLink = '#$1'; return str_replace('$1', $hashtag, $hashtagLink); } }