1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-05 13:47:24 +02:00

[3.1.0] More PHP4->PHP5 conversions, notably reference removal of most methods that return objects

- Removed HTMLPurifier_Error
- Documentation updates
- Removed more copy() methods in favor of clone
- HTMLPurifier::getInstance() to HTMLPurifier::instance()
- Fix InterchangeBuilder to use HTMLPURIFIER_PREFIX

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1689 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2008-04-23 02:40:17 +00:00
parent 893cdd0301
commit eaabccdd9b
49 changed files with 237 additions and 210 deletions

View File

@@ -65,14 +65,31 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
$parser = new HTMLPurifier_URIParser();
$uri = $parser->parse('http://example.com');
$this->config->set('URI', 'DefinitionID', 'HTMLPurifier_AttrDef_URITest->testURIDefinitionValidation');
$uri_def =& $this->config->getDefinition('URI');
// overload with mock
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->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);
}
/*

View File

@@ -11,7 +11,7 @@ class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
function testAttributesTransformedGlobalPre() {
$this->config->set('HTML', 'DefinitionID',
'HTMLPurifier_AttrValidator_ErrorsTest::testAttributesTransformedGlobalPre');
$def =& $this->config->getHTMLDefinition(true);
$def = $this->config->getHTMLDefinition(true);
generate_mock_once('HTMLPurifier_AttrTransform');
$transform = new HTMLPurifier_AttrTransformMock();
$input = array('original' => 'value');

View File

@@ -219,27 +219,25 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
$def = $config->getCSSDefinition();
$this->assertIsA($def, 'HTMLPurifier_CSSDefinition');
$def =& $config->getHTMLDefinition();
$def2 =& $config->getHTMLDefinition();
$def = $config->getHTMLDefinition();
$def2 = $config->getHTMLDefinition();
$this->assertIsA($def, 'HTMLPurifier_HTMLDefinition');
$this->assertReference($def, $def2);
$this->assertSame($def, $def2);
$this->assertTrue($def->setup);
// test re-calculation if HTML changes
unset($def, $def2);
$def2 = $config->getHTMLDefinition(); // forcibly de-reference
$old_def = clone $def2;
$config->set('HTML', 'Doctype', 'HTML 4.01 Transitional');
$def = $config->getHTMLDefinition();
$this->assertIsA($def, 'HTMLPurifier_HTMLDefinition');
$this->assertNotEqual($def, $def2);
$this->assertNotEqual($def, $old_def);
$this->assertTrue($def->setup);
// test retrieval of raw definition
$config->set('HTML', 'DefinitionID', 'HTMLPurifier_ConfigTest->test_getHTMLDefinition()');
$config->set('HTML', 'DefinitionRev', 3);
$def =& $config->getHTMLDefinition(true);
$this->assertNotEqual($def, $def2);
$def = $config->getHTMLDefinition(true);
$this->assertNotEqual($def, $old_def);
$this->assertEqual(false, $def->setup);
// auto initialization
@@ -250,8 +248,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
function test_getHTMLDefinition_rawError() {
$config = HTMLPurifier_Config::createDefault();
$this->expectError('Cannot retrieve raw version without specifying %HTML.DefinitionID');
$def =& $config->getHTMLDefinition(true);
$this->expectException(new HTMLPurifier_Exception('Cannot retrieve raw version without specifying %HTML.DefinitionID'));
$def = $config->getHTMLDefinition(true);
}
function test_getCSSDefinition() {
@@ -265,7 +263,7 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
$this->schema->add('Cache', 'DefinitionImpl', null, 'string', true);
$this->schema->addNamespace('Crust', 'Krusty Krabs');
$config = new HTMLPurifier_Config($this->schema);
$this->expectError("Definition of Crust type not supported");
$this->expectException(new HTMLPurifier_Exception("Definition of Crust type not supported"));
$config->getDefinition('Crust');
}

View File

@@ -7,7 +7,7 @@ class HTMLPurifier_DoctypeRegistryTest extends HTMLPurifier_Harness
$registry = new HTMLPurifier_DoctypeRegistry();
$d =& $registry->register(
$d = $registry->register(
$name = 'XHTML 1.0 Transitional',
$xml = true,
$modules = array('module-one', 'module-two'),
@@ -18,10 +18,10 @@ class HTMLPurifier_DoctypeRegistryTest extends HTMLPurifier_Harness
$d2 = new HTMLPurifier_Doctype($name, $xml, $modules, $tidyModules, $aliases);
$this->assertIdentical($d, $d2);
$this->assertReference($d, $registry->get('XHTML 1.0 Transitional'));
$this->assertSame($d, $registry->get('XHTML 1.0 Transitional'));
// test shorthand
$d =& $registry->register(
$d = $registry->register(
$name = 'XHTML 1.0 Strict', true, 'module', 'Tidy', 'X10S'
);
$d2 = new HTMLPurifier_Doctype($name, true, array('module'), array('Tidy'), array('X10S'));
@@ -49,26 +49,26 @@ class HTMLPurifier_DoctypeRegistryTest extends HTMLPurifier_Harness
$registry = new HTMLPurifier_DoctypeRegistry();
$d1 =& $registry->register('Doc1', true, array(), array(), array('1'));
$d1 = $registry->register('Doc1', true, array(), array(), array('1'));
$this->assertReference($d1, $registry->get('Doc1'));
$this->assertReference($d1, $registry->get('1'));
$this->assertSame($d1, $registry->get('Doc1'));
$this->assertSame($d1, $registry->get('1'));
$d2 =& $registry->register('Doc2', true, array(), array(), array('2'));
$d2 = $registry->register('Doc2', true, array(), array(), array('2'));
$this->assertReference($d2, $registry->get('Doc2'));
$this->assertReference($d2, $registry->get('2'));
$this->assertSame($d2, $registry->get('Doc2'));
$this->assertSame($d2, $registry->get('2'));
$d3 =& $registry->register('1', true, array(), array(), array());
$d3 = $registry->register('1', true, array(), array(), array());
// literal name overrides alias
$this->assertReference($d3, $registry->get('1'));
$this->assertSame($d3, $registry->get('1'));
$d4 =& $registry->register('One', true, array(), array(), array('1'));
$d4 = $registry->register('One', true, array(), array(), array('1'));
$this->assertReference($d4, $registry->get('One'));
$this->assertSame($d4, $registry->get('One'));
// still it overrides
$this->assertReference($d3, $registry->get('1'));
$this->assertSame($d3, $registry->get('1'));
}

View File

@@ -75,7 +75,7 @@ a[href|title]
$config = HTMLPurifier_Config::create(array(
'HTML.DefinitionID' => 'HTMLPurifier_HTMLDefinitionTest->test_addAttribute'
));
$def =& $config->getHTMLDefinition(true);
$def = $config->getHTMLDefinition(true);
$def->addAttribute('span', 'custom', 'Enum#attribute');
$purifier = new HTMLPurifier($config);
@@ -90,7 +90,7 @@ a[href|title]
$config = HTMLPurifier_Config::create(array(
'HTML.DefinitionID' => 'HTMLPurifier_HTMLDefinitionTest->test_addAttribute_multiple'
));
$def =& $config->getHTMLDefinition(true);
$def = $config->getHTMLDefinition(true);
$def->addAttribute('span', 'custom', 'Enum#attribute');
$def->addAttribute('span', 'foo', 'Text');
@@ -106,7 +106,7 @@ a[href|title]
$config = HTMLPurifier_Config::create(array(
'HTML.DefinitionID' => 'HTMLPurifier_HTMLDefinitionTest->test_addElement'
));
$def =& $config->getHTMLDefinition(true);
$def = $config->getHTMLDefinition(true);
$def->addElement('marquee', 'Inline', 'Inline', 'Common', array('width' => 'Length'));
$purifier = new HTMLPurifier($config);

View File

@@ -206,7 +206,7 @@ class HTMLPurifier_HTMLModule_TidyTest extends HTMLPurifier_Harness
));
$module2 = new HTMLPurifier_HTMLModule_Tidy();
$e =& $module2->addBlankElement('element');
$e = $module2->addBlankElement('element');
$e->attr_transform_pre['attr'] = $attr;
$e->attr_transform_post['attr'] = $attr_post;
$e->child = $child;

View File

@@ -18,7 +18,7 @@ class HTMLPurifier_HTMLModuleTest extends HTMLPurifier_Harness
function test_addElement() {
$module = new HTMLPurifier_HTMLModule();
$def =& $module->addElement(
$def = $module->addElement(
'a', 'Inline', 'Optional: #PCDATA', array('Common'),
array(
'href' => 'URI'
@@ -107,7 +107,7 @@ class HTMLPurifier_HTMLModuleTest extends HTMLPurifier_Harness
function test_addBlankElement() {
$module = new HTMLPurifier_HTMLModule();
$def =& $module->addBlankElement('a');
$def = $module->addBlankElement('a');
$def2 = new HTMLPurifier_ElementDef();
$def2->standalone = false;

View File

@@ -83,7 +83,7 @@ alert(<b>bold</b>);
$this->config->set('HTML', 'DefinitionID',
'HTMLPurifier_Strategy_RemoveForeignElementsTest'.
'->testRequiredAttributesTestNotPerformedOnEndTag');
$def =& $this->config->getHTMLDefinition(true);
$def = $this->config->getHTMLDefinition(true);
$def->addElement('f', 'Block', 'Optional: #PCDATA', false, array('req*' => 'Text'));
$this->assertResult('<f req="text">Foo</f> Bar');
}