]>
Commit | Line | Data |
---|---|---|
44453773 CW |
1 | <?php |
2 | require_once dirname(__FILE__) . '/../functions.php'; | |
3 | /** | |
4 | * Unit tests for functions.php | |
5 | * | |
6 | * @author Christian Weiske <cweiske@php.net> | |
7 | */ | |
8 | class FunctionsTest extends PHPUnit_Framework_TestCase | |
9 | { | |
24eb4c78 CW |
10 | protected $tmpFile = null; |
11 | public function __construct() | |
12 | { | |
13 | $this->tmpFile = sys_get_temp_dir() . '/tt-rss-unittest.dat'; | |
14 | } | |
15 | ||
16 | public function tearDown() | |
17 | { | |
18 | if (file_exists($this->tmpFile)) { | |
19 | unlink($this->tmpFile); | |
20 | } | |
21 | } | |
22 | ||
44453773 CW |
23 | /** |
24 | * Test fix_url with feed:// urls | |
25 | */ | |
26 | public function testFixUrlFeed() | |
27 | { | |
28 | $this->assertEquals('http://tt-rss.org/', fix_url('feed://tt-rss.org')); | |
29 | $this->assertEquals('http://tt-rss.org/', fix_url('feed://tt-rss.org/')); | |
30 | } | |
31 | ||
32 | /** | |
33 | * Test fix_url with non-http protocols | |
34 | */ | |
35 | public function testFixUrlProtocols() | |
36 | { | |
37 | $this->assertEquals('https://tt-rss.org/', fix_url('https://tt-rss.org')); | |
38 | $this->assertEquals('ftp://tt-rss.org/', fix_url('ftp://tt-rss.org/')); | |
39 | $this->assertEquals( | |
40 | 'reallylongprotocolisthat://tt-rss.org/', | |
41 | fix_url('reallylongprotocolisthat://tt-rss.org') | |
42 | ); | |
43 | } | |
44 | ||
45 | /** | |
46 | * Test fix_url with domain names only | |
47 | */ | |
48 | public function testFixUrlDomainOnly() | |
49 | { | |
50 | $this->assertEquals('http://tt-rss.org/', fix_url('tt-rss.org')); | |
51 | $this->assertEquals('http://tt-rss.org/', fix_url('tt-rss.org/')); | |
52 | $this->assertEquals('http://tt-rss.org/', fix_url('http://tt-rss.org')); | |
53 | $this->assertEquals('http://tt-rss.org/', fix_url('http://tt-rss.org/')); | |
54 | } | |
55 | ||
56 | /** | |
57 | * Test fix_url with domain + paths | |
58 | */ | |
59 | public function testFixUrlWithPaths() | |
60 | { | |
61 | $this->assertEquals('http://tt-rss.org/foo', fix_url('tt-rss.org/foo')); | |
62 | ||
63 | $this->assertEquals( | |
64 | 'http://tt-rss.org/foo/bar/baz', | |
65 | fix_url('tt-rss.org/foo/bar/baz') | |
66 | ); | |
67 | $this->assertEquals( | |
68 | 'http://tt-rss.org/foo/bar/baz/', | |
69 | fix_url('tt-rss.org/foo/bar/baz/') | |
70 | ); | |
71 | } | |
24eb4c78 CW |
72 | |
73 | ||
74 | /** | |
75 | * Test url_is_html() on html with a doctype | |
76 | */ | |
77 | public function testUrlIsHtmlNormalHtmlWithDoctype() | |
78 | { | |
79 | file_put_contents( | |
80 | $this->tmpFile, <<<HTM | |
81 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
82 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> | |
83 | <head> | |
84 | HTM | |
85 | ); | |
86 | $this->assertTrue(url_is_html($this->tmpFile)); | |
87 | ||
88 | file_put_contents( | |
89 | $this->tmpFile, <<<HTM | |
90 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
91 | <html> | |
92 | <head> | |
93 | HTM | |
94 | ); | |
95 | $this->assertTrue(url_is_html($this->tmpFile)); | |
96 | } | |
97 | ||
98 | /** | |
99 | * Test url_is_html() on html with a doctype and xml header | |
100 | */ | |
101 | public function testUrlIsHtmlNormalHtmlWithDoctypeAndXml() | |
102 | { | |
103 | file_put_contents( | |
104 | $this->tmpFile, <<<HTM | |
105 | <?xml version="1.0" encoding="utf-8"?> | |
106 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
107 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> | |
108 | <head> | |
109 | HTM | |
110 | ); | |
111 | $this->assertTrue(url_is_html($this->tmpFile)); | |
112 | } | |
113 | ||
114 | /** | |
115 | * Test url_is_html() on html without a doctype | |
116 | */ | |
117 | public function testUrlIsHtmlNormalHtmlWithoutDoctype() | |
118 | { | |
119 | file_put_contents( | |
120 | $this->tmpFile, <<<HTM | |
121 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> | |
122 | <head> | |
123 | HTM | |
124 | ); | |
125 | $this->assertTrue(url_is_html($this->tmpFile)); | |
126 | } | |
127 | ||
128 | /** | |
129 | * Test url_is_html() on UPPERCASE HTML | |
130 | */ | |
131 | public function testUrlIsHtmlNormalHtmlUppercase() | |
132 | { | |
133 | file_put_contents( | |
134 | $this->tmpFile, <<<HTM | |
135 | <HTML XMLNS="http://www.w3.org/1999/xhtml" XML:LANG="en"> | |
136 | <HEAD> | |
137 | HTM | |
138 | ); | |
139 | $this->assertTrue(url_is_html($this->tmpFile)); | |
140 | ||
141 | file_put_contents( | |
142 | $this->tmpFile, <<<HTM | |
143 | <HTML> | |
144 | <HEAD> | |
145 | HTM | |
146 | ); | |
147 | $this->assertTrue(url_is_html($this->tmpFile)); | |
148 | } | |
149 | ||
150 | /** | |
151 | * Test url_is_html() on atom | |
152 | */ | |
153 | public function testUrlIsHtmlAtom() | |
154 | { | |
155 | file_put_contents( | |
156 | $this->tmpFile, <<<HTM | |
157 | <?xml version="1.0" encoding="utf-8"?> | |
158 | <feed xmlns="http://www.w3.org/2005/Atom"> | |
159 | <title>Christians Tagebuch</title> | |
160 | HTM | |
161 | ); | |
162 | $this->assertFalse(url_is_html($this->tmpFile)); | |
163 | } | |
164 | ||
165 | /** | |
166 | * Test url_is_html() on RSS | |
167 | */ | |
168 | public function testUrlIsHtmlRss() | |
169 | { | |
170 | file_put_contents( | |
171 | $this->tmpFile, <<<HTM | |
172 | <?xml version="1.0" encoding="UTF-8"?> | |
173 | <?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"> | |
174 | <channel> | |
175 | <title><![CDATA[Planet-PEAR]]></title> | |
176 | HTM | |
177 | ); | |
178 | $this->assertFalse(url_is_html($this->tmpFile)); | |
179 | } | |
44453773 CW |
180 | } |
181 | ||
182 | ?> |