3 require_once 'application/LinkUtils.php';
8 class LinkUtilsTest
extends PHPUnit_Framework_TestCase
11 * Test html_extract_title() when the title is found.
13 public function testHtmlExtractExistentTitle()
15 $title = 'Read me please.';
16 $html = '<html><meta>stuff</meta><title>'. $title .'</title></html>';
17 $this->assertEquals($title, html_extract_title($html));
21 * Test html_extract_title() when the title is not found.
23 public function testHtmlExtractNonExistentTitle()
25 $html = '<html><meta>stuff</meta></html>';
26 $this->assertFalse(html_extract_title($html));
30 * Test get_charset() with all priorities.
32 public function testGetCharset()
34 $headers = array('Content-Type' => 'text/html; charset=Headers');
35 $html = '<html><meta>stuff</meta><meta charset="Html"/></html>';
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(), ''));
44 * Test headers_extract_charset() when the charset is found.
46 public function testHeadersExtractExistentCharset()
48 $charset = 'x-MacCroatian';
49 $headers = array('Content-Type' => 'text/html; charset='. $charset);
50 $this->assertEquals(strtolower($charset), headers_extract_charset($headers));
54 * Test headers_extract_charset() when the charset is not found.
56 public function testHeadersExtractNonExistentCharset()
59 $this->assertFalse(headers_extract_charset($headers));
61 $headers = array('Content-Type' => 'text/html');
62 $this->assertFalse(headers_extract_charset($headers));
66 * Test html_extract_charset() when the charset is found.
68 public function testHtmlExtractExistentCharset()
70 $charset = 'x-MacCroatian';
71 $html = '<html><meta>stuff2</meta><meta charset="'. $charset .'"/></html>';
72 $this->assertEquals(strtolower($charset), html_extract_charset($html));
76 * Test html_extract_charset() when the charset is not found.
78 public function testHtmlExtractNonExistentCharset()
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));