]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - tests/LinkUtilsTest.php
Avoids populating a markdown empty container if there's no description.
[github/shaarli/Shaarli.git] / tests / LinkUtilsTest.php
CommitLineData
1557cefb
A
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}