first commit

This commit is contained in:
aschwarz
2023-02-27 10:20:09 +01:00
commit 09ee4a8728
2309 changed files with 449255 additions and 0 deletions

View File

@ -0,0 +1,24 @@
<?php
class HTMLPurifier_AttrDef_HTML_BoolTest extends HTMLPurifier_AttrDefHarness
{
public function test()
{
$this->def = new HTMLPurifier_AttrDef_HTML_Bool('foo');
$this->assertDef('foo');
$this->assertDef('', 'foo');
$this->assertDef('bar', 'foo');
}
public function test_make()
{
$factory = new HTMLPurifier_AttrDef_HTML_Bool();
$def = $factory->make('foo');
$def2 = new HTMLPurifier_AttrDef_HTML_Bool('foo');
$this->assertIdentical($def, $def2);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,53 @@
<?php
class HTMLPurifier_AttrDef_HTML_ClassTest extends HTMLPurifier_AttrDef_HTML_NmtokensTest
{
public function setUp()
{
parent::setUp();
$this->def = new HTMLPurifier_AttrDef_HTML_Class();
}
public function testAllowedClasses()
{
$this->config->set('Attr.AllowedClasses', array('foo'));
$this->assertDef('foo');
$this->assertDef('bar', false);
$this->assertDef('foo bar', 'foo');
}
public function testForbiddenClasses()
{
$this->config->set('Attr.ForbiddenClasses', array('bar'));
$this->assertDef('foo');
$this->assertDef('bar', false);
$this->assertDef('foo bar', 'foo');
}
public function testDefault()
{
$this->assertDef('valid');
$this->assertDef('a0-_');
$this->assertDef('-valid');
$this->assertDef('_valid');
$this->assertDef('double valid');
$this->assertDef('0stillvalid');
$this->assertDef('-0');
// test conditional replacement
$this->assertDef('validassoc 0valid', 'validassoc 0valid');
// test whitespace leniency
$this->assertDef(" double\nvalid\r", 'double valid');
// test case sensitivity
$this->assertDef('VALID');
// test duplicate removal
$this->assertDef('valid valid', 'valid');
}
public function testXHTML11Behavior()
{
$this->config->set('HTML.Doctype', 'XHTML 1.1');
$this->assertDef('0invalid', false);
$this->assertDef('valid valid', 'valid');
}
}

View File

@ -0,0 +1,22 @@
<?php
class HTMLPurifier_AttrDef_HTML_ColorTest extends HTMLPurifier_AttrDefHarness
{
public function test()
{
$this->def = new HTMLPurifier_AttrDef_HTML_Color();
$this->assertDef('', false);
$this->assertDef('foo', false);
$this->assertDef('43', false);
$this->assertDef('red', '#FF0000');
$this->assertDef('RED', '#FF0000');
$this->assertDef('#FF0000');
$this->assertDef('#453443');
$this->assertDef('453443', '#453443');
$this->assertDef('#345', '#334455');
$this->assertDef('120', '#112200');
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,31 @@
<?php
class HTMLPurifier_AttrDef_HTML_FrameTargetTest extends HTMLPurifier_AttrDefHarness
{
public function setup()
{
parent::setup();
$this->def = new HTMLPurifier_AttrDef_HTML_FrameTarget();
}
public function testNoneAllowed()
{
$this->assertDef('', false);
$this->assertDef('foo', false);
$this->assertDef('_blank', false);
$this->assertDef('baz', false);
}
public function test()
{
$this->config->set('Attr.AllowedFrameTargets', 'foo,_blank');
$this->assertDef('', false);
$this->assertDef('foo');
$this->assertDef('_blank');
$this->assertDef('baz', false);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,121 @@
<?php
class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
{
public function setUp()
{
parent::setUp();
$id_accumulator = new HTMLPurifier_IDAccumulator();
$this->context->register('IDAccumulator', $id_accumulator);
$this->config->set('Attr.EnableID', true);
$this->def = new HTMLPurifier_AttrDef_HTML_ID();
}
public function test()
{
// valid ID names
$this->assertDef('alpha');
$this->assertDef('al_ha');
$this->assertDef('a0-:.');
$this->assertDef('a');
// invalid ID names
$this->assertDef('<asa', false);
$this->assertDef('0123', false);
$this->assertDef('.asa', false);
// test duplicate detection
$this->assertDef('once');
$this->assertDef('once', false);
// valid once whitespace stripped, but needs to be amended
$this->assertDef(' whee ', 'whee');
}
public function testPrefix()
{
$this->config->set('Attr.IDPrefix', 'user_');
$this->assertDef('alpha', 'user_alpha');
$this->assertDef('<asa', false);
$this->assertDef('once', 'user_once');
$this->assertDef('once', false);
// if already prefixed, leave alone
$this->assertDef('user_alas');
$this->assertDef('user_user_alas'); // how to bypass
}
public function testTwoPrefixes()
{
$this->config->set('Attr.IDPrefix', 'user_');
$this->config->set('Attr.IDPrefixLocal', 'story95_');
$this->assertDef('alpha', 'user_story95_alpha');
$this->assertDef('<asa', false);
$this->assertDef('once', 'user_story95_once');
$this->assertDef('once', false);
$this->assertDef('user_story95_alas');
$this->assertDef('user_alas', 'user_story95_user_alas'); // !
}
public function testLocalPrefixWithoutMainPrefix()
{
// no effect when IDPrefix isn't set
$this->config->set('Attr.IDPrefix', '');
$this->config->set('Attr.IDPrefixLocal', 'story95_');
$this->expectError('%Attr.IDPrefixLocal cannot be used unless '.
'%Attr.IDPrefix is set');
$this->assertDef('amherst');
}
// reference functionality is disabled for now
public function disabled_testIDReference()
{
$this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
$this->assertDef('good_id');
$this->assertDef('good_id'); // duplicates okay
$this->assertDef('<b>', false);
$this->def = new HTMLPurifier_AttrDef_HTML_ID();
$this->assertDef('good_id');
$this->assertDef('good_id', false); // duplicate now not okay
$this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
$this->assertDef('good_id'); // reference still okay
}
public function testRegexp()
{
$this->config->set('Attr.IDBlacklistRegexp', '/^g_/');
$this->assertDef('good_id');
$this->assertDef('g_bad_id', false);
}
public function testRelaxed()
{
$this->config->set('Attr.ID.HTML5', true);
$this->assertDef('123');
$this->assertDef('x[1]');
$this->assertDef('not ok', false);
$this->assertDef(' ', false);
$this->assertDef('', false);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,33 @@
<?php
class HTMLPurifier_AttrDef_HTML_LengthTest extends HTMLPurifier_AttrDef_HTML_PixelsTest
{
public function setup()
{
$this->def = new HTMLPurifier_AttrDef_HTML_Length();
}
public function test()
{
// pixel check
parent::test();
// percent check
$this->assertDef('25%');
// Firefox maintains percent, so will we
$this->assertDef('0%');
// 0% <= percent <= 100%
$this->assertDef('-15%', '0%');
$this->assertDef('120%', '100%');
// fractional percents, apparently, aren't allowed
$this->assertDef('56.5%', '56%');
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,21 @@
<?php
class HTMLPurifier_AttrDef_HTML_LinkTypesTest extends HTMLPurifier_AttrDefHarness
{
public function testNull()
{
$this->def = new HTMLPurifier_AttrDef_HTML_LinkTypes('rel');
$this->config->set('Attr.AllowedRel', array('nofollow', 'foo'));
$this->assertDef('', false);
$this->assertDef('nofollow', true);
$this->assertDef('nofollow foo', true);
$this->assertDef('nofollow bar', 'nofollow');
$this->assertDef('bar', false);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,29 @@
<?php
class HTMLPurifier_AttrDef_HTML_MultiLengthTest extends HTMLPurifier_AttrDef_HTML_LengthTest
{
public function setup()
{
$this->def = new HTMLPurifier_AttrDef_HTML_MultiLength();
}
public function test()
{
// length check
parent::test();
$this->assertDef('*');
$this->assertDef('1*', '*');
$this->assertDef('56*');
$this->assertDef('**', false); // plain old bad
$this->assertDef('5.4*', '5*'); // no decimals
$this->assertDef('-3*', false); // no negatives
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,36 @@
<?php
class HTMLPurifier_AttrDef_HTML_NmtokensTest extends HTMLPurifier_AttrDefHarness
{
public function setUp()
{
parent::setUp();
$this->def = new HTMLPurifier_AttrDef_HTML_Nmtokens();
}
public function testDefault()
{
$this->assertDef('valid');
$this->assertDef('a0-_');
$this->assertDef('-valid');
$this->assertDef('_valid');
$this->assertDef('double valid');
$this->assertDef('0invalid', false);
$this->assertDef('-0', false);
// test conditional replacement
$this->assertDef('validassoc 0invalid', 'validassoc');
// test whitespace leniency
$this->assertDef(" double\nvalid\r", 'double valid');
// test case sensitivity
$this->assertDef('VALID');
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,47 @@
<?php
class HTMLPurifier_AttrDef_HTML_PixelsTest extends HTMLPurifier_AttrDefHarness
{
public function setup()
{
$this->def = new HTMLPurifier_AttrDef_HTML_Pixels();
}
public function test()
{
$this->assertDef('1');
$this->assertDef('0');
$this->assertDef('2px', '2'); // rm px suffix
$this->assertDef('dfs', false); // totally invalid value
// conceivably we could repair this value, but we won't for now
$this->assertDef('9in', false);
// test trim
$this->assertDef(' 45 ', '45');
// no negatives
$this->assertDef('-2', '0');
// remove empty
$this->assertDef('', false);
// round down
$this->assertDef('4.9', '4');
}
public function test_make()
{
$factory = new HTMLPurifier_AttrDef_HTML_Pixels();
$this->def = $factory->make('30');
$this->assertDef('25');
$this->assertDef('35', '30');
}
}
// vim: et sw=4 sts=4