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

Remove trailing whitespace.

Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
Edward Z. Yang
2008-12-06 02:28:20 -05:00
parent 3a6b63dff1
commit 2c955af135
476 changed files with 5595 additions and 5547 deletions

View File

@@ -2,26 +2,26 @@
class HTMLPurifier_AttrDef_CSS_AlphaValueTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_CSS_AlphaValue();
$this->assertDef('0');
$this->assertDef('1');
$this->assertDef('.2');
// clamping to [0.0, 1,0]
$this->assertDef('1.2', '1');
$this->assertDef('-3', '0');
$this->assertDef('0.0', '0');
$this->assertDef('1.0', '1');
$this->assertDef('000', '0');
$this->assertDef('asdf', false);
}
}

View File

@@ -2,11 +2,11 @@
class HTMLPurifier_AttrDef_CSS_BackgroundPositionTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_CSS_BackgroundPosition();
// explicitly cited in spec
$this->assertDef('0% 0%');
$this->assertDef('100% 100%');
@@ -25,7 +25,7 @@ class HTMLPurifier_AttrDef_CSS_BackgroundPositionTest extends HTMLPurifier_AttrD
$this->assertDef('left bottom');
$this->assertDef('center bottom');
$this->assertDef('right bottom');
// reordered due to internal impl details
$this->assertDef('top left', 'left top');
$this->assertDef('top center', 'center top');
@@ -36,32 +36,32 @@ class HTMLPurifier_AttrDef_CSS_BackgroundPositionTest extends HTMLPurifier_AttrD
$this->assertDef('bottom left', 'left bottom');
$this->assertDef('bottom center', 'center bottom');
$this->assertDef('bottom right', 'right bottom');
// more cases from the defined syntax
$this->assertDef('1.32in 4ex');
$this->assertDef('-14% -84.65%');
$this->assertDef('-1in -4ex');
$this->assertDef('-1pc 2.3%');
// keyword mixing
$this->assertDef('3em top');
$this->assertDef('left 50%');
// fixable keyword mixing
$this->assertDef('top 3em', '3em top');
$this->assertDef('50% left', 'left 50%');
// whitespace collapsing
$this->assertDef('3em top', '3em top');
$this->assertDef("left\n \t foo ", 'left');
// invalid uses (we're going to be strict on these)
$this->assertDef('foo bar', false);
$this->assertDef('left left', 'left');
$this->assertDef('left right top bottom center left', 'left bottom');
$this->assertDef('0fr 9%', '9%');
}
}

View File

@@ -2,12 +2,12 @@
class HTMLPurifier_AttrDef_CSS_BackgroundTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$config = HTMLPurifier_Config::createDefault();
$this->def = new HTMLPurifier_AttrDef_CSS_Background($config);
$valid = '#333 url(chess.png) repeat fixed 50% top';
$this->assertDef($valid);
$this->assertDef('url("chess.png") #333 50% top repeat fixed', $valid);
@@ -15,8 +15,8 @@ class HTMLPurifier_AttrDef_CSS_BackgroundTest extends HTMLPurifier_AttrDefHarnes
'rgb(34, 56, 33) url(chess.png) repeat fixed top',
'rgb(34,56,33) url(chess.png) repeat fixed top'
);
}
}

View File

@@ -2,19 +2,19 @@
class HTMLPurifier_AttrDef_CSS_BorderTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$config = HTMLPurifier_Config::createDefault();
$this->def = new HTMLPurifier_AttrDef_CSS_Border($config);
$this->assertDef('thick solid red', 'thick solid #FF0000');
$this->assertDef('thick solid');
$this->assertDef('solid red', 'solid #FF0000');
$this->assertDef('1px solid #000');
$this->assertDef('1px solid rgb(0, 0, 0)', '1px solid rgb(0,0,0)');
}
}

View File

