aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/LinkUtilsTest.php
diff options
context:
space:
mode:
authorArthur <arthur@hoa.ro>2016-07-09 07:36:23 +0200
committerGitHub <noreply@github.com>2016-07-09 07:36:23 +0200
commit0c4c7ae818336d5b0f94562e551ca1a3f34d3435 (patch)
tree5f0da042d12c10c8e09deb788c928e0644e9cdcb /tests/LinkUtilsTest.php
parent649af5b501d2a90448242f53764ff693e9854039 (diff)
parent9ccca40189652e529732683abcdf54fcf775c9ec (diff)
downloadShaarli-0c4c7ae818336d5b0f94562e551ca1a3f34d3435.tar.gz
Shaarli-0c4c7ae818336d5b0f94562e551ca1a3f34d3435.tar.zst
Shaarli-0c4c7ae818336d5b0f94562e551ca1a3f34d3435.zip
Merge pull request #558 from ArthurHoaro/hashtag4
Hashtag system
Diffstat (limited to 'tests/LinkUtilsTest.php')
-rw-r--r--tests/LinkUtilsTest.php88
1 files changed, 88 insertions, 0 deletions
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 = '&nbsp; Are you &nbsp; thrilled &nbsp;by flags &nbsp; ?'. PHP_EOL .'&nbsp;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}