X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fbookmark%2FLinkUtilsTest.php;h=29941c8cd0ed32307faa0eea5bde9b99b3d77967;hb=458b6b9918ec27154dd45416947bb93bedb97109;hp=78cb8f2abda69c07b26e9bfe54d7c508eec5ec40;hpb=6a4872520cbbc012b5a8358cd50c78844afe8d07;p=github%2Fshaarli%2FShaarli.git
diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php
index 78cb8f2a..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));
}
/**
@@ -388,15 +488,6 @@ class LinkUtilsTest extends TestCase
$this->assertEmpty($keywords);
}
- /**
- * Test count_private.
- */
- public function testCountPrivateLinks()
- {
- $refDB = new ReferenceLinkDB();
- $this->assertEquals($refDB->countPrivateLinks(), count_private($refDB->getLinks()));
- }
-
/**
* Test text2clickable.
*/
@@ -448,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);
}
/**
@@ -465,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);
}
/**
@@ -500,7 +591,7 @@ class LinkUtilsTest extends TestCase
*/
private function getHashtagLink($hashtag, $index = '')
{
- $hashtagLink = '#$1';
+ $hashtagLink = '#$1';
return str_replace('$1', $hashtag, $hashtagLink);
}
}