@@ -2,11 +2,11 @@
class HTMLPurifier_AttrDef_CSS_ColorTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_CSS_Color();
$this->assertDef('#F00');
$this->assertDef('#fff');
$this->assertDef('#eeeeee');
@@ -14,27 +14,27 @@ class HTMLPurifier_AttrDef_CSS_ColorTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('rgb(255, 0, 0)', 'rgb(255,0,0)'); // rm spaces
$this->assertDef('rgb(100%,0%,0%)');
$this->assertDef('rgb(50.5%,23.2%,43.9%)'); // decimals okay
$this->assertDef('#G00', false);
$this->assertDef('cmyk(40, 23, 43, 23)', false);
$this->assertDef('rgb(0%, 23, 68%)', false);
// clip numbers outside sRGB gamut
$this->assertDef('rgb(200%, -10%, 0%)', 'rgb(100%,0%,0%)');
$this->assertDef('rgb(256,-23,34)', 'rgb(255,0,34)');
// color keywords, of course
$this->assertDef('red', '#FF0000');
// malformed hex declaration
$this->assertDef('808080', '#808080');
$this->assertDef('000000', '#000000');
$this->assertDef('fed', '#fed');
// maybe hex transformations would be another nice feature
// at the very least transform rgb percent to rgb integer
}
}

View File

@@ -3,29 +3,29 @@
class HTMLPurifier_AttrDef_CSS_Composite_Testable extends
HTMLPurifier_AttrDef_CSS_Composite
{
// we need to pass by ref to get the mocks in
function HTMLPurifier_AttrDef_CSS_Composite_Testable(&$defs) {
$this->defs =& $defs;
}
}
class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness
{
protected $def1, $def2;
function test() {
generate_mock_once('HTMLPurifier_AttrDef');
$config = HTMLPurifier_Config::createDefault();
$context = new HTMLPurifier_Context();
// first test: value properly validates on first definition
// so second def is never called
$def1 = new HTMLPurifier_AttrDefMock();
$def2 = new HTMLPurifier_AttrDefMock();
$defs = array(&$def1, &$def2);
@@ -36,12 +36,12 @@ class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness
$def1->expectOnce('validate', $def1_params);
$def1->setReturnValue('validate', $output, $def1_params);
$def2->expectNever('validate');
$result = $def->validate($input, $config, $context);
$this->assertIdentical($output, $result);
// second test, first def fails, second def works
$def1 = new HTMLPurifier_AttrDefMock();
$def2 = new HTMLPurifier_AttrDefMock();
$defs = array(&$def1, &$def2);
@@ -53,12 +53,12 @@ class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness
$def1->setReturnValue('validate', false, $def_params);
$def2->expectOnce('validate', $def_params);
$def2->setReturnValue('validate', $output, $def_params);
$result = $def->validate($input, $config, $context);
$this->assertIdentical($output, $result);
// third test, all fail, so composite faiils
$def1 = new HTMLPurifier_AttrDefMock();
$def2 = new HTMLPurifier_AttrDefMock();
$defs = array(&$def1, &$def2);
@@ -70,11 +70,11 @@ class HTMLPurifier_AttrDef_CSS_CompositeTest extends HTMLPurifier_AttrDefHarness
$def1->setReturnValue('validate', false, $def_params);
$def2->expectOnce('validate', $def_params);
$def2->setReturnValue('validate', false, $def_params);
$result = $def->validate($input, $config, $context);
$this->assertIdentical($output, $result);
}
}

View File

@@ -2,27 +2,27 @@
class HTMLPurifier_AttrDef_CSS_FilterTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_CSS_Filter();
$this->assertDef('none');
$this->assertDef('alpha(opacity=0)');
$this->assertDef('alpha(opacity=100)');
$this->assertDef('alpha(opacity=50)');
$this->assertDef('alpha(opacity=342)', 'alpha(opacity=100)');
$this->assertDef('alpha(opacity=-23)', 'alpha(opacity=0)');
$this->assertDef('alpha ( opacity = 0 )', 'alpha(opacity=0)');
$this->assertDef('alpha(opacity=0,opacity=100)', 'alpha(opacity=0)');
$this->assertDef('progid:DXImageTransform.Microsoft.Alpha(opacity=20)');
$this->assertDef('progid:DXImageTransform.Microsoft.BasicImage(rotation=2, mirror=1)', false);
}
}

View File

@@ -2,11 +2,11 @@
class HTMLPurifier_AttrDef_CSS_FontFamilyTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_CSS_FontFamily();
$this->assertDef('Gill, Helvetica, sans-serif');
$this->assertDef('\'Times New Roman\', serif');
$this->assertDef('"Times New Roman"', "'Times New Roman'");
@@ -33,6 +33,6 @@ class HTMLPurifier_AttrDef_CSS_FontFamilyTest extends HTMLPurifier_AttrDefHarnes
$this->assertDef("'\\00045 a'", "'E a'");
$this->assertDef("'\\\nf'", "f");
}
}

