first commit

This commit is contained in:
aschwarz
2023-02-23 10:52:06 +01:00
commit 8bb9cee456
2426 changed files with 471082 additions and 0 deletions

View File

@ -0,0 +1,45 @@
<?php
class HTMLPurifier_AttrTransform_BackgroundTest extends HTMLPurifier_AttrTransformHarness
{
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_Background();
}
public function testEmptyInput()
{
$this->assertResult( array() );
}
public function testBasicTransform()
{
$this->assertResult(
array('background' => 'logo.png'),
array('style' => 'background-image:url(logo.png);')
);
}
public function testPrependNewCSS()
{
$this->assertResult(
array('background' => 'logo.png', 'style' => 'font-weight:bold'),
array('style' => 'background-image:url(logo.png);font-weight:bold')
);
}
public function testLenientTreatmentOfInvalidInput()
{
// notice that we rely on the CSS validator later to fix this invalid
// stuff
$this->assertResult(
array('background' => 'logo.png);foo:('),
array('style' => 'background-image:url(logo.png);foo:();')
);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,34 @@
<?php
class HTMLPurifier_AttrTransform_BdoDirTest extends HTMLPurifier_AttrTransformHarness
{
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_BdoDir();
}
public function testAddDefaultDir()
{
$this->assertResult( array(), array('dir' => 'ltr') );
}
public function testPreserveExistingDir()
{
$this->assertResult( array('dir' => 'rtl') );
}
public function testAlternateDefault()
{
$this->config->set('Attr.DefaultTextDir', 'rtl');
$this->assertResult(
array(),
array('dir' => 'rtl')
);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,49 @@
<?php
// we currently rely on the CSS validator to fix any problems.
// This means that this transform, strictly speaking, supports
// a superset of the functionality.
class HTMLPurifier_AttrTransform_BgColorTest extends HTMLPurifier_AttrTransformHarness
{
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_BgColor();
}
public function testEmptyInput()
{
$this->assertResult( array() );
}
public function testBasicTransform()
{
$this->assertResult(
array('bgcolor' => '#000000'),
array('style' => 'background-color:#000000;')
);
}
public function testPrependNewCSS()
{
$this->assertResult(
array('bgcolor' => '#000000', 'style' => 'font-weight:bold'),
array('style' => 'background-color:#000000;font-weight:bold')
);
}
public function testLenientTreatmentOfInvalidInput()
{
// this may change when we natively support the datatype and
// validate its contents before forwarding it on
$this->assertResult(
array('bgcolor' => '#F00'),
array('style' => 'background-color:#F00;')
);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,43 @@
<?php
class HTMLPurifier_AttrTransform_BoolToCSSTest extends HTMLPurifier_AttrTransformHarness
{
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_BoolToCSS('foo', 'bar:3in;');
}
public function testEmptyInput()
{
$this->assertResult( array() );
}
public function testBasicTransform()
{
$this->assertResult(
array('foo' => 'foo'),
array('style' => 'bar:3in;')
);
}
public function testIgnoreValueOfBooleanAttribute()
{
$this->assertResult(
array('foo' => 'no'),
array('style' => 'bar:3in;')
);
}
public function testPrependCSS()
{
$this->assertResult(
array('foo' => 'foo', 'style' => 'background-color:#F00;'),
array('style' => 'bar:3in;background-color:#F00;')
);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,43 @@
<?php
class HTMLPurifier_AttrTransform_BorderTest extends HTMLPurifier_AttrTransformHarness
{
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_Border();
}
public function testEmptyInput()
{
$this->assertResult( array() );
}
public function testBasicTransform()
{
$this->assertResult(
array('border' => '1'),
array('style' => 'border:1px solid;')
);
}
public function testLenientTreatmentOfInvalidInput()
{
$this->assertResult(
array('border' => '10%'),
array('style' => 'border:10%px solid;')
);
}
public function testPrependNewCSS()
{
$this->assertResult(
array('border' => '23', 'style' => 'font-weight:bold;'),
array('style' => 'border:23px solid;font-weight:bold;')
);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,82 @@
<?php
class HTMLPurifier_AttrTransform_EnumToCSSTest extends HTMLPurifier_AttrTransformHarness
{
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
'left' => 'text-align:left;',
'right' => 'text-align:right;'
));
}
public function testEmptyInput()
{
$this->assertResult( array() );
}
public function testPreserveArraysWithoutInterestingAttributes()
{
$this->assertResult( array('style' => 'font-weight:bold;') );
}
public function testConvertAlignLeft()
{
$this->assertResult(
array('align' => 'left'),
array('style' => 'text-align:left;')
);
}
public function testConvertAlignRight()
{
$this->assertResult(
array('align' => 'right'),
array('style' => 'text-align:right;')
);
}
public function testRemoveInvalidAlign()
{
$this->assertResult(
array('align' => 'invalid'),
array()
);
}
public function testPrependNewCSS()
{
$this->assertResult(
array('align' => 'left', 'style' => 'font-weight:bold;'),
array('style' => 'text-align:left;font-weight:bold;')
);
}
public function testCaseInsensitive()
{
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
'right' => 'text-align:right;'
));
$this->assertResult(
array('align' => 'RIGHT'),
array('style' => 'text-align:right;')
);
}
public function testCaseSensitive()
{
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
'right' => 'text-align:right;'
), true);
$this->assertResult(
array('align' => 'RIGHT'),
array()
);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,61 @@
<?php
class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransformHarness
{
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_ImgRequired();
}
public function testAddMissingAttr()
{
$this->config->set('Core.RemoveInvalidImg', false);
$this->assertResult(
array(),
array('src' => '', 'alt' => 'Invalid image')
);
}
public function testAlternateDefaults()
{
$this->config->set('Attr.DefaultInvalidImage', 'blank.png');
$this->config->set('Attr.DefaultInvalidImageAlt', 'Pawned!');
$this->config->set('Attr.DefaultImageAlt', 'not pawned');
$this->config->set('Core.RemoveInvalidImg', false);
$this->assertResult(
array(),
array('src' => 'blank.png', 'alt' => 'Pawned!')
);
}
public function testGenerateAlt()
{
$this->assertResult(
array('src' => '/path/to/foobar.png'),
array('src' => '/path/to/foobar.png', 'alt' => 'foobar.png')
);
}
public function testAddDefaultSrc()
{
$this->config->set('Core.RemoveInvalidImg', false);
$this->assertResult(
array('alt' => 'intrigue'),
array('alt' => 'intrigue', 'src' => '')
);
}
public function testAddDefaultAlt()
{
$this->config->set('Attr.DefaultImageAlt', 'default');
$this->assertResult(
array('src' => ''),
array('src' => '', 'alt' => 'default')
);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,62 @@
<?php
class HTMLPurifier_AttrTransform_ImgSpaceTest extends HTMLPurifier_AttrTransformHarness
{
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_ImgSpace('vspace');
}
public function testEmptyInput()
{
$this->assertResult( array() );
}
public function testVerticalBasicUsage()
{
$this->assertResult(
array('vspace' => '1'),
array('style' => 'margin-top:1px;margin-bottom:1px;')
);
}
public function testLenientHandlingOfInvalidInput()
{
$this->assertResult(
array('vspace' => '10%'),
array('style' => 'margin-top:10%px;margin-bottom:10%px;')
);
}
public function testPrependNewCSS()
{
$this->assertResult(
array('vspace' => '23', 'style' => 'font-weight:bold;'),
array('style' => 'margin-top:23px;margin-bottom:23px;font-weight:bold;')
);
}
public function testHorizontalBasicUsage()
{
$this->obj = new HTMLPurifier_AttrTransform_ImgSpace('hspace');
$this->assertResult(
array('hspace' => '1'),
array('style' => 'margin-left:1px;margin-right:1px;')
);
}
public function testInvalidConstructionParameter()
{
$this->expectError('ispace is not valid space attribute');
$this->obj = new HTMLPurifier_AttrTransform_ImgSpace('ispace');
$this->assertResult(
array('ispace' => '1'),
array()
);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,105 @@
<?php
class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHarness
{
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_Input();
}
public function testEmptyInput()
{
$this->assertResult(array());
}
public function testInvalidCheckedWithEmpty()
{
$this->assertResult(array('checked' => 'checked'), array());
}
public function testInvalidCheckedWithPassword()
{
$this->assertResult(array(
'checked' => 'checked',
'type' => 'password'
), array(
'type' => 'password'
));
}
public function testValidCheckedWithUcCheckbox()
{
$this->assertResult(array(
'checked' => 'checked',
'type' => 'CHECKBOX',
'value' => 'bar',
));
}
public function testInvalidMaxlength()
{
$this->assertResult(array(
'maxlength' => '10',
'type' => 'checkbox',
'value' => 'foo',
), array(
'type' => 'checkbox',
'value' => 'foo',
));
}
public function testValidMaxLength()
{
$this->assertResult(array(
'maxlength' => '10',
));
}
// these two are really bad test-cases
public function testSizeWithCheckbox()
{
$this->assertResult(array(
'type' => 'checkbox',
'value' => 'foo',
'size' => '100px',
), array(
'type' => 'checkbox',
'value' => 'foo',
'size' => '100',
));
}
public function testSizeWithText()
{
$this->assertResult(array(
'type' => 'password',
'size' => '100px', // spurious value, to indicate no validation takes place
), array(
'type' => 'password',
'size' => '100px',
));
}
public function testInvalidSrc()
{
$this->assertResult(array(
'src' => 'img.png',
), array());
}
public function testMissingValue()
{
$this->assertResult(array(
'type' => 'checkbox',
), array(
'type' => 'checkbox',
'value' => '',
));
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,52 @@
<?php
class HTMLPurifier_AttrTransform_LangTest
extends HTMLPurifier_AttrTransformHarness
{
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_Lang();
}
public function testEmptyInput()
{
$this->assertResult(array());
}
public function testCopyLangToXMLLang()
{
$this->assertResult(
array('lang' => 'en'),
array('lang' => 'en', 'xml:lang' => 'en')
);
}
public function testPreserveAttributes()
{
$this->assertResult(
array('src' => 'vert.png', 'lang' => 'fr'),
array('src' => 'vert.png', 'lang' => 'fr', 'xml:lang' => 'fr')
);
}
public function testCopyXMLLangToLang()
{
$this->assertResult(
array('xml:lang' => 'en'),
array('xml:lang' => 'en', 'lang' => 'en')
);
}
public function testXMLLangOverridesLang()
{
$this->assertResult(
array('lang' => 'fr', 'xml:lang' => 'de'),
array('lang' => 'de', 'xml:lang' => 'de')
);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,51 @@
<?php
class HTMLPurifier_AttrTransform_LengthTest extends HTMLPurifier_AttrTransformHarness
{
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_Length('width');
}
public function testEmptyInput()
{
$this->assertResult( array() );
}
public function testTransformPixel()
{
$this->assertResult(
array('width' => '10'),
array('style' => 'width:10px;')
);
}
public function testTransformPercentage()
{
$this->assertResult(
array('width' => '10%'),
array('style' => 'width:10%;')
);
}
public function testPrependNewCSS()
{
$this->assertResult(
array('width' => '10%', 'style' => 'font-weight:bold'),
array('style' => 'width:10%;font-weight:bold')
);
}
public function testLenientTreatmentOfInvalidInput()
{
$this->assertResult(
array('width' => 'asdf'),
array('style' => 'width:asdf;')
);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,45 @@
<?php
class HTMLPurifier_AttrTransform_NameSyncTest extends HTMLPurifier_AttrTransformHarness
{
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_NameSync();
$this->accumulator = new HTMLPurifier_IDAccumulator();
$this->context->register('IDAccumulator', $this->accumulator);
$this->config->set('Attr.EnableID', true);
}
public function testEmpty()
{
$this->assertResult( array() );
}
public function testAllowSame()
{
$this->assertResult(
array('name' => 'free', 'id' => 'free')
);
}
public function testAllowDifferent()
{
$this->assertResult(
array('name' => 'tryit', 'id' => 'thisgood')
);
}
public function testCheckName()
{
$this->accumulator->add('notok');
$this->assertResult(
array('name' => 'notok', 'id' => 'ok'),
array('id' => 'ok')
);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,35 @@
<?php
class HTMLPurifier_AttrTransform_NameTest extends HTMLPurifier_AttrTransformHarness
{
public function setUp()
{
parent::setUp();
$this->obj = new HTMLPurifier_AttrTransform_Name();
}
public function testEmpty()
{
$this->assertResult( array() );
}
public function testTransformNameToID()
{
$this->assertResult(
array('name' => 'free'),
array('id' => 'free')
);
}
public function testExistingIDOverridesName()
{
$this->assertResult(
array('name' => 'tryit', 'id' => 'tobad'),
array('id' => 'tobad')
);
}
}
// vim: et sw=4 sts=4