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));
18 $html = '<html><title>'. $title .'</title>blabla<title>another</title></html>';
19 $this->assertEquals($title, html_extract_title($html));
23 * Test html_extract_title() when the title is not found.
25 public function testHtmlExtractNonExistentTitle()
27 $html = '<html><meta>stuff</meta></html>';
28 $this->assertFalse(html_extract_title($html));
32 * Test get_charset() with all priorities.
34 public function testGetCharset()
36 $headers = array('Content-Type' => 'text/html; charset=Headers');
37 $html = '<html><meta>stuff</meta><meta charset="Html"/></html>';
39 $this->assertEquals('headers', get_charset($headers, $html, $default));
40 $this->assertEquals('html', get_charset(array(), $html, $default));
41 $this->assertEquals($default, get_charset(array(), '', $default));
42 $this->assertEquals('utf-8', get_charset(array(), ''));
46 * Test headers_extract_charset() when the charset is found.
48 public function testHeadersExtractExistentCharset()
50 $charset = 'x-MacCroatian';
51 $headers = array('Content-Type' => 'text/html; charset='. $charset);
52 $this->assertEquals(strtolower($charset), headers_extract_charset($headers));
56 * Test headers_extract_charset() when the charset is not found.
58 public function testHeadersExtractNonExistentCharset()
61 $this->assertFalse(headers_extract_charset($headers));
63 $headers = array('Content-Type' => 'text/html');
64 $this->assertFalse(headers_extract_charset($headers));
68 * Test html_extract_charset() when the charset is found.
70 public function testHtmlExtractExistentCharset()
72 $charset = 'x-MacCroatian';
73 $html = '<html><meta>stuff2</meta><meta charset="'. $charset .'"/></html>';
74 $this->assertEquals(strtolower($charset), html_extract_charset($html));
78 * Test html_extract_charset() when the charset is not found.
80 public function testHtmlExtractNonExistentCharset()
82 $html = '<html><meta>stuff</meta></html>';
83 $this->assertFalse(html_extract_charset($html));
84 $html = '<html><meta>stuff</meta><meta charset=""/></html>';
85 $this->assertFalse(html_extract_charset($html));