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 testDisableURI() { $this->purifier = new HTMLPurifier( array('Attr.DisableURI' => 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('HTML.EnableAttrID' => 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 ) ); } }