Release 2.1.0, merged in 1313 to HEAD.
[htmlpurifier.git] / tests / HTMLPurifier / URIParserTest.php
blob370e90ca0e2af0d2794448e504ce8933d389d771
1 <?php
3 require_once 'HTMLPurifier/URIParser.php';
4 require_once 'HTMLPurifier/URI.php';
6 class HTMLPurifier_URIParserTest extends HTMLPurifier_Harness
9 function assertParsing(
10 $uri, $scheme, $userinfo, $host, $port, $path, $query, $fragment, $config = null, $context = null
11 ) {
12 $this->prepareCommon($config, $context);
13 $parser = new HTMLPurifier_URIParser();
14 $result = $parser->parse($uri, $config, $context);
15 $expect = new HTMLPurifier_URI($scheme, $userinfo, $host, $port, $path, $query, $fragment);
16 $this->assertEqual($result, $expect);
19 function testRegular() {
20 $this->assertParsing(
21 'http://www.example.com/webhp?q=foo#result2',
22 'http', null, 'www.example.com', null, '/webhp', 'q=foo', 'result2'
26 function testPortAndUsername() {
27 $this->assertParsing(
28 'http://user@authority.part:80/now/the/path?query#fragment',
29 'http', 'user', 'authority.part', 80, '/now/the/path', 'query', 'fragment'
33 function testPercentEncoding() {
34 $this->assertParsing(
35 'http://en.wikipedia.org/wiki/Clich%C3%A9',
36 'http', null, 'en.wikipedia.org', null, '/wiki/Clich%C3%A9', null, null
40 function testEmptyQuery() {
41 $this->assertParsing(
42 'http://www.example.com/?#',
43 'http', null, 'www.example.com', null, '/', '', null
47 function testEmptyPath() {
48 $this->assertParsing(
49 'http://www.example.com',
50 'http', null, 'www.example.com', null, '', null, null
54 function testOpaqueURI() {
55 $this->assertParsing(
56 'mailto:bob@example.com',
57 'mailto', null, null, null, 'bob@example.com', null, null
61 function testIPv4Address() {
62 $this->assertParsing(
63 'http://192.0.34.166/',
64 'http', null, '192.0.34.166', null, '/', null, null
68 function testFakeIPv4Address() {
69 $this->assertParsing(
70 'http://333.123.32.123/',
71 'http', null, '333.123.32.123', null, '/', null, null
75 function testIPv6Address() {
76 $this->assertParsing(
77 'http://[2001:db8::7]/c=GB?objectClass?one',
78 'http', null, '[2001:db8::7]', null, '/c=GB', 'objectClass?one', null
82 function testInternationalizedDomainName() {
83 $this->assertParsing(
84 "http://t\xC5\xABdali\xC5\x86.lv",
85 'http', null, "t\xC5\xABdali\xC5\x86.lv", null, '', null, null
89 function testInvalidPort() {
90 $this->assertParsing(
91 'http://example.com:foobar',
92 'http', null, 'example.com', null, '', null, null
96 function testPathAbsolute() {
97 $this->assertParsing(
98 'http:/this/is/path',
99 'http', null, null, null, '/this/is/path', null, null
103 function testPathRootless() {
104 // this should not be used but is allowed
105 $this->assertParsing(
106 'http:this/is/path',
107 'http', null, null, null, 'this/is/path', null, null
111 function testPathEmpty() {
112 $this->assertParsing(
113 'http:',
114 'http', null, null, null, '', null, null
118 function testRelativeURI() {
119 $this->assertParsing(
120 '/a/b',
121 null, null, null, null, '/a/b', null, null
125 function testMalformedTag() {
126 $this->assertParsing(
127 'http://www.example.com/\'>"',
128 'http', null, 'www.example.com', null, '/', null, null
132 function testEmpty() {
133 $this->assertParsing(
135 null, null, null, null, '', null, null