View File

@@ -2,12 +2,12 @@
class HTMLPurifier_AttrDef_CSS_FontTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$config = HTMLPurifier_Config::createDefault();
$this->def = new HTMLPurifier_AttrDef_CSS_Font($config);
// hodgepodge of usage cases from W3C spec, but " -> '
$this->assertDef('12px/14px sans-serif');
$this->assertDef('80% sans-serif');
@@ -17,17 +17,17 @@ class HTMLPurifier_AttrDef_CSS_FontTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('300 italic 1.3em/1.7em \'FB Armada\', sans-serif');
$this->assertDef('600 9px Charcoal');
$this->assertDef('600 9px/ 12px Charcoal', '600 9px/12px Charcoal');
// spacing
$this->assertDef('12px / 14px sans-serif', '12px/14px sans-serif');
// system fonts
$this->assertDef('menu');
$this->assertDef('800', false);
$this->assertDef('600 9px//12px Charcoal', false);
}
}

View File

@@ -2,47 +2,47 @@
class HTMLPurifier_AttrDef_CSS_ImportantDecoratorTest extends HTMLPurifier_AttrDefHarness
{
/** Mock AttrDef decorator is wrapping */
protected $mock;
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) {
if ($output === null) $output = $input;
$this->mock->expectOnce('validate', array($input, $this->config, $this->context));
$this->mock->setReturnValue('validate', $output);
}
function testImportant() {
$this->setMock('23');
$this->assertDef('23 !important');
}
function testImportantInternalDefChanged() {
$this->setMock('23', '24');
$this->assertDef('23 !important', '24 !important');
}
function testImportantWithSpace() {
$this->setMock('23');
$this->assertDef('23 ! important ', '23 !important');
}
function testFakeImportant() {
$this->setMock('! foo important');
$this->assertDef('! foo important');
}
function testStrip() {
$this->def = new HTMLPurifier_AttrDef_CSS_ImportantDecorator($this->mock, false);
$this->setMock('23');
$this->assertDef('23 ! important ', '23');
}
}

View File

@@ -2,11 +2,11 @@
class HTMLPurifier_AttrDef_CSS_LengthTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_CSS_Length();
$this->assertDef('0');
$this->assertDef('0px');
$this->assertDef('4.5px');
@@ -18,23 +18,23 @@ class HTMLPurifier_AttrDef_CSS_LengthTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('3mm');
$this->assertDef('3pt');
$this->assertDef('3pc');
$this->assertDef('3PX', '3px');
$this->assertDef('3', false);
$this->assertDef('3miles', false);
}
function testNonNegative() {
$this->def = new HTMLPurifier_AttrDef_CSS_Length('0');
$this->assertDef('3cm');
$this->assertDef('-3mm', false);
}
function testBounding() {
$this->def = new HTMLPurifier_AttrDef_CSS_Length('-1in', '1in');
$this->assertDef('1cm');
@@ -42,6 +42,6 @@ class HTMLPurifier_AttrDef_CSS_LengthTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('0');
$this->assertDef('1em', false);
}
}

View File

@@ -2,12 +2,12 @@
class HTMLPurifier_AttrDef_CSS_ListStyleTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$config = HTMLPurifier_Config::createDefault();
$this->def = new HTMLPurifier_AttrDef_CSS_ListStyle($config);
$this->assertDef('lower-alpha');
$this->assertDef('upper-roman inside');
$this->assertDef('circle outside');
@@ -15,10 +15,10 @@ class HTMLPurifier_AttrDef_CSS_ListStyleTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('none');
$this->assertDef('url(foo.gif)');
$this->assertDef('circle url(foo.gif) inside');
// invalid values
$this->assertDef('outside inside', 'outside');
// ordering
$this->assertDef('url(foo.gif) none', 'none url(foo.gif)');
$this->assertDef('circle lower-alpha', 'circle');
@@ -26,9 +26,9 @@ class HTMLPurifier_AttrDef_CSS_ListStyleTest extends HTMLPurifier_AttrDefHarness
// cases, so we're going off the W3C CSS validator
$this->assertDef('disc none', 'disc');
$this->assertDef('none disc', 'none');
}
}

View File

