Release 2.1.0, merged in 1313 to HEAD.
[htmlpurifier.git] / tests / HTMLPurifier / AttrDef / URITest.php
blob58b77248804b929ea22499bc37e6318d460d06c1
1 <?php
3 require_once 'HTMLPurifier/AttrDefHarness.php';
4 require_once 'HTMLPurifier/AttrDef/URI.php';
5 require_once 'HTMLPurifier/URIParser.php';
7 /**
8 * @todo Aim for complete code coverage with mocks
9 */
10 class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
13 function setUp() {
14 $this->def = new HTMLPurifier_AttrDef_URI();
15 parent::setUp();
18 function testIntegration() {
19 $this->assertDef('http://www.google.com/');
20 $this->assertDef('http:', '');
21 $this->assertDef('http:/foo', '/foo');
22 $this->assertDef('javascript:bad_stuff();', false);
23 $this->assertDef('ftp://www.example.com/');
24 $this->assertDef('news:rec.alt');
25 $this->assertDef('nntp://news.example.com/324234');
26 $this->assertDef('mailto:bob@example.com');
29 function testIntegrationWithPercentEncoder() {
30 $this->assertDef(
31 'http://www.example.com/%56%fc%GJ%5%FC',
32 'http://www.example.com/V%FC%25GJ%255%FC'
36 function testEmbeds() {
37 $this->def = new HTMLPurifier_AttrDef_URI(true);
38 $this->assertDef('http://sub.example.com/alas?foo=asd');
39 $this->assertDef('mailto:foo@example.com', false);
42 function testConfigMunge() {
43 $this->config->set('URI', 'Munge', 'http://www.google.com/url?q=%s');
44 $this->assertDef(
45 'http://www.example.com/',
46 'http://www.google.com/url?q=http%3A%2F%2Fwww.example.com%2F'
48 $this->assertDef('index.html');
49 $this->assertDef('javascript:foobar();', false);
52 function testDefaultSchemeRemovedInBlank() {
53 $this->assertDef('http:', '');
56 function testDefaultSchemeRemovedInRelativeURI() {
57 $this->assertDef('http:/foo/bar', '/foo/bar');
60 function testDefaultSchemeNotRemovedInAbsoluteURI() {
61 $this->assertDef('http://example.com/foo/bar');
64 function testAltSchemeNotRemoved() {
65 $this->assertDef('mailto:this-looks-like-a-path@example.com');
68 function testURIDefinitionValidation() {
69 $parser = new HTMLPurifier_URIParser();
70 $uri = $parser->parse('http://example.com');
71 $this->config->set('URI', 'DefinitionID', 'HTMLPurifier_AttrDef_URITest->testURIDefinitionValidation');
72 $uri_def =& $this->config->getDefinition('URI');
73 // overload with mock
74 generate_mock_once('HTMLPurifier_URIDefinition');
75 $uri_def = new HTMLPurifier_URIDefinitionMock();
76 $uri_def->expectOnce('filter', array($uri, '*', '*'));
77 $uri_def->setReturnValue('filter', true, array($uri, '*', '*'));
78 $uri_def->setup = true;
79 $this->assertDef('http://example.com');
83 function test_validate_configWhitelist() {
85 $this->config->set('URI', 'HostPolicy', 'DenyAll');
86 $this->config->set('URI', 'HostWhitelist', array(null, 'google.com'));
88 $this->assertDef('http://example.com/fo/google.com', false);
89 $this->assertDef('server.txt');
90 $this->assertDef('ftp://www.google.com/?t=a');
91 $this->assertDef('http://google.com.tricky.spamsite.net', false);