aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/LinkUtilsTest.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2016-01-11 21:47:00 +0100
committerVirtualTam <virtualtam@flibidi.net>2016-01-11 21:47:00 +0100
commit92ba7b573f2833bd35c7eb2fc7fdbeb1a0ac7b44 (patch)
tree787f6d8fdabe8ea2fc0c37b61d616e667cdfbda5 /tests/LinkUtilsTest.php
parentc0a50f3663e207d5df007e0fa321219c1b32d6ea (diff)
parent1557cefbd76257ceb830f65806831b490faf0acc (diff)
downloadShaarli-92ba7b573f2833bd35c7eb2fc7fdbeb1a0ac7b44.tar.gz
Shaarli-92ba7b573f2833bd35c7eb2fc7fdbeb1a0ac7b44.tar.zst
Shaarli-92ba7b573f2833bd35c7eb2fc7fdbeb1a0ac7b44.zip
Merge pull request #432 from ArthurHoaro/title-retrieve
Fixes #410 - Retrieve title fails in multiple cases
Diffstat (limited to 'tests/LinkUtilsTest.php')
-rw-r--r--tests/LinkUtilsTest.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/LinkUtilsTest.php b/tests/LinkUtilsTest.php
new file mode 100644
index 00000000..c2257590
--- /dev/null
+++ b/tests/LinkUtilsTest.php
@@ -0,0 +1,85 @@
1<?php
2
3require_once 'application/LinkUtils.php';
4
5/**
6* Class LinkUtilsTest.
7*/
8class LinkUtilsTest extends PHPUnit_Framework_TestCase
9{
10 /**
11 * Test html_extract_title() when the title is found.
12 */
13 public function testHtmlExtractExistentTitle()
14 {
15 $title = 'Read me please.';
16 $html = '<html><meta>stuff</meta><title>'. $title .'</title></html>';
17 $this->assertEquals($title, html_extract_title($html));
18 }
19
20 /**
21 * Test html_extract_title() when the title is not found.
22 */
23 public function testHtmlExtractNonExistentTitle()
24 {
25 $html = '<html><meta>stuff</meta></html>';
26 $this->assertFalse(html_extract_title($html));
27 }
28
29 /**
30 * Test get_charset() with all priorities.
31 */
32 public function testGetCharset()
33 {
34 $headers = array('Content-Type' => 'text/html; charset=Headers');
35 $html = '<html><meta>stuff</meta><meta charset="Html"/></html>';
36 $default = 'default';
37 $this->assertEquals('headers', get_charset($headers, $html, $default));
38 $this->assertEquals('html', get_charset(array(), $html, $default));
39 $this->assertEquals($default, get_charset(array(), '', $default));
40 $this->assertEquals('utf-8', get_charset(array(), ''));
41 }
42
43 /**
44 * Test headers_extract_charset() when the charset is found.
45 */
46 public function testHeadersExtractExistentCharset()
47 {
48 $charset = 'x-MacCroatian';
49 $headers = array('Content-Type' => 'text/html; charset='. $charset);
50 $this->assertEquals(strtolower($charset), headers_extract_charset($headers));
51 }
52
53 /**
54 * Test headers_extract_charset() when the charset is not found.
55 */
56 public function testHeadersExtractNonExistentCharset()
57 {
58 $headers = array();
59 $this->assertFalse(headers_extract_charset($headers));
60
61 $headers = array('Content-Type' => 'text/html');
62 $this->assertFalse(headers_extract_charset($headers));
63 }
64
65 /**
66 * Test html_extract_charset() when the charset is found.
67 */
68 public function testHtmlExtractExistentCharset()
69 {
70 $charset = 'x-MacCroatian';
71 $html = '<html><meta>stuff2</meta><meta charset="'. $charset .'"/></html>';
72 $this->assertEquals(strtolower($charset), html_extract_charset($html));
73 }
74
75 /**
76 * Test html_extract_charset() when the charset is not found.
77 */
78 public function testHtmlExtractNonExistentCharset()
79 {
80 $html = '<html><meta>stuff</meta></html>';
81 $this->assertFalse(html_extract_charset($html));
82 $html = '<html><meta>stuff</meta><meta charset=""/></html>';
83 $this->assertFalse(html_extract_charset($html));
84 }
85}