diff options
Diffstat (limited to 'tests/bookmark/LinkUtilsTest.php')
-rw-r--r-- | tests/bookmark/LinkUtilsTest.php | 61 |
1 files changed, 26 insertions, 35 deletions
diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php index 1b8688e6..25fb3043 100644 --- a/tests/bookmark/LinkUtilsTest.php +++ b/tests/bookmark/LinkUtilsTest.php | |||
@@ -216,56 +216,27 @@ class LinkUtilsTest extends \PHPUnit\Framework\TestCase | |||
216 | } | 216 | } |
217 | 217 | ||
218 | /** | 218 | /** |
219 | * Test text2clickable without a redirector being set. | 219 | * Test text2clickable. |
220 | */ | 220 | */ |
221 | public function testText2clickableWithoutRedirector() | 221 | public function testText2clickable() |
222 | { | 222 | { |
223 | $text = 'stuff http://hello.there/is=someone#here otherstuff'; | 223 | $text = 'stuff http://hello.there/is=someone#here otherstuff'; |
224 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here">' | 224 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here">' |
225 | . 'http://hello.there/is=someone#here</a> otherstuff'; | 225 | . 'http://hello.there/is=someone#here</a> otherstuff'; |
226 | $processedText = text2clickable($text, ''); | 226 | $processedText = text2clickable($text); |
227 | $this->assertEquals($expectedText, $processedText); | 227 | $this->assertEquals($expectedText, $processedText); |
228 | 228 | ||
229 | $text = 'stuff http://hello.there/is=someone#here(please) otherstuff'; | 229 | $text = 'stuff http://hello.there/is=someone#here(please) otherstuff'; |
230 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">' | 230 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">' |
231 | . 'http://hello.there/is=someone#here(please)</a> otherstuff'; | 231 | . 'http://hello.there/is=someone#here(please)</a> otherstuff'; |
232 | $processedText = text2clickable($text, ''); | 232 | $processedText = text2clickable($text); |
233 | $this->assertEquals($expectedText, $processedText); | 233 | $this->assertEquals($expectedText, $processedText); |
234 | 234 | ||
235 | $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff'; | 235 | $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff'; |
236 | $text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff'; | ||
236 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">' | 237 | $expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">' |
237 | . 'http://hello.there/is=someone#here(please)&no</a> otherstuff'; | 238 | . 'http://hello.there/is=someone#here(please)&no</a> otherstuff'; |
238 | $processedText = text2clickable($text, ''); | 239 | $processedText = text2clickable($text); |
239 | $this->assertEquals($expectedText, $processedText); | ||
240 | } | ||
241 | |||
242 | /** | ||
243 | * Test text2clickable with a redirector set. | ||
244 | */ | ||
245 | public function testText2clickableWithRedirector() | ||
246 | { | ||
247 | $text = 'stuff http://hello.there/is=someone#here otherstuff'; | ||
248 | $redirector = 'http://redirector.to'; | ||
249 | $expectedText = 'stuff <a href="' . | ||
250 | $redirector . | ||
251 | urlencode('http://hello.there/is=someone#here') . | ||
252 | '">http://hello.there/is=someone#here</a> otherstuff'; | ||
253 | $processedText = text2clickable($text, $redirector); | ||
254 | $this->assertEquals($expectedText, $processedText); | ||
255 | } | ||
256 | |||
257 | /** | ||
258 | * Test text2clickable a redirector set and without URL encode. | ||
259 | */ | ||
260 | public function testText2clickableWithRedirectorDontEncode() | ||
261 | { | ||
262 | $text = 'stuff http://hello.there/?is=someone&or=something#here otherstuff'; | ||
263 | $redirector = 'http://redirector.to'; | ||
264 | $expectedText = 'stuff <a href="' . | ||
265 | $redirector . | ||
266 | 'http://hello.there/?is=someone&or=something#here' . | ||
267 | '">http://hello.there/?is=someone&or=something#here</a> otherstuff'; | ||
268 | $processedText = text2clickable($text, $redirector, false); | ||
269 | $this->assertEquals($expectedText, $processedText); | 240 | $this->assertEquals($expectedText, $processedText); |
270 | } | 241 | } |
271 | 242 | ||
@@ -318,6 +289,26 @@ class LinkUtilsTest extends \PHPUnit\Framework\TestCase | |||
318 | } | 289 | } |
319 | 290 | ||
320 | /** | 291 | /** |
292 | * Test is_note with note URLs. | ||
293 | */ | ||
294 | public function testIsNote() | ||
295 | { | ||
296 | $this->assertTrue(is_note('?')); | ||
297 | $this->assertTrue(is_note('?abcDEf')); | ||
298 | $this->assertTrue(is_note('?_abcDEf#123')); | ||
299 | } | ||
300 | |||
301 | /** | ||
302 | * Test is_note with non note URLs. | ||
303 | */ | ||
304 | public function testIsNotNote() | ||
305 | { | ||
306 | $this->assertFalse(is_note('')); | ||
307 | $this->assertFalse(is_note('nope')); | ||
308 | $this->assertFalse(is_note('https://github.com/shaarli/Shaarli/?hi')); | ||
309 | } | ||
310 | |||
311 | /** | ||
321 | * Util function to build an hashtag link. | 312 | * Util function to build an hashtag link. |
322 | * | 313 | * |
323 | * @param string $hashtag Hashtag name. | 314 | * @param string $hashtag Hashtag name. |