mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-01 11:50:28 +02:00
[1.5.0] AttrDef partitioned into HTML, CSS and URI segments. Also, some minor bugs with MultiLength fixed.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@747 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
100
tests/HTMLPurifier/AttrDef/HTML/IDTest.php
Normal file
100
tests/HTMLPurifier/AttrDef/HTML/IDTest.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/AttrDefHarness.php';
|
||||
require_once 'HTMLPurifier/AttrDef/HTML/ID.php';
|
||||
require_once 'HTMLPurifier/IDAccumulator.php';
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
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'); // !
|
||||
|
||||
// no effect when IDPrefix isn't set
|
||||
$this->config->set('Attr', 'IDPrefix', '');
|
||||
$this->expectError('%Attr.IDPrefixLocal cannot be used unless '.
|
||||
'%Attr.IDPrefix is set');
|
||||
$this->assertDef('amherst');
|
||||
|
||||
}
|
||||
|
||||
// reference functionality is disabled for now
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
35
tests/HTMLPurifier/AttrDef/HTML/LengthTest.php
Normal file
35
tests/HTMLPurifier/AttrDef/HTML/LengthTest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/AttrDef/HTML/PixelsTest.php';
|
||||
require_once 'HTMLPurifier/AttrDef/HTML/Length.php';
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_LengthTest extends HTMLPurifier_AttrDef_HTML_PixelsTest
|
||||
{
|
||||
|
||||
function setup() {
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_Length();
|
||||
}
|
||||
|
||||
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%');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
31
tests/HTMLPurifier/AttrDef/HTML/MultiLengthTest.php
Normal file
31
tests/HTMLPurifier/AttrDef/HTML/MultiLengthTest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/AttrDef/HTML/LengthTest.php';
|
||||
require_once 'HTMLPurifier/AttrDef/HTML/MultiLength.php';
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_MultiLengthTest extends HTMLPurifier_AttrDef_HTML_LengthTest
|
||||
{
|
||||
|
||||
function setup() {
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_MultiLength();
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
35
tests/HTMLPurifier/AttrDef/HTML/NmtokensTest.php
Normal file
35
tests/HTMLPurifier/AttrDef/HTML/NmtokensTest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/AttrDefHarness.php';
|
||||
require_once 'HTMLPurifier/AttrDef/HTML/Nmtokens.php';
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_NmtokensTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
function testDefault() {
|
||||
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_Nmtokens();
|
||||
|
||||
$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');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
41
tests/HTMLPurifier/AttrDef/HTML/PixelsTest.php
Normal file
41
tests/HTMLPurifier/AttrDef/HTML/PixelsTest.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/AttrDefHarness.php';
|
||||
require_once 'HTMLPurifier/AttrDef/HTML/Pixels.php';
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_PixelsTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
function setup() {
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_Pixels();
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user