3 class HTMLPurifier_URIDefinitionTest
extends HTMLPurifier_URIHarness
6 protected function createFilterMock($expect = true, $result = true, $post = false, $setup = true) {
8 generate_mock_once('HTMLPurifier_URIFilter');
9 $mock = new HTMLPurifier_URIFilterMock();
10 if ($expect) $mock->expectOnce('filter');
11 else $mock->expectNever('filter');
12 $mock->setReturnValue('filter', $result);
13 $mock->setReturnValue('prepare', $setup);
19 function test_filter() {
20 $def = new HTMLPurifier_URIDefinition();
21 $def->addFilter($this->createFilterMock(), $this->config
);
22 $def->addFilter($this->createFilterMock(), $this->config
);
23 $uri = $this->createURI('test');
24 $this->assertTrue($def->filter($uri, $this->config
, $this->context
));
27 function test_filter_earlyAbortIfFail() {
28 $def = new HTMLPurifier_URIDefinition();
29 $def->addFilter($this->createFilterMock(true, false), $this->config
);
30 $def->addFilter($this->createFilterMock(false), $this->config
); // never called
31 $uri = $this->createURI('test');
32 $this->assertFalse($def->filter($uri, $this->config
, $this->context
));
35 function test_setupMemberVariables_collisionPrecedenceIsHostBaseScheme() {
36 $this->config
->set('URI.Host', $host = 'example.com');
37 $this->config
->set('URI.Base', $base = 'http://sub.example.com/foo/bar.html');
38 $this->config
->set('URI.DefaultScheme', 'ftp');
39 $def = new HTMLPurifier_URIDefinition();
40 $def->setup($this->config
);
41 $this->assertIdentical($def->host
, $host);
42 $this->assertIdentical($def->base
, $this->createURI($base));
43 $this->assertIdentical($def->defaultScheme
, 'http'); // not ftp!
46 function test_setupMemberVariables_onlyScheme() {
47 $this->config
->set('URI.DefaultScheme', 'ftp');
48 $def = new HTMLPurifier_URIDefinition();
49 $def->setup($this->config
);
50 $this->assertIdentical($def->defaultScheme
, 'ftp');
53 function test_setupMemberVariables_onlyBase() {
54 $this->config
->set('URI.Base', 'http://sub.example.com/foo/bar.html');
55 $def = new HTMLPurifier_URIDefinition();
56 $def->setup($this->config
);
57 $this->assertIdentical($def->host
, 'sub.example.com');