@@ -3,25 +3,25 @@
// borrowed for the sakes of this test
class HTMLPurifier_AttrDef_CSS_MultipleTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_CSS_Multiple(
new HTMLPurifier_AttrDef_Integer()
);
$this->assertDef('1 2 3 4');
$this->assertDef('6');
$this->assertDef('4 5');
$this->assertDef(' 2 54 2 3', '2 54 2 3');
$this->assertDef("6\r3", '6 3');
$this->assertDef('asdf', false);
$this->assertDef('a s d f', false);
$this->assertDef('1 2 3 4 5', '1 2 3 4');
$this->assertDef('1 2 invalid 3', '1 2 3');
}
}

View File

@@ -2,11 +2,11 @@
class HTMLPurifier_AttrDef_CSS_NumberTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_CSS_Number();
$this->assertDef('0');
$this->assertDef('0.0', '0');
$this->assertDef('1.0', '1');
@@ -15,36 +15,36 @@ class HTMLPurifier_AttrDef_CSS_NumberTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('.5');
$this->assertDef('0.5', '.5');
$this->assertDef('-56.9');
$this->assertDef('0.', '0');
$this->assertDef('.0', '0');
$this->assertDef('0.0', '0');
$this->assertDef('1.', '1');
$this->assertDef('.1', '.1');
$this->assertDef('1.0', '1');
$this->assertDef('0.1', '.1');
$this->assertDef('000', '0');
$this->assertDef(' 9', '9');
$this->assertDef('+5.0000', '5');
$this->assertDef('02.20', '2.2');
$this->assertDef('2.', '2');
$this->assertDef('.', false);
$this->assertDef('asdf', false);
$this->assertDef('0.5.6', false);
}
function testNonNegative() {
$this->def = new HTMLPurifier_AttrDef_CSS_Number(true);
$this->assertDef('23');
$this->assertDef('-12', false);
}
}

View File

@@ -2,22 +2,22 @@
class HTMLPurifier_AttrDef_CSS_PercentageTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_CSS_Percentage();
$this->assertDef('10%');
$this->assertDef('1.607%');
$this->assertDef('-567%');
$this->assertDef(' 100% ', '100%');
$this->assertDef('5', false);
$this->assertDef('asdf', false);
$this->assertDef('%', false);
}
}

View File

@@ -2,25 +2,25 @@
class HTMLPurifier_AttrDef_CSS_TextDecorationTest extends HTMLPurifier_AttrDefHarness
{
function testCaseInsensitive() {
$this->def = new HTMLPurifier_AttrDef_CSS_TextDecoration();
$this->assertDef('none');
$this->assertDef('none underline', 'underline');
$this->assertDef('underline');
$this->assertDef('overline');
$this->assertDef('line-through overline underline');
$this->assertDef('overline line-through');
$this->assertDef('UNDERLINE', 'underline');
$this->assertDef(' underline line-through ', 'underline line-through');
$this->assertDef('foobar underline', 'underline');
$this->assertDef('blink', false);
}
}

View File

@@ -2,16 +2,16 @@
class HTMLPurifier_AttrDef_CSS_URITest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_CSS_URI();
$this->assertDef('', false);
// we could be nice but we won't be
$this->assertDef('http://www.example.com/', false);
// no quotes are used, since that's the most widely supported
// syntax
$this->assertDef('url(', false);
@@ -22,11 +22,11 @@ class HTMLPurifier_AttrDef_CSS_URITest extends HTMLPurifier_AttrDefHarness
$this->assertDef("url('http://www.example.com/')", $result);
$this->assertDef(
' url( "http://www.example.com/" ) ', $result);
// escaping
$this->assertDef("url(http://www.example.com/foo,bar\))",
$this->assertDef("url(http://www.example.com/foo,bar\))",
"url(http://www.example.com/foo\,bar\))");
}
}

View File

