aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/bookmark/LinkUtilsTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/bookmark/LinkUtilsTest.php')
-rw-r--r--tests/bookmark/LinkUtilsTest.php351
1 files changed, 222 insertions, 129 deletions
diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php
index 591976f2..3321242f 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()
@@ -83,8 +94,78 @@ class LinkUtilsTest extends TestCase
83 public function testHtmlExtractExistentNameTag() 94 public function testHtmlExtractExistentNameTag()
84 { 95 {
85 $description = 'Bob and Alice share cookies.'; 96 $description = 'Bob and Alice share cookies.';
97
98 // Simple one line
86 $html = '<html><meta>stuff2</meta><meta name="description" content="' . $description . '"/></html>'; 99 $html = '<html><meta>stuff2</meta><meta name="description" content="' . $description . '"/></html>';
87 $this->assertEquals($description, html_extract_tag('description', $html)); 100 $this->assertEquals($description, html_extract_tag('description', $html));
101
102 // Simple OpenGraph
103 $html = '<meta property="og:description" content="' . $description . '">';
104 $this->assertEquals($description, html_extract_tag('description', $html));
105
106 // Simple reversed OpenGraph
107 $html = '<meta content="' . $description . '" property="og:description">';
108 $this->assertEquals($description, html_extract_tag('description', $html));
109
110 // ItemProp OpenGraph
111 $html = '<meta itemprop="og:description" content="' . $description . '">';
112 $this->assertEquals($description, html_extract_tag('description', $html));
113
114 // OpenGraph without quotes
115 $html = '<meta property=og:description content="' . $description . '">';
116 $this->assertEquals($description, html_extract_tag('description', $html));
117
118 // OpenGraph reversed without quotes
119 $html = '<meta content="' . $description . '" property=og:description>';
120 $this->assertEquals($description, html_extract_tag('description', $html));
121
122 // OpenGraph with noise
123 $html = '<meta tag1="content1" property="og:description" tag2="content2" content="' .
124 $description . '" tag3="content3">';
125 $this->assertEquals($description, html_extract_tag('description', $html));
126
127 // OpenGraph reversed with noise
128 $html = '<meta tag1="content1" content="' . $description . '" ' .
129 'tag3="content3" tag2="content2" property="og:description">';
130 $this->assertEquals($description, html_extract_tag('description', $html));
131
132 // OpenGraph multiple properties start
133 $html = '<meta property="unrelated og:description" content="' . $description . '">';
134 $this->assertEquals($description, html_extract_tag('description', $html));
135
136 // OpenGraph multiple properties end
137 $html = '<meta property="og:description unrelated" content="' . $description . '">';
138 $this->assertEquals($description, html_extract_tag('description', $html));
139
140 // OpenGraph multiple properties both end
141 $html = '<meta property="og:unrelated1 og:description og:unrelated2" content="' . $description . '">';
142 $this->assertEquals($description, html_extract_tag('description', $html));
143
144 // OpenGraph multiple properties both end with noise
145 $html = '<meta tag1="content1" property="og:unrelated1 og:description og:unrelated2" '.
146 'tag2="content2" content="' . $description . '" tag3="content3">';
147 $this->assertEquals($description, html_extract_tag('description', $html));
148
149 // OpenGraph reversed multiple properties start
150 $html = '<meta content="' . $description . '" property="unrelated og:description">';
151 $this->assertEquals($description, html_extract_tag('description', $html));
152
153 // OpenGraph reversed multiple properties end
154 $html = '<meta content="' . $description . '" property="og:description unrelated">';
155 $this->assertEquals($description, html_extract_tag('description', $html));
156
157 // OpenGraph reversed multiple properties both end
158 $html = '<meta content="' . $description . '" property="og:unrelated1 og:description og:unrelated2">';
159 $this->assertEquals($description, html_extract_tag('description', $html));
160
161 // OpenGraph reversed multiple properties both end with noise
162 $html = '<meta tag1="content1" content="' . $description . '" tag2="content2" '.
163 'property="og:unrelated1 og:description og:unrelated2" tag3="content3">';
164 $this->assertEquals($description, html_extract_tag('description', $html));
165
166 // Suggestion from #1375
167 $html = '<meta property="og:description" name="description" content="' . $description . '">';
168 $this->assertEquals($description, html_extract_tag('description', $html));
88 } 169 }
89 170
90 /** 171 /**
@@ -94,6 +175,25 @@ class LinkUtilsTest extends TestCase
94 { 175 {
95 $html = '<html><meta>stuff2</meta><meta name="image" content="img"/></html>'; 176 $html = '<html><meta>stuff2</meta><meta name="image" content="img"/></html>';
96 $this->assertFalse(html_extract_tag('description', $html)); 177 $this->assertFalse(html_extract_tag('description', $html));
178
179 // Partial meta tag
180 $html = '<meta content="Brief description">';
181 $this->assertFalse(html_extract_tag('description', $html));
182
183 $html = '<meta property="og:description">';
184 $this->assertFalse(html_extract_tag('description', $html));
185
186 $html = '<meta tag1="content1" property="og:description">';
187 $this->assertFalse(html_extract_tag('description', $html));
188
189 $html = '<meta property="og:description" tag1="content1">';
190 $this->assertFalse(html_extract_tag('description', $html));
191
192 $html = '<meta tag1="content1" content="Brief description">';
193 $this->assertFalse(html_extract_tag('description', $html));
194
195 $html = '<meta content="Brief description" tag1="content1">';
196 $this->assertFalse(html_extract_tag('description', $html));
97 } 197 }
98 198
99 /** 199 /**
@@ -116,60 +216,91 @@ class LinkUtilsTest extends TestCase
116 } 216 }
117 217
118 /** 218 /**
219 * Test the header callback with valid value
220 */
221 public function testCurlHeaderCallbackOk(): void
222 {
223 $callback = get_curl_header_callback($charset, 'ut_curl_getinfo_ok');
224 $data = [
225 'HTTP/1.1 200 OK',
226 'Server: GitHub.com',
227 'Date: Sat, 28 Oct 2017 12:01:33 GMT',
228 'Content-Type: text/html; charset=utf-8',
229 'Status: 200 OK',
230 ];
231
232 foreach ($data as $chunk) {
233 static::assertIsInt($callback(null, $chunk));
234 }
235
236 static::assertSame('utf-8', $charset);
237 }
238
239 /**
119 * Test the download callback with valid value 240 * Test the download callback with valid value
120 */ 241 */
121 public function testCurlDownloadCallbackOk() 242 public function testCurlDownloadCallbackOk(): void
122 { 243 {
244 $charset = 'utf-8';
123 $callback = get_curl_download_callback( 245 $callback = get_curl_download_callback(
124 $charset, 246 $charset,
125 $title, 247 $title,
126 $desc, 248 $desc,
127 $keywords, 249 $keywords,
128 false, 250 false
129 'ut_curl_getinfo_ok'
130 ); 251 );
252
131 $data = [ 253 $data = [
132 'HTTP/1.1 200 OK', 254 'th=device-width">'
133 'Server: GitHub.com',
134 'Date: Sat, 28 Oct 2017 12:01:33 GMT',
135 'Content-Type: text/html; charset=utf-8',
136 'Status: 200 OK',
137 'end' => 'th=device-width">'
138 . '<title>Refactoring · GitHub</title>' 255 . '<title>Refactoring · GitHub</title>'
139 . '<link rel="search" type="application/opensea', 256 . '<link rel="search" type="application/opensea',
140 '<title>ignored</title>' 257 '<title>ignored</title>'
141 . '<meta name="description" content="desc" />' 258 . '<meta name="description" content="desc" />'
142 . '<meta name="keywords" content="key1,key2" />', 259 . '<meta name="keywords" content="key1,key2" />',
143 ]; 260 ];
144 foreach ($data as $key => $line) { 261
145 $ignore = null; 262 foreach ($data as $chunk) {
146 $expected = $key !== 'end' ? strlen($line) : false; 263 static::assertSame(strlen($chunk), $callback(null, $chunk));
147 $this->assertEquals($expected, $callback($ignore, $line));
148 if ($expected === false) {
149 break;
150 }
151 } 264 }
152 $this->assertEquals('utf-8', $charset); 265
153 $this->assertEquals('Refactoring · GitHub', $title); 266 static::assertSame('utf-8', $charset);
154 $this->assertEmpty($desc); 267 static::assertSame('Refactoring · GitHub', $title);
155 $this->assertEmpty($keywords); 268 static::assertEmpty($desc);
269 static::assertEmpty($keywords);
270 }
271
272 /**
273 * Test the header callback with valid value
274 */
275 public function testCurlHeaderCallbackNoCharset(): void
276 {
277 $callback = get_curl_header_callback($charset, 'ut_curl_getinfo_no_charset');
278 $data = [
279 'HTTP/1.1 200 OK',
280 ];
281
282 foreach ($data as $chunk) {
283 static::assertSame(strlen($chunk), $callback(null, $chunk));
284 }
285
286 static::assertFalse($charset);
156 } 287 }
157 288
158 /** 289 /**
159 * Test the download callback with valid values and no charset 290 * Test the download callback with valid values and no charset
160 */ 291 */
161 public function testCurlDownloadCallbackOkNoCharset() 292 public function testCurlDownloadCallbackOkNoCharset(): void
162 { 293 {
294 $charset = null;
163 $callback = get_curl_download_callback( 295 $callback = get_curl_download_callback(
164 $charset, 296 $charset,
165 $title, 297 $title,
166 $desc, 298 $desc,
167 $keywords, 299 $keywords,
168 false, 300 false
169 'ut_curl_getinfo_no_charset'
170 ); 301 );
302
171 $data = [ 303 $data = [
172 'HTTP/1.1 200 OK',
173 'end' => 'th=device-width">' 304 'end' => 'th=device-width">'
174 . '<title>Refactoring · GitHub</title>' 305 . '<title>Refactoring · GitHub</title>'
175 . '<link rel="search" type="application/opensea', 306 . '<link rel="search" type="application/opensea',
@@ -177,10 +308,11 @@ class LinkUtilsTest extends TestCase
177 . '<meta name="description" content="desc" />' 308 . '<meta name="description" content="desc" />'
178 . '<meta name="keywords" content="key1,key2" />', 309 . '<meta name="keywords" content="key1,key2" />',
179 ]; 310 ];
180 foreach ($data as $key => $line) { 311
181 $ignore = null; 312 foreach ($data as $chunk) {
182 $this->assertEquals(strlen($line), $callback($ignore, $line)); 313 static::assertSame(strlen($chunk), $callback(null, $chunk));
183 } 314 }
315
184 $this->assertEmpty($charset); 316 $this->assertEmpty($charset);
185 $this->assertEquals('Refactoring · GitHub', $title); 317 $this->assertEquals('Refactoring · GitHub', $title);
186 $this->assertEmpty($desc); 318 $this->assertEmpty($desc);
@@ -190,18 +322,18 @@ class LinkUtilsTest extends TestCase
190 /** 322 /**
191 * Test the download callback with valid values and no charset 323 * Test the download callback with valid values and no charset
192 */ 324 */
193 public function testCurlDownloadCallbackOkHtmlCharset() 325 public function testCurlDownloadCallbackOkHtmlCharset(): void
194 { 326 {
327 $charset = null;
195 $callback = get_curl_download_callback( 328 $callback = get_curl_download_callback(
196 $charset, 329 $charset,
197 $title, 330 $title,
198 $desc, 331 $desc,
199 $keywords, 332 $keywords,
200 false, 333 false
201 'ut_curl_getinfo_no_charset'
202 ); 334 );
335
203 $data = [ 336 $data = [
204 'HTTP/1.1 200 OK',
205 '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />', 337 '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />',
206 'end' => 'th=device-width">' 338 'end' => 'th=device-width">'
207 . '<title>Refactoring · GitHub</title>' 339 . '<title>Refactoring · GitHub</title>'
@@ -210,14 +342,10 @@ class LinkUtilsTest extends TestCase
210 . '<meta name="description" content="desc" />' 342 . '<meta name="description" content="desc" />'
211 . '<meta name="keywords" content="key1,key2" />', 343 . '<meta name="keywords" content="key1,key2" />',
212 ]; 344 ];
213 foreach ($data as $key => $line) { 345 foreach ($data as $chunk) {
214 $ignore = null; 346 static::assertSame(strlen($chunk), $callback(null, $chunk));
215 $expected = $key !== 'end' ? strlen($line) : false;
216 $this->assertEquals($expected, $callback($ignore, $line));
217 if ($expected === false) {
218 break;
219 }
220 } 347 }
348
221 $this->assertEquals('utf-8', $charset); 349 $this->assertEquals('utf-8', $charset);
222 $this->assertEquals('Refactoring · GitHub', $title); 350 $this->assertEquals('Refactoring · GitHub', $title);
223 $this->assertEmpty($desc); 351 $this->assertEmpty($desc);
@@ -227,25 +355,26 @@ class LinkUtilsTest extends TestCase
227 /** 355 /**
228 * Test the download callback with valid values and no title 356 * Test the download callback with valid values and no title
229 */ 357 */
230 public function testCurlDownloadCallbackOkNoTitle() 358 public function testCurlDownloadCallbackOkNoTitle(): void
231 { 359 {
360 $charset = 'utf-8';
232 $callback = get_curl_download_callback( 361 $callback = get_curl_download_callback(
233 $charset, 362 $charset,
234 $title, 363 $title,
235 $desc, 364 $desc,
236 $keywords, 365 $keywords,
237 false, 366 false
238 'ut_curl_getinfo_ok'
239 ); 367 );
368
240 $data = [ 369 $data = [
241 'HTTP/1.1 200 OK',
242 'end' => 'th=device-width">Refactoring · GitHub<link rel="search" type="application/opensea', 370 'end' => 'th=device-width">Refactoring · GitHub<link rel="search" type="application/opensea',
243 'ignored', 371 'ignored',
244 ]; 372 ];
245 foreach ($data as $key => $line) { 373
246 $ignore = null; 374 foreach ($data as $chunk) {
247 $this->assertEquals(strlen($line), $callback($ignore, $line)); 375 static::assertSame(strlen($chunk), $callback(null, $chunk));
248 } 376 }
377
249 $this->assertEquals('utf-8', $charset); 378 $this->assertEquals('utf-8', $charset);
250 $this->assertEmpty($title); 379 $this->assertEmpty($title);
251 $this->assertEmpty($desc); 380 $this->assertEmpty($desc);
@@ -253,81 +382,55 @@ class LinkUtilsTest extends TestCase
253 } 382 }
254 383
255 /** 384 /**
256 * Test the download callback with an invalid content type. 385 * Test the header callback with an invalid content type.
257 */ 386 */
258 public function testCurlDownloadCallbackInvalidContentType() 387 public function testCurlHeaderCallbackInvalidContentType(): void
259 { 388 {
260 $callback = get_curl_download_callback( 389 $callback = get_curl_header_callback($charset, 'ut_curl_getinfo_ct_ko');
261 $charset, 390 $data = [
262 $title, 391 'HTTP/1.1 200 OK',
263 $desc, 392 ];
264 $keywords, 393
265 false, 394 static::assertFalse($callback(null, $data[0]));
266 'ut_curl_getinfo_ct_ko' 395 static::assertNull($charset);
267 );
268 $ignore = null;
269 $this->assertFalse($callback($ignore, ''));
270 $this->assertEmpty($charset);
271 $this->assertEmpty($title);
272 } 396 }
273 397
274 /** 398 /**
275 * Test the download callback with an invalid response code. 399 * Test the header callback with an invalid response code.
276 */ 400 */
277 public function testCurlDownloadCallbackInvalidResponseCode() 401 public function testCurlHeaderCallbackInvalidResponseCode(): void
278 { 402 {
279 $callback = $callback = get_curl_download_callback( 403 $callback = get_curl_header_callback($charset, 'ut_curl_getinfo_rc_ko');
280 $charset, 404
281 $title, 405 static::assertFalse($callback(null, ''));
282 $desc, 406 static::assertNull($charset);
283 $keywords,
284 false,
285 'ut_curl_getinfo_rc_ko'
286 );
287 $ignore = null;
288 $this->assertFalse($callback($ignore, ''));
289 $this->assertEmpty($charset);
290 $this->assertEmpty($title);
291 } 407 }
292 408
293 /** 409 /**
294 * Test the download callback with an invalid content type and response code. 410 * Test the header callback with an invalid content type and response code.
295 */ 411 */
296 public function testCurlDownloadCallbackInvalidContentTypeAndResponseCode() 412 public function testCurlHeaderCallbackInvalidContentTypeAndResponseCode(): void
297 { 413 {
298 $callback = $callback = get_curl_download_callback( 414 $callback = get_curl_header_callback($charset, 'ut_curl_getinfo_rs_ct_ko');
299 $charset, 415
300 $title, 416 static::assertFalse($callback(null, ''));
301 $desc, 417 static::assertNull($charset);
302 $keywords,
303 false,
304 'ut_curl_getinfo_rs_ct_ko'
305 );
306 $ignore = null;
307 $this->assertFalse($callback($ignore, ''));
308 $this->assertEmpty($charset);
309 $this->assertEmpty($title);
310 } 418 }
311 419
312 /** 420 /**
313 * Test the download callback with valid value, and retrieve_description option enabled. 421 * Test the download callback with valid value, and retrieve_description option enabled.
314 */ 422 */
315 public function testCurlDownloadCallbackOkWithDesc() 423 public function testCurlDownloadCallbackOkWithDesc(): void
316 { 424 {
425 $charset = 'utf-8';
317 $callback = get_curl_download_callback( 426 $callback = get_curl_download_callback(
318 $charset, 427 $charset,
319 $title, 428 $title,
320 $desc, 429 $desc,
321 $keywords, 430 $keywords,
322 true, 431 true
323 'ut_curl_getinfo_ok'
324 ); 432 );
325 $data = [ 433 $data = [
326 'HTTP/1.1 200 OK',
327 'Server: GitHub.com',
328 'Date: Sat, 28 Oct 2017 12:01:33 GMT',
329 'Content-Type: text/html; charset=utf-8',
330 'Status: 200 OK',
331 'th=device-width">' 434 'th=device-width">'
332 . '<title>Refactoring · GitHub</title>' 435 . '<title>Refactoring · GitHub</title>'
333 . '<link rel="search" type="application/opensea', 436 . '<link rel="search" type="application/opensea',
@@ -335,14 +438,11 @@ class LinkUtilsTest extends TestCase
335 . '<meta name="description" content="link desc" />' 438 . '<meta name="description" content="link desc" />'
336 . '<meta name="keywords" content="key1,key2" />', 439 . '<meta name="keywords" content="key1,key2" />',
337 ]; 440 ];
338 foreach ($data as $key => $line) { 441
339 $ignore = null; 442 foreach ($data as $chunk) {
340 $expected = $key !== 'end' ? strlen($line) : false; 443 static::assertSame(strlen($chunk), $callback(null, $chunk));
341 $this->assertEquals($expected, $callback($ignore, $line));
342 if ($expected === false) {
343 break;
344 }
345 } 444 }
445
346 $this->assertEquals('utf-8', $charset); 446 $this->assertEquals('utf-8', $charset);
347 $this->assertEquals('Refactoring · GitHub', $title); 447 $this->assertEquals('Refactoring · GitHub', $title);
348 $this->assertEquals('link desc', $desc); 448 $this->assertEquals('link desc', $desc);
@@ -353,8 +453,9 @@ class LinkUtilsTest extends TestCase
353 * Test the download callback with valid value, and retrieve_description option enabled, 453 * Test the download callback with valid value, and retrieve_description option enabled,
354 * but no desc or keyword defined in the page. 454 * but no desc or keyword defined in the page.
355 */ 455 */
356 public function testCurlDownloadCallbackOkWithDescNotFound() 456 public function testCurlDownloadCallbackOkWithDescNotFound(): void
357 { 457 {
458 $charset = 'utf-8';
358 $callback = get_curl_download_callback( 459 $callback = get_curl_download_callback(
359 $charset, 460 $charset,
360 $title, 461 $title,
@@ -364,24 +465,16 @@ class LinkUtilsTest extends TestCase
364 'ut_curl_getinfo_ok' 465 'ut_curl_getinfo_ok'
365 ); 466 );
366 $data = [ 467 $data = [
367 'HTTP/1.1 200 OK',
368 'Server: GitHub.com',
369 'Date: Sat, 28 Oct 2017 12:01:33 GMT',
370 'Content-Type: text/html; charset=utf-8',
371 'Status: 200 OK',
372 'th=device-width">' 468 'th=device-width">'
373 . '<title>Refactoring · GitHub</title>' 469 . '<title>Refactoring · GitHub</title>'
374 . '<link rel="search" type="application/opensea', 470 . '<link rel="search" type="application/opensea',
375 'end' => '<title>ignored</title>', 471 'end' => '<title>ignored</title>',
376 ]; 472 ];
377 foreach ($data as $key => $line) { 473
378 $ignore = null; 474 foreach ($data as $chunk) {
379 $expected = $key !== 'end' ? strlen($line) : false; 475 static::assertSame(strlen($chunk), $callback(null, $chunk));
380 $this->assertEquals($expected, $callback($ignore, $line));
381 if ($expected === false) {
382 break;
383 }
384 } 476 }
477
385 $this->assertEquals('utf-8', $charset); 478 $this->assertEquals('utf-8', $charset);
386 $this->assertEquals('Refactoring · GitHub', $title); 479 $this->assertEquals('Refactoring · GitHub', $title);
387 $this->assertEmpty($desc); 480 $this->assertEmpty($desc);
@@ -439,13 +532,13 @@ class LinkUtilsTest extends TestCase
439 カタカナ #カタカナ」カタカナ\n'; 532 カタカナ #カタカナ」カタカナ\n';
440 $autolinkedDescription = hashtag_autolink($rawDescription, $index); 533 $autolinkedDescription = hashtag_autolink($rawDescription, $index);
441 534
442 $this->assertContains($this->getHashtagLink('hashtag', $index), $autolinkedDescription); 535 $this->assertContainsPolyfill($this->getHashtagLink('hashtag', $index), $autolinkedDescription);
443 $this->assertNotContains(' #hashtag', $autolinkedDescription); 536 $this->assertNotContainsPolyfill(' #hashtag', $autolinkedDescription);
444 $this->assertNotContains('>#nothashtag', $autolinkedDescription); 537 $this->assertNotContainsPolyfill('>#nothashtag', $autolinkedDescription);
445 $this->assertContains($this->getHashtagLink('ашок', $index), $autolinkedDescription); 538 $this->assertContainsPolyfill($this->getHashtagLink('ашок', $index), $autolinkedDescription);
446 $this->assertContains($this->getHashtagLink('カタカナ', $index), $autolinkedDescription); 539 $this->assertContainsPolyfill($this->getHashtagLink('カタカナ', $index), $autolinkedDescription);
447 $this->assertContains($this->getHashtagLink('hashtag_hashtag', $index), $autolinkedDescription); 540 $this->assertContainsPolyfill($this->getHashtagLink('hashtag_hashtag', $index), $autolinkedDescription);
448 $this->assertNotContains($this->getHashtagLink('hashtag-nothashtag', $index), $autolinkedDescription); 541 $this->assertNotContainsPolyfill($this->getHashtagLink('hashtag-nothashtag', $index), $autolinkedDescription);
449 } 542 }
450 543
451 /** 544 /**
@@ -456,9 +549,9 @@ class LinkUtilsTest extends TestCase
456 $rawDescription = 'blabla #hashtag x#nothashtag'; 549 $rawDescription = 'blabla #hashtag x#nothashtag';
457 $autolinkedDescription = hashtag_autolink($rawDescription); 550 $autolinkedDescription = hashtag_autolink($rawDescription);
458 551
459 $this->assertContains($this->getHashtagLink('hashtag'), $autolinkedDescription); 552 $this->assertContainsPolyfill($this->getHashtagLink('hashtag'), $autolinkedDescription);
460 $this->assertNotContains(' #hashtag', $autolinkedDescription); 553 $this->assertNotContainsPolyfill(' #hashtag', $autolinkedDescription);
461 $this->assertNotContains('>#nothashtag', $autolinkedDescription); 554 $this->assertNotContainsPolyfill('>#nothashtag', $autolinkedDescription);
462 } 555 }
463 556
464 /** 557 /**
@@ -491,7 +584,7 @@ class LinkUtilsTest extends TestCase
491 */ 584 */
492 private function getHashtagLink($hashtag, $index = '') 585 private function getHashtagLink($hashtag, $index = '')
493 { 586 {
494 $hashtagLink = '<a href="' . $index . '?addtag=$1" title="Hashtag $1">#$1</a>'; 587 $hashtagLink = '<a href="' . $index . './add-tag/$1" title="Hashtag $1">#$1</a>';
495 return str_replace('$1', $hashtag, $hashtagLink); 588 return str_replace('$1', $hashtag, $hashtagLink);
496 } 589 }
497} 590}