3 class HTMLPurifier_URIDefinitionTest
extends HTMLPurifier_URIHarness
6 protected function createFilterMock($expect = true, $result = true, $post = false, $setup = true)
9 generate_mock_once('HTMLPurifier_URIFilter');
10 $mock = new HTMLPurifier_URIFilterMock();
11 if ($expect) $mock->expectOnce('filter');
12 else $mock->expectNever('filter');
13 $mock->returns('filter', $result);
14 $mock->returns('prepare', $setup);
20 public function test_filter()
22 $def = new HTMLPurifier_URIDefinition();
23 $def->addFilter($this->createFilterMock(), $this->config
);
24 $def->addFilter($this->createFilterMock(), $this->config
);
25 $uri = $this->createURI('test');
26 $this->assertTrue($def->filter($uri, $this->config
, $this->context
));
29 public function test_filter_earlyAbortIfFail()
31 $def = new HTMLPurifier_URIDefinition();
32 $def->addFilter($this->createFilterMock(true, false), $this->config
);
33 $def->addFilter($this->createFilterMock(false), $this->config
); // never called
34 $uri = $this->createURI('test');
35 $this->assertFalse($def->filter($uri, $this->config
, $this->context
));
38 public function test_setupMemberVariables_collisionPrecedenceIsHostBaseScheme()
40 $this->config
->set('URI.Host', $host = 'example.com');
41 $this->config
->set('URI.Base', $base = 'http://sub.example.com/foo/bar.html');
42 $this->config
->set('URI.DefaultScheme', 'ftp');
43 $def = new HTMLPurifier_URIDefinition();
44 $def->setup($this->config
);
45 $this->assertIdentical($def->host
, $host);
46 $this->assertIdentical($def->base
, $this->createURI($base));
47 $this->assertIdentical($def->defaultScheme
, 'http'); // not ftp!
50 public function test_setupMemberVariables_onlyScheme()
52 $this->config
->set('URI.DefaultScheme', 'ftp');
53 $def = new HTMLPurifier_URIDefinition();
54 $def->setup($this->config
);
55 $this->assertIdentical($def->defaultScheme
, 'ftp');
58 public function test_setupMemberVariables_onlyBase()
60 $this->config
->set('URI.Base', 'http://sub.example.com/foo/bar.html');
61 $def = new HTMLPurifier_URIDefinition();
62 $def->setup($this->config
);
63 $this->assertIdentical($def->host
, 'sub.example.com');