@@ -2,14 +2,14 @@
class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
{
function setup() {
parent::setup();
$this->def = new HTMLPurifier_AttrDef_CSS();
}
function test() {
// regular cases, singular
$this->assertDef('text-align:right;');
$this->assertDef('border-left-style:solid;');
@@ -82,67 +82,67 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('background-position:left 90%;');
$this->assertDef('border-spacing:1em;');
$this->assertDef('border-spacing:1em 2em;');
// duplicates
$this->assertDef('text-align:right;text-align:left;',
'text-align:left;');
// a few composites
$this->assertDef('font-variant:small-caps;font-weight:900;');
$this->assertDef('float:right;text-align:right;');
// selective removal
$this->assertDef('text-transform:capitalize;destroy:it;',
'text-transform:capitalize;');
// inherit works for everything
$this->assertDef('text-align:inherit;');
// bad props
$this->assertDef('nodice:foobar;', false);
$this->assertDef('position:absolute;', false);
$this->assertDef('background-image:url(javascript:alert\(\));', false);
// airy input
$this->assertDef(' font-weight : bold; color : #ff0000',
'font-weight:bold;color:#ff0000;');
// case-insensitivity
$this->assertDef('FLOAT:LEFT;', 'float:left;');
// !important stripping
$this->assertDef('float:left !important;', 'float:left;');
}
function testProprietary() {
$this->config->set('CSS', 'Proprietary', true);
$this->assertDef('scrollbar-arrow-color:#ff0;');
$this->assertDef('scrollbar-base-color:#ff6347;');
$this->assertDef('scrollbar-darkshadow-color:#ffa500;');
$this->assertDef('scrollbar-face-color:#008080;');
$this->assertDef('scrollbar-highlight-color:#ff69b4;');
$this->assertDef('scrollbar-shadow-color:#f0f;');
$this->assertDef('opacity:.2;');
$this->assertDef('-moz-opacity:.2;');
$this->assertDef('-khtml-opacity:.2;');
$this->assertDef('filter:alpha(opacity=20);');
}
function testImportant() {
$this->config->set('CSS', 'AllowImportant', true);
$this->assertDef('float:left !important;');
}
function testTricky() {
$this->config->set('CSS', 'AllowTricky', true);
$this->assertDef('display:none;');
$this->assertDef('visibility:visible;');
$this->assertDef('overflow:scroll;');
}
}

View File

@@ -2,35 +2,35 @@
class HTMLPurifier_AttrDef_EnumTest extends HTMLPurifier_AttrDefHarness
{
function testCaseInsensitive() {
$this->def = new HTMLPurifier_AttrDef_Enum(array('one', 'two'));
$this->assertDef('one');
$this->assertDef('ONE', 'one');
}
function testCaseSensitive() {
$this->def = new HTMLPurifier_AttrDef_Enum(array('one', 'two'), true);
$this->assertDef('one');
$this->assertDef('ONE', false);
}
function testFixing() {
$this->def = new HTMLPurifier_AttrDef_Enum(array('one'));
$this->assertDef(' one ', 'one');
}
function test_make() {
$factory = new HTMLPurifier_AttrDef_Enum();
$def = $factory->make('foo,bar');
$def2 = new HTMLPurifier_AttrDef_Enum(array('foo', 'bar'));
$this->assertIdentical($def, $def2);
$def = $factory->make('s:foo,BAR');
$def2 = new HTMLPurifier_AttrDef_Enum(array('foo', 'BAR'), true);
$this->assertIdentical($def, $def2);
}
}

View File

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

View File

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

View File

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

View File

@@ -2,68 +2,68 @@
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'); // !
}
function testLocalPrefixWithoutMainPrefix() {
// no effect when IDPrefix isn't set
$this->config->set('Attr', 'IDPrefix', '');
@@ -71,37 +71,37 @@ class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
$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
}
function testRegexp() {
$this->config->set('Attr', 'IDBlacklistRegexp', '/^g_/');
$this->assertDef('good_id');
$this->assertDef('g_bad_id', false);
}
}

View File

@@ -2,30 +2,30 @@
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%');
}
}

View File

@@ -2,19 +2,19 @@
class HTMLPurifier_AttrDef_HTML_LinkTypesTest extends HTMLPurifier_AttrDefHarness
{
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);
}
}

View File

@@ -2,26 +2,26 @@
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
}
}

View File

@@ -2,30 +2,30 @@
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');
}
}

View File

@@ -2,43 +2,43 @@
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');
}
function test_make() {
$factory = new HTMLPurifier_AttrDef_HTML_Pixels();
$this->def = $factory->make('30');
$this->assertDef('25');
$this->assertDef('35', '30');
}
}

View File

