1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-07-30 19:00:10 +02:00

PSR-2 reformatting PHPDoc corrections

With minor corrections.

Signed-off-by: Marcus Bointon <marcus@synchromedia.co.uk>
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
This commit is contained in:
Marcus Bointon
2013-07-16 13:56:14 +02:00
committed by Edward Z. Yang
parent 19eee14899
commit fac747bdbd
433 changed files with 13302 additions and 6690 deletions

View File

@@ -9,8 +9,8 @@ Mock::generatePartial(
class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
{
function testConstruction() {
public function testConstruction()
{
generate_mock_once('HTMLPurifier_AttrTypes');
$collections = new HTMLPurifier_AttrCollections_TestForConstruct();
@@ -61,8 +61,8 @@ class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
}
function test_performInclusions() {
public function test_performInclusions()
{
generate_mock_once('HTMLPurifier_AttrTypes');
$types = new HTMLPurifier_AttrTypesMock();
@@ -99,8 +99,8 @@ class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
}
function test_expandIdentifiers() {
public function test_expandIdentifiers()
{
generate_mock_once('HTMLPurifier_AttrTypes');
$types = new HTMLPurifier_AttrTypesMock();

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_CSS_AlphaValueTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_CSS_AlphaValue();
$this->assertDef('0');

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_CSS_BackgroundPositionTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_CSS_BackgroundPosition();
// explicitly cited in spec

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_CSS_BackgroundTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$config = HTMLPurifier_Config::createDefault();
$this->def = new HTMLPurifier_AttrDef_CSS_Background($config);

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_CSS_BorderTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$config = HTMLPurifier_Config::createDefault();
$this->def = new HTMLPurifier_AttrDef_CSS_Border($config);

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_CSS_ColorTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_CSS_Color();
$this->assertDef('#F00');

View File

@@ -5,7 +5,8 @@ class HTMLPurifier_AttrDef_CSS_Composite_Testable extends
{
// we need to pass by ref to get the mocks in
function HTMLPurifier_AttrDef_CSS_Composite_Testable(&$defs) {
public function HTMLPurifier_AttrDef_CSS_Composite_Testable(&$defs)
{
$this->defs =& $defs;
}
@@ -16,8 +17,8 @@ class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness
protected $def1, $def2;
function test() {
public function test()
{
generate_mock_once('HTMLPurifier_AttrDef');
$config = HTMLPurifier_Config::createDefault();

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_CSS_FilterTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_CSS_Filter();
$this->assertDef('none');

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_CSS_FontFamilyTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_CSS_FontFamily();
$this->assertDef('Gill, Helvetica, sans-serif');
@@ -36,7 +36,8 @@ class HTMLPurifier_AttrDef_CSS_FontFamilyTest extends HTMLPurifier_AttrDefHarnes
//$this->assertDef('"\'"', "\"'\"");
}
function testAllowed() {
public function testAllowed()
{
$this->config->set('CSS.AllowedFonts', array('serif', 'Times New Roman'));
$this->assertDef('serif');

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_CSS_FontTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$config = HTMLPurifier_Config::createDefault();
$this->def = new HTMLPurifier_AttrDef_CSS_Font($config);

View File

@@ -6,39 +6,46 @@ class HTMLPurifier_AttrDef_CSS_ImportantDecoratorTest extends HTMLPurifier_AttrD
/** Mock AttrDef decorator is wrapping */
protected $mock;
function setUp() {
public function setUp()
{
generate_mock_once('HTMLPurifier_AttrDef');
$this->mock = new HTMLPurifier_AttrDefMock();
$this->def = new HTMLPurifier_AttrDef_CSS_ImportantDecorator($this->mock, true);
}
protected function setMock($input, $output = null) {
protected function setMock($input, $output = null)
{
if ($output === null) $output = $input;
$this->mock->expectOnce('validate', array($input, $this->config, $this->context));
$this->mock->setReturnValue('validate', $output);
}
function testImportant() {
public function testImportant()
{
$this->setMock('23');
$this->assertDef('23 !important');
}
function testImportantInternalDefChanged() {
public function testImportantInternalDefChanged()
{
$this->setMock('23', '24');
$this->assertDef('23 !important', '24 !important');
}
function testImportantWithSpace() {
public function testImportantWithSpace()
{
$this->setMock('23');
$this->assertDef('23 ! important ', '23 !important');
}
function testFakeImportant() {
public function testFakeImportant()
{
$this->setMock('! foo important');
$this->assertDef('! foo important');
}
function testStrip() {
public function testStrip()
{
$this->def = new HTMLPurifier_AttrDef_CSS_ImportantDecorator($this->mock, false);
$this->setMock('23');
$this->assertDef('23 ! important ', '23');

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_CSS_LengthTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_CSS_Length();
$this->assertDef('0');
@@ -26,8 +26,8 @@ class HTMLPurifier_AttrDef_CSS_LengthTest extends HTMLPurifier_AttrDefHarness
}
function testNonNegative() {
public function testNonNegative()
{
$this->def = new HTMLPurifier_AttrDef_CSS_Length('0');
$this->assertDef('3cm');
@@ -35,7 +35,8 @@ class HTMLPurifier_AttrDef_CSS_LengthTest extends HTMLPurifier_AttrDefHarness
}
function testBounding() {
public function testBounding()
{
$this->def = new HTMLPurifier_AttrDef_CSS_Length('-1in', '1in');
$this->assertDef('1cm');
$this->assertDef('-1cm');

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_CSS_ListStyleTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$config = HTMLPurifier_Config::createDefault();
$this->def = new HTMLPurifier_AttrDef_CSS_ListStyle($config);

View File

@@ -4,7 +4,8 @@
class HTMLPurifier_AttrDef_CSS_MultipleTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_CSS_Multiple(
new HTMLPurifier_AttrDef_Integer()
);

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_CSS_NumberTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_CSS_Number();
$this->assertDef('0');
@@ -38,8 +38,8 @@ class HTMLPurifier_AttrDef_CSS_NumberTest extends HTMLPurifier_AttrDefHarness
}
function testNonNegative() {
public function testNonNegative()
{
$this->def = new HTMLPurifier_AttrDef_CSS_Number(true);
$this->assertDef('23');
$this->assertDef('-12', false);

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_CSS_PercentageTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_CSS_Percentage();
$this->assertDef('10%');

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_CSS_TextDecorationTest extends HTMLPurifier_AttrDefHarness
{
function testCaseInsensitive() {
public function testCaseInsensitive()
{
$this->def = new HTMLPurifier_AttrDef_CSS_TextDecoration();
$this->assertDef('none');

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_CSS_URITest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_CSS_URI();
$this->assertDef('', false);

View File

@@ -3,13 +3,14 @@
class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
{
function setup() {
public function setup()
{
parent::setup();
$this->def = new HTMLPurifier_AttrDef_CSS();
}
function test() {
public function test()
{
// regular cases, singular
$this->assertDef('text-align:right;');
$this->assertDef('border-left-style:solid;');
@@ -115,7 +116,8 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
}
function testProprietary() {
public function testProprietary()
{
$this->config->set('CSS.Proprietary', true);
$this->assertDef('scrollbar-arrow-color:#ff0;');
@@ -132,25 +134,29 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
}
function testImportant() {
public function testImportant()
{
$this->config->set('CSS.AllowImportant', true);
$this->assertDef('float:left !important;');
}
function testTricky() {
public function testTricky()
{
$this->config->set('CSS.AllowTricky', true);
$this->assertDef('display:none;');
$this->assertDef('visibility:visible;');
$this->assertDef('overflow:scroll;');
}
function testForbidden() {
public function testForbidden()
{
$this->config->set('CSS.ForbiddenProperties', 'float');
$this->assertDef('float:left;', false);
$this->assertDef('text-align:right;');
}
function testTrusted() {
public function testTrusted()
{
$this->config->set('CSS.Trusted', true);
$this->assertDef('position:relative;');
$this->assertDef('left:2px;');

View File

@@ -3,24 +3,28 @@
class HTMLPurifier_AttrDef_EnumTest extends HTMLPurifier_AttrDefHarness
{
function testCaseInsensitive() {
public function testCaseInsensitive()
{
$this->def = new HTMLPurifier_AttrDef_Enum(array('one', 'two'));
$this->assertDef('one');
$this->assertDef('ONE', 'one');
}
function testCaseSensitive() {
public function testCaseSensitive()
{
$this->def = new HTMLPurifier_AttrDef_Enum(array('one', 'two'), true);
$this->assertDef('one');
$this->assertDef('ONE', false);
}
function testFixing() {
public function testFixing()
{
$this->def = new HTMLPurifier_AttrDef_Enum(array('one'));
$this->assertDef(' one ', 'one');
}
function test_make() {
public function test_make()
{
$factory = new HTMLPurifier_AttrDef_Enum();
$def = $factory->make('foo,bar');

View File

@@ -3,14 +3,16 @@
class HTMLPurifier_AttrDef_HTML_BoolTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_HTML_Bool('foo');
$this->assertDef('foo');
$this->assertDef('', false);
$this->assertDef('bar', 'foo');
}
function test_make() {
public function test_make()
{
$factory = new HTMLPurifier_AttrDef_HTML_Bool();
$def = $factory->make('foo');
$def2 = new HTMLPurifier_AttrDef_HTML_Bool('foo');

View File

@@ -2,23 +2,27 @@
class HTMLPurifier_AttrDef_HTML_ClassTest extends HTMLPurifier_AttrDef_HTML_NmtokensTest
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->def = new HTMLPurifier_AttrDef_HTML_Class();
}
function testAllowedClasses() {
public function testAllowedClasses()
{
$this->config->set('Attr.AllowedClasses', array('foo'));
$this->assertDef('foo');
$this->assertDef('bar', false);
$this->assertDef('foo bar', 'foo');
}
function testForbiddenClasses() {
public function testForbiddenClasses()
{
$this->config->set('Attr.ForbiddenClasses', array('bar'));
$this->assertDef('foo');
$this->assertDef('bar', false);
$this->assertDef('foo bar', 'foo');
}
function testDefault() {
public function testDefault()
{
$this->assertDef('valid');
$this->assertDef('a0-_');
$this->assertDef('-valid');
@@ -40,7 +44,8 @@ class HTMLPurifier_AttrDef_HTML_ClassTest extends HTMLPurifier_AttrDef_HTML_Nmto
// test duplicate removal
$this->assertDef('valid valid', 'valid');
}
function testXHTML11Behavior() {
public function testXHTML11Behavior()
{
$this->config->set('HTML.Doctype', 'XHTML 1.1');
$this->assertDef('0invalid', false);
$this->assertDef('valid valid', 'valid');

View File

@@ -3,7 +3,8 @@
class HTMLPurifier_AttrDef_HTML_ColorTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_HTML_Color();
$this->assertDef('', false);
$this->assertDef('foo', false);

View File

@@ -3,19 +3,22 @@
class HTMLPurifier_AttrDef_HTML_FrameTargetTest extends HTMLPurifier_AttrDefHarness
{
function setup() {
public function setup()
{
parent::setup();
$this->def = new HTMLPurifier_AttrDef_HTML_FrameTarget();
}
function testNoneAllowed() {
public function testNoneAllowed()
{
$this->assertDef('', false);
$this->assertDef('foo', false);
$this->assertDef('_blank', false);
$this->assertDef('baz', false);
}
function test() {
public function test()
{
$this->config->set('Attr.AllowedFrameTargets', 'foo,_blank');
$this->assertDef('', false);
$this->assertDef('foo');

View File

@@ -3,7 +3,8 @@
class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$id_accumulator = new HTMLPurifier_IDAccumulator();
@@ -13,8 +14,8 @@ class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
}
function test() {
public function test()
{
// valid ID names
$this->assertDef('alpha');
$this->assertDef('al_ha');
@@ -35,8 +36,8 @@ class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
}
function testPrefix() {
public function testPrefix()
{
$this->config->set('Attr.IDPrefix', 'user_');
$this->assertDef('alpha', 'user_alpha');
@@ -50,8 +51,8 @@ class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
}
function testTwoPrefixes() {
public function testTwoPrefixes()
{
$this->config->set('Attr.IDPrefix', 'user_');
$this->config->set('Attr.IDPrefixLocal', 'story95_');
@@ -64,7 +65,8 @@ class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('user_alas', 'user_story95_user_alas'); // !
}
function testLocalPrefixWithoutMainPrefix() {
public function testLocalPrefixWithoutMainPrefix()
{
// no effect when IDPrefix isn't set
$this->config->set('Attr.IDPrefix', '');
$this->config->set('Attr.IDPrefixLocal', 'story95_');
@@ -75,8 +77,8 @@ class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
}
// reference functionality is disabled for now
function disabled_testIDReference() {
public function disabled_testIDReference()
{
$this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
$this->assertDef('good_id');
@@ -94,8 +96,8 @@ class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
}
function testRegexp() {
public function testRegexp()
{
$this->config->set('Attr.IDBlacklistRegexp', '/^g_/');
$this->assertDef('good_id');

View File

@@ -3,12 +3,13 @@
class HTMLPurifier_AttrDef_HTML_LengthTest extends HTMLPurifier_AttrDef_HTML_PixelsTest
{
function setup() {
public function setup()
{
$this->def = new HTMLPurifier_AttrDef_HTML_Length();
}
function test() {
public function test()
{
// pixel check
parent::test();

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_HTML_LinkTypesTest extends HTMLPurifier_AttrDefHarness
{
function testNull() {
public function testNull()
{
$this->def = new HTMLPurifier_AttrDef_HTML_LinkTypes('rel');
$this->config->set('Attr.AllowedRel', array('nofollow', 'foo'));

View File

@@ -3,12 +3,13 @@
class HTMLPurifier_AttrDef_HTML_MultiLengthTest extends HTMLPurifier_AttrDef_HTML_LengthTest
{
function setup() {
public function setup()
{
$this->def = new HTMLPurifier_AttrDef_HTML_MultiLength();
}
function test() {
public function test()
{
// length check
parent::test();

View File

@@ -3,13 +3,14 @@
class HTMLPurifier_AttrDef_HTML_NmtokensTest extends HTMLPurifier_AttrDefHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->def = new HTMLPurifier_AttrDef_HTML_Nmtokens();
}
function testDefault() {
public function testDefault()
{
$this->assertDef('valid');
$this->assertDef('a0-_');
$this->assertDef('-valid');

View File

@@ -3,12 +3,13 @@
class HTMLPurifier_AttrDef_HTML_PixelsTest extends HTMLPurifier_AttrDefHarness
{
function setup() {
public function setup()
{
$this->def = new HTMLPurifier_AttrDef_HTML_Pixels();
}
function test() {
public function test()
{
$this->assertDef('1');
$this->assertDef('0');
@@ -33,7 +34,8 @@ class HTMLPurifier_AttrDef_HTML_PixelsTest extends HTMLPurifier_AttrDefHarness
}
function test_make() {
public function test_make()
{
$factory = new HTMLPurifier_AttrDef_HTML_Pixels();
$this->def = $factory->make('30');
$this->assertDef('25');

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_IntegerTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_Integer();
$this->assertDef('0');
@@ -23,7 +23,8 @@ class HTMLPurifier_AttrDef_IntegerTest extends HTMLPurifier_AttrDefHarness
}
function assertRange($negative, $zero, $positive) {
public function assertRange($negative, $zero, $positive)
{
$this->assertDef('-100', $negative);
$this->assertDef('-1', $negative);
$this->assertDef('0', $zero);
@@ -31,8 +32,8 @@ class HTMLPurifier_AttrDef_IntegerTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('42', $positive);
}
function testRange() {
public function testRange()
{
$this->def = new HTMLPurifier_AttrDef_Integer(false);
$this->assertRange(false, true, true); // non-negative

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_LangTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_Lang();
// basic good uses

View File

@@ -5,7 +5,8 @@ class HTMLPurifier_AttrDef_SwitchTest extends HTMLPurifier_AttrDefHarness
protected $with, $without;
function setUp() {
public function setUp()
{
parent::setUp();
generate_mock_once('HTMLPurifier_AttrDef');
$this->with = new HTMLPurifier_AttrDefMock();
@@ -13,7 +14,8 @@ class HTMLPurifier_AttrDef_SwitchTest extends HTMLPurifier_AttrDefHarness
$this->def = new HTMLPurifier_AttrDef_Switch('tag', $this->with, $this->without);
}
function testWith() {
public function testWith()
{
$token = new HTMLPurifier_Token_Start('tag');
$this->context->register('CurrentToken', $token);
$this->with->expectOnce('validate');
@@ -21,7 +23,8 @@ class HTMLPurifier_AttrDef_SwitchTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('bar', 'foo');
}
function testWithout() {
public function testWithout()
{
$token = new HTMLPurifier_Token_Start('other-tag');
$this->context->register('CurrentToken', $token);
$this->without->expectOnce('validate');

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_AttrDef_TextTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_Text();
$this->assertDef('This is spiffy text!');

View File

@@ -4,7 +4,8 @@ class HTMLPurifier_AttrDef_URI_Email_SimpleCheckTest
extends HTMLPurifier_AttrDef_URI_EmailHarness
{
function setUp() {
public function setUp()
{
$this->def = new HTMLPurifier_AttrDef_URI_Email_SimpleCheck();
}

View File

@@ -6,7 +6,8 @@ class HTMLPurifier_AttrDef_URI_EmailHarness extends HTMLPurifier_AttrDefHarness
/**
* Tests common email strings that are obviously pass/fail
*/
function testCore() {
public function testCore()
{
$this->assertDef('bob@example.com');
$this->assertDef(' bob@example.com ', 'bob@example.com');
$this->assertDef('bob.thebuilder@example.net');

View File

@@ -6,8 +6,8 @@
class HTMLPurifier_AttrDef_URI_HostTest extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_URI_Host();
$this->assertDef('[2001:DB8:0:0:8:800:200C:417A]'); // IPv6
@@ -40,7 +40,8 @@ class HTMLPurifier_AttrDef_URI_HostTest extends HTMLPurifier_AttrDefHarness
}
function testIDNA() {
public function testIDNA()
{
if (!$GLOBALS['HTMLPurifierTest']['Net_IDNA2']) {
return false;
}

View File

@@ -6,8 +6,8 @@
class HTMLPurifier_AttrDef_URI_IPv4Test extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_URI_IPv4();
$this->assertDef('127.0.0.1'); // standard IPv4, loopback, non-routable

View File

@@ -6,8 +6,8 @@
class HTMLPurifier_AttrDef_URI_IPv6Test extends HTMLPurifier_AttrDefHarness
{
function test() {
public function test()
{
$this->def = new HTMLPurifier_AttrDef_URI_IPv6();
$this->assertDef('2001:DB8:0:0:8:800:200C:417A'); // unicast, full

View File

@@ -6,12 +6,14 @@
class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
{
function setUp() {
public function setUp()
{
$this->def = new HTMLPurifier_AttrDef_URI();
parent::setUp();
}
function testIntegration() {
public function testIntegration()
{
$this->assertDef('http://www.google.com/');
$this->assertDef('http:', '');
$this->assertDef('http:/foo', '/foo');
@@ -22,33 +24,38 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
$this->assertDef('mailto:bob@example.com');
}
function testIntegrationWithPercentEncoder() {
public function testIntegrationWithPercentEncoder()
{
$this->assertDef(
'http://www.example.com/%56%fc%GJ%5%FC',
'http://www.example.com/V%FC%25GJ%255%FC'
);
}
function testPercentEncoding() {
public function testPercentEncoding()
{
$this->assertDef(
'http:colon:mercenary',
'colon%3Amercenary'
);
}
function testPercentEncodingPreserve() {
public function testPercentEncodingPreserve()
{
$this->assertDef(
'http://www.example.com/abcABC123-_.!~*()\''
);
}
function testEmbeds() {
public function testEmbeds()
{
$this->def = new HTMLPurifier_AttrDef_URI(true);
$this->assertDef('http://sub.example.com/alas?foo=asd');
$this->assertDef('mailto:foo@example.com', false);
}
function testConfigMunge() {
public function testConfigMunge()
{
$this->config->set('URI.Munge', 'http://www.google.com/url?q=%s');
$this->assertDef(
'http://www.example.com/',
@@ -58,32 +65,39 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
$this->assertDef('javascript:foobar();', false);
}
function testDefaultSchemeRemovedInBlank() {
public function testDefaultSchemeRemovedInBlank()
{
$this->assertDef('http:', '');
}
function testDefaultSchemeRemovedInRelativeURI() {
public function testDefaultSchemeRemovedInRelativeURI()
{
$this->assertDef('http:/foo/bar', '/foo/bar');
}
function testDefaultSchemeNotRemovedInAbsoluteURI() {
public function testDefaultSchemeNotRemovedInAbsoluteURI()
{
$this->assertDef('http://example.com/foo/bar');
}
function testAltSchemeNotRemoved() {
public function testAltSchemeNotRemoved()
{
$this->assertDef('mailto:this-looks-like-a-path@example.com');
}
function testResolveNullSchemeAmbiguity() {
public function testResolveNullSchemeAmbiguity()
{
$this->assertDef('///foo', '/foo');
}
function testResolveNullSchemeDoubleAmbiguity() {
public function testResolveNullSchemeDoubleAmbiguity()
{
$this->config->set('URI.Host', 'example.com');
$this->assertDef('////foo', '//example.com//foo');
}
function testURIDefinitionValidation() {
public function testURIDefinitionValidation()
{
$parser = new HTMLPurifier_URIParser();
$uri = $parser->parse('http://example.com');
$this->config->set('URI.DefinitionID', 'HTMLPurifier_AttrDef_URITest->testURIDefinitionValidation');
@@ -116,7 +130,8 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
HTMLPurifier_DefinitionCacheFactory::instance($old);
}
function test_make() {
public function test_make()
{
$factory = new HTMLPurifier_AttrDef_URI();
$def = $factory->make('');
$def2 = new HTMLPurifier_AttrDef_URI();
@@ -128,8 +143,8 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
}
/*
function test_validate_configWhitelist() {
public function test_validate_configWhitelist()
{
$this->config->set('URI.HostPolicy', 'DenyAll');
$this->config->set('URI.HostWhitelist', array(null, 'google.com'));

View File

@@ -6,13 +6,15 @@ class HTMLPurifier_AttrDefHarness extends HTMLPurifier_Harness
protected $def;
protected $context, $config;
public function setUp() {
public function setUp()
{
$this->config = HTMLPurifier_Config::createDefault();
$this->context = new HTMLPurifier_Context();
}
// cannot be used for accumulator
function assertDef($string, $expect = true) {
public function assertDef($string, $expect = true)
{
// $expect can be a string or bool
$result = $this->def->validate($string, $this->config, $this->context);
if ($expect === true) {

View File

@@ -8,8 +8,8 @@ Mock::generatePartial(
class HTMLPurifier_AttrDefTest extends HTMLPurifier_Harness
{
function test_parseCDATA() {
public function test_parseCDATA()
{
$def = new HTMLPurifier_AttrDefTestable();
$this->assertIdentical('', $def->parseCDATA(''));
@@ -19,8 +19,8 @@ class HTMLPurifier_AttrDefTest extends HTMLPurifier_Harness
}
function test_make() {
public function test_make()
{
$def = new HTMLPurifier_AttrDefTestable();
$def2 = $def->make('');
$this->assertIdentical($def, $def2);

View File

@@ -3,30 +3,35 @@
class HTMLPurifier_AttrTransform_BackgroundTest extends HTMLPurifier_AttrTransformHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_Background();
}
function testEmptyInput() {
public function testEmptyInput()
{
$this->assertResult( array() );
}
function testBasicTransform() {
public function testBasicTransform()
{
$this->assertResult(
array('background' => 'logo.png'),
array('style' => 'background-image:url(logo.png);')
);
}
function testPrependNewCSS() {
public function testPrependNewCSS()
{
$this->assertResult(
array('background' => 'logo.png', 'style' => 'font-weight:bold'),
array('style' => 'background-image:url(logo.png);font-weight:bold')
);
}
function testLenientTreatmentOfInvalidInput() {
public function testLenientTreatmentOfInvalidInput()
{
// notice that we rely on the CSS validator later to fix this invalid
// stuff
$this->assertResult(

View File

@@ -3,20 +3,24 @@
class HTMLPurifier_AttrTransform_BdoDirTest extends HTMLPurifier_AttrTransformHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_BdoDir();
}
function testAddDefaultDir() {
public function testAddDefaultDir()
{
$this->assertResult( array(), array('dir' => 'ltr') );
}
function testPreserveExistingDir() {
public function testPreserveExistingDir()
{
$this->assertResult( array('dir' => 'rtl') );
}
function testAlternateDefault() {
public function testAlternateDefault()
{
$this->config->set('Attr.DefaultTextDir', 'rtl');
$this->assertResult(
array(),

View File

@@ -7,30 +7,35 @@
class HTMLPurifier_AttrTransform_BgColorTest extends HTMLPurifier_AttrTransformHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_BgColor();
}
function testEmptyInput() {
public function testEmptyInput()
{
$this->assertResult( array() );
}
function testBasicTransform() {
public function testBasicTransform()
{
$this->assertResult(
array('bgcolor' => '#000000'),
array('style' => 'background-color:#000000;')
);
}
function testPrependNewCSS() {
public function testPrependNewCSS()
{
$this->assertResult(
array('bgcolor' => '#000000', 'style' => 'font-weight:bold'),
array('style' => 'background-color:#000000;font-weight:bold')
);
}
function testLenientTreatmentOfInvalidInput() {
public function testLenientTreatmentOfInvalidInput()
{
// this may change when we natively support the datatype and
// validate its contents before forwarding it on
$this->assertResult(

View File

@@ -3,30 +3,35 @@
class HTMLPurifier_AttrTransform_BoolToCSSTest extends HTMLPurifier_AttrTransformHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_BoolToCSS('foo', 'bar:3in;');
}
function testEmptyInput() {
public function testEmptyInput()
{
$this->assertResult( array() );
}
function testBasicTransform() {
public function testBasicTransform()
{
$this->assertResult(
array('foo' => 'foo'),
array('style' => 'bar:3in;')
);
}
function testIgnoreValueOfBooleanAttribute() {
public function testIgnoreValueOfBooleanAttribute()
{
$this->assertResult(
array('foo' => 'no'),
array('style' => 'bar:3in;')
);
}
function testPrependCSS() {
public function testPrependCSS()
{
$this->assertResult(
array('foo' => 'foo', 'style' => 'background-color:#F00;'),
array('style' => 'bar:3in;background-color:#F00;')

View File

@@ -3,30 +3,35 @@
class HTMLPurifier_AttrTransform_BorderTest extends HTMLPurifier_AttrTransformHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_Border();
}
function testEmptyInput() {
public function testEmptyInput()
{
$this->assertResult( array() );
}
function testBasicTransform() {
public function testBasicTransform()
{
$this->assertResult(
array('border' => '1'),
array('style' => 'border:1px solid;')
);
}
function testLenientTreatmentOfInvalidInput() {
public function testLenientTreatmentOfInvalidInput()
{
$this->assertResult(
array('border' => '10%'),
array('style' => 'border:10%px solid;')
);
}
function testPrependNewCSS() {
public function testPrependNewCSS()
{
$this->assertResult(
array('border' => '23', 'style' => 'font-weight:bold;'),
array('style' => 'border:23px solid;font-weight:bold;')

View File

@@ -3,7 +3,8 @@
class HTMLPurifier_AttrTransform_EnumToCSSTest extends HTMLPurifier_AttrTransformHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
'left' => 'text-align:left;',
@@ -11,36 +12,42 @@ class HTMLPurifier_AttrTransform_EnumToCSSTest extends HTMLPurifier_AttrTransfor
));
}
function testEmptyInput() {
public function testEmptyInput()
{
$this->assertResult( array() );
}
function testPreserveArraysWithoutInterestingAttributes() {
public function testPreserveArraysWithoutInterestingAttributes()
{
$this->assertResult( array('style' => 'font-weight:bold;') );
}
function testConvertAlignLeft() {
public function testConvertAlignLeft()
{
$this->assertResult(
array('align' => 'left'),
array('style' => 'text-align:left;')
);
}
function testConvertAlignRight() {
public function testConvertAlignRight()
{
$this->assertResult(
array('align' => 'right'),
array('style' => 'text-align:right;')
);
}
function testRemoveInvalidAlign() {
public function testRemoveInvalidAlign()
{
$this->assertResult(
array('align' => 'invalid'),
array()
);
}
function testPrependNewCSS() {
public function testPrependNewCSS()
{
$this->assertResult(
array('align' => 'left', 'style' => 'font-weight:bold;'),
array('style' => 'text-align:left;font-weight:bold;')
@@ -48,7 +55,8 @@ class HTMLPurifier_AttrTransform_EnumToCSSTest extends HTMLPurifier_AttrTransfor
}
function testCaseInsensitive() {
public function testCaseInsensitive()
{
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
'right' => 'text-align:right;'
));
@@ -58,7 +66,8 @@ class HTMLPurifier_AttrTransform_EnumToCSSTest extends HTMLPurifier_AttrTransfor
);
}
function testCaseSensitive() {
public function testCaseSensitive()
{
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
'right' => 'text-align:right;'
), true);

View File

@@ -3,12 +3,14 @@
class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransformHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_ImgRequired();
}
function testAddMissingAttr() {
public function testAddMissingAttr()
{
$this->config->set('Core.RemoveInvalidImg', false);
$this->assertResult(
array(),
@@ -16,7 +18,8 @@ class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransf
);
}
function testAlternateDefaults() {
public function testAlternateDefaults()
{
$this->config->set('Attr.DefaultInvalidImage', 'blank.png');
$this->config->set('Attr.DefaultInvalidImageAlt', 'Pawned!');
$this->config->set('Attr.DefaultImageAlt', 'not pawned');
@@ -27,14 +30,16 @@ class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransf
);
}
function testGenerateAlt() {
public function testGenerateAlt()
{
$this->assertResult(
array('src' => '/path/to/foobar.png'),
array('src' => '/path/to/foobar.png', 'alt' => 'foobar.png')
);
}
function testAddDefaultSrc() {
public function testAddDefaultSrc()
{
$this->config->set('Core.RemoveInvalidImg', false);
$this->assertResult(
array('alt' => 'intrigue'),
@@ -42,7 +47,8 @@ class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransf
);
}
function testAddDefaultAlt() {
public function testAddDefaultAlt()
{
$this->config->set('Attr.DefaultImageAlt', 'default');
$this->assertResult(
array('src' => ''),

View File

@@ -3,37 +3,43 @@
class HTMLPurifier_AttrTransform_ImgSpaceTest extends HTMLPurifier_AttrTransformHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_ImgSpace('vspace');
}
function testEmptyInput() {
public function testEmptyInput()
{
$this->assertResult( array() );
}
function testVerticalBasicUsage() {
public function testVerticalBasicUsage()
{
$this->assertResult(
array('vspace' => '1'),
array('style' => 'margin-top:1px;margin-bottom:1px;')
);
}
function testLenientHandlingOfInvalidInput() {
public function testLenientHandlingOfInvalidInput()
{
$this->assertResult(
array('vspace' => '10%'),
array('style' => 'margin-top:10%px;margin-bottom:10%px;')
);
}
function testPrependNewCSS() {
public function testPrependNewCSS()
{
$this->assertResult(
array('vspace' => '23', 'style' => 'font-weight:bold;'),
array('style' => 'margin-top:23px;margin-bottom:23px;font-weight:bold;')
);
}
function testHorizontalBasicUsage() {
public function testHorizontalBasicUsage()
{
$this->obj = new HTMLPurifier_AttrTransform_ImgSpace('hspace');
$this->assertResult(
array('hspace' => '1'),
@@ -41,7 +47,8 @@ class HTMLPurifier_AttrTransform_ImgSpaceTest extends HTMLPurifier_AttrTransform
);
}
function testInvalidConstructionParameter() {
public function testInvalidConstructionParameter()
{
$this->expectError('ispace is not valid space attribute');
$this->obj = new HTMLPurifier_AttrTransform_ImgSpace('ispace');
$this->assertResult(

View File

@@ -3,20 +3,24 @@
class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_Input();
}
function testEmptyInput() {
public function testEmptyInput()
{
$this->assertResult(array());
}
function testInvalidCheckedWithEmpty() {
public function testInvalidCheckedWithEmpty()
{
$this->assertResult(array('checked' => 'checked'), array());
}
function testInvalidCheckedWithPassword() {
public function testInvalidCheckedWithPassword()
{
$this->assertResult(array(
'checked' => 'checked',
'type' => 'password'
@@ -25,7 +29,8 @@ class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHar
));
}
function testValidCheckedWithUcCheckbox() {
public function testValidCheckedWithUcCheckbox()
{
$this->assertResult(array(
'checked' => 'checked',
'type' => 'CHECKBOX',
@@ -33,7 +38,8 @@ class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHar
));
}
function testInvalidMaxlength() {
public function testInvalidMaxlength()
{
$this->assertResult(array(
'maxlength' => '10',
'type' => 'checkbox',
@@ -44,7 +50,8 @@ class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHar
));
}
function testValidMaxLength() {
public function testValidMaxLength()
{
$this->assertResult(array(
'maxlength' => '10',
));
@@ -52,7 +59,8 @@ class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHar
// these two are really bad test-cases
function testSizeWithCheckbox() {
public function testSizeWithCheckbox()
{
$this->assertResult(array(
'type' => 'checkbox',
'value' => 'foo',
@@ -64,7 +72,8 @@ class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHar
));
}
function testSizeWithText() {
public function testSizeWithText()
{
$this->assertResult(array(
'type' => 'password',
'size' => '100px', // spurious value, to indicate no validation takes place
@@ -74,13 +83,15 @@ class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHar
));
}
function testInvalidSrc() {
public function testInvalidSrc()
{
$this->assertResult(array(
'src' => 'img.png',
), array());
}
function testMissingValue() {
public function testMissingValue()
{
$this->assertResult(array(
'type' => 'checkbox',
), array(

View File

@@ -4,37 +4,43 @@ class HTMLPurifier_AttrTransform_LangTest
extends HTMLPurifier_AttrTransformHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_Lang();
}
function testEmptyInput() {
public function testEmptyInput()
{
$this->assertResult(array());
}
function testCopyLangToXMLLang() {
public function testCopyLangToXMLLang()
{
$this->assertResult(
array('lang' => 'en'),
array('lang' => 'en', 'xml:lang' => 'en')
);
}
function testPreserveAttributes() {
public function testPreserveAttributes()
{
$this->assertResult(
array('src' => 'vert.png', 'lang' => 'fr'),
array('src' => 'vert.png', 'lang' => 'fr', 'xml:lang' => 'fr')
);
}
function testCopyXMLLangToLang() {
public function testCopyXMLLangToLang()
{
$this->assertResult(
array('xml:lang' => 'en'),
array('xml:lang' => 'en', 'lang' => 'en')
);
}
function testXMLLangOverridesLang() {
public function testXMLLangOverridesLang()
{
$this->assertResult(
array('lang' => 'fr', 'xml:lang' => 'de'),
array('lang' => 'de', 'xml:lang' => 'de')

View File

@@ -3,37 +3,43 @@
class HTMLPurifier_AttrTransform_LengthTest extends HTMLPurifier_AttrTransformHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_Length('width');
}
function testEmptyInput() {
public function testEmptyInput()
{
$this->assertResult( array() );
}
function testTransformPixel() {
public function testTransformPixel()
{
$this->assertResult(
array('width' => '10'),
array('style' => 'width:10px;')
);
}
function testTransformPercentage() {
public function testTransformPercentage()
{
$this->assertResult(
array('width' => '10%'),
array('style' => 'width:10%;')
);
}
function testPrependNewCSS() {
public function testPrependNewCSS()
{
$this->assertResult(
array('width' => '10%', 'style' => 'font-weight:bold'),
array('style' => 'width:10%;font-weight:bold')
);
}
function testLenientTreatmentOfInvalidInput() {
public function testLenientTreatmentOfInvalidInput()
{
$this->assertResult(
array('width' => 'asdf'),
array('style' => 'width:asdf;')

View File

@@ -3,7 +3,8 @@
class HTMLPurifier_AttrTransform_NameSyncTest extends HTMLPurifier_AttrTransformHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_NameSync();
$this->accumulator = new HTMLPurifier_IDAccumulator();
@@ -11,23 +12,27 @@ class HTMLPurifier_AttrTransform_NameSyncTest extends HTMLPurifier_AttrTransform
$this->config->set('Attr.EnableID', true);
}
function testEmpty() {
public function testEmpty()
{
$this->assertResult( array() );
}
function testAllowSame() {
public function testAllowSame()
{
$this->assertResult(
array('name' => 'free', 'id' => 'free')
);
}
function testAllowDifferent() {
public function testAllowDifferent()
{
$this->assertResult(
array('name' => 'tryit', 'id' => 'thisgood')
);
}
function testCheckName() {
public function testCheckName()
{
$this->accumulator->add('notok');
$this->assertResult(
array('name' => 'notok', 'id' => 'ok'),

View File

@@ -3,23 +3,27 @@
class HTMLPurifier_AttrTransform_NameTest extends HTMLPurifier_AttrTransformHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_Name();
}
function testEmpty() {
public function testEmpty()
{
$this->assertResult( array() );
}
function testTransformNameToID() {
public function testTransformNameToID()
{
$this->assertResult(
array('name' => 'free'),
array('id' => 'free')
);
}
function testExistingIDOverridesName() {
public function testExistingIDOverridesName()
{
$this->assertResult(
array('name' => 'tryit', 'id' => 'tobad'),
array('id' => 'tobad')

View File

@@ -3,7 +3,8 @@
class HTMLPurifier_AttrTransformHarness extends HTMLPurifier_ComplexHarness
{
public function setUp() {
public function setUp()
{
parent::setUp();
$this->func = 'transform';
}

View File

@@ -8,8 +8,8 @@ Mock::generatePartial(
class HTMLPurifier_AttrTransformTest extends HTMLPurifier_Harness
{
function test_prependCSS() {
public function test_prependCSS()
{
$t = new HTMLPurifier_AttrTransformTestable();
$attr = array();
@@ -26,8 +26,8 @@ class HTMLPurifier_AttrTransformTest extends HTMLPurifier_Harness
}
function test_confiscateAttr() {
public function test_confiscateAttr()
{
$t = new HTMLPurifier_AttrTransformTestable();
$attr = array('flavor' => 'sweet');

View File

@@ -3,7 +3,8 @@
class HTMLPurifier_AttrTypesTest extends HTMLPurifier_Harness
{
function test_get() {
public function test_get()
{
$types = new HTMLPurifier_AttrTypes();
$this->assertIdentical(

View File

@@ -3,7 +3,8 @@
class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
{
public function setup() {
public function setup()
{
parent::setup();
$config = HTMLPurifier_Config::createDefault();
$this->language = HTMLPurifier_LanguageFactory::instance()->create($config, $this->context);
@@ -12,12 +13,14 @@ class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
$this->context->register('Generator', new HTMLPurifier_Generator($config, $this->context));
}
protected function invoke($input) {
protected function invoke($input)
{
$validator = new HTMLPurifier_AttrValidator();
$validator->validateToken($input, $this->config, $this->context);
}
function testAttributesTransformedGlobalPre() {
public function testAttributesTransformedGlobalPre()
{
$def = $this->config->getHTMLDefinition(true);
generate_mock_once('HTMLPurifier_AttrTransform');
$transform = new HTMLPurifier_AttrTransformMock();
@@ -36,7 +39,8 @@ class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
$this->assertIdentical($result, $expect);
}
function testAttributesTransformedLocalPre() {
public function testAttributesTransformedLocalPre()
{
$this->config->set('HTML.TidyLevel', 'heavy');
$input = array('align' => 'right');
$output = array('style' => 'text-align:right;');
@@ -51,7 +55,8 @@ class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
// too lazy to check for global post and global pre
function testAttributeRemoved() {
public function testAttributeRemoved()
{
$token = new HTMLPurifier_Token_Start('p', array('foobar' => 'right'), 1);
$this->invoke($token);
$result = $this->collector->getRaw();

View File

@@ -5,7 +5,8 @@ class HTMLPurifier_ChildDef_ChameleonTest extends HTMLPurifier_ChildDefHarness
protected $isInline;
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_ChildDef_Chameleon(
'b | i', // allowed only when in inline context
@@ -14,21 +15,24 @@ class HTMLPurifier_ChildDef_ChameleonTest extends HTMLPurifier_ChildDefHarness
$this->context->register('IsInline', $this->isInline);
}
function testInlineAlwaysAllowed() {
public function testInlineAlwaysAllowed()
{
$this->isInline = true;
$this->assertResult(
'<b>Allowed.</b>'
);
}
function testBlockNotAllowedInInline() {
public function testBlockNotAllowedInInline()
{
$this->isInline = true;
$this->assertResult(
'<div>Not allowed.</div>', ''
);
}
function testBlockAllowedInNonInline() {
public function testBlockAllowedInNonInline()
{
$this->isInline = false;
$this->assertResult(
'<div>Allowed.</div>'

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
{
function test() {
public function test()
{
$this->obj = new HTMLPurifier_ChildDef_Custom('(a,b?,c*,d+,(a,b)*)');
$this->assertEqual($this->obj->elements, array('a' => true,
@@ -19,7 +19,8 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
}
function testNesting() {
public function testNesting()
{
$this->obj = new HTMLPurifier_ChildDef_Custom('(a,b,(c|d))+');
$this->assertEqual($this->obj->elements, array('a' => true,
'b' => true, 'c' => true, 'd' => true));
@@ -28,7 +29,8 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
$this->assertResult('<a /><b /><c /><d />', false);
}
function testNestedEitherOr() {
public function testNestedEitherOr()
{
$this->obj = new HTMLPurifier_ChildDef_Custom('b,(a|(c|d))+');
$this->assertEqual($this->obj->elements, array('a' => true,
'b' => true, 'c' => true, 'd' => true));
@@ -39,7 +41,8 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
$this->assertResult('<acd />', false);
}
function testNestedQuantifier() {
public function testNestedQuantifier()
{
$this->obj = new HTMLPurifier_ChildDef_Custom('(b,c+)*');
$this->assertEqual($this->obj->elements, array('b' => true, 'c' => true));
$this->assertResult('');
@@ -49,8 +52,8 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
$this->assertResult('<b /><c /><b />', false);
}
function testEitherOr() {
public function testEitherOr()
{
$this->obj = new HTMLPurifier_ChildDef_Custom('a|b');
$this->assertEqual($this->obj->elements, array('a' => true, 'b' => true));
$this->assertResult('', false);
@@ -60,8 +63,8 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
}
function testCommafication() {
public function testCommafication()
{
$this->obj = new HTMLPurifier_ChildDef_Custom('a,b');
$this->assertEqual($this->obj->elements, array('a' => true, 'b' => true));
$this->assertResult('<a /><b />');
@@ -69,14 +72,16 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
}
function testPcdata() {
public function testPcdata()
{
$this->obj = new HTMLPurifier_ChildDef_Custom('#PCDATA,a');
$this->assertEqual($this->obj->elements, array('#PCDATA' => true, 'a' => true));
$this->assertResult('foo<a />');
$this->assertResult('<a />', false);
}
function testWhitespace() {
public function testWhitespace()
{
$this->obj = new HTMLPurifier_ChildDef_Custom('a');
$this->assertEqual($this->obj->elements, array('a' => true));
$this->assertResult('foo<a />', false);

View File

@@ -3,45 +3,55 @@
class HTMLPurifier_ChildDef_ListTest extends HTMLPurifier_ChildDefHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_ChildDef_List();
}
function testEmptyInput() {
public function testEmptyInput()
{
$this->assertResult('', false);
}
function testSingleLi() {
public function testSingleLi()
{
$this->assertResult('<li />');
}
function testSomeLi() {
public function testSomeLi()
{
$this->assertResult('<li>asdf</li><li />');
}
function testIllegal() {
public function testIllegal()
{
// XXX actually this never gets triggered in practice
$this->assertResult('<li /><b />', '<li /><li><b /></li>');
}
function testOlAtBeginning() {
public function testOlAtBeginning()
{
$this->assertResult('<ol />', '<li><ol /></li>');
}
function testOlAtBeginningWithOtherJunk() {
public function testOlAtBeginningWithOtherJunk()
{
$this->assertResult('<ol /><li />', '<li><ol /></li><li />');
}
function testOlInMiddle() {
public function testOlInMiddle()
{
$this->assertResult('<li>Foo</li><ol><li>Bar</li></ol>', '<li>Foo<ol><li>Bar</li></ol></li>');
}
function testMultipleOl() {
public function testMultipleOl()
{
$this->assertResult('<li /><ol /><ol />', '<li><ol /><ol /></li>');
}
function testUlAtBeginning() {
public function testUlAtBeginning()
{
$this->assertResult('<ul />', '<li><ul /></li>');
}

View File

@@ -3,28 +3,34 @@
class HTMLPurifier_ChildDef_OptionalTest extends HTMLPurifier_ChildDefHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_ChildDef_Optional('b | i');
}
function testBasicUsage() {
public function testBasicUsage()
{
$this->assertResult('<b>Bold text</b><img />', '<b>Bold text</b>');
}
function testRemoveForbiddenText() {
public function testRemoveForbiddenText()
{
$this->assertResult('Not allowed text', '');
}
function testEmpty() {
public function testEmpty()
{
$this->assertResult('');
}
function testWhitespace() {
public function testWhitespace()
{
$this->assertResult(' ');
}
function testMultipleWhitespace() {
public function testMultipleWhitespace()
{
$this->assertResult(' ');
}

View File

@@ -3,7 +3,8 @@
class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness
{
function testPrepareString() {
public function testPrepareString()
{
$def = new HTMLPurifier_ChildDef_Required('foobar | bang |gizmo');
$this->assertIdentical($def->elements,
array(
@@ -13,7 +14,8 @@ class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness
));
}
function testPrepareArray() {
public function testPrepareArray()
{
$def = new HTMLPurifier_ChildDef_Required(array('href', 'src'));
$this->assertIdentical($def->elements,
array(
@@ -22,16 +24,19 @@ class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness
));
}
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_ChildDef_Required('dt | dd');
}
function testEmptyInput() {
public function testEmptyInput()
{
$this->assertResult('', false);
}
function testRemoveIllegalTagsAndElements() {
public function testRemoveIllegalTagsAndElements()
{
$this->assertResult(
'<dt>Term</dt>Text in an illegal location'.
'<dd>Definition</dd><b>Illegal tag</b>',
@@ -39,28 +44,33 @@ class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness
$this->assertResult('How do you do!', false);
}
function testIgnoreWhitespace() {
public function testIgnoreWhitespace()
{
// whitespace shouldn't trigger it
$this->assertResult("\n<dd>Definition</dd> ");
}
function testPreserveWhitespaceAfterRemoval() {
public function testPreserveWhitespaceAfterRemoval()
{
$this->assertResult(
'<dd>Definition</dd> <b></b> ',
'<dd>Definition</dd> '
);
}
function testDeleteNodeIfOnlyWhitespace() {
public function testDeleteNodeIfOnlyWhitespace()
{
$this->assertResult("\t ", false);
}
function testPCDATAAllowed() {
public function testPCDATAAllowed()
{
$this->obj = new HTMLPurifier_ChildDef_Required('#PCDATA | b');
$this->assertResult('Out <b>Bold text</b><img />', 'Out <b>Bold text</b>');
}
function testPCDATAAllowedWithEscaping() {
public function testPCDATAAllowedWithEscaping()
{
$this->obj = new HTMLPurifier_ChildDef_Required('#PCDATA | b');
$this->config->set('Core.EscapeInvalidChildren', true);
$this->assertResult(

View File

@@ -4,73 +4,86 @@ class HTMLPurifier_ChildDef_StrictBlockquoteTest
extends HTMLPurifier_ChildDefHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_ChildDef_StrictBlockquote('div | p');
}
function testEmptyInput() {
public function testEmptyInput()
{
$this->assertResult('');
}
function testPreserveValidP() {
public function testPreserveValidP()
{
$this->assertResult('<p>Valid</p>');
}
function testPreserveValidDiv() {
public function testPreserveValidDiv()
{
$this->assertResult('<div>Still valid</div>');
}
function testWrapTextWithP() {
public function testWrapTextWithP()
{
$this->assertResult('Needs wrap', '<p>Needs wrap</p>');
}
function testNoWrapForWhitespaceOrValidElements() {
public function testNoWrapForWhitespaceOrValidElements()
{
$this->assertResult('<p>Do not wrap</p> <p>Whitespace</p>');
}
function testWrapTextNextToValidElements() {
public function testWrapTextNextToValidElements()
{
$this->assertResult(
'Wrap'. '<p>Do not wrap</p>',
'<p>Wrap</p><p>Do not wrap</p>'
);
}
function testWrapInlineElements() {
public function testWrapInlineElements()
{
$this->assertResult(
'<p>Do not</p>'.'<b>Wrap</b>',
'<p>Do not</p><p><b>Wrap</b></p>'
);
}
function testWrapAndRemoveInvalidTags() {
public function testWrapAndRemoveInvalidTags()
{
$this->assertResult(
'<li>Not allowed</li>Paragraph.<p>Hmm.</p>',
'<p>Not allowedParagraph.</p><p>Hmm.</p>'
);
}
function testWrapComplicatedSring() {
public function testWrapComplicatedSring()
{
$this->assertResult(
$var = 'He said<br />perhaps<br />we should <b>nuke</b> them.',
"<p>$var</p>"
);
}
function testWrapAndRemoveInvalidTagsComplex() {
public function testWrapAndRemoveInvalidTagsComplex()
{
$this->assertResult(
'<foo>Bar</foo><bas /><b>People</b>Conniving.'. '<p>Fools!</p>',
'<p>Bar'. '<b>People</b>Conniving.</p><p>Fools!</p>'
);
}
function testAlternateWrapper() {
public function testAlternateWrapper()
{
$this->config->set('HTML.BlockWrapper', 'div');
$this->assertResult('Needs wrap', '<div>Needs wrap</div>');
}
function testError() {
public function testError()
{
$this->expectError('Cannot use non-block element as block wrapper');
$this->obj = new HTMLPurifier_ChildDef_StrictBlockquote('div | p');
$this->config->set('HTML.BlockWrapper', 'dav');

View File

@@ -6,62 +6,73 @@
class HTMLPurifier_ChildDef_TableTest extends HTMLPurifier_ChildDefHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_ChildDef_Table();
}
function testEmptyInput() {
public function testEmptyInput()
{
$this->assertResult('', false);
}
function testSingleRow() {
public function testSingleRow()
{
$this->assertResult('<tr />');
}
function testComplexContents() {
public function testComplexContents()
{
$this->assertResult('<caption /><col /><thead /><tfoot /><tbody>'.
'<tr><td>asdf</td></tr></tbody>');
$this->assertResult('<col /><col /><col /><tr />');
}
function testReorderContents() {
public function testReorderContents()
{
$this->assertResult(
'<col /><colgroup /><tbody /><tfoot /><thead /><tr>1</tr><caption /><tr />',
'<caption /><col /><colgroup /><thead /><tfoot /><tbody /><tbody><tr>1</tr><tr /></tbody>');
}
function testXhtml11Illegal() {
public function testXhtml11Illegal()
{
$this->assertResult(
'<thead><tr><th>a</th></tr></thead><tr><td>a</td></tr>',
'<thead><tr><th>a</th></tr></thead><tbody><tr><td>a</td></tr></tbody>'
);
}
function testTrOverflowAndClose() {
public function testTrOverflowAndClose()
{
$this->assertResult(
'<tr><td>a</td></tr><tr><td>b</td></tr><tbody><tr><td>c</td></tr></tbody><tr><td>d</td></tr>',
'<tbody><tr><td>a</td></tr><tr><td>b</td></tr></tbody><tbody><tr><td>c</td></tr></tbody><tbody><tr><td>d</td></tr></tbody>'
);
}
function testDuplicateProcessing() {
public function testDuplicateProcessing()
{
$this->assertResult(
'<caption>1</caption><caption /><tbody /><tbody /><tfoot>1</tfoot><tfoot />',
'<caption>1</caption><tfoot>1</tfoot><tbody /><tbody /><tbody />'
);
}
function testRemoveText() {
public function testRemoveText()
{
$this->assertResult('foo', false);
}
function testStickyWhitespaceOnTr() {
public function testStickyWhitespaceOnTr()
{
$this->config->set('Output.Newline', "\n");
$this->assertResult("\n <tr />\n <tr />\n ");
}
function testStickyWhitespaceOnTSection() {
public function testStickyWhitespaceOnTSection()
{
$this->config->set('Output.Newline', "\n");
$this->assertResult(
"\n\t<tbody />\n\t\t<tfoot />\n\t\t\t",

View File

@@ -3,7 +3,8 @@
class HTMLPurifier_ChildDefHarness extends HTMLPurifier_ComplexHarness
{
public function setUp() {
public function setUp()
{
parent::setUp();
$this->obj = null;
$this->func = 'validateChildren';

View File

@@ -9,48 +9,51 @@ class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
{
/**
* Instance of the object that will execute the method
* Instance of the object that will execute the method.
* @type object
*/
protected $obj;
/**
* Name of the function to be executed
* Name of the function to be executed.
* @type string
*/
protected $func;
/**
* Whether or not the method deals in tokens. If set to true, assertResult()
* Whether or not the method deals in tokens.
* If set to true, assertResult()
* will transparently convert HTML to and back from tokens.
* @type bool
*/
protected $to_tokens = false;
/**
* Whether or not to convert tokens back into HTML before performing
* equality check, has no effect on bools.
* @type bool
*/
protected $to_html = false;
/**
* Instance of an HTMLPurifier_Lexer implementation.
* @type HTMLPurifier_Lexer
*/
protected $lexer;
public function __construct() {
public function __construct()
{
$this->lexer = new HTMLPurifier_Lexer_DirectLex();
parent::__construct();
}
/**
* Asserts a specific result from a one parameter + config/context function
* @param $input Input parameter
* @param $expect Expectation
* @param $config Configuration array in form of Ns.Directive => Value.
* Has no effect if $this->config is set.
* @param $context_array Context array in form of Key => Value or an actual
* context object.
* @param string $input Input parameter
* @param bool|string $expect Expectation
*/
protected function assertResult($input, $expect = true) {
protected function assertResult($input, $expect = true)
{
if ($this->to_tokens && is_string($input)) {
// $func may cause $input to change, so "clone" another copy
// to sacrifice
@@ -89,14 +92,16 @@ class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
/**
* Tokenize HTML into tokens, uses member variables for common variables
*/
protected function tokenize($html) {
protected function tokenize($html)
{
return $this->lexer->tokenizeHTML($html, $this->config, $this->context);
}
/**
* Generate textual HTML from tokens
*/
protected function generate($tokens) {
protected function generate($tokens)
{
$generator = new HTMLPurifier_Generator($this->config, $this->context);
return $generator->generateFromTokens($tokens);
}

View File

@@ -5,11 +5,13 @@ class HTMLPurifier_ConfigSchema_InterchangeTest extends UnitTestCase
protected $interchange;
public function setup() {
public function setup()
{
$this->interchange = new HTMLPurifier_ConfigSchema_Interchange();
}
function testAddDirective() {
public function testAddDirective()
{
$v = new HTMLPurifier_ConfigSchema_Interchange_Directive();
$v->id = new HTMLPurifier_ConfigSchema_Interchange_Id('Namespace.Directive');
$this->interchange->addDirective($v);

View File

@@ -3,87 +3,105 @@
class HTMLPurifier_ConfigSchema_ValidatorAtomTest extends UnitTestCase
{
protected function expectValidationException($msg) {
protected function expectValidationException($msg)
{
$this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
}
protected function makeAtom($value) {
protected function makeAtom($value)
{
$obj = new stdClass();
$obj->property = $value;
// Note that 'property' and 'context' are magic wildcard values
return new HTMLPurifier_ConfigSchema_ValidatorAtom('context', $obj, 'property');
}
function testAssertIsString() {
public function testAssertIsString()
{
$this->makeAtom('foo')->assertIsString();
}
function testAssertIsStringFail() {
public function testAssertIsStringFail()
{
$this->expectValidationException("Property in context must be a string");
$this->makeAtom(3)->assertIsString();
}
function testAssertNotNull() {
public function testAssertNotNull()
{
$this->makeAtom('foo')->assertNotNull();
}
function testAssertNotNullFail() {
public function testAssertNotNullFail()
{
$this->expectValidationException("Property in context must not be null");
$this->makeAtom(null)->assertNotNull();
}
function testAssertAlnum() {
public function testAssertAlnum()
{
$this->makeAtom('foo2')->assertAlnum();
}
function testAssertAlnumFail() {
public function testAssertAlnumFail()
{
$this->expectValidationException("Property in context must be alphanumeric");
$this->makeAtom('%a')->assertAlnum();
}
function testAssertAlnumFailIsString() {
public function testAssertAlnumFailIsString()
{
$this->expectValidationException("Property in context must be a string");
$this->makeAtom(3)->assertAlnum();
}
function testAssertNotEmpty() {
public function testAssertNotEmpty()
{
$this->makeAtom('foo')->assertNotEmpty();
}
function testAssertNotEmptyFail() {
public function testAssertNotEmptyFail()
{
$this->expectValidationException("Property in context must not be empty");
$this->makeAtom('')->assertNotEmpty();
}
function testAssertIsBool() {
public function testAssertIsBool()
{
$this->makeAtom(false)->assertIsBool();
}
function testAssertIsBoolFail() {
public function testAssertIsBoolFail()
{
$this->expectValidationException("Property in context must be a boolean");
$this->makeAtom('0')->assertIsBool();
}
function testAssertIsArray() {
public function testAssertIsArray()
{
$this->makeAtom(array())->assertIsArray();
}
function testAssertIsArrayFail() {
public function testAssertIsArrayFail()
{
$this->expectValidationException("Property in context must be an array");
$this->makeAtom('asdf')->assertIsArray();
}
function testAssertIsLookup() {
public function testAssertIsLookup()
{
$this->makeAtom(array('foo' => true))->assertIsLookup();
}
function testAssertIsLookupFail() {
public function testAssertIsLookupFail()
{
$this->expectValidationException("Property in context must be a lookup array");
$this->makeAtom(array('foo' => 4))->assertIsLookup();
}
function testAssertIsLookupFailIsArray() {
public function testAssertIsLookupFailIsArray()
{
$this->expectValidationException("Property in context must be an array");
$this->makeAtom('asdf')->assertIsLookup();
}

View File

@@ -8,19 +8,22 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
{
public $validator, $interchange;
public function setup() {
public function setup()
{
$this->validator = new HTMLPurifier_ConfigSchema_Validator();
$this->interchange = new HTMLPurifier_ConfigSchema_Interchange();
}
function testDirectiveIntegrityViolation() {
public function testDirectiveIntegrityViolation()
{
$d = $this->makeDirective('Ns.Dir');
$d->id = new HTMLPurifier_ConfigSchema_Interchange_Id('Ns.Dir2');
$this->expectValidationException("Integrity violation: key 'Ns.Dir' does not match internal id 'Ns.Dir2'");
$this->validator->validate($this->interchange);
}
function testDirectiveTypeNotEmpty() {
public function testDirectiveTypeNotEmpty()
{
$d = $this->makeDirective('Ns.Dir');
$d->default = 0;
$d->description = 'Description';
@@ -29,7 +32,8 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
$this->validator->validate($this->interchange);
}
function testDirectiveDefaultInvalid() {
public function testDirectiveDefaultInvalid()
{
$d = $this->makeDirective('Ns.Dir');
$d->default = 'asdf';
$d->type = 'int';
@@ -39,7 +43,8 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
$this->validator->validate($this->interchange);
}
function testDirectiveIdIsString() {
public function testDirectiveIdIsString()
{
$d = $this->makeDirective(3);
$d->default = 0;
$d->type = 'int';
@@ -49,7 +54,8 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
$this->validator->validate($this->interchange);
}
function testDirectiveTypeAllowsNullIsBool() {
public function testDirectiveTypeAllowsNullIsBool()
{
$d = $this->makeDirective('Ns.Dir');
$d->default = 0;
$d->type = 'int';
@@ -60,7 +66,8 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
$this->validator->validate($this->interchange);
}
function testDirectiveValueAliasesIsArray() {
public function testDirectiveValueAliasesIsArray()
{
$d = $this->makeDirective('Ns.Dir');
$d->default = 'a';
$d->type = 'string';
@@ -71,7 +78,8 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
$this->validator->validate($this->interchange);
}
function testDirectiveAllowedIsLookup() {
public function testDirectiveAllowedIsLookup()
{
$d = $this->makeDirective('Ns.Dir');
$d->default = 'foo';
$d->type = 'string';
@@ -85,14 +93,16 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
// helper functions
protected function makeDirective($key) {
protected function makeDirective($key)
{
$directive = new HTMLPurifier_ConfigSchema_Interchange_Directive();
$directive->id = new HTMLPurifier_ConfigSchema_Interchange_Id($key);
$this->interchange->addDirective($directive);
return $directive;
}
protected function expectValidationException($msg) {
protected function expectValidationException($msg)
{
$this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
}

View File

@@ -9,18 +9,21 @@ class HTMLPurifier_ConfigSchema_ValidatorTestCase extends UnitTestCase
protected $_path, $_parser, $_builder;
public $validator;
public function __construct($path) {
public function __construct($path)
{
$this->_path = $path;
$this->_parser = new HTMLPurifier_StringHashParser();
$this->_builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
parent::__construct($path);
}
public function setup() {
public function setup()
{
$this->validator = new HTMLPurifier_ConfigSchema_Validator();
}
function testValidator() {
public function testValidator()
{
$hashes = $this->_parser->parseMultiFile($this->_path);
$interchange = new HTMLPurifier_ConfigSchema_Interchange();
$error = null;

View File

@@ -5,11 +5,13 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
protected $schema;
public function setup() {
public function setup()
{
$this->schema = new HTMLPurifier_ConfigSchema();
}
function test_define() {
public function test_define()
{
$this->schema->add('Car.Seats', 5, 'int', false);
$this->assertIdentical($this->schema->defaults['Car.Seats'], 5);
@@ -22,7 +24,8 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
}
function test_defineAllowedValues() {
public function test_defineAllowedValues()
{
$this->schema->add('QuantumNumber.Spin', 0.5, 'float', false);
$this->schema->add('QuantumNumber.Current', 's', 'string', false);
$this->schema->add('QuantumNumber.Difficulty', null, 'string', true);
@@ -44,7 +47,8 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
}
function test_defineValueAliases() {
public function test_defineValueAliases()
{
$this->schema->add('Abbrev.HTH', 'Happy to Help', 'string', false);
$this->schema->addAllowedValues(
'Abbrev.HTH', array(
@@ -84,7 +88,8 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
}
function testAlias() {
public function testAlias()
{
$this->schema->add('Home.Rug', 3, 'int', false);
$this->schema->addAlias('Home.Carpet', 'Home.Rug');

View File

@@ -6,14 +6,16 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
protected $schema;
protected $oldFactory;
public function setUp() {
public function setUp()
{
// set up a dummy schema object for testing
$this->schema = new HTMLPurifier_ConfigSchema();
}
// test functionality based on ConfigSchema
function testNormal() {
public function testNormal()
{
$this->schema->add('Element.Abbr', 'H', 'string', false);
$this->schema->add('Element.Name', 'hydrogen', 'istring', false);
$this->schema->add('Element.Number', 1, 'int', false);
@@ -72,8 +74,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
}
function testEnumerated() {
public function testEnumerated()
{
// case sensitive
$this->schema->add('Instrument.Manufacturer', 'Yamaha', 'string', false);
$this->schema->addAllowedValues('Instrument.Manufacturer', array(
@@ -121,8 +123,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
}
function testNull() {
public function testNull()
{
$this->schema->add('ReportCard.English', null, 'string', true);
$this->schema->add('ReportCard.Absences', 0, 'int', false);
@@ -142,8 +144,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
}
function testAliases() {
public function testAliases()
{
$this->schema->add('Home.Rug', 3, 'int', false);
$this->schema->addAlias('Home.Carpet', 'Home.Rug');
@@ -164,8 +166,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
// test functionality based on method
function test_getBatch() {
public function test_getBatch()
{
$this->schema->add('Variables.TangentialAcceleration', 'a_tan', 'string', false);
$this->schema->add('Variables.AngularAcceleration', 'alpha', 'string', false);
@@ -188,8 +190,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
}
function test_loadIni() {
public function test_loadIni()
{
$this->schema->add('Shortcut.Copy', 'c', 'istring', false);
$this->schema->add('Shortcut.Paste', 'v', 'istring', false);
$this->schema->add('Shortcut.Cut', 'x', 'istring', false);
@@ -205,8 +207,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
}
function test_getHTMLDefinition() {
public function test_getHTMLDefinition()
{
// we actually want to use the old copy, because the definition
// generation routines have dependencies on configuration values
@@ -233,7 +235,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
}
function test_getHTMLDefinition_deprecatedRawError() {
public function test_getHTMLDefinition_deprecatedRawError()
{
$config = HTMLPurifier_Config::createDefault();
$config->chatty = false;
// test deprecated retrieval of raw definition
@@ -248,13 +251,15 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
$this->assertTrue($def->setup);
}
function test_getHTMLDefinition_optimizedRawError() {
public function test_getHTMLDefinition_optimizedRawError()
{
$this->expectException(new HTMLPurifier_Exception("Cannot set optimized = true when raw = false"));
$config = HTMLPurifier_Config::createDefault();
$config->getHTMLDefinition(false, true);
}
function test_getHTMLDefinition_rawAfterSetupError() {
public function test_getHTMLDefinition_rawAfterSetupError()
{
$this->expectException(new HTMLPurifier_Exception("Cannot retrieve raw definition after it has already been setup"));
$config = HTMLPurifier_Config::createDefault();
$config->chatty = false;
@@ -262,7 +267,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
$config->getHTMLDefinition(true);
}
function test_getHTMLDefinition_inconsistentOptimizedError() {
public function test_getHTMLDefinition_inconsistentOptimizedError()
{
$this->expectError("Useless DefinitionID declaration");
$this->expectException(new HTMLPurifier_Exception("Inconsistent use of optimized and unoptimized raw definition retrievals"));
$config = HTMLPurifier_Config::create(array('HTML.DefinitionID' => 'HTMLPurifier_ConfigTest->test_getHTMLDefinition_inconsistentOptimizedError'));
@@ -271,7 +277,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
$config->getHTMLDefinition(true, true);
}
function test_getHTMLDefinition_inconsistentOptimizedError2() {
public function test_getHTMLDefinition_inconsistentOptimizedError2()
{
$this->expectException(new HTMLPurifier_Exception("Inconsistent use of optimized and unoptimized raw definition retrievals"));
$config = HTMLPurifier_Config::create(array('HTML.DefinitionID' => 'HTMLPurifier_ConfigTest->test_getHTMLDefinition_inconsistentOptimizedError2'));
$config->chatty = false;
@@ -279,26 +286,30 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
$config->getHTMLDefinition(true, false);
}
function test_getHTMLDefinition_rawError() {
public function test_getHTMLDefinition_rawError()
{
$config = HTMLPurifier_Config::createDefault();
$this->expectException(new HTMLPurifier_Exception('Cannot retrieve raw version without specifying %HTML.DefinitionID'));
$def = $config->getHTMLDefinition(true, true);
}
function test_getCSSDefinition() {
public function test_getCSSDefinition()
{
$config = HTMLPurifier_Config::createDefault();
$def = $config->getCSSDefinition();
$this->assertIsA($def, 'HTMLPurifier_CSSDefinition');
}
function test_getDefinition() {
public function test_getDefinition()
{
$this->schema->add('Cache.DefinitionImpl', null, 'string', true);
$config = new HTMLPurifier_Config($this->schema);
$this->expectException(new HTMLPurifier_Exception("Definition of Crust type not supported"));
$config->getDefinition('Crust');
}
function test_loadArray() {
public function test_loadArray()
{
// setup a few dummy namespaces/directives for our testing
$this->schema->add('Zoo.Aadvark', 0, 'int', false);
$this->schema->add('Zoo.Boar', 0, 'int', false);
@@ -337,8 +348,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
}
function test_create() {
public function test_create()
{
$this->schema->add('Cake.Sprinkles', 666, 'int', false);
$this->schema->add('Cake.Flavor', 'vanilla', 'string', false);
@@ -359,8 +370,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
}
function test_finalize() {
public function test_finalize()
{
// test finalization
$this->schema->add('Poem.Meter', 'iambic', 'string', false);
@@ -384,8 +395,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
}
function test_loadArrayFromForm() {
public function test_loadArrayFromForm()
{
$this->schema->add('Pancake.Mix', 'buttermilk', 'string', false);
$this->schema->add('Pancake.Served', true, 'bool', false);
$this->schema->add('Toppings.Syrup', true, 'bool', false);
@@ -444,7 +455,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
*/
}
function test_getAllowedDirectivesForForm() {
public function test_getAllowedDirectivesForForm()
{
$this->schema->add('Unused.Unused', 'Foobar', 'string', false);
$this->schema->add('Partial.Allowed', true, 'bool', false);
$this->schema->add('Partial.Unused', 'Foobar', 'string', false);
@@ -464,7 +476,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
}
function testDeprecatedAPI() {
public function testDeprecatedAPI()
{
$this->schema->add('Foo.Bar', 2, 'int', false);
$config = new HTMLPurifier_Config($this->schema);
$config->chatty = false;
@@ -474,7 +487,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
$this->assertIdentical($config->get('Foo', 'Bar'), 4);
}
function testInherit() {
public function testInherit()
{
$this->schema->add('Phantom.Masked', 25, 'int', false);
$this->schema->add('Phantom.Unmasked', 89, 'int', false);
$this->schema->add('Phantom.Latemasked', 11, 'int', false);
@@ -487,14 +501,16 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
$this->assertIdentical($subconfig->get('Phantom.Latemasked'), 100);
}
function testSerialize() {
public function testSerialize()
{
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.Allowed', 'a');
$config2 = unserialize($config->serialize());
$this->assertIdentical($config->get('HTML.Allowed'), $config2->get('HTML.Allowed'));
}
function testDefinitionCachingNothing() {
public function testDefinitionCachingNothing()
{
list($mock, $config) = $this->setupCacheMock('HTML');
// should not touch the cache
$mock->expectNever('get');
@@ -506,7 +522,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
$this->teardownCacheMock();
}
function testDefinitionCachingOptimized() {
public function testDefinitionCachingOptimized()
{
list($mock, $config) = $this->setupCacheMock('HTML');
$mock->expectNever('set');
$config->set('HTML.DefinitionID', 'HTMLPurifier_ConfigTest->testDefinitionCachingOptimized');
@@ -519,7 +536,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
$this->teardownCacheMock();
}
function testDefinitionCachingOptimizedHit() {
public function testDefinitionCachingOptimizedHit()
{
$fake_config = HTMLPurifier_Config::createDefault();
$fake_def = $fake_config->getHTMLDefinition();
list($mock, $config) = $this->setupCacheMock('HTML');
@@ -535,7 +553,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
$this->teardownCacheMock();
}
protected function setupCacheMock($type) {
protected function setupCacheMock($type)
{
// inject our definition cache mock globally (borrowed from
// DefinitionFactoryTest)
generate_mock_once("HTMLPurifier_DefinitionCacheFactory");
@@ -548,7 +567,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
$factory->setReturnValue('create', $mock, array($type, $config));
return array($mock, $config);
}
protected function teardownCacheMock() {
protected function teardownCacheMock()
{
HTMLPurifier_DefinitionCacheFactory::instance($this->oldFactory);
}

View File

@@ -6,12 +6,13 @@ class HTMLPurifier_ContextTest extends HTMLPurifier_Harness
protected $context;
public function setUp() {
public function setUp()
{
$this->context = new HTMLPurifier_Context();
}
function testStandardUsage() {
public function testStandardUsage()
{
generate_mock_once('HTMLPurifier_IDAccumulator');
$this->assertFalse($this->context->exists('IDAccumulator'));
@@ -35,8 +36,8 @@ class HTMLPurifier_ContextTest extends HTMLPurifier_Harness
}
function testReRegister() {
public function testReRegister()
{
$var = true;
$this->context->register('OnceOnly', $var);
@@ -49,8 +50,8 @@ class HTMLPurifier_ContextTest extends HTMLPurifier_Harness
}
function test_loadArray() {
public function test_loadArray()
{
// references can be *really* wonky!
$context_manual = new HTMLPurifier_Context();

View File

@@ -5,48 +5,56 @@ generate_mock_once('HTMLPurifier_DefinitionCache');
class HTMLPurifier_DefinitionCache_Decorator_CleanupTest extends HTMLPurifier_DefinitionCache_DecoratorHarness
{
function setup() {
public function setup()
{
$this->cache = new HTMLPurifier_DefinitionCache_Decorator_Cleanup();
parent::setup();
}
function setupMockForSuccess($op) {
public function setupMockForSuccess($op)
{
$this->mock->expectOnce($op, array($this->def, $this->config));
$this->mock->setReturnValue($op, true, array($this->def, $this->config));
$this->mock->expectNever('cleanup');
}
function setupMockForFailure($op) {
public function setupMockForFailure($op)
{
$this->mock->expectOnce($op, array($this->def, $this->config));
$this->mock->setReturnValue($op, false, array($this->def, $this->config));
$this->mock->expectOnce('cleanup', array($this->config));
}
function test_get() {
public function test_get()
{
$this->mock->expectOnce('get', array($this->config));
$this->mock->setReturnValue('get', true, array($this->config));
$this->mock->expectNever('cleanup');
$this->assertEqual($this->cache->get($this->config), $this->def);
}
function test_get_failure() {
public function test_get_failure()
{
$this->mock->expectOnce('get', array($this->config));
$this->mock->setReturnValue('get', false, array($this->config));
$this->mock->expectOnce('cleanup', array($this->config));
$this->assertEqual($this->cache->get($this->config), false);
}
function test_set() {
public function test_set()
{
$this->setupMockForSuccess('set');
$this->assertEqual($this->cache->set($this->def, $this->config), true);
}
function test_replace() {
public function test_replace()
{
$this->setupMockForSuccess('replace');
$this->assertEqual($this->cache->replace($this->def, $this->config), true);
}
function test_add() {
public function test_add()
{
$this->setupMockForSuccess('add');
$this->assertEqual($this->cache->add($this->def, $this->config), true);
}

View File

@@ -5,61 +5,71 @@ generate_mock_once('HTMLPurifier_DefinitionCache');
class HTMLPurifier_DefinitionCache_Decorator_MemoryTest extends HTMLPurifier_DefinitionCache_DecoratorHarness
{
function setup() {
public function setup()
{
$this->cache = new HTMLPurifier_DefinitionCache_Decorator_Memory();
parent::setup();
}
function setupMockForSuccess($op) {
public function setupMockForSuccess($op)
{
$this->mock->expectOnce($op, array($this->def, $this->config));
$this->mock->setReturnValue($op, true, array($this->def, $this->config));
$this->mock->expectNever('get');
}
function setupMockForFailure($op) {
public function setupMockForFailure($op)
{
$this->mock->expectOnce($op, array($this->def, $this->config));
$this->mock->setReturnValue($op, false, array($this->def, $this->config));
$this->mock->expectOnce('get', array($this->config));
}
function test_get() {
public function test_get()
{
$this->mock->expectOnce('get', array($this->config)); // only ONE call!
$this->mock->setReturnValue('get', $this->def, array($this->config));
$this->assertEqual($this->cache->get($this->config), $this->def);
$this->assertEqual($this->cache->get($this->config), $this->def);
}
function test_set() {
public function test_set()
{
$this->setupMockForSuccess('set', 'get');
$this->assertEqual($this->cache->set($this->def, $this->config), true);
$this->assertEqual($this->cache->get($this->config), $this->def);
}
function test_set_failure() {
public function test_set_failure()
{
$this->setupMockForFailure('set', 'get');
$this->assertEqual($this->cache->set($this->def, $this->config), false);
$this->cache->get($this->config);
}
function test_replace() {
public function test_replace()
{
$this->setupMockForSuccess('replace', 'get');
$this->assertEqual($this->cache->replace($this->def, $this->config), true);
$this->assertEqual($this->cache->get($this->config), $this->def);
}
function test_replace_failure() {
public function test_replace_failure()
{
$this->setupMockForFailure('replace', 'get');
$this->assertEqual($this->cache->replace($this->def, $this->config), false);
$this->cache->get($this->config);
}
function test_add() {
public function test_add()
{
$this->setupMockForSuccess('add', 'get');
$this->assertEqual($this->cache->add($this->def, $this->config), true);
$this->assertEqual($this->cache->get($this->config), $this->def);
}
function test_add_failure() {
public function test_add_failure()
{
$this->setupMockForFailure('add', 'get');
$this->assertEqual($this->cache->add($this->def, $this->config), false);
$this->cache->get($this->config);

View File

@@ -5,7 +5,8 @@ generate_mock_once('HTMLPurifier_DefinitionCache');
class HTMLPurifier_DefinitionCache_DecoratorHarness extends HTMLPurifier_DefinitionCacheHarness
{
function setup() {
public function setup()
{
$this->mock = new HTMLPurifier_DefinitionCacheMock();
$this->mock->type = 'Test';
$this->cache = $this->cache->decorate($this->mock);
@@ -13,7 +14,8 @@ class HTMLPurifier_DefinitionCache_DecoratorHarness extends HTMLPurifier_Definit
$this->config = $this->generateConfigMock();
}
function teardown() {
public function teardown()
{
unset($this->mock);
unset($this->cache);
}

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_DefinitionCache_DecoratorTest extends HTMLPurifier_DefinitionCacheHarness
{
function test() {
public function test()
{
generate_mock_once('HTMLPurifier_DefinitionCache');
$mock = new HTMLPurifier_DefinitionCacheMock();
$mock->type = 'Test';

View File

@@ -3,7 +3,8 @@
class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_DefinitionCacheHarness
{
function test() {
public function test()
{
// XXX SimpleTest does some really crazy stuff in the background
// to do equality checks. Unfortunately, this makes some
// versions of PHP segfault. So we need to define a better,
@@ -66,7 +67,8 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio
}
function test_errors() {
public function test_errors()
{
$cache = new HTMLPurifier_DefinitionCache_Serializer('Test');
$def = $this->generateDefinition();
$def->setup = true;
@@ -83,8 +85,8 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio
$cache->replace($def, $config);
}
function test_flush() {
public function test_flush()
{
$cache = new HTMLPurifier_DefinitionCache_Serializer('Test');
$config1 = $this->generateConfigMock('test1');
@@ -111,8 +113,8 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio
}
function testCleanup() {
public function testCleanup()
{
$cache = new HTMLPurifier_DefinitionCache_Serializer('Test');
// in order of age, oldest first
@@ -139,8 +141,8 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio
}
function testCleanupOnlySameID() {
public function testCleanupOnlySameID()
{
$cache = new HTMLPurifier_DefinitionCache_Serializer('Test');
$config1 = $this->generateConfigMock('serial1');
@@ -168,7 +170,8 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio
/**
* Asserts that a file exists, ignoring the stat cache
*/
function assertFileExist($file) {
public function assertFileExist($file)
{
clearstatcache();
$this->assertTrue(file_exists($file), 'Expected ' . $file . ' exists');
}
@@ -176,13 +179,14 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio
/**
* Asserts that a file does not exist, ignoring the stat cache
*/
function assertFileNotExist($file) {
public function assertFileNotExist($file)
{
clearstatcache();
$this->assertFalse(file_exists($file), 'Expected ' . $file . ' does not exist');
}
function testAlternatePath() {
public function testAlternatePath()
{
$cache = new HTMLPurifier_DefinitionCache_Serializer('Test');
$config = $this->generateConfigMock('serial');
$config->version = '1.0.0';
@@ -199,8 +203,8 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio
}
function testAlternatePermissions() {
public function testAlternatePermissions()
{
$cache = new HTMLPurifier_DefinitionCache_Serializer('Test');
$config = $this->generateConfigMock('serial');
$config->version = '1.0.0';

View File

@@ -6,23 +6,27 @@ class HTMLPurifier_DefinitionCacheFactoryTest extends HTMLPurifier_Harness
protected $factory;
protected $oldFactory;
public function setUp() {
public function setUp()
{
parent::setup();
$this->factory = new HTMLPurifier_DefinitionCacheFactory();
$this->oldFactory = HTMLPurifier_DefinitionCacheFactory::instance();
HTMLPurifier_DefinitionCacheFactory::instance($this->factory);
}
public function tearDown() {
public function tearDown()
{
HTMLPurifier_DefinitionCacheFactory::instance($this->oldFactory);
}
function test_create() {
public function test_create()
{
$cache = $this->factory->create('Test', $this->config);
$this->assertEqual($cache, new HTMLPurifier_DefinitionCache_Serializer('Test'));
}
function test_create_withDecorator() {
public function test_create_withDecorator()
{
$this->factory->addDecorator('Memory');
$cache = $this->factory->create('Test', $this->config);
$cache_real = new HTMLPurifier_DefinitionCache_Decorator_Memory();
@@ -30,7 +34,8 @@ class HTMLPurifier_DefinitionCacheFactoryTest extends HTMLPurifier_Harness
$this->assertEqual($cache, $cache_real);
}
function test_create_withDecoratorObject() {
public function test_create_withDecoratorObject()
{
$this->factory->addDecorator(new HTMLPurifier_DefinitionCache_Decorator_Memory());
$cache = $this->factory->create('Test', $this->config);
$cache_real = new HTMLPurifier_DefinitionCache_Decorator_Memory();
@@ -38,26 +43,30 @@ class HTMLPurifier_DefinitionCacheFactoryTest extends HTMLPurifier_Harness
$this->assertEqual($cache, $cache_real);
}
function test_create_recycling() {
public function test_create_recycling()
{
$cache = $this->factory->create('Test', $this->config);
$cache2 = $this->factory->create('Test', $this->config);
$this->assertReference($cache, $cache2);
}
function test_create_invalid() {
public function test_create_invalid()
{
$this->config->set('Cache.DefinitionImpl', 'Invalid');
$this->expectError('Unrecognized DefinitionCache Invalid, using Serializer instead');
$cache = $this->factory->create('Test', $this->config);
$this->assertIsA($cache, 'HTMLPurifier_DefinitionCache_Serializer');
}
function test_null() {
public function test_null()
{
$this->config->set('Cache.DefinitionImpl', null);
$cache = $this->factory->create('Test', $this->config);
$this->assertEqual($cache, new HTMLPurifier_DefinitionCache_Null('Test'));
}
function test_register() {
public function test_register()
{
generate_mock_once('HTMLPurifier_DefinitionCache');
$this->config->set('Cache.DefinitionImpl', 'TestCache');
$this->factory->register('TestCache', $class = 'HTMLPurifier_DefinitionCacheMock');

View File

@@ -8,7 +8,8 @@ class HTMLPurifier_DefinitionCacheHarness extends HTMLPurifier_Harness
* to a getBatch() call
* @param $values Values to return when getBatch is invoked
*/
protected function generateConfigMock($serial = 'defaultserial') {
protected function generateConfigMock($serial = 'defaultserial')
{
generate_mock_once('HTMLPurifier_Config');
$config = new HTMLPurifier_ConfigMock();
$config->setReturnValue('getBatchSerial', $serial, array('Test'));
@@ -19,7 +20,8 @@ class HTMLPurifier_DefinitionCacheHarness extends HTMLPurifier_Harness
/**
* Returns an anonymous def that has been setup and named Test
*/
protected function generateDefinition($member_vars = array()) {
protected function generateDefinition($member_vars = array())
{
$def = new HTMLPurifier_DefinitionTestable();
$def->setup = true;
$def->type = 'Test';

View File

@@ -3,7 +3,8 @@
class HTMLPurifier_DefinitionCacheTest extends HTMLPurifier_Harness
{
function test_isOld() {
public function test_isOld()
{
// using null subclass because parent is abstract
$cache = new HTMLPurifier_DefinitionCache_Null('Test');

View File

@@ -2,13 +2,15 @@
class HTMLPurifier_DefinitionTest extends HTMLPurifier_Harness
{
function test_setup() {
public function test_setup()
{
$def = new HTMLPurifier_DefinitionTestable();
$config = HTMLPurifier_Config::createDefault();
$def->expectOnce('doSetup', array($config));
$def->setup($config);
}
function test_setup_redundant() {
public function test_setup_redundant()
{
$def = new HTMLPurifier_DefinitionTestable();
$config = HTMLPurifier_Config::createDefault();
$def->expectNever('doSetup');

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_DoctypeRegistryTest extends HTMLPurifier_Harness
{
function test_register() {
public function test_register()
{
$registry = new HTMLPurifier_DoctypeRegistry();
$d = $registry->register(
@@ -30,8 +30,8 @@ class HTMLPurifier_DoctypeRegistryTest extends HTMLPurifier_Harness
}
function test_get() {
public function test_get()
{
// see also alias and register tests
$registry = new HTMLPurifier_DoctypeRegistry();
@@ -45,8 +45,8 @@ class HTMLPurifier_DoctypeRegistryTest extends HTMLPurifier_Harness
}
function testAliases() {
public function testAliases()
{
$registry = new HTMLPurifier_DoctypeRegistry();
$d1 = $registry->register('Doc1', true, array(), array(), array('1'));

View File

@@ -3,8 +3,8 @@
class HTMLPurifier_ElementDefTest extends HTMLPurifier_Harness
{
function test_mergeIn() {
public function test_mergeIn()
{
$def1 = new HTMLPurifier_ElementDef();
$def2 = new HTMLPurifier_ElementDef();
$def3 = new HTMLPurifier_ElementDef();

View File

@@ -5,18 +5,21 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
protected $_entity_lookup;
function setUp() {
public function setUp()
{
$this->_entity_lookup = HTMLPurifier_EntityLookup::instance();
parent::setUp();
}
function assertCleanUTF8($string, $expect = null) {
public function assertCleanUTF8($string, $expect = null)
{
if ($expect === null) $expect = $string;
$this->assertIdentical(HTMLPurifier_Encoder::cleanUTF8($string), $expect, 'iconv: %s');
$this->assertIdentical(HTMLPurifier_Encoder::cleanUTF8($string, true), $expect, 'PHP: %s');
}
function test_cleanUTF8() {
public function test_cleanUTF8()
{
$this->assertCleanUTF8('Normal string.');
$this->assertCleanUTF8("Test\tAllowed\nControl\rCharacters");
$this->assertCleanUTF8("null byte: \0", 'null byte: ');
@@ -29,7 +32,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
$this->assertCleanUTF8("\xED\xB0\x80", '');
}
function test_convertToUTF8_noConvert() {
public function test_convertToUTF8_noConvert()
{
// UTF-8 means that we don't touch it
$this->assertIdentical(
HTMLPurifier_Encoder::convertToUTF8("\xF6", $this->config, $this->context),
@@ -38,7 +42,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
);
}
function test_convertToUTF8_spuriousEncoding() {
public function test_convertToUTF8_spuriousEncoding()
{
if (!HTMLPurifier_Encoder::iconvAvailable()) return;
$this->config->set('Core.Encoding', 'utf99');
$this->expectError('Invalid encoding utf99');
@@ -48,7 +53,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
);
}
function test_convertToUTF8_iso8859_1() {
public function test_convertToUTF8_iso8859_1()
{
$this->config->set('Core.Encoding', 'ISO-8859-1');
$this->assertIdentical(
HTMLPurifier_Encoder::convertToUTF8("\xF6", $this->config, $this->context),
@@ -56,7 +62,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
);
}
function test_convertToUTF8_withoutIconv() {
public function test_convertToUTF8_withoutIconv()
{
$this->config->set('Core.Encoding', 'ISO-8859-1');
$this->config->set('Test.ForceNoIconv', true);
$this->assertIdentical(
@@ -66,11 +73,13 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
}
function getZhongWen() {
public function getZhongWen()
{
return "\xE4\xB8\xAD\xE6\x96\x87 (Chinese)";
}
function test_convertFromUTF8_utf8() {
public function test_convertFromUTF8_utf8()
{
// UTF-8 means that we don't touch it
$this->assertIdentical(
HTMLPurifier_Encoder::convertFromUTF8("\xC3\xB6", $this->config, $this->context),
@@ -78,7 +87,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
);
}
function test_convertFromUTF8_iso8859_1() {
public function test_convertFromUTF8_iso8859_1()
{
$this->config->set('Core.Encoding', 'ISO-8859-1');
$this->assertIdentical(
HTMLPurifier_Encoder::convertFromUTF8("\xC3\xB6", $this->config, $this->context),
@@ -87,7 +97,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
);
}
function test_convertFromUTF8_iconvNoChars() {
public function test_convertFromUTF8_iconvNoChars()
{
if (!HTMLPurifier_Encoder::iconvAvailable()) return;
$this->config->set('Core.Encoding', 'ISO-8859-1');
$this->assertIdentical(
@@ -96,7 +107,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
);
}
function test_convertFromUTF8_phpNormal() {
public function test_convertFromUTF8_phpNormal()
{
// Plain PHP implementation has slightly different behavior
$this->config->set('Core.Encoding', 'ISO-8859-1');
$this->config->set('Test.ForceNoIconv', true);
@@ -107,7 +119,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
);
}
function test_convertFromUTF8_phpNoChars() {
public function test_convertFromUTF8_phpNoChars()
{
$this->config->set('Core.Encoding', 'ISO-8859-1');
$this->config->set('Test.ForceNoIconv', true);
$this->assertIdentical(
@@ -116,7 +129,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
);
}
function test_convertFromUTF8_withProtection() {
public function test_convertFromUTF8_withProtection()
{
// Preserve the characters!
$this->config->set('Core.Encoding', 'ISO-8859-1');
$this->config->set('Core.EscapeNonASCIICharacters', true);
@@ -126,7 +140,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
);
}
function test_convertFromUTF8_withProtectionButUtf8() {
public function test_convertFromUTF8_withProtectionButUtf8()
{
// Preserve the characters!
$this->config->set('Core.EscapeNonASCIICharacters', true);
$this->assertIdentical(
@@ -135,8 +150,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
);
}
function test_convertToASCIIDumbLossless() {
public function test_convertToASCIIDumbLossless()
{
// Uppercase thorn letter
$this->assertIdentical(
HTMLPurifier_Encoder::convertToASCIIDumbLossless("\xC3\x9Eorn"),
@@ -156,7 +171,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
}
function assertASCIISupportCheck($enc, $ret) {
public function assertASCIISupportCheck($enc, $ret)
{
$test = HTMLPurifier_Encoder::testEncodingSupportsASCII($enc, true);
if ($test === false) return;
$this->assertIdentical(
@@ -169,7 +185,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
);
}
function test_testEncodingSupportsASCII() {
public function test_testEncodingSupportsASCII()
{
if (HTMLPurifier_Encoder::iconvAvailable()) {
$this->assertASCIISupportCheck('Shift_JIS', array("\xC2\xA5" => '\\', "\xE2\x80\xBE" => '~'));
$this->assertASCIISupportCheck('JOHAB', array("\xE2\x82\xA9" => '\\'));
@@ -178,7 +195,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
$this->assertASCIISupportCheck('dontexist', array()); // canary
}
function testShiftJIS() {
public function testShiftJIS()
{
if (!HTMLPurifier_Encoder::iconvAvailable()) return;
$this->config->set('Core.Encoding', 'Shift_JIS');
// This actually looks like a Yen, but we're going to treat it differently
@@ -192,7 +210,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
);
}
function testIconvTruncateBug() {
public function testIconvTruncateBug()
{
if (!HTMLPurifier_Encoder::iconvAvailable()) return;
if (HTMLPurifier_Encoder::testIconvTruncateBug() !== HTMLPurifier_Encoder::ICONV_TRUNCATES) return;
$this->config->set('Core.Encoding', 'ISO-8859-1');
@@ -202,7 +221,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
);
}
function testIconvChunking() {
public function testIconvChunking()
{
if (!HTMLPurifier_Encoder::iconvAvailable()) return;
if (HTMLPurifier_Encoder::testIconvTruncateBug() !== HTMLPurifier_Encoder::ICONV_TRUNCATES) return;
$this->assertIdentical(HTMLPurifier_Encoder::iconv('utf-8', 'iso-8859-1//IGNORE', "a\xF3\xA0\x80\xA0b", 4), 'ab');

View File

@@ -5,8 +5,8 @@
class HTMLPurifier_EntityLookupTest extends HTMLPurifier_Harness
{
function test() {
public function test()
{
$lookup = HTMLPurifier_EntityLookup::instance();
// latin char

View File

@@ -5,12 +5,14 @@ class HTMLPurifier_EntityParserTest extends HTMLPurifier_Harness
protected $EntityParser;
public function setUp() {
public function setUp()
{
$this->EntityParser = new HTMLPurifier_EntityParser();
$this->_entity_lookup = HTMLPurifier_EntityLookup::instance();
}
function test_substituteNonSpecialEntities() {
public function test_substituteNonSpecialEntities()
{
$char_theta = $this->_entity_lookup->table['theta'];
$this->assertIdentical($char_theta,
$this->EntityParser->substituteNonSpecialEntities('&theta;') );
@@ -73,7 +75,8 @@ class HTMLPurifier_EntityParserTest extends HTMLPurifier_Harness
}
function test_substituteSpecialEntities() {
public function test_substituteSpecialEntities()
{
$this->assertIdentical(
"'",
$this->EntityParser->substituteSpecialEntities('&#39;')

View File

@@ -12,18 +12,22 @@ class HTMLPurifier_ErrorCollectorEMock extends HTMLPurifier_ErrorCollectorMock
private $_expected_context = array();
private $_expected_context_at = array();
public function prepare($context) {
public function prepare($context)
{
$this->_context = $context;
}
public function expectContext($key, $value) {
public function expectContext($key, $value)
{
$this->_expected_context[$key] = $value;
}
public function expectContextAt($step, $key, $value) {
public function expectContextAt($step, $key, $value)
{
$this->_expected_context_at[$step][$key] = $value;
}
public function send($v1, $v2) {
public function send($v1, $v2)
{
// test for context
$context = SimpleTest::getContext();
$test = $context->getTest();

View File

@@ -9,7 +9,8 @@ class HTMLPurifier_ErrorCollectorTest extends HTMLPurifier_Harness
protected $language, $generator, $line;
protected $collector;
public function setup() {
public function setup()
{
generate_mock_once('HTMLPurifier_Language');
generate_mock_once('HTMLPurifier_Generator');
parent::setup();
@@ -26,8 +27,8 @@ class HTMLPurifier_ErrorCollectorTest extends HTMLPurifier_Harness
$this->collector = new HTMLPurifier_ErrorCollector($this->context);
}
function test() {
public function test()
{
$language = $this->language;
$language->setReturnValue('getMessage', 'Message 1', array('message-1'));
$language->setReturnValue('formatMessage', 'Message 2', array('message-2', array(1 => 'param')));
@@ -57,7 +58,8 @@ class HTMLPurifier_ErrorCollectorTest extends HTMLPurifier_Harness
}
function testNoErrors() {
public function testNoErrors()
{
$this->language->setReturnValue('getMessage', 'No errors', array('ErrorCollector: No errors'));
$formatted_result = '<p>No errors</p>';
@@ -67,7 +69,8 @@ class HTMLPurifier_ErrorCollectorTest extends HTMLPurifier_Harness
);
}
function testNoLineNumbers() {
public function testNoLineNumbers()
{
$this->language->setReturnValue('getMessage', 'Message 1', array('message-1'));
$this->language->setReturnValue('getMessage', 'Message 2', array('message-2'));
@@ -88,8 +91,8 @@ class HTMLPurifier_ErrorCollectorTest extends HTMLPurifier_Harness
*/
}
function testContextSubstitutions() {
public function testContextSubstitutions()
{
$current_token = false;
$this->context->register('CurrentToken', $current_token);
@@ -120,7 +123,8 @@ class HTMLPurifier_ErrorCollectorTest extends HTMLPurifier_Harness
}
/*
function testNestedErrors() {
public function testNestedErrors()
{
$this->language->setReturnValue('getMessage', 'Message 1', array('message-1'));
$this->language->setReturnValue('getMessage', 'Message 2', array('message-2'));
$this->language->setReturnValue('formatMessage', 'End Message', array('end-message', array(1 => 'param')));

View File

@@ -10,7 +10,8 @@ class HTMLPurifier_ErrorsHarness extends HTMLPurifier_Harness
protected $config, $context;
protected $collector, $generator, $callCount;
public function setup() {
public function setup()
{
$this->config = HTMLPurifier_Config::create(array('Core.CollectErrors' => true));
$this->context = new HTMLPurifier_Context();
generate_mock_once('HTMLPurifier_ErrorCollector');
@@ -20,16 +21,19 @@ class HTMLPurifier_ErrorsHarness extends HTMLPurifier_Harness
$this->callCount = 0;
}
protected function expectNoErrorCollection() {
protected function expectNoErrorCollection()
{
$this->collector->expectNever('send');
}
protected function expectErrorCollection() {
protected function expectErrorCollection()
{
$args = func_get_args();
$this->collector->expectOnce('send', $args);
}
protected function expectContext($key, $value) {
protected function expectContext($key, $value)
{
$this->collector->expectContext($key, $value);
}

View File

@@ -7,7 +7,8 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
{
// usual use case:
function test_tokenizeHTML_extractStyleBlocks() {
public function test_tokenizeHTML_extractStyleBlocks()
{
$this->config->set('Filter.ExtractStyleBlocks', true);
$purifier = new HTMLPurifier($this->config);
$result = $purifier->purify('<style type="text/css">.foo {text-align:center;bogus:remove-me;} body.class[foo="attr"] {text-align:right;}</style>Test<style>* {font-size:12pt;}</style>');
@@ -20,7 +21,8 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
);
}
function assertExtractStyleBlocks($html, $expect = true, $styles = array()) {
public function assertExtractStyleBlocks($html, $expect = true, $styles = array())
{
$filter = new HTMLPurifier_Filter_ExtractStyleBlocks(); // disable cleaning
if ($expect === true) $expect = $html;
$this->config->set('Filter.ExtractStyleBlocks.TidyImpl', false);
@@ -29,15 +31,18 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
$this->assertIdentical($this->context->get('StyleBlocks'), $styles);
}
function test_extractStyleBlocks_preserve() {
public function test_extractStyleBlocks_preserve()
{
$this->assertExtractStyleBlocks('Foobar');
}
function test_extractStyleBlocks_allStyle() {
public function test_extractStyleBlocks_allStyle()
{
$this->assertExtractStyleBlocks('<style>foo</style>', '', array('foo'));
}
function test_extractStyleBlocks_multipleBlocks() {
public function test_extractStyleBlocks_multipleBlocks()
{
$this->assertExtractStyleBlocks(
"<style>1</style><style>2</style>NOP<style>4</style>",
"NOP",
@@ -45,7 +50,8 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
);
}
function test_extractStyleBlocks_blockWithAttributes() {
public function test_extractStyleBlocks_blockWithAttributes()
{
$this->assertExtractStyleBlocks(
'<style type="text/css">css</style>',
'',
@@ -53,7 +59,8 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
);
}
function test_extractStyleBlocks_styleWithPadding() {
public function test_extractStyleBlocks_styleWithPadding()
{
$this->assertExtractStyleBlocks(
"Alas<styled>Awesome</styled>\n<style>foo</style> Trendy!",
"Alas<styled>Awesome</styled>\n Trendy!",
@@ -61,7 +68,8 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
);
}
function assertCleanCSS($input, $expect = true) {
public function assertCleanCSS($input, $expect = true)
{
$filter = new HTMLPurifier_Filter_ExtractStyleBlocks();
if ($expect === true) $expect = $input;
$this->normalize($input);
@@ -70,15 +78,18 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
$this->assertIdentical($result, $expect);
}
function test_cleanCSS_malformed() {
public function test_cleanCSS_malformed()
{
$this->assertCleanCSS('</style>', '');
}
function test_cleanCSS_selector() {
public function test_cleanCSS_selector()
{
$this->assertCleanCSS("a .foo #id div.cl#foo {\nfont-weight:700;\n}");
}
function test_cleanCSS_angledBrackets() {
public function test_cleanCSS_angledBrackets()
{
// [Content] No longer can smuggle in angled brackets using
// font-family; when we add support for 'content', reinstate
// this test.
@@ -88,7 +99,8 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
//);
}
function test_cleanCSS_angledBrackets2() {
public function test_cleanCSS_angledBrackets2()
{
// CSSTidy's behavior in this case is wrong, and should be fixed
//$this->assertCleanCSS(
// "span[title=\"</style>\"] {\nfont-size:12pt;\n}",
@@ -96,18 +108,21 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
//);
}
function test_cleanCSS_bogus() {
public function test_cleanCSS_bogus()
{
$this->assertCleanCSS("div {bogus:tree;}", "div {\n}");
}
/* [CONTENT]
function test_cleanCSS_escapeCodes() {
public function test_cleanCSS_escapeCodes()
{
$this->assertCleanCSS(
".class {\nfont-family:\"\\3C /style\\3E \";\n}"
);
}
function test_cleanCSS_noEscapeCodes() {
public function test_cleanCSS_noEscapeCodes()
{
$this->config->set('Filter.ExtractStyleBlocks.Escaping', false);
$this->assertCleanCSS(
".class {\nfont-family:\"</style>\";\n}"
@@ -115,7 +130,8 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
}
*/
function test_cleanCSS_scope() {
public function test_cleanCSS_scope()
{
$this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo');
$this->assertCleanCSS(
"p {\ntext-indent:1em;\n}",
@@ -123,7 +139,8 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
);
}
function test_cleanCSS_scopeWithSelectorCommas() {
public function test_cleanCSS_scopeWithSelectorCommas()
{
$this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo');
$this->assertCleanCSS(
"b, i {\ntext-decoration:underline;\n}",
@@ -131,17 +148,20 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
);
}
function test_cleanCSS_scopeWithNaughtySelector() {
public function test_cleanCSS_scopeWithNaughtySelector()
{
$this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo');
$this->assertCleanCSS(" + p {\ntext-indent:1em;\n}", '');
}
function test_cleanCSS_scopeWithMultipleNaughtySelectors() {
public function test_cleanCSS_scopeWithMultipleNaughtySelectors()
{
$this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo');
$this->assertCleanCSS(" ++ ++ p {\ntext-indent:1em;\n}", '');
}
function test_cleanCSS_scopeWithCommas() {
public function test_cleanCSS_scopeWithCommas()
{
$this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo, .bar');
$this->assertCleanCSS(
"p {\ntext-indent:1em;\n}",
@@ -149,7 +169,8 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
);
}
function test_cleanCSS_scopeAllWithCommas() {
public function test_cleanCSS_scopeAllWithCommas()
{
$this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo, .bar');
$this->assertCleanCSS(
"p, div {\ntext-indent:1em;\n}",
@@ -157,7 +178,8 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
);
}
function test_cleanCSS_scopeWithConflicts() {
public function test_cleanCSS_scopeWithConflicts()
{
$this->config->set('Filter.ExtractStyleBlocks.Scope', 'p');
$this->assertCleanCSS(
"div {
@@ -178,7 +200,8 @@ text-align:left;
);
}
function test_removeComments() {
public function test_removeComments()
{
$this->assertCleanCSS(
"<!--
div {
@@ -191,7 +214,8 @@ text-align:right;
);
}
function test_atSelector() {
public function test_atSelector()
{
$this->assertCleanCSS(
"{
b { text-align: center; }
@@ -200,7 +224,8 @@ text-align:right;
);
}
function test_selectorValidation() {
public function test_selectorValidation()
{
$this->assertCleanCSS(
"&, & {
text-align: center;
@@ -226,7 +251,8 @@ text-align:center;
$this->assertCleanCSS("doesnt-exist { text-align:center }", "");
}
function test_cleanCSS_caseSensitive() {
public function test_cleanCSS_caseSensitive()
{
$this->assertCleanCSS("a .foo #ID div.cl#foo {\nbackground:url(\"http://foo/BAR\");\n}");
}

View File

@@ -8,12 +8,14 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
*/
private $_entity_lookup;
public function __construct() {
public function __construct()
{
parent::__construct();
$this->_entity_lookup = HTMLPurifier_EntityLookup::instance();
}
public function setUp() {
public function setUp()
{
parent::setUp();
$this->config->set('Output.Newline', "\n");
}
@@ -21,24 +23,28 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
/**
* Creates a generator based on config and context member variables.
*/
protected function createGenerator() {
protected function createGenerator()
{
return new HTMLPurifier_Generator($this->config, $this->context);
}
protected function assertGenerateFromToken($token, $html) {
protected function assertGenerateFromToken($token, $html)
{
$generator = $this->createGenerator();
$result = $generator->generateFromToken($token);
$this->assertIdentical($result, $html);
}
function test_generateFromToken_text() {
public function test_generateFromToken_text()
{
$this->assertGenerateFromToken(
new HTMLPurifier_Token_Text('Foobar.<>'),
'Foobar.&lt;&gt;'
);
}
function test_generateFromToken_startWithAttr() {
public function test_generateFromToken_startWithAttr()
{
$this->assertGenerateFromToken(
new HTMLPurifier_Token_Start('a',
array('href' => 'dyn?a=foo&b=bar')
@@ -47,14 +53,16 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
);
}
function test_generateFromToken_end() {
public function test_generateFromToken_end()
{
$this->assertGenerateFromToken(
new HTMLPurifier_Token_End('b'),
'</b>'
);
}
function test_generateFromToken_emptyWithAttr() {
public function test_generateFromToken_emptyWithAttr()
{
$this->assertGenerateFromToken(
new HTMLPurifier_Token_Empty('br',
array('style' => 'font-family:"Courier New";')
@@ -63,26 +71,30 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
);
}
function test_generateFromToken_startNoAttr() {
public function test_generateFromToken_startNoAttr()
{
$this->assertGenerateFromToken(
new HTMLPurifier_Token_Start('asdf'),
'<asdf>'
);
}
function test_generateFromToken_emptyNoAttr() {
public function test_generateFromToken_emptyNoAttr()
{
$this->assertGenerateFromToken(
new HTMLPurifier_Token_Empty('br'),
'<br />'
);
}
function test_generateFromToken_error() {
public function test_generateFromToken_error()
{
$this->expectError('Cannot generate HTML from non-HTMLPurifier_Token object');
$this->assertGenerateFromToken( null, '' );
}
function test_generateFromToken_unicode() {
public function test_generateFromToken_unicode()
{
$theta_char = $this->_entity_lookup->table['theta'];
$this->assertGenerateFromToken(
new HTMLPurifier_Token_Text($theta_char),
@@ -90,14 +102,16 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
);
}
function test_generateFromToken_backtick() {
public function test_generateFromToken_backtick()
{
$this->assertGenerateFromToken(
new HTMLPurifier_Token_Start('img', array('alt' => '`foo')),
'<img alt="`foo ">'
);
}
function test_generateFromToken_backtickDisabled() {
public function test_generateFromToken_backtickDisabled()
{
$this->config->set('Output.FixInnerHTML', false);
$this->assertGenerateFromToken(
new HTMLPurifier_Token_Start('img', array('alt' => '`')),
@@ -105,52 +119,60 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
);
}
function test_generateFromToken_backtickNoChange() {
public function test_generateFromToken_backtickNoChange()
{
$this->assertGenerateFromToken(
new HTMLPurifier_Token_Start('img', array('alt' => '`foo` bar')),
'<img alt="`foo` bar">'
);
}
function assertGenerateAttributes($attr, $expect, $element = false) {
public function assertGenerateAttributes($attr, $expect, $element = false)
{
$generator = $this->createGenerator();
$result = $generator->generateAttributes($attr, $element);
$this->assertIdentical($result, $expect);
}
function test_generateAttributes_blank() {
public function test_generateAttributes_blank()
{
$this->assertGenerateAttributes(array(), '');
}
function test_generateAttributes_basic() {
public function test_generateAttributes_basic()
{
$this->assertGenerateAttributes(
array('href' => 'dyn?a=foo&b=bar'),
'href="dyn?a=foo&amp;b=bar"'
);
}
function test_generateAttributes_doubleQuote() {
public function test_generateAttributes_doubleQuote()
{
$this->assertGenerateAttributes(
array('style' => 'font-family:"Courier New";'),
'style="font-family:&quot;Courier New&quot;;"'
);
}
function test_generateAttributes_singleQuote() {
public function test_generateAttributes_singleQuote()
{
$this->assertGenerateAttributes(
array('style' => 'font-family:\'Courier New\';'),
'style="font-family:\'Courier New\';"'
);
}
function test_generateAttributes_multiple() {
public function test_generateAttributes_multiple()
{
$this->assertGenerateAttributes(
array('src' => 'picture.jpg', 'alt' => 'Short & interesting'),
'src="picture.jpg" alt="Short &amp; interesting"'
);
}
function test_generateAttributes_specialChar() {
public function test_generateAttributes_specialChar()
{
$theta_char = $this->_entity_lookup->table['theta'];
$this->assertGenerateAttributes(
array('title' => 'Theta is ' . $theta_char),
@@ -159,15 +181,16 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
}
function test_generateAttributes_minimized() {
public function test_generateAttributes_minimized()
{
$this->config->set('HTML.Doctype', 'HTML 4.01 Transitional');
$this->assertGenerateAttributes(
array('compact' => 'compact'), 'compact', 'menu'
);
}
function test_generateFromTokens() {
public function test_generateFromTokens()
{
$this->assertGeneration(
array(
new HTMLPurifier_Token_Start('b'),
@@ -179,13 +202,15 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
}
protected function assertGeneration($tokens, $expect) {
protected function assertGeneration($tokens, $expect)
{
$generator = new HTMLPurifier_Generator($this->config, $this->context);
$result = $generator->generateFromTokens($tokens);
$this->assertIdentical($expect, $result);
}
function test_generateFromTokens_Scripting() {
public function test_generateFromTokens_Scripting()
{
$this->assertGeneration(
array(
new HTMLPurifier_Token_Start('script'),
@@ -196,7 +221,8 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
);
}
function test_generateFromTokens_Scripting_missingCloseTag() {
public function test_generateFromTokens_Scripting_missingCloseTag()
{
$this->assertGeneration(
array(
new HTMLPurifier_Token_Start('script'),
@@ -206,7 +232,8 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
);
}
function test_generateFromTokens_Scripting_doubleBlock() {
public function test_generateFromTokens_Scripting_doubleBlock()
{
$this->assertGeneration(
array(
new HTMLPurifier_Token_Start('script'),
@@ -218,7 +245,8 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
);
}
function test_generateFromTokens_Scripting_disableWrapper() {
public function test_generateFromTokens_Scripting_disableWrapper()
{
$this->config->set('Output.CommentScriptContents', false);
$this->assertGeneration(
array(
@@ -230,7 +258,8 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
);
}
function test_generateFromTokens_XHTMLoff() {
public function test_generateFromTokens_XHTMLoff()
{
$this->config->set('HTML.XHTML', false);
// omit trailing slash
@@ -251,7 +280,8 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
}
function test_generateFromTokens_TidyFormat() {
public function test_generateFromTokens_TidyFormat()
{
// abort test if tidy isn't loaded
if (!extension_loaded('tidy')) return;
@@ -273,7 +303,8 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
}
function test_generateFromTokens_sortAttr() {
public function test_generateFromTokens_sortAttr()
{
$this->config->set('Output.SortAttr', true);
$this->assertGeneration(

View File

@@ -3,15 +3,16 @@
class HTMLPurifier_HTMLDefinitionTest extends HTMLPurifier_Harness
{
function expectError($error = false, $message = '%s') {
public function expectError($error = false, $message = '%s')
{
// Because we're testing a definition, it's vital that the cache
// is turned off for tests that expect errors.
$this->config->set('Cache.DefinitionImpl', null);
parent::expectError($error);
}
function test_parseTinyMCEAllowedList() {
public function test_parseTinyMCEAllowedList()
{
$def = new HTMLPurifier_HTMLDefinition();
// note: this is case-sensitive, but its config schema
@@ -67,8 +68,8 @@ a[href|title]
}
function test_Allowed() {
public function test_Allowed()
{
$config1 = HTMLPurifier_Config::create(array(
'HTML.AllowedElements' => array('b', 'i', 'p', 'a'),
'HTML.AllowedAttributes' => array('a@href', '*@id')
@@ -82,83 +83,97 @@ a[href|title]
}
function assertPurification_AllowedElements_p() {
public function assertPurification_AllowedElements_p()
{
$this->assertPurification('<p><b>Jelly</b></p>', '<p>Jelly</p>');
}
function test_AllowedElements() {
public function test_AllowedElements()
{
$this->config->set('HTML.AllowedElements', 'p');
$this->assertPurification_AllowedElements_p();
}
function test_AllowedElements_multiple() {
public function test_AllowedElements_multiple()
{
$this->config->set('HTML.AllowedElements', 'p,div');
$this->assertPurification('<div><p><b>Jelly</b></p></div>', '<div><p>Jelly</p></div>');
}
function test_AllowedElements_invalidElement() {
public function test_AllowedElements_invalidElement()
{
$this->config->set('HTML.AllowedElements', 'obviously_invalid,p');
$this->expectError(new PatternExpectation("/Element 'obviously_invalid' is not supported/"));
$this->assertPurification_AllowedElements_p();
}
function test_AllowedElements_invalidElement_xssAttempt() {
public function test_AllowedElements_invalidElement_xssAttempt()
{
$this->config->set('HTML.AllowedElements', '<script>,p');
$this->expectError(new PatternExpectation("/Element '&lt;script&gt;' is not supported/"));
$this->assertPurification_AllowedElements_p();
}
function test_AllowedElements_multipleInvalidElements() {
public function test_AllowedElements_multipleInvalidElements()
{
$this->config->set('HTML.AllowedElements', 'dr-wiggles,dr-pepper,p');
$this->expectError(new PatternExpectation("/Element 'dr-wiggles' is not supported/"));
$this->expectError(new PatternExpectation("/Element 'dr-pepper' is not supported/"));
$this->assertPurification_AllowedElements_p();
}
function assertPurification_AllowedAttributes_global_style() {
public function assertPurification_AllowedAttributes_global_style()
{
$this->assertPurification(
'<p style="font-weight:bold;" class="foo">Jelly</p><br style="clear:both;" />',
'<p style="font-weight:bold;">Jelly</p><br style="clear:both;" />');
}
function test_AllowedAttributes_global_preferredSyntax() {
public function test_AllowedAttributes_global_preferredSyntax()
{
$this->config->set('HTML.AllowedElements', array('p', 'br'));
$this->config->set('HTML.AllowedAttributes', 'style');
$this->assertPurification_AllowedAttributes_global_style();
}
function test_AllowedAttributes_global_verboseSyntax() {
public function test_AllowedAttributes_global_verboseSyntax()
{
$this->config->set('HTML.AllowedElements', array('p', 'br'));
$this->config->set('HTML.AllowedAttributes', '*@style');
$this->assertPurification_AllowedAttributes_global_style();
}
function test_AllowedAttributes_global_discouragedSyntax() {
public function test_AllowedAttributes_global_discouragedSyntax()
{
// Emit errors eventually
$this->config->set('HTML.AllowedElements', array('p', 'br'));
$this->config->set('HTML.AllowedAttributes', '*.style');
$this->assertPurification_AllowedAttributes_global_style();
}
function assertPurification_AllowedAttributes_local_p_style() {
public function assertPurification_AllowedAttributes_local_p_style()
{
$this->assertPurification(
'<p style="font-weight:bold;" class="foo">Jelly</p><br style="clear:both;" />',
'<p style="font-weight:bold;">Jelly</p><br />');
}
function test_AllowedAttributes_local_preferredSyntax() {
public function test_AllowedAttributes_local_preferredSyntax()
{
$this->config->set('HTML.AllowedElements', array('p', 'br'));
$this->config->set('HTML.AllowedAttributes', 'p@style');
$this->assertPurification_AllowedAttributes_local_p_style();
}
function test_AllowedAttributes_local_discouragedSyntax() {
public function test_AllowedAttributes_local_discouragedSyntax()
{
$this->config->set('HTML.AllowedElements', array('p', 'br'));
$this->config->set('HTML.AllowedAttributes', 'p.style');
$this->assertPurification_AllowedAttributes_local_p_style();
}
function test_AllowedAttributes_multiple() {
public function test_AllowedAttributes_multiple()
{
$this->config->set('HTML.AllowedElements', array('p', 'br'));
$this->config->set('HTML.AllowedAttributes', 'p@style,br@class,title');
$this->assertPurification(
@@ -167,34 +182,39 @@ a[href|title]
);
}
function test_AllowedAttributes_local_invalidAttribute() {
public function test_AllowedAttributes_local_invalidAttribute()
{
$this->config->set('HTML.AllowedElements', array('p', 'br'));
$this->config->set('HTML.AllowedAttributes', array('p@style', 'p@<foo>'));
$this->expectError(new PatternExpectation("/Attribute '&lt;foo&gt;' in element 'p' not supported/"));
$this->assertPurification_AllowedAttributes_local_p_style();
}
function test_AllowedAttributes_global_invalidAttribute() {
public function test_AllowedAttributes_global_invalidAttribute()
{
$this->config->set('HTML.AllowedElements', array('p', 'br'));
$this->config->set('HTML.AllowedAttributes', array('style', '<foo>'));
$this->expectError(new PatternExpectation("/Global attribute '&lt;foo&gt;' is not supported in any elements/"));
$this->assertPurification_AllowedAttributes_global_style();
}
function test_AllowedAttributes_local_invalidAttributeDueToMissingElement() {
public function test_AllowedAttributes_local_invalidAttributeDueToMissingElement()
{
$this->config->set('HTML.AllowedElements', array('p', 'br'));
$this->config->set('HTML.AllowedAttributes', 'p.style,foo.style');
$this->expectError(new PatternExpectation("/Cannot allow attribute 'style' if element 'foo' is not allowed\/supported/"));
$this->assertPurification_AllowedAttributes_local_p_style();
}
function test_AllowedAttributes_duplicate() {
public function test_AllowedAttributes_duplicate()
{
$this->config->set('HTML.AllowedElements', array('p', 'br'));
$this->config->set('HTML.AllowedAttributes', 'p.style,p@style');
$this->assertPurification_AllowedAttributes_local_p_style();
}
function test_AllowedAttributes_multipleErrors() {
public function test_AllowedAttributes_multipleErrors()
{
$this->config->set('HTML.AllowedElements', array('p', 'br'));
$this->config->set('HTML.AllowedAttributes', 'p.style,foo.style,<foo>');
$this->expectError(new PatternExpectation("/Cannot allow attribute 'style' if element 'foo' is not allowed\/supported/"));
@@ -202,58 +222,67 @@ a[href|title]
$this->assertPurification_AllowedAttributes_local_p_style();
}
function test_ForbiddenElements() {
public function test_ForbiddenElements()
{
$this->config->set('HTML.ForbiddenElements', 'b');
$this->assertPurification('<b>b</b><i>i</i>', 'b<i>i</i>');
}
function test_ForbiddenElements_invalidElement() {
public function test_ForbiddenElements_invalidElement()
{
$this->config->set('HTML.ForbiddenElements', 'obviously_incorrect');
// no error!
$this->assertPurification('<i>i</i>');
}
function assertPurification_ForbiddenAttributes_b_style() {
public function assertPurification_ForbiddenAttributes_b_style()
{
$this->assertPurification(
'<b style="float:left;">b</b><i style="float:left;">i</i>',
'<b>b</b><i style="float:left;">i</i>');
}
function test_ForbiddenAttributes() {
public function test_ForbiddenAttributes()
{
$this->config->set('HTML.ForbiddenAttributes', 'b@style');
$this->assertPurification_ForbiddenAttributes_b_style();
}
function test_ForbiddenAttributes_incorrectSyntax() {
public function test_ForbiddenAttributes_incorrectSyntax()
{
$this->config->set('HTML.ForbiddenAttributes', 'b.style');
$this->expectError("Error with b.style: tag.attr syntax not supported for HTML.ForbiddenAttributes; use tag@attr instead");
$this->assertPurification('<b style="float:left;">Test</b>');
}
function test_ForbiddenAttributes_incorrectGlobalSyntax() {
public function test_ForbiddenAttributes_incorrectGlobalSyntax()
{
$this->config->set('HTML.ForbiddenAttributes', '*.style');
$this->expectError("Error with *.style: *.attr syntax not supported for HTML.ForbiddenAttributes; use attr instead");
$this->assertPurification('<b style="float:left;">Test</b>');
}
function assertPurification_ForbiddenAttributes_style() {
public function assertPurification_ForbiddenAttributes_style()
{
$this->assertPurification(
'<b class="foo" style="float:left;">b</b><i style="float:left;">i</i>',
'<b class="foo">b</b><i>i</i>');
}
function test_ForbiddenAttributes_global() {
public function test_ForbiddenAttributes_global()
{
$this->config->set('HTML.ForbiddenAttributes', 'style');
$this->assertPurification_ForbiddenAttributes_style();
}
function test_ForbiddenAttributes_globalVerboseFormat() {
public function test_ForbiddenAttributes_globalVerboseFormat()
{
$this->config->set('HTML.ForbiddenAttributes', '*@style');
$this->assertPurification_ForbiddenAttributes_style();
}
function test_addAttribute() {
public function test_addAttribute()
{
$config = HTMLPurifier_Config::createDefault();
$def = $config->getHTMLDefinition(true);
$def->addAttribute('span', 'custom', 'Enum#attribute');
@@ -265,8 +294,8 @@ a[href|title]
}
function test_addAttribute_multiple() {
public function test_addAttribute_multiple()
{
$config = HTMLPurifier_Config::createDefault();
$def = $config->getHTMLDefinition(true);
$def->addAttribute('span', 'custom', 'Enum#attribute');
@@ -279,8 +308,8 @@ a[href|title]
}
function test_addElement() {
public function test_addElement()
{
$config = HTMLPurifier_Config::createDefault();
$def = $config->getHTMLDefinition(true);
$def->addElement('marquee', 'Inline', 'Inline', 'Common', array('width' => 'Length'));
@@ -292,7 +321,8 @@ a[href|title]
}
function test_injector() {
public function test_injector()
{
generate_mock_once('HTMLPurifier_Injector');
$injector = new HTMLPurifier_InjectorMock();
$injector->name = 'MyInjector';
@@ -308,7 +338,8 @@ a[href|title]
);
}
function test_injectorMissingNeeded() {
public function test_injectorMissingNeeded()
{
generate_mock_once('HTMLPurifier_Injector');
$injector = new HTMLPurifier_InjectorMock();
$injector->name = 'MyInjector';
@@ -322,7 +353,8 @@ a[href|title]
);
}
function test_injectorIntegration() {
public function test_injectorIntegration()
{
$module = $this->config->getHTMLDefinition(true)->getAnonymousModule();
$module->info_injector[] = 'Linkify';
@@ -332,7 +364,8 @@ a[href|title]
);
}
function test_injectorIntegrationFail() {
public function test_injectorIntegrationFail()
{
$this->config->set('HTML.Allowed', 'p');
$module = $this->config->getHTMLDefinition(true)->getAnonymousModule();
@@ -344,7 +377,8 @@ a[href|title]
);
}
function test_notAllowedRequiredAttributeError() {
public function test_notAllowedRequiredAttributeError()
{
$this->expectError("Required attribute 'src' in element 'img' was not allowed, which means 'img' will not be allowed either");
$this->config->set('HTML.Allowed', 'img[alt]');
$this->config->getHTMLDefinition();

View File

@@ -3,13 +3,15 @@
class HTMLPurifier_HTMLModule_FormsTest extends HTMLPurifier_HTMLModuleHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->config->set('HTML.Trusted', true);
$this->config->set('Attr.EnableID', true);
}
function testBasicUse() {
public function testBasicUse()
{
$this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
$this->assertResult( // need support for label for later
'
@@ -29,7 +31,8 @@ class HTMLPurifier_HTMLModule_FormsTest extends HTMLPurifier_HTMLModuleHarness
);
}
function testSelectOption() {
public function testSelectOption()
{
$this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
$this->assertResult('
<form action="http://somesite.com/prog/component-select" method="post">
@@ -49,7 +52,8 @@ class HTMLPurifier_HTMLModule_FormsTest extends HTMLPurifier_HTMLModuleHarness
');
}
function testSelectOptgroup() {
public function testSelectOptgroup()
{
$this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
$this->assertResult('
<form action="http://somesite.com/prog/someprog" method="post">
@@ -75,7 +79,8 @@ class HTMLPurifier_HTMLModule_FormsTest extends HTMLPurifier_HTMLModuleHarness
');
}
function testTextarea() {
public function testTextarea()
{
$this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
$this->assertResult('
<form action="http://somesite.com/prog/text-read" method="post">
@@ -92,7 +97,8 @@ class HTMLPurifier_HTMLModule_FormsTest extends HTMLPurifier_HTMLModuleHarness
// label tests omitted
function testFieldset() {
public function testFieldset()
{
$this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
$this->assertResult('
<form action="..." method="post">
@@ -125,27 +131,32 @@ class HTMLPurifier_HTMLModule_FormsTest extends HTMLPurifier_HTMLModuleHarness
');
}
function testInputTransform() {
public function testInputTransform()
{
$this->config->set('HTML.Doctype', 'XHTML 1.0 Strict');
$this->assertResult('<input type="checkbox" />', '<input type="checkbox" value="" />');
}
function testTextareaTransform() {
public function testTextareaTransform()
{
$this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
$this->assertResult('<textarea></textarea>', '<textarea cols="22" rows="3"></textarea>');
}
function testTextInFieldset() {
public function testTextInFieldset()
{
$this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
$this->assertResult('<fieldset> <legend></legend>foo</fieldset>');
}
function testStrict() {
public function testStrict()
{
$this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
$this->assertResult('<form action=""></form>', '');
}
function testLegacy() {
public function testLegacy()
{
$this->assertResult('<form action=""></form>');
$this->assertResult('<form action=""><input align="left" /></form>');
}

View File

@@ -4,25 +4,29 @@ class HTMLPurifier_HTMLModule_ImageTest extends HTMLPurifier_HTMLModuleHarness
{
function testNormal() {
public function testNormal()
{
$this->assertResult('<img height="40" width="40" src="" alt="" />');
}
function testLengthTooLarge() {
public function testLengthTooLarge()
{
$this->assertResult(
'<img height="40000" width="40000" src="" alt="" />',
'<img height="1200" width="1200" src="" alt="" />'
);
}
function testLengthPercentage() {
public function testLengthPercentage()
{
$this->assertResult(
'<img height="100%" width="100%" src="" alt="" />',
'<img src="" alt="" />'
);
}
function testLengthCustomMax() {
public function testLengthCustomMax()
{
$this->config->set('HTML.MaxImgLength', 20);
$this->assertResult(
'<img height="30" width="30" src="" alt="" />',
@@ -30,7 +34,8 @@ class HTMLPurifier_HTMLModule_ImageTest extends HTMLPurifier_HTMLModuleHarness
);
}
function testLengthCrashFixDisabled() {
public function testLengthCrashFixDisabled()
{
$this->config->set('HTML.MaxImgLength', null);
$this->assertResult(
'<img height="100%" width="100%" src="" alt="" />'
@@ -40,7 +45,8 @@ class HTMLPurifier_HTMLModule_ImageTest extends HTMLPurifier_HTMLModuleHarness
);
}
function testLengthTrusted() {
public function testLengthTrusted()
{
$this->config->set('HTML.Trusted', true);
$this->assertResult(
'<img height="100%" width="100%" src="" alt="" />'

View File

@@ -3,25 +3,29 @@
class HTMLPurifier_HTMLModule_NameTest extends HTMLPurifier_HTMLModuleHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
}
function testBasicUse() {
public function testBasicUse()
{
$this->config->set('Attr.EnableID', true);
$this->assertResult(
'<a name="foo">bar</a>'
);
}
function testCDATA() {
public function testCDATA()
{
$this->config->set('HTML.Attr.Name.UseCDATA', true);
$this->assertResult(
'<a name="2">Baz</a><a name="2">Bar</a>'
);
}
function testCDATAWithHeavyTidy() {
public function testCDATAWithHeavyTidy()
{
$this->config->set('HTML.Attr.Name.UseCDATA', true);
$this->config->set('HTML.TidyLevel', 'heavy');
$this->assertResult('<a name="2">Baz</a>');

View File

@@ -3,20 +3,23 @@
class HTMLPurifier_HTMLModule_NofollowTest extends HTMLPurifier_HTMLModuleHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->config->set('HTML.Nofollow', true);
$this->config->set('Attr.AllowedRel', array("nofollow", "blah"));
}
function testNofollow() {
public function testNofollow()
{
$this->assertResult(
'<a href="http://google.com">x</a><a href="http://google.com" rel="blah">a</a><a href="/local">b</a><a href="mailto:foo@example.com">c</a>',
'<a href="http://google.com" rel="nofollow">x</a><a href="http://google.com" rel="blah nofollow">a</a><a href="/local">b</a><a href="mailto:foo@example.com">c</a>'
);
}
function testNofollowDupe() {
public function testNofollowDupe()
{
$this->assertResult(
'<a href="http://google.com" rel="nofollow">x</a><a href="http://google.com" rel="blah nofollow">a</a><a href="/local">b</a><a href="mailto:foo@example.com">c</a>'
);

View File

@@ -3,23 +3,27 @@
class HTMLPurifier_HTMLModule_ObjectTest extends HTMLPurifier_HTMLModuleHarness
{
function setUp() {
public function setUp()
{
parent::setUp();
$this->config->set('HTML.Trusted', true);
}
function testDefaultRemoval() {
public function testDefaultRemoval()
{
$this->config->set('HTML.Trusted', false);
$this->assertResult(
'<object></object>', ''
);
}
function testMinimal() {
public function testMinimal()
{
$this->assertResult('<object></object>');
}
function testStandardUseCase() {
public function testStandardUseCase()
{
$this->assertResult(
'<object type="video/x-ms-wmv" data="http://domain.com/video.wmv" width="320" height="256">
<param name="src" value="http://domain.com/video.wmv" />

Some files were not shown because too many files have changed in this diff Show More