purifier = new HTMLPurifier(); } function assertPurification($input, $expect = null, $config = array()) { if ($expect === null) $expect = $input; $result = $this->purifier->purify($input, $config); $this->assertIdentical($expect, $result); } function testNull() { $this->assertPurification("Null byte\0", "Null byte"); } function testStrict() { $config = HTMLPurifier_Config::createDefault(); $config->set('HTML', 'Strict', true); $this->purifier = new HTMLPurifier( $config ); // verbose syntax $this->assertPurification( 'Illegal underline', 'Illegal underline' ); $this->assertPurification( '
Illegal contents
', '

Illegal contents

' ); } function testDifferentAllowedElements() { $this->purifier = new HTMLPurifier(array( 'HTML.AllowedElements' => array('b', 'i', 'p', 'a'), 'HTML.AllowedAttributes' => array('a.href', '*.id') )); $this->assertPurification( '

Par.

Paragraph

TextBold' ); $this->assertPurification( 'Not allowedFoobar', 'Not allowedFoobar' // no ID!!! ); } function testBlacklistElements() { $this->purifier = new HTMLPurifier(array( 'HTML.ForbiddenElements' => array('b'), 'HTML.ForbiddenAttributes' => array('a.href') )); $this->assertPurification( '

Par.

' ); $this->assertPurification( 'Par.', 'Par.' ); } function testDifferentAllowedCSSProperties() { $this->purifier = new HTMLPurifier(array( 'CSS.AllowedProperties' => array('color', 'background-color') )); $this->assertPurification( '
red
' ); $this->assertPurification( '
red
', '
red
' ); } function testDisableURI() { $this->purifier = new HTMLPurifier( array('URI.Disable' => true) ); $this->assertPurification( '', '' ); } function test_purifyArray() { $this->purifier = new HTMLPurifier(); $this->assertIdentical( $this->purifier->purifyArray( array('Good', 'Sketchy', 'foo' => '') ), array('Good', 'Sketchy', 'foo' => '') ); $this->assertIsA($this->purifier->context, 'array'); } function testEnableAttrID() { $this->purifier = new HTMLPurifier(); $this->assertPurification( 'foobar', 'foobar' ); $this->purifier = new HTMLPurifier(array('Attr.EnableID' => true)); $this->assertPurification('foobar'); $this->assertPurification('Omigosh!'); } function testScript() { $this->purifier = new HTMLPurifier(array('HTML.Trusted' => true)); $ideal = ''; $this->assertPurification($ideal); $this->assertPurification( '', $ideal ); $this->assertPurification( '', $ideal ); $this->assertPurification( '', $ideal ); $this->assertPurification( '', $ideal ); } function testGetInstance() { $purifier = HTMLPurifier::getInstance(); $purifier2 = HTMLPurifier::getInstance(); $this->assertReference($purifier, $purifier2); } function testMakeAbsolute() { $this->assertPurification( 'Foobar', 'Foobar', array( 'URI.Base' => 'http://example.com/bar/baz.php', 'URI.MakeAbsolute' => true ) ); } function test_addFilter_deprecated() { $purifier = new HTMLPurifier(); $this->expectError('HTMLPurifier->addFilter() is deprecated, use configuration directives in the Filter namespace or Filter.Custom'); generate_mock_once('HTMLPurifier_Filter'); $purifier->addFilter($mock = new HTMLPurifier_FilterMock()); $mock->expectOnce('preFilter'); $mock->expectOnce('postFilter'); $purifier->purify('foo'); } }