@@ -2,11 +2,11 @@
class HTMLPurifier_AttrDef_IntegerTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_Integer();
$this->assertDef('0');
$this->assertDef('1');
$this->assertDef('-1');
@@ -15,14 +15,14 @@ class HTMLPurifier_AttrDef_IntegerTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('+24', '24');
$this->assertDef(' 14 ', '14');
$this->assertDef('-0', '0');
$this->assertDef('-1.4', false);
$this->assertDef('3.4', false);
$this->assertDef('asdf', false); // must not return zero
$this->assertDef('2in', false); // must not return zero
}
function assertRange($negative, $zero, $positive) {
$this->assertDef('-100', $negative);
$this->assertDef('-1', $negative);
@@ -30,31 +30,31 @@ class HTMLPurifier_AttrDef_IntegerTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('1', $positive);
$this->assertDef('42', $positive);
}
function testRange() {
$this->def = new HTMLPurifier_AttrDef_Integer(false);
$this->assertRange(false, true, true); // non-negative
$this->def = new HTMLPurifier_AttrDef_Integer(false, false);
$this->assertRange(false, false, true); // positive
// fringe cases
$this->def = new HTMLPurifier_AttrDef_Integer(false, false, false);
$this->assertRange(false, false, false); // allow none
$this->def = new HTMLPurifier_AttrDef_Integer(true, false, false);
$this->assertRange(true, false, false); // negative
$this->def = new HTMLPurifier_AttrDef_Integer(false, true, false);
$this->assertRange(false, true, false); // zero
$this->def = new HTMLPurifier_AttrDef_Integer(true, true, false);
$this->assertRange(true, true, false); // non-positive
}
}

View File

@@ -2,27 +2,27 @@
class HTMLPurifier_AttrDef_LangTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_Lang();
// basic good uses
$this->assertDef('en');
$this->assertDef('en-us');
$this->assertDef(' en ', 'en'); // trim
$this->assertDef('EN', 'en'); // case insensitivity
// (thanks Eugen Pankratz for noticing the typos!)
$this->assertDef('En-Us-Edison', 'en-us-edison'); // complex ci
$this->assertDef('fr en', false); // multiple languages
$this->assertDef('%', false); // bad character
// test overlong language according to syntax
$this->assertDef('thisistoolongsoitgetscut', false);
// primary subtag rules
// I'm somewhat hesitant to allow x and i as primary language codes,
// because they usually are never used in real life. However,
@@ -44,7 +44,7 @@ class HTMLPurifier_AttrDef_LangTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('four', false);
// for similar reasons, disallow any other one character language
$this->assertDef('f', false);
// second subtag rules
// one letter subtags prohibited until revision. This is, however,
// less volatile than the restrictions on the primary subtags.
@@ -57,28 +57,28 @@ class HTMLPurifier_AttrDef_LangTest extends HTMLPurifier_AttrDefHarness
// be checked without maintaining country code lookup tables (for
// two characters) or special registration tables (for all above).
$this->assertDef('en-uk', true);
// further subtag rules: only syntactic constraints
$this->assertDef('en-us-edison');
$this->assertDef('en-us-toolonghaha', 'en-us');
$this->assertDef('en-us-a-silly-long-one');
// rfc 3066 stipulates that if a three letter and a two letter code
// are available, the two letter one MUST be used. Without a language
// code lookup table, we cannot implement this functionality.
// although the HTML protocol, technically speaking, allows you to
// omit language tags, this implicitly means that the parent element's
// language is the one applicable, which, in some cases, is incorrect.
// Thus, we allow und, only slightly defying the RFC's SHOULD NOT
// designation.
$this->assertDef('und');
// because attributes only allow one language, mul is allowed, complying
// with the RFC's SHOULD NOT designation.
$this->assertDef('mul');
}
}

View File

@@ -2,9 +2,9 @@
class HTMLPurifier_AttrDef_SwitchTest extends HTMLPurifier_AttrDefHarness
{
protected $with, $without;
function setUp() {
parent::setUp();
generate_mock_once('HTMLPurifier_AttrDef');
@@ -12,7 +12,7 @@ class HTMLPurifier_AttrDef_SwitchTest extends HTMLPurifier_AttrDefHarness
$this->without = new HTMLPurifier_AttrDefMock();
$this->def = new HTMLPurifier_AttrDef_Switch('tag', $this->with, $this->without);
}
function testWith() {
$token = new HTMLPurifier_Token_Start('tag');
$this->context->register('CurrentToken', $token);
@@ -20,7 +20,7 @@ class HTMLPurifier_AttrDef_SwitchTest extends HTMLPurifier_AttrDefHarness
$this->with->setReturnValue('validate', 'foo');
$this->assertDef('bar', 'foo');
}
function testWithout() {
$token = new HTMLPurifier_Token_Start('other-tag');
$this->context->register('CurrentToken', $token);
@@ -28,5 +28,5 @@ class HTMLPurifier_AttrDef_SwitchTest extends HTMLPurifier_AttrDefHarness
$this->without->setReturnValue('validate', 'foo');
$this->assertDef('bar', 'foo');
}
}

