2 require_once dirname(__FILE__
) . '/../functions.php';
4 * Unit tests for functions.php
6 * @author Christian Weiske <cweiske@php.net>
8 class FunctionsTest
extends PHPUnit_Framework_TestCase
10 protected $tmpFile = null;
11 public function __construct()
13 $this->tmpFile
= sys_get_temp_dir() . '/tt-rss-unittest.dat';
16 public function tearDown()
18 if (file_exists($this->tmpFile
)) {
19 unlink($this->tmpFile
);
24 * Test fix_url with feed:// urls
26 public function testFixUrlFeed()
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/'));
33 * Test fix_url with non-http protocols
35 public function testFixUrlProtocols()
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/'));
40 'reallylongprotocolisthat://tt-rss.org/',
41 fix_url('reallylongprotocolisthat://tt-rss.org')
46 * Test fix_url with domain names only
48 public function testFixUrlDomainOnly()
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/'));
57 * Test fix_url with domain + paths
59 public function testFixUrlWithPaths()
61 $this->assertEquals('http://tt-rss.org/foo', fix_url('tt-rss.org/foo'));
64 'http://tt-rss.org/foo/bar/baz',
65 fix_url('tt-rss.org/foo/bar/baz')
68 'http://tt-rss.org/foo/bar/baz/',
69 fix_url('tt-rss.org/foo/bar/baz/')
75 * Test url_is_html() on html with a doctype
77 public function testUrlIsHtmlNormalHtmlWithDoctype()
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">
86 $this->assertTrue(url_is_html($this->tmpFile
));
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">
95 $this->assertTrue(url_is_html($this->tmpFile
));
99 * Test url_is_html() on html with a doctype and xml header
101 public function testUrlIsHtmlNormalHtmlWithDoctypeAndXml()
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">
111 $this->assertTrue(url_is_html($this->tmpFile
));
115 * Test url_is_html() on html without a doctype
117 public function testUrlIsHtmlNormalHtmlWithoutDoctype()
120 $this->tmpFile
, <<<HTM
121 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
125 $this->assertTrue(url_is_html($this->tmpFile
));
129 * Test url_is_html() on UPPERCASE HTML
131 public function testUrlIsHtmlNormalHtmlUppercase()
134 $this->tmpFile
, <<<HTM
135 <HTML XMLNS="http://www.w3.org/1999/xhtml" XML:LANG="en">
139 $this->assertTrue(url_is_html($this->tmpFile
));
142 $this->tmpFile
, <<<HTM
147 $this->assertTrue(url_is_html($this->tmpFile
));
151 * Test url_is_html() on atom
153 public function testUrlIsHtmlAtom()
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>
162 $this->assertFalse(url_is_html($this->tmpFile
));
166 * Test url_is_html() on RSS
168 public function testUrlIsHtmlRss()
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">
175 <title><![CDATA[Planet-PEAR]]></title>
178 $this->assertFalse(url_is_html($this->tmpFile
));
184 * Test rewrite_relative_url() with a relative path
186 public function testRewriteRelativeUrlRelative()
189 'http://tt-rss.org/foo/bar',
190 rewrite_relative_url('http://tt-rss.org', 'foo/bar')
193 'http://tt-rss.org/foo/bar',
194 rewrite_relative_url('http://tt-rss.org/', 'foo/bar')
197 'http://tt-rss.org/bar',
198 rewrite_relative_url('http://tt-rss.org/foo', 'bar')
201 'http://tt-rss.org/foo/bar',
202 rewrite_relative_url('http://tt-rss.org/foo/', 'bar')
205 'http://tt-rss.org/f/o/bar',
206 rewrite_relative_url('http://tt-rss.org/f/o/o', 'bar')
209 'http://tt-rss.org/f/o/o/bar',
210 rewrite_relative_url('http://tt-rss.org/f/o/o/', 'bar')
215 * Test rewrite_relative_url() with an absolute path
217 public function testRewriteRelativeUrlAbsolutePath()
220 'http://tt-rss.org/bar/',
221 rewrite_relative_url('http://tt-rss.org/foo/', '/bar/')
224 'http://tt-rss.org/bar/',
225 rewrite_relative_url('http://tt-rss.org/so/what/is/next', '/bar/')
228 'http://tt-rss.org/bar/',
229 rewrite_relative_url('http://tt-rss.org/so/what/is/next/', '/bar/')
234 * Test rewrite_relative_url() with an absolute URL
236 public function testRewriteRelativeUrlAbsoluteUrl()
239 'http://example.org/bar/',
240 rewrite_relative_url('http://tt-rss.org/foo/', 'http://example.org/bar/')