Beispiel #1
0
 function testURIDefinitionValidation()
 {
     $parser = new HTMLPurifier_URIParser();
     $uri = $parser->parse('http://example.com');
     $this->config->set('URI.DefinitionID', 'HTMLPurifier_AttrDef_URITest->testURIDefinitionValidation');
     generate_mock_once('HTMLPurifier_URIDefinition');
     $uri_def = new HTMLPurifier_URIDefinitionMock();
     $uri_def->expectOnce('filter', array($uri, '*', '*'));
     $uri_def->setReturnValue('filter', true, array($uri, '*', '*'));
     $uri_def->expectOnce('postFilter', array($uri, '*', '*'));
     $uri_def->setReturnValue('postFilter', true, array($uri, '*', '*'));
     $uri_def->setup = true;
     // Since definitions are no longer passed by reference, we need
     // to muck around with the cache to insert our mock. This is
     // technically a little bad, since the cache shouldn't change
     // behavior, but I don't feel too good about letting users
     // overload entire definitions.
     generate_mock_once('HTMLPurifier_DefinitionCache');
     $cache_mock = new HTMLPurifier_DefinitionCacheMock();
     $cache_mock->setReturnValue('get', $uri_def);
     generate_mock_once('HTMLPurifier_DefinitionCacheFactory');
     $factory_mock = new HTMLPurifier_DefinitionCacheFactoryMock();
     $old = HTMLPurifier_DefinitionCacheFactory::instance();
     HTMLPurifier_DefinitionCacheFactory::instance($factory_mock);
     $factory_mock->setReturnValue('create', $cache_mock);
     $this->assertDef('http://example.com');
     HTMLPurifier_DefinitionCacheFactory::instance($old);
 }
Beispiel #2
0
 protected function assertParsing($uri, $scheme, $userinfo, $host, $port, $path, $query, $fragment, $config = null, $context = null)
 {
     $this->prepareCommon($config, $context);
     $parser = new HTMLPurifier_URIParser();
     $result = $parser->parse($uri, $config, $context);
     $expect = new HTMLPurifier_URI($scheme, $userinfo, $host, $port, $path, $query, $fragment);
     $this->assertEqual($result, $expect);
 }
 protected function setupMemberVariables($config)
 {
     $this->host = $config->get('URI', 'Host');
     $base_uri = $config->get('URI', 'Base');
     if (!is_null($base_uri)) {
         $parser = new HTMLPurifier_URIParser();
         $this->base = $parser->parse($base_uri);
         $this->defaultScheme = $this->base->scheme;
         if (is_null($this->host)) {
             $this->host = $this->base->host;
         }
     }
     if (is_null($this->defaultScheme)) {
         $this->defaultScheme = $config->get('URI', 'DefaultScheme');
     }
 }
 protected function createURI($uri)
 {
     $parser = new HTMLPurifier_URIParser();
     return $parser->parse($uri);
 }