View File

@@ -2,15 +2,15 @@
class HTMLPurifier_AttrDef_TextTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_Text();
$this->assertDef('This is spiffy text!');
$this->assertDef(" Casual\tCDATA parse\ncheck. ", 'Casual CDATA parse check.');
}
}

View File

@@ -3,10 +3,10 @@
class HTMLPurifier_AttrDef_URI_Email_SimpleCheckTest
extends HTMLPurifier_AttrDef_URI_EmailHarness
{
function setUp() {
$this->def = new HTMLPurifier_AttrDef_URI_Email_SimpleCheck();
}
}

View File

@@ -2,7 +2,7 @@
class HTMLPurifier_AttrDef_URI_EmailHarness extends HTMLPurifier_AttrDefHarness
{
/**
* Tests common email strings that are obviously pass/fail
*/
@@ -12,19 +12,19 @@ class HTMLPurifier_AttrDef_URI_EmailHarness extends HTMLPurifier_AttrDefHarness
$this->assertDef('bob.thebuilder@example.net');
$this->assertDef('Bob_the_Builder-the-2nd@example.org');
$this->assertDef('Bob%20the%20Builder@white-space.test');
// extended format, with real name
//$this->assertDef('Bob%20Builder%20%3Cbobby.bob.bob@it.is.example.com%3E');
//$this->assertDef('Bob Builder <bobby.bob.bob@it.is.example.com>');
// time to fail
$this->assertDef('bob', false);
$this->assertDef('bob@home@work', false);
$this->assertDef('@example.com', false);
$this->assertDef('bob@', false);
$this->assertDef('', false);
}
}

View File

@@ -5,15 +5,15 @@
class HTMLPurifier_AttrDef_URI_HostTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_URI_Host();
$this->assertDef('[2001:DB8:0:0:8:800:200C:417A]'); // IPv6
$this->assertDef('124.15.6.89'); // IPv4
$this->assertDef('www.google.com'); // reg-name
// more domain name tests
$this->assertDef('test.');
$this->assertDef('sub.test.');
@@ -34,8 +34,8 @@ class HTMLPurifier_AttrDef_URI_HostTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('ff.top');
$this->assertDef('f1.top');
$this->assertDef('f-.top', false);
}
}

View File

@@ -5,19 +5,19 @@
class HTMLPurifier_AttrDef_URI_IPv4Test extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_URI_IPv4();
$this->assertDef('127.0.0.1'); // standard IPv4, loopback, non-routable
$this->assertDef('0.0.0.0'); // standard IPv4, unspecified, non-routable
$this->assertDef('255.255.255.255'); // standard IPv4
$this->assertDef('300.0.0.0', false); // standard IPv4, out of range
$this->assertDef('124.15.6.89/60', false); // standard IPv4, prefix not allowed
$this->assertDef('', false); // nothing
$this->assertDef('', false); // nothing
}
}

View File

@@ -5,18 +5,18 @@
class HTMLPurifier_AttrDef_URI_IPv6Test extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_URI_IPv6();
$this->assertDef('2001:DB8:0:0:8:800:200C:417A'); // unicast, full
$this->assertDef('FF01:0:0:0:0:0:0:101'); // multicast, full
$this->assertDef('0:0:0:0:0:0:0:1'); // loopback, full
$this->assertDef('0:0:0:0:0:0:0:0'); // unspecified, full
$this->assertDef('2001:DB8::8:800:200C:417A'); // unicast, compressed
$this->assertDef('FF01::101'); // multicast, compressed
$this->assertDef('::1'); // loopback, compressed, non-routable
$this->assertDef('::'); // unspecified, compressed, non-routable
$this->assertDef('0:0:0:0:0:0:13.1.68.3'); // IPv4-compatible IPv6 address, full, deprecated
@@ -31,12 +31,12 @@ class HTMLPurifier_AttrDef_URI_IPv6Test extends HTMLPurifier_AttrDefHarness
$this->assertDef('FF00::/8'); // compressed, multicast address type
$this->assertDef('FE80::/10'); // compressed, link-local unicast, non-routable
$this->assertDef('FEC0::/10'); // compressed, site-local unicast, deprecated
$this->assertDef('2001:DB8:0:0:8:800:200C:417A:221', false); // unicast, full
$this->assertDef('FF01::101::2', false); //multicast, compressed
$this->assertDef('', false); // nothing
$this->assertDef('', false); // nothing
}
}

View File

@@ -5,12 +5,12 @@
*/
class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
{
function setUp() {
$this->def = new HTMLPurifier_AttrDef_URI();
parent::setUp();
}
function testIntegration() {
$this->assertDef('http://www.google.com/');
$this->assertDef('http:', '');
@@ -21,33 +21,33 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
$this->assertDef('nntp://news.example.com/324234');
$this->assertDef('mailto:bob@example.com');
}
function testIntegrationWithPercentEncoder() {
$this->assertDef(
'http://www.example.com/%56%fc%GJ%5%FC',
'http://www.example.com/V%FC%25GJ%255%FC'
);
}
function testPercentEncoding() {
$this->assertDef(
'http:colon:mercenary',
'colon%3Amercenary'
);
}
function testPercentEncodingPreserve() {
$this->assertDef(
'http://www.example.com/abcABC123-_.!~*()\''
);
}
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() {
$this->config->set('URI', 'Munge', 'http://www.google.com/url?q=%s');
$this->assertDef(
@@ -57,28 +57,28 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
$this->assertDef('index.html');
$this->assertDef('javascript:foobar();', false);
}
function testDefaultSchemeRemovedInBlank() {
$this->assertDef('http:', '');
}
function testDefaultSchemeRemovedInRelativeURI() {
$this->assertDef('http:/foo/bar', '/foo/bar');
}
function testDefaultSchemeNotRemovedInAbsoluteURI() {
$this->assertDef('http://example.com/foo/bar');
}
function testAltSchemeNotRemoved() {
$this->assertDef('mailto:this-looks-like-a-path@example.com');
}
function testURIDefinitionValidation() {
$parser = new HTMLPurifier_URIParser();
$uri = $parser->parse('http://example.com');
$this->config->set('URI', 'DefinitionID', 'HTMLPurifier_AttrDef_URITest->testURIDefinitionValidation');
generate_mock_once('HTMLPurifier_URIDefinition');
$uri_def = new HTMLPurifier_URIDefinitionMock();
$uri_def->expectOnce('filter', array($uri, '*', '*'));
@@ -86,7 +86,7 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
$uri_def->expectOnce('postFilter', array($uri, '*', '*'));
$uri_def->setReturnValue('postFilter', true, array($uri, '*', '*'));
$uri_def->setup = true;
// Since definitions are no longer passed by reference, we need
// to muck around with the cache to insert our mock. This is
// technically a little bad, since the cache shouldn't change
@@ -95,43 +95,43 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
generate_mock_once('HTMLPurifier_DefinitionCache');
$cache_mock = new HTMLPurifier_DefinitionCacheMock();
$cache_mock->setReturnValue('get', $uri_def);
generate_mock_once('HTMLPurifier_DefinitionCacheFactory');
$factory_mock = new HTMLPurifier_DefinitionCacheFactoryMock();
$old = HTMLPurifier_DefinitionCacheFactory::instance();
HTMLPurifier_DefinitionCacheFactory::instance($factory_mock);
$factory_mock->setReturnValue('create', $cache_mock);
$this->assertDef('http://example.com');
HTMLPurifier_DefinitionCacheFactory::instance($old);
}
function test_make() {
$factory = new HTMLPurifier_AttrDef_URI();
$def = $factory->make('');
$def2 = new HTMLPurifier_AttrDef_URI();
$this->assertIdentical($def, $def2);
$def = $factory->make('embedded');
$def2 = new HTMLPurifier_AttrDef_URI(true);
$this->assertIdentical($def, $def2);
}
/*
function test_validate_configWhitelist() {
$this->config->set('URI', 'HostPolicy', 'DenyAll');
$this->config->set('URI', 'HostWhitelist', array(null, 'google.com'));
$this->assertDef('http://example.com/fo/google.com', false);
$this->assertDef('server.txt');
$this->assertDef('ftp://www.google.com/?t=a');
$this->assertDef('http://google.com.tricky.spamsite.net', false);
}
*/
}