mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-05 13:47:24 +02:00
Remove trailing whitespace.
Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
@@ -8,17 +8,17 @@ Mock::generatePartial(
|
||||
|
||||
class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
function testConstruction() {
|
||||
|
||||
|
||||
generate_mock_once('HTMLPurifier_AttrTypes');
|
||||
|
||||
|
||||
$collections = new HTMLPurifier_AttrCollections_TestForConstruct();
|
||||
|
||||
|
||||
$types = new HTMLPurifier_AttrTypesMock();
|
||||
|
||||
|
||||
$modules = array();
|
||||
|
||||
|
||||
$modules['Module1'] = new HTMLPurifier_HTMLModule();
|
||||
$modules['Module1']->attr_collections = array(
|
||||
'Core' => array(
|
||||
@@ -30,7 +30,7 @@ class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
|
||||
'attribute-3' => 'Type3-old' // overwritten
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$modules['Module2'] = new HTMLPurifier_HTMLModule();
|
||||
$modules['Module2']->attr_collections = array(
|
||||
'Core' => array(
|
||||
@@ -41,7 +41,7 @@ class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
|
||||
),
|
||||
'Brocolli' => array()
|
||||
);
|
||||
|
||||
|
||||
$collections->__construct($types, $modules);
|
||||
// this is without identifier expansion or inclusions
|
||||
$this->assertIdentical(
|
||||
@@ -58,13 +58,13 @@ class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
|
||||
'Brocolli' => array()
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_performInclusions() {
|
||||
|
||||
|
||||
generate_mock_once('HTMLPurifier_AttrTypes');
|
||||
|
||||
|
||||
$types = new HTMLPurifier_AttrTypesMock();
|
||||
$collections = new HTMLPurifier_AttrCollections($types, array());
|
||||
$collections->info = array(
|
||||
@@ -72,17 +72,17 @@ class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
|
||||
'Inclusion' => array(0 => array('SubInclusion'), 'attr' => 'Type'),
|
||||
'SubInclusion' => array('attr2' => 'Type')
|
||||
);
|
||||
|
||||
|
||||
$collections->performInclusions($collections->info['Core']);
|
||||
$this->assertIdentical(
|
||||
$collections->info['Core'],
|
||||
array(
|
||||
'attr-original' => 'Type',
|
||||
'attr-original' => 'Type',
|
||||
'attr' => 'Type',
|
||||
'attr2' => 'Type'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
// test recursive
|
||||
$collections->info = array(
|
||||
'One' => array(0 => array('Two'), 'one' => 'Type'),
|
||||
@@ -96,28 +96,28 @@ class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
|
||||
'two' => 'Type'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_expandIdentifiers() {
|
||||
|
||||
|
||||
generate_mock_once('HTMLPurifier_AttrTypes');
|
||||
|
||||
|
||||
$types = new HTMLPurifier_AttrTypesMock();
|
||||
$collections = new HTMLPurifier_AttrCollections($types, array());
|
||||
|
||||
|
||||
$attr = array(
|
||||
'attr1' => 'Color',
|
||||
'attr2*' => 'URI'
|
||||
);
|
||||
$c_object = new HTMLPurifier_AttrDef_HTML_Color();
|
||||
$u_object = new HTMLPurifier_AttrDef_URI();
|
||||
|
||||
|
||||
$types->setReturnValue('get', $c_object, array('Color'));
|
||||
$types->setReturnValue('get', $u_object, array('URI'));
|
||||
|
||||
|
||||
$collections->expandIdentifiers($attr, $types);
|
||||
|
||||
|
||||
$u_object->required = true;
|
||||
$this->assertIdentical(
|
||||
$attr,
|
||||
@@ -126,8 +126,8 @@ class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
|
||||
'attr2' => $u_object
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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%');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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'
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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)');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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');
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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');
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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\))");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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;');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_ColorTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
|
||||
function test() {
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_Color();
|
||||
$this->assertDef('', false);
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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%');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -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.');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
||||
}
|
||||
}
|
@@ -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
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -2,15 +2,15 @@
|
||||
|
||||
class HTMLPurifier_AttrDefHarness extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
protected $def;
|
||||
protected $context, $config;
|
||||
|
||||
|
||||
public function setUp() {
|
||||
$this->config = HTMLPurifier_Config::createDefault();
|
||||
$this->context = new HTMLPurifier_Context();
|
||||
}
|
||||
|
||||
|
||||
// cannot be used for accumulator
|
||||
function assertDef($string, $expect = true) {
|
||||
// $expect can be a string or bool
|
||||
@@ -21,6 +21,6 @@ class HTMLPurifier_AttrDefHarness extends HTMLPurifier_Harness
|
||||
$this->assertIdentical($expect, $result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -7,25 +7,25 @@ Mock::generatePartial(
|
||||
|
||||
class HTMLPurifier_AttrDefTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
function test_parseCDATA() {
|
||||
|
||||
|
||||
$def = new HTMLPurifier_AttrDefTestable();
|
||||
|
||||
|
||||
$this->assertIdentical('', $def->parseCDATA(''));
|
||||
$this->assertIdentical('', $def->parseCDATA("\t\n\r \t\t"));
|
||||
$this->assertIdentical('foo', $def->parseCDATA("\t\n\r foo\t\t"));
|
||||
$this->assertIdentical('translate to space', $def->parseCDATA("translate\nto\tspace"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_make() {
|
||||
|
||||
|
||||
$def = new HTMLPurifier_AttrDefTestable();
|
||||
$def2 = $def->make('');
|
||||
$this->assertIdentical($def, $def2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,30 +2,30 @@
|
||||
|
||||
class HTMLPurifier_AttrTransform_BackgroundTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_Background();
|
||||
}
|
||||
|
||||
|
||||
function testEmptyInput() {
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
|
||||
function testBasicTransform() {
|
||||
$this->assertResult(
|
||||
array('background' => 'logo.png'),
|
||||
array('style' => 'background-image:url(logo.png);')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testPrependNewCSS() {
|
||||
$this->assertResult(
|
||||
array('background' => 'logo.png', 'style' => 'font-weight:bold'),
|
||||
array('style' => 'background-image:url(logo.png);font-weight:bold')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testLenientTreatmentOfInvalidInput() {
|
||||
// notice that we rely on the CSS validator later to fix this invalid
|
||||
// stuff
|
||||
@@ -34,6 +34,6 @@ class HTMLPurifier_AttrTransform_BackgroundTest extends HTMLPurifier_AttrTransfo
|
||||
array('style' => 'background-image:url(logo.png);foo:();')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,28 +2,28 @@
|
||||
|
||||
class HTMLPurifier_AttrTransform_BdoDirTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_BdoDir();
|
||||
}
|
||||
|
||||
|
||||
function testAddDefaultDir() {
|
||||
$this->assertResult( array(), array('dir' => 'ltr') );
|
||||
}
|
||||
|
||||
|
||||
function testPreserveExistingDir() {
|
||||
$this->assertResult( array('dir' => 'rtl') );
|
||||
}
|
||||
|
||||
|
||||
function testAlternateDefault() {
|
||||
$this->config->set('Attr', 'DefaultTextDir', 'rtl');
|
||||
$this->assertResult(
|
||||
array(),
|
||||
array('dir' => 'rtl')
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -6,30 +6,30 @@
|
||||
|
||||
class HTMLPurifier_AttrTransform_BgColorTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_BgColor();
|
||||
}
|
||||
|
||||
|
||||
function testEmptyInput() {
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
|
||||
function testBasicTransform() {
|
||||
$this->assertResult(
|
||||
array('bgcolor' => '#000000'),
|
||||
array('style' => 'background-color:#000000;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testPrependNewCSS() {
|
||||
$this->assertResult(
|
||||
array('bgcolor' => '#000000', 'style' => 'font-weight:bold'),
|
||||
array('style' => 'background-color:#000000;font-weight:bold')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testLenientTreatmentOfInvalidInput() {
|
||||
// this may change when we natively support the datatype and
|
||||
// validate its contents before forwarding it on
|
||||
@@ -38,6 +38,6 @@ class HTMLPurifier_AttrTransform_BgColorTest extends HTMLPurifier_AttrTransformH
|
||||
array('style' => 'background-color:#F00;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,36 +2,36 @@
|
||||
|
||||
class HTMLPurifier_AttrTransform_BoolToCSSTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_BoolToCSS('foo', 'bar:3in;');
|
||||
}
|
||||
|
||||
|
||||
function testEmptyInput() {
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
|
||||
function testBasicTransform() {
|
||||
$this->assertResult(
|
||||
array('foo' => 'foo'),
|
||||
array('style' => 'bar:3in;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testIgnoreValueOfBooleanAttribute() {
|
||||
$this->assertResult(
|
||||
array('foo' => 'no'),
|
||||
array('style' => 'bar:3in;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testPrependCSS() {
|
||||
$this->assertResult(
|
||||
array('foo' => 'foo', 'style' => 'background-color:#F00;'),
|
||||
array('style' => 'bar:3in;background-color:#F00;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,36 +2,36 @@
|
||||
|
||||
class HTMLPurifier_AttrTransform_BorderTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_Border();
|
||||
}
|
||||
|
||||
|
||||
function testEmptyInput() {
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
|
||||
function testBasicTransform() {
|
||||
$this->assertResult(
|
||||
array('border' => '1'),
|
||||
array('style' => 'border:1px solid;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testLenientTreatmentOfInvalidInput() {
|
||||
$this->assertResult(
|
||||
array('border' => '10%'),
|
||||
array('style' => 'border:10%px solid;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testPrependNewCSS() {
|
||||
$this->assertResult(
|
||||
array('border' => '23', 'style' => 'font-weight:bold;'),
|
||||
array('style' => 'border:23px solid;font-weight:bold;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
class HTMLPurifier_AttrTransform_EnumToCSSTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
||||
@@ -10,44 +10,44 @@ class HTMLPurifier_AttrTransform_EnumToCSSTest extends HTMLPurifier_AttrTransfor
|
||||
'right' => 'text-align:right;'
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function testEmptyInput() {
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
|
||||
function testPreserveArraysWithoutInterestingAttributes() {
|
||||
$this->assertResult( array('style' => 'font-weight:bold;') );
|
||||
}
|
||||
|
||||
|
||||
function testConvertAlignLeft() {
|
||||
$this->assertResult(
|
||||
array('align' => 'left'),
|
||||
array('style' => 'text-align:left;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testConvertAlignRight() {
|
||||
$this->assertResult(
|
||||
array('align' => 'right'),
|
||||
array('style' => 'text-align:right;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testRemoveInvalidAlign() {
|
||||
$this->assertResult(
|
||||
array('align' => 'invalid'),
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testPrependNewCSS() {
|
||||
$this->assertResult(
|
||||
array('align' => 'left', 'style' => 'font-weight:bold;'),
|
||||
array('style' => 'text-align:left;font-weight:bold;')
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testCaseInsensitive() {
|
||||
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
||||
'right' => 'text-align:right;'
|
||||
@@ -57,7 +57,7 @@ class HTMLPurifier_AttrTransform_EnumToCSSTest extends HTMLPurifier_AttrTransfor
|
||||
array('style' => 'text-align:right;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testCaseSensitive() {
|
||||
$this->obj = new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
||||
'right' => 'text-align:right;'
|
||||
@@ -67,6 +67,6 @@ class HTMLPurifier_AttrTransform_EnumToCSSTest extends HTMLPurifier_AttrTransfor
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,12 +2,12 @@
|
||||
|
||||
class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_ImgRequired();
|
||||
}
|
||||
|
||||
|
||||
function testAddMissingAttr() {
|
||||
$this->config->set('Core', 'RemoveInvalidImg', false);
|
||||
$this->assertResult(
|
||||
@@ -15,7 +15,7 @@ class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransf
|
||||
array('src' => '', 'alt' => 'Invalid image')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testAlternateDefaults() {
|
||||
$this->config->set('Attr', 'DefaultInvalidImage', 'blank.png');
|
||||
$this->config->set('Attr', 'DefaultInvalidImageAlt', 'Pawned!');
|
||||
@@ -26,14 +26,14 @@ class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransf
|
||||
array('src' => 'blank.png', 'alt' => 'Pawned!')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testGenerateAlt() {
|
||||
$this->assertResult(
|
||||
array('src' => '/path/to/foobar.png'),
|
||||
array('src' => '/path/to/foobar.png', 'alt' => 'foobar.png')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testAddDefaultSrc() {
|
||||
$this->config->set('Core', 'RemoveInvalidImg', false);
|
||||
$this->assertResult(
|
||||
@@ -41,7 +41,7 @@ class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransf
|
||||
array('alt' => 'intrigue', 'src' => '')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testAddDefaultAlt() {
|
||||
$this->config->set('Attr', 'DefaultImageAlt', 'default');
|
||||
$this->assertResult(
|
||||
@@ -49,6 +49,6 @@ class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransf
|
||||
array('src' => '', 'alt' => 'default')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,37 +2,37 @@
|
||||
|
||||
class HTMLPurifier_AttrTransform_ImgSpaceTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_ImgSpace('vspace');
|
||||
}
|
||||
|
||||
|
||||
function testEmptyInput() {
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
|
||||
function testVerticalBasicUsage() {
|
||||
$this->assertResult(
|
||||
array('vspace' => '1'),
|
||||
array('style' => 'margin-top:1px;margin-bottom:1px;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testLenientHandlingOfInvalidInput() {
|
||||
$this->assertResult(
|
||||
array('vspace' => '10%'),
|
||||
array('style' => 'margin-top:10%px;margin-bottom:10%px;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testPrependNewCSS() {
|
||||
$this->assertResult(
|
||||
array('vspace' => '23', 'style' => 'font-weight:bold;'),
|
||||
array('style' => 'margin-top:23px;margin-bottom:23px;font-weight:bold;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testHorizontalBasicUsage() {
|
||||
$this->obj = new HTMLPurifier_AttrTransform_ImgSpace('hspace');
|
||||
$this->assertResult(
|
||||
@@ -40,7 +40,7 @@ class HTMLPurifier_AttrTransform_ImgSpaceTest extends HTMLPurifier_AttrTransform
|
||||
array('style' => 'margin-left:1px;margin-right:1px;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testInvalidConstructionParameter() {
|
||||
$this->expectError('ispace is not valid space attribute');
|
||||
$this->obj = new HTMLPurifier_AttrTransform_ImgSpace('ispace');
|
||||
@@ -49,6 +49,6 @@ class HTMLPurifier_AttrTransform_ImgSpaceTest extends HTMLPurifier_AttrTransform
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,29 +2,29 @@
|
||||
|
||||
class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_Input();
|
||||
}
|
||||
|
||||
|
||||
function testEmptyInput() {
|
||||
$this->assertResult(array());
|
||||
}
|
||||
|
||||
|
||||
function testInvalidCheckedWithEmpty() {
|
||||
$this->assertResult(array('checked' => 'checked'), array());
|
||||
}
|
||||
|
||||
|
||||
function testInvalidCheckedWithPassword() {
|
||||
$this->assertResult(array(
|
||||
'checked' => 'checked',
|
||||
'checked' => 'checked',
|
||||
'type' => 'password'
|
||||
), array(
|
||||
'type' => 'password'
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function testValidCheckedWithUcCheckbox() {
|
||||
$this->assertResult(array(
|
||||
'checked' => 'checked',
|
||||
@@ -32,7 +32,7 @@ class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHar
|
||||
'value' => 'bar',
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function testInvalidMaxlength() {
|
||||
$this->assertResult(array(
|
||||
'maxlength' => '10',
|
||||
@@ -43,15 +43,15 @@ class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHar
|
||||
'value' => 'foo',
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function testValidMaxLength() {
|
||||
$this->assertResult(array(
|
||||
'maxlength' => '10',
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
// these two are really bad test-cases
|
||||
|
||||
|
||||
function testSizeWithCheckbox() {
|
||||
$this->assertResult(array(
|
||||
'type' => 'checkbox',
|
||||
@@ -63,7 +63,7 @@ class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHar
|
||||
'size' => '100',
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function testSizeWithText() {
|
||||
$this->assertResult(array(
|
||||
'type' => 'password',
|
||||
@@ -73,13 +73,13 @@ class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHar
|
||||
'size' => '100px',
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function testInvalidSrc() {
|
||||
$this->assertResult(array(
|
||||
'src' => 'img.png',
|
||||
), array());
|
||||
}
|
||||
|
||||
|
||||
function testMissingValue() {
|
||||
$this->assertResult(array(
|
||||
'type' => 'checkbox',
|
||||
@@ -88,6 +88,6 @@ class HTMLPurifier_AttrTransform_InputTest extends HTMLPurifier_AttrTransformHar
|
||||
'value' => '',
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -3,43 +3,43 @@
|
||||
class HTMLPurifier_AttrTransform_LangTest
|
||||
extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_Lang();
|
||||
}
|
||||
|
||||
|
||||
function testEmptyInput() {
|
||||
$this->assertResult(array());
|
||||
}
|
||||
|
||||
|
||||
function testCopyLangToXMLLang() {
|
||||
$this->assertResult(
|
||||
array('lang' => 'en'),
|
||||
array('lang' => 'en', 'xml:lang' => 'en')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testPreserveAttributes() {
|
||||
$this->assertResult(
|
||||
array('src' => 'vert.png', 'lang' => 'fr'),
|
||||
array('src' => 'vert.png', 'lang' => 'fr', 'xml:lang' => 'fr')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testCopyXMLLangToLang() {
|
||||
$this->assertResult(
|
||||
array('xml:lang' => 'en'),
|
||||
array('xml:lang' => 'en', 'lang' => 'en')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testXMLLangOverridesLang() {
|
||||
$this->assertResult(
|
||||
array('lang' => 'fr', 'xml:lang' => 'de'),
|
||||
array('lang' => 'de', 'xml:lang' => 'de')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,43 +2,43 @@
|
||||
|
||||
class HTMLPurifier_AttrTransform_LengthTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_Length('width');
|
||||
}
|
||||
|
||||
|
||||
function testEmptyInput() {
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
|
||||
function testTransformPixel() {
|
||||
$this->assertResult(
|
||||
array('width' => '10'),
|
||||
array('style' => 'width:10px;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testTransformPercentage() {
|
||||
$this->assertResult(
|
||||
array('width' => '10%'),
|
||||
array('style' => 'width:10%;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testPrependNewCSS() {
|
||||
$this->assertResult(
|
||||
array('width' => '10%', 'style' => 'font-weight:bold'),
|
||||
array('style' => 'width:10%;font-weight:bold')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testLenientTreatmentOfInvalidInput() {
|
||||
$this->assertResult(
|
||||
array('width' => 'asdf'),
|
||||
array('style' => 'width:asdf;')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,29 +2,29 @@
|
||||
|
||||
class HTMLPurifier_AttrTransform_NameTest extends HTMLPurifier_AttrTransformHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_AttrTransform_Name();
|
||||
}
|
||||
|
||||
|
||||
function testEmpty() {
|
||||
$this->assertResult( array() );
|
||||
}
|
||||
|
||||
|
||||
function testTransformNameToID() {
|
||||
$this->assertResult(
|
||||
array('name' => 'free'),
|
||||
array('id' => 'free')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testExistingIDOverridesName() {
|
||||
$this->assertResult(
|
||||
array('name' => 'tryit', 'id' => 'tobad'),
|
||||
array('id' => 'tobad')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,11 +2,11 @@
|
||||
|
||||
class HTMLPurifier_AttrTransformHarness extends HTMLPurifier_ComplexHarness
|
||||
{
|
||||
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->func = 'transform';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -7,38 +7,38 @@ Mock::generatePartial(
|
||||
|
||||
class HTMLPurifier_AttrTransformTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
function test_prependCSS() {
|
||||
|
||||
|
||||
$t = new HTMLPurifier_AttrTransformTestable();
|
||||
|
||||
|
||||
$attr = array();
|
||||
$t->prependCSS($attr, 'style:new;');
|
||||
$this->assertIdentical(array('style' => 'style:new;'), $attr);
|
||||
|
||||
|
||||
$attr = array('style' => 'style:original;');
|
||||
$t->prependCSS($attr, 'style:new;');
|
||||
$this->assertIdentical(array('style' => 'style:new;style:original;'), $attr);
|
||||
|
||||
|
||||
$attr = array('style' => 'style:original;', 'misc' => 'un-related');
|
||||
$t->prependCSS($attr, 'style:new;');
|
||||
$this->assertIdentical(array('style' => 'style:new;style:original;', 'misc' => 'un-related'), $attr);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_confiscateAttr() {
|
||||
|
||||
|
||||
$t = new HTMLPurifier_AttrTransformTestable();
|
||||
|
||||
|
||||
$attr = array('flavor' => 'sweet');
|
||||
$this->assertIdentical('sweet', $t->confiscateAttr($attr, 'flavor'));
|
||||
$this->assertIdentical(array(), $attr);
|
||||
|
||||
|
||||
$attr = array('flavor' => 'sweet');
|
||||
$this->assertIdentical(null, $t->confiscateAttr($attr, 'color'));
|
||||
$this->assertIdentical(array('flavor' => 'sweet'), $attr);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,24 +2,24 @@
|
||||
|
||||
class HTMLPurifier_AttrTypesTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
function test_get() {
|
||||
$types = new HTMLPurifier_AttrTypes();
|
||||
|
||||
|
||||
$this->assertIdentical(
|
||||
$types->get('CDATA'),
|
||||
new HTMLPurifier_AttrDef_Text()
|
||||
);
|
||||
|
||||
|
||||
$this->expectError('Cannot retrieve undefined attribute type foobar');
|
||||
$types->get('foobar');
|
||||
|
||||
|
||||
$this->assertIdentical(
|
||||
$types->get('Enum#foo,bar'),
|
||||
new HTMLPurifier_AttrDef_Enum(array('foo', 'bar'))
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
|
||||
{
|
||||
|
||||
|
||||
public function setup() {
|
||||
parent::setup();
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
@@ -11,12 +11,12 @@ class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
|
||||
$this->collector = new HTMLPurifier_ErrorCollector($this->context);
|
||||
$this->context->register('Generator', new HTMLPurifier_Generator($config, $this->context));
|
||||
}
|
||||
|
||||
|
||||
protected function invoke($input) {
|
||||
$validator = new HTMLPurifier_AttrValidator();
|
||||
$validator->validateToken($input, $this->config, $this->context);
|
||||
}
|
||||
|
||||
|
||||
function testAttributesTransformedGlobalPre() {
|
||||
$this->config->set('HTML', 'DefinitionID',
|
||||
'HTMLPurifier_AttrValidator_ErrorsTest::testAttributesTransformedGlobalPre');
|
||||
@@ -27,17 +27,17 @@ class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
|
||||
$output = array('class' => 'value'); // must be valid
|
||||
$transform->setReturnValue('transform', $output, array($input, new AnythingExpectation(), new AnythingExpectation()));
|
||||
$def->info_attr_transform_pre[] = $transform;
|
||||
|
||||
|
||||
$token = new HTMLPurifier_Token_Start('span', $input, 1);
|
||||
$this->invoke($token);
|
||||
|
||||
|
||||
$result = $this->collector->getRaw();
|
||||
$expect = array(
|
||||
array(1, E_NOTICE, 'Attributes on <span> transformed from original to class', array()),
|
||||
);
|
||||
$this->assertIdentical($result, $expect);
|
||||
}
|
||||
|
||||
|
||||
function testAttributesTransformedLocalPre() {
|
||||
$this->config->set('HTML', 'TidyLevel', 'heavy');
|
||||
$input = array('align' => 'right');
|
||||
@@ -50,9 +50,9 @@ class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
|
||||
);
|
||||
$this->assertIdentical($result, $expect);
|
||||
}
|
||||
|
||||
|
||||
// too lazy to check for global post and global pre
|
||||
|
||||
|
||||
function testAttributeRemoved() {
|
||||
$token = new HTMLPurifier_Token_Start('p', array('foobar' => 'right'), 1);
|
||||
$this->invoke($token);
|
||||
@@ -62,6 +62,6 @@ class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
|
||||
);
|
||||
$this->assertIdentical($result, $expect);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,9 +2,9 @@
|
||||
|
||||
class HTMLPurifier_ChildDef_ChameleonTest extends HTMLPurifier_ChildDefHarness
|
||||
{
|
||||
|
||||
|
||||
protected $isInline;
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_ChildDef_Chameleon(
|
||||
@@ -13,27 +13,27 @@ class HTMLPurifier_ChildDef_ChameleonTest extends HTMLPurifier_ChildDefHarness
|
||||
);
|
||||
$this->context->register('IsInline', $this->isInline);
|
||||
}
|
||||
|
||||
|
||||
function testInlineAlwaysAllowed() {
|
||||
$this->isInline = true;
|
||||
$this->assertResult(
|
||||
'<b>Allowed.</b>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testBlockNotAllowedInInline() {
|
||||
$this->isInline = true;
|
||||
$this->assertResult(
|
||||
'<div>Not allowed.</div>', ''
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testBlockAllowedInNonInline() {
|
||||
$this->isInline = false;
|
||||
$this->assertResult(
|
||||
'<div>Allowed.</div>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,23 +2,23 @@
|
||||
|
||||
class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
|
||||
{
|
||||
|
||||
|
||||
function test() {
|
||||
|
||||
|
||||
$this->obj = new HTMLPurifier_ChildDef_Custom('(a,b?,c*,d+,(a,b)*)');
|
||||
|
||||
|
||||
$this->assertEqual($this->obj->elements, array('a' => true,
|
||||
'b' => true, 'c' => true, 'd' => true));
|
||||
|
||||
|
||||
$this->assertResult('', false);
|
||||
$this->assertResult('<a /><a />', false);
|
||||
|
||||
|
||||
$this->assertResult('<a /><b /><c /><d /><a /><b />');
|
||||
$this->assertResult('<a /><d>Dob</d><a /><b>foo</b>'.
|
||||
'<a href="moo" /><b>foo</b>');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testNesting() {
|
||||
$this->obj = new HTMLPurifier_ChildDef_Custom('(a,b,(c|d))+');
|
||||
$this->assertEqual($this->obj->elements, array('a' => true,
|
||||
@@ -27,7 +27,7 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
|
||||
$this->assertResult('<a /><b /><c /><a /><b /><d />');
|
||||
$this->assertResult('<a /><b /><c /><d />', false);
|
||||
}
|
||||
|
||||
|
||||
function testNestedEitherOr() {
|
||||
$this->obj = new HTMLPurifier_ChildDef_Custom('b,(a|(c|d))+');
|
||||
$this->assertEqual($this->obj->elements, array('a' => true,
|
||||
@@ -38,7 +38,7 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
|
||||
$this->assertResult('<b /><a />');
|
||||
$this->assertResult('<acd />', false);
|
||||
}
|
||||
|
||||
|
||||
function testNestedQuantifier() {
|
||||
$this->obj = new HTMLPurifier_ChildDef_Custom('(b,c+)*');
|
||||
$this->assertEqual($this->obj->elements, array('b' => true, 'c' => true));
|
||||
@@ -48,34 +48,34 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
|
||||
$this->assertResult('<b /><c /><b /><c />');
|
||||
$this->assertResult('<b /><c /><b />', false);
|
||||
}
|
||||
|
||||
|
||||
function testEitherOr() {
|
||||
|
||||
|
||||
$this->obj = new HTMLPurifier_ChildDef_Custom('a|b');
|
||||
$this->assertEqual($this->obj->elements, array('a' => true, 'b' => true));
|
||||
$this->assertResult('', false);
|
||||
$this->assertResult('<a />');
|
||||
$this->assertResult('<b />');
|
||||
$this->assertResult('<a /><b />', false);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testCommafication() {
|
||||
|
||||
|
||||
$this->obj = new HTMLPurifier_ChildDef_Custom('a,b');
|
||||
$this->assertEqual($this->obj->elements, array('a' => true, 'b' => true));
|
||||
$this->assertResult('<a /><b />');
|
||||
$this->assertResult('<ab />', false);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$this->obj = new HTMLPurifier_ChildDef_Custom('a');
|
||||
$this->assertEqual($this->obj->elements, array('a' => true));
|
||||
@@ -83,6 +83,6 @@ class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
|
||||
$this->assertResult('<a />');
|
||||
$this->assertResult(' <a />');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,30 +2,30 @@
|
||||
|
||||
class HTMLPurifier_ChildDef_OptionalTest extends HTMLPurifier_ChildDefHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_ChildDef_Optional('b | i');
|
||||
}
|
||||
|
||||
|
||||
function testBasicUsage() {
|
||||
$this->assertResult('<b>Bold text</b><img />', '<b>Bold text</b>');
|
||||
}
|
||||
|
||||
|
||||
function testRemoveForbiddenText() {
|
||||
$this->assertResult('Not allowed text', '');
|
||||
}
|
||||
|
||||
|
||||
function testEmpty() {
|
||||
$this->assertResult('');
|
||||
}
|
||||
|
||||
|
||||
function testWhitespace() {
|
||||
$this->assertResult(' ');
|
||||
}
|
||||
|
||||
|
||||
function testMultipleWhitespace() {
|
||||
$this->assertResult(' ');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness
|
||||
{
|
||||
|
||||
|
||||
function testPrepareString() {
|
||||
$def = new HTMLPurifier_ChildDef_Required('foobar | bang |gizmo');
|
||||
$this->assertIdentical($def->elements,
|
||||
@@ -12,7 +12,7 @@ class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness
|
||||
,'gizmo' => true
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function testPrepareArray() {
|
||||
$def = new HTMLPurifier_ChildDef_Required(array('href', 'src'));
|
||||
$this->assertIdentical($def->elements,
|
||||
@@ -21,16 +21,16 @@ class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness
|
||||
,'src' => true
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_ChildDef_Required('dt | dd');
|
||||
}
|
||||
|
||||
|
||||
function testEmptyInput() {
|
||||
$this->assertResult('', false);
|
||||
}
|
||||
|
||||
|
||||
function testRemoveIllegalTagsAndElements() {
|
||||
$this->assertResult(
|
||||
'<dt>Term</dt>Text in an illegal location'.
|
||||
@@ -38,28 +38,28 @@ class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness
|
||||
'<dt>Term</dt><dd>Definition</dd>');
|
||||
$this->assertResult('How do you do!', false);
|
||||
}
|
||||
|
||||
|
||||
function testIgnoreWhitespace() {
|
||||
// whitespace shouldn't trigger it
|
||||
$this->assertResult("\n<dd>Definition</dd> ");
|
||||
}
|
||||
|
||||
|
||||
function testPreserveWhitespaceAfterRemoval() {
|
||||
$this->assertResult(
|
||||
'<dd>Definition</dd> <b></b> ',
|
||||
'<dd>Definition</dd> '
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testDeleteNodeIfOnlyWhitespace() {
|
||||
$this->assertResult("\t ", false);
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$this->obj = new HTMLPurifier_ChildDef_Required('#PCDATA | b');
|
||||
$this->config->set('Core', 'EscapeInvalidChildren', true);
|
||||
|
@@ -3,73 +3,73 @@
|
||||
class HTMLPurifier_ChildDef_StrictBlockquoteTest
|
||||
extends HTMLPurifier_ChildDefHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_ChildDef_StrictBlockquote('div | p');
|
||||
}
|
||||
|
||||
|
||||
function testEmptyInput() {
|
||||
$this->assertResult('');
|
||||
}
|
||||
|
||||
|
||||
function testPreserveValidP() {
|
||||
$this->assertResult('<p>Valid</p>');
|
||||
}
|
||||
|
||||
|
||||
function testPreserveValidDiv() {
|
||||
$this->assertResult('<div>Still valid</div>');
|
||||
}
|
||||
|
||||
|
||||
function testWrapTextWithP() {
|
||||
$this->assertResult('Needs wrap', '<p>Needs wrap</p>');
|
||||
}
|
||||
|
||||
|
||||
function testNoWrapForWhitespaceOrValidElements() {
|
||||
$this->assertResult('<p>Do not wrap</p> <p>Whitespace</p>');
|
||||
}
|
||||
|
||||
|
||||
function testWrapTextNextToValidElements() {
|
||||
$this->assertResult(
|
||||
'Wrap'. '<p>Do not wrap</p>',
|
||||
'<p>Wrap</p><p>Do not wrap</p>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testWrapInlineElements() {
|
||||
$this->assertResult(
|
||||
'<p>Do not</p>'.'<b>Wrap</b>',
|
||||
'<p>Do not</p><p><b>Wrap</b></p>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testWrapAndRemoveInvalidTags() {
|
||||
$this->assertResult(
|
||||
'<li>Not allowed</li>Paragraph.<p>Hmm.</p>',
|
||||
'<p>Not allowedParagraph.</p><p>Hmm.</p>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testWrapComplicatedSring() {
|
||||
$this->assertResult(
|
||||
$var = 'He said<br />perhaps<br />we should <b>nuke</b> them.',
|
||||
"<p>$var</p>"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$this->config->set('HTML', 'BlockWrapper', 'div');
|
||||
$this->assertResult('Needs wrap', '<div>Needs wrap</div>');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testError() {
|
||||
$this->expectError('Cannot use non-block element as block wrapper');
|
||||
$this->obj = new HTMLPurifier_ChildDef_StrictBlockquote('div | p');
|
||||
@@ -77,6 +77,6 @@ extends HTMLPurifier_ChildDefHarness
|
||||
$this->config->set('Cache', 'DefinitionImpl', null);
|
||||
$this->assertResult('Needs wrap', '<p>Needs wrap</p>');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -5,56 +5,56 @@
|
||||
|
||||
class HTMLPurifier_ChildDef_TableTest extends HTMLPurifier_ChildDefHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = new HTMLPurifier_ChildDef_Table();
|
||||
}
|
||||
|
||||
|
||||
function testEmptyInput() {
|
||||
$this->assertResult('', false);
|
||||
}
|
||||
|
||||
|
||||
function testSingleRow() {
|
||||
$this->assertResult('<tr />');
|
||||
}
|
||||
|
||||
|
||||
function testComplexContents() {
|
||||
$this->assertResult('<caption /><col /><thead /><tfoot /><tbody>'.
|
||||
'<tr><td>asdf</td></tr></tbody>');
|
||||
$this->assertResult('<col /><col /><col /><tr />');
|
||||
}
|
||||
|
||||
|
||||
function testReorderContents() {
|
||||
$this->assertResult(
|
||||
'<col /><colgroup /><tbody /><tfoot /><thead /><tr>1</tr><caption /><tr />',
|
||||
'<caption /><col /><colgroup /><thead /><tfoot /><tbody /><tr>1</tr><tr />');
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$this->assertResult('foo', false);
|
||||
}
|
||||
|
||||
|
||||
function testStickyWhitespaceOnTr() {
|
||||
$this->config->set('Output', 'Newline', "\n");
|
||||
$this->assertResult("\n <tr />\n <tr />\n ");
|
||||
}
|
||||
|
||||
|
||||
function testStickyWhitespaceOnTSection() {
|
||||
$this->config->set('Output', 'Newline', "\n");
|
||||
$this->assertResult(
|
||||
"\n\t<tbody />\n\t\t<tfoot />\n\t\t\t",
|
||||
"\n\t\t<tfoot />\n\t<tbody />\n\t\t\t"
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
class HTMLPurifier_ChildDefHarness extends HTMLPurifier_ComplexHarness
|
||||
{
|
||||
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->obj = null;
|
||||
@@ -10,7 +10,7 @@ class HTMLPurifier_ChildDefHarness extends HTMLPurifier_ComplexHarness
|
||||
$this->to_tokens = true;
|
||||
$this->to_html = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -7,39 +7,39 @@
|
||||
*/
|
||||
class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Instance of the object that will execute the method
|
||||
*/
|
||||
protected $obj;
|
||||
|
||||
|
||||
/**
|
||||
* Name of the function to be executed
|
||||
*/
|
||||
protected $func;
|
||||
|
||||
|
||||
/**
|
||||
* Whether or not the method deals in tokens. If set to true, assertResult()
|
||||
* will transparently convert HTML to and back from tokens.
|
||||
*/
|
||||
protected $to_tokens = false;
|
||||
|
||||
|
||||
/**
|
||||
* Whether or not to convert tokens back into HTML before performing
|
||||
* equality check, has no effect on bools.
|
||||
*/
|
||||
protected $to_html = false;
|
||||
|
||||
|
||||
/**
|
||||
* Instance of an HTMLPurifier_Lexer implementation.
|
||||
*/
|
||||
protected $lexer;
|
||||
|
||||
|
||||
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
|
||||
@@ -50,7 +50,7 @@ class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
|
||||
* context object.
|
||||
*/
|
||||
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
|
||||
@@ -59,11 +59,11 @@ class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
|
||||
} else {
|
||||
$input_c = $input;
|
||||
}
|
||||
|
||||
|
||||
// call the function
|
||||
$func = $this->func;
|
||||
$result = $this->obj->$func($input_c, $this->config, $this->context);
|
||||
|
||||
|
||||
// test a bool result
|
||||
if (is_bool($result)) {
|
||||
$this->assertIdentical($expect, $result);
|
||||
@@ -71,7 +71,7 @@ class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
|
||||
} elseif (is_bool($expect)) {
|
||||
$expect = $input;
|
||||
}
|
||||
|
||||
|
||||
if ($this->to_html) {
|
||||
$result = $this->generate($result);
|
||||
if (is_array($expect)) {
|
||||
@@ -79,20 +79,20 @@ class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
|
||||
}
|
||||
}
|
||||
$this->assertIdentical($expect, $result);
|
||||
|
||||
|
||||
if ($expect !== $result) {
|
||||
echo '<pre>' . htmlspecialchars($result) . '</pre>';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tokenize HTML into tokens, uses member variables for common variables
|
||||
*/
|
||||
protected function tokenize($html) {
|
||||
return $this->lexer->tokenizeHTML($html, $this->config, $this->context);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate textual HTML from tokens
|
||||
*/
|
||||
@@ -100,7 +100,7 @@ class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
|
||||
$generator = new HTMLPurifier_Generator($this->config, $this->context);
|
||||
return $generator->generateFromTokens($tokens);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -2,25 +2,25 @@
|
||||
|
||||
class HTMLPurifier_ConfigSchema_InterchangeTest extends UnitTestCase
|
||||
{
|
||||
|
||||
|
||||
protected $interchange;
|
||||
|
||||
|
||||
public function setup() {
|
||||
$this->interchange = new HTMLPurifier_ConfigSchema_Interchange();
|
||||
}
|
||||
|
||||
|
||||
function testAddNamespace() {
|
||||
$v = new HTMLPurifier_ConfigSchema_Interchange_Namespace();
|
||||
$v->namespace = 'Namespace';
|
||||
$this->interchange->addNamespace($v);
|
||||
$this->assertIdentical($v, $this->interchange->namespaces['Namespace']);
|
||||
}
|
||||
|
||||
|
||||
function testAddDirective() {
|
||||
$v = new HTMLPurifier_ConfigSchema_Interchange_Directive();
|
||||
$v->id = new HTMLPurifier_ConfigSchema_Interchange_Id('Namespace', 'Directive');
|
||||
$this->interchange->addDirective($v);
|
||||
$this->assertIdentical($v, $this->interchange->directives['Namespace.Directive']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -7,4 +7,4 @@ ID: Ns.Dir
|
||||
TYPE: string
|
||||
DESCRIPTION: Description
|
||||
DEFAULT: 'asdf'
|
||||
ALLOWED:
|
||||
ALLOWED:
|
||||
|
@@ -2,87 +2,87 @@
|
||||
|
||||
class HTMLPurifier_ConfigSchema_ValidatorAtomTest extends UnitTestCase
|
||||
{
|
||||
|
||||
|
||||
protected function expectValidationException($msg) {
|
||||
$this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$this->makeAtom('foo')->assertIsString();
|
||||
}
|
||||
|
||||
|
||||
function testAssertIsStringFail() {
|
||||
$this->expectValidationException("Property in context must be a string");
|
||||
$this->makeAtom(3)->assertIsString();
|
||||
}
|
||||
|
||||
|
||||
function testAssertNotNull() {
|
||||
$this->makeAtom('foo')->assertNotNull();
|
||||
}
|
||||
|
||||
|
||||
function testAssertNotNullFail() {
|
||||
$this->expectValidationException("Property in context must not be null");
|
||||
$this->makeAtom(null)->assertNotNull();
|
||||
}
|
||||
|
||||
|
||||
function testAssertAlnum() {
|
||||
$this->makeAtom('foo2')->assertAlnum();
|
||||
}
|
||||
|
||||
|
||||
function testAssertAlnumFail() {
|
||||
$this->expectValidationException("Property in context must be alphanumeric");
|
||||
$this->makeAtom('%a')->assertAlnum();
|
||||
}
|
||||
|
||||
|
||||
function testAssertAlnumFailIsString() {
|
||||
$this->expectValidationException("Property in context must be a string");
|
||||
$this->makeAtom(3)->assertAlnum();
|
||||
}
|
||||
|
||||
|
||||
function testAssertNotEmpty() {
|
||||
$this->makeAtom('foo')->assertNotEmpty();
|
||||
}
|
||||
|
||||
|
||||
function testAssertNotEmptyFail() {
|
||||
$this->expectValidationException("Property in context must not be empty");
|
||||
$this->makeAtom('')->assertNotEmpty();
|
||||
}
|
||||
|
||||
|
||||
function testAssertIsBool() {
|
||||
$this->makeAtom(false)->assertIsBool();
|
||||
}
|
||||
|
||||
|
||||
function testAssertIsBoolFail() {
|
||||
$this->expectValidationException("Property in context must be a boolean");
|
||||
$this->makeAtom('0')->assertIsBool();
|
||||
}
|
||||
|
||||
|
||||
function testAssertIsArray() {
|
||||
$this->makeAtom(array())->assertIsArray();
|
||||
}
|
||||
|
||||
|
||||
function testAssertIsArrayFail() {
|
||||
$this->expectValidationException("Property in context must be an array");
|
||||
$this->makeAtom('asdf')->assertIsArray();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function testAssertIsLookup() {
|
||||
$this->makeAtom(array('foo' => true))->assertIsLookup();
|
||||
}
|
||||
|
||||
|
||||
function testAssertIsLookupFail() {
|
||||
$this->expectValidationException("Property in context must be a lookup array");
|
||||
$this->makeAtom(array('foo' => 4))->assertIsLookup();
|
||||
}
|
||||
|
||||
|
||||
function testAssertIsLookupFailIsArray() {
|
||||
$this->expectValidationException("Property in context must be an array");
|
||||
$this->makeAtom('asdf')->assertIsLookup();
|
||||
|
@@ -7,71 +7,71 @@
|
||||
class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
|
||||
{
|
||||
public $validator, $interchange;
|
||||
|
||||
|
||||
public function setup() {
|
||||
$this->validator = new HTMLPurifier_ConfigSchema_Validator();
|
||||
$this->interchange = new HTMLPurifier_ConfigSchema_Interchange();
|
||||
}
|
||||
|
||||
|
||||
function testNamespaceIntegrityViolation() {
|
||||
$ns = $this->makeNamespace('Ns');
|
||||
$ns->namespace = 'AltNs';
|
||||
$this->expectValidationException("Integrity violation: key 'Ns' does not match internal id 'AltNs'");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
|
||||
function testNamespaceNamespaceIsString() {
|
||||
$this->makeNamespace(3);
|
||||
$this->expectValidationException("Namespace in namespace '3' must be a string");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
|
||||
function testNamespaceDescriptionIsString() {
|
||||
$ns = $this->makeNamespace('Ns');
|
||||
$ns->description = 3;
|
||||
$this->expectValidationException("Description in namespace 'Ns' must be a string");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$this->makeNamespace('Ns');
|
||||
$d = $this->makeDirective('Ns', 'Dir');
|
||||
$d->default = 0;
|
||||
$d->description = 'Description';
|
||||
|
||||
|
||||
$this->expectValidationException("Type in directive 'Ns.Dir' must not be empty");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
|
||||
function testDirectiveDefaultInvalid() {
|
||||
$this->makeNamespace('Ns');
|
||||
$d = $this->makeDirective('Ns', 'Dir');
|
||||
$d->default = 'asdf';
|
||||
$d->type = 'int';
|
||||
$d->description = 'Description';
|
||||
|
||||
|
||||
$this->expectValidationException("Default in directive 'Ns.Dir' had error: Expected type int, got string");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
|
||||
function testDirectiveIdDirectiveIsString() {
|
||||
$this->makeNamespace('Ns');
|
||||
$d = $this->makeDirective('Ns', 3);
|
||||
$d->default = 0;
|
||||
$d->type = 'int';
|
||||
$d->description = 'Description';
|
||||
|
||||
|
||||
$this->expectValidationException("Directive in id 'Ns.3' in directive 'Ns.3' must be a string");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
|
||||
function testDirectiveTypeAllowsNullIsBool() {
|
||||
$this->makeNamespace('Ns');
|
||||
$d = $this->makeDirective('Ns', 'Dir');
|
||||
@@ -79,11 +79,11 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
|
||||
$d->type = 'int';
|
||||
$d->description = 'Description';
|
||||
$d->typeAllowsNull = 'yes';
|
||||
|
||||
|
||||
$this->expectValidationException("TypeAllowsNull in directive 'Ns.Dir' must be a boolean");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
|
||||
function testDirectiveValueAliasesIsArray() {
|
||||
$this->makeNamespace('Ns');
|
||||
$d = $this->makeDirective('Ns', 'Dir');
|
||||
@@ -91,11 +91,11 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
|
||||
$d->type = 'string';
|
||||
$d->description = 'Description';
|
||||
$d->valueAliases = 2;
|
||||
|
||||
|
||||
$this->expectValidationException("ValueAliases in directive 'Ns.Dir' must be an array");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
|
||||
function testDirectiveAllowedIsLookup() {
|
||||
$this->makeNamespace('Ns');
|
||||
$d = $this->makeDirective('Ns', 'Dir');
|
||||
@@ -103,13 +103,13 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
|
||||
$d->type = 'string';
|
||||
$d->description = 'Description';
|
||||
$d->allowed = array('foo' => 1);
|
||||
|
||||
|
||||
$this->expectValidationException("Allowed in directive 'Ns.Dir' must be a lookup array");
|
||||
$this->validator->validate($this->interchange);
|
||||
}
|
||||
|
||||
|
||||
// helper functions
|
||||
|
||||
|
||||
protected function makeNamespace($n) {
|
||||
$namespace = new HTMLPurifier_ConfigSchema_Interchange_Namespace();
|
||||
$namespace->namespace = $n;
|
||||
@@ -117,16 +117,16 @@ class HTMLPurifier_ConfigSchema_ValidatorTest extends UnitTestCase
|
||||
$this->interchange->addNamespace($namespace);
|
||||
return $namespace;
|
||||
}
|
||||
|
||||
|
||||
protected function makeDirective($n, $d) {
|
||||
$directive = new HTMLPurifier_ConfigSchema_Interchange_Directive();
|
||||
$directive->id = new HTMLPurifier_ConfigSchema_Interchange_Id($n, $d);
|
||||
$this->interchange->addDirective($directive);
|
||||
return $directive;
|
||||
}
|
||||
|
||||
|
||||
protected function expectValidationException($msg) {
|
||||
$this->expectException(new HTMLPurifier_ConfigSchema_Exception($msg));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -5,21 +5,21 @@
|
||||
*/
|
||||
class HTMLPurifier_ConfigSchema_ValidatorTestCase extends UnitTestCase
|
||||
{
|
||||
|
||||
|
||||
protected $_path, $_parser, $_builder;
|
||||
public $validator;
|
||||
|
||||
|
||||
public function __construct($path) {
|
||||
$this->_path = $path;
|
||||
$this->_parser = new HTMLPurifier_StringHashParser();
|
||||
$this->_builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
|
||||
parent::__construct($path);
|
||||
}
|
||||
|
||||
|
||||
public function setup() {
|
||||
$this->validator = new HTMLPurifier_ConfigSchema_Validator();
|
||||
}
|
||||
|
||||
|
||||
function testValidator() {
|
||||
$hashes = $this->_parser->parseMultiFile($this->_path);
|
||||
$interchange = new HTMLPurifier_ConfigSchema_Interchange();
|
||||
@@ -38,5 +38,5 @@ class HTMLPurifier_ConfigSchema_ValidatorTestCase extends UnitTestCase
|
||||
$this->validator->validate($interchange);
|
||||
$this->pass();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -2,57 +2,57 @@
|
||||
|
||||
class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
protected $schema;
|
||||
|
||||
|
||||
public function setup() {
|
||||
$this->schema = new HTMLPurifier_ConfigSchema();
|
||||
}
|
||||
|
||||
|
||||
function test_defineNamespace() {
|
||||
$this->schema->addNamespace('http');
|
||||
$this->assertIdentical($this->schema->info['http'], array());
|
||||
$this->assertIdentical($this->schema->defaults['http'], array());
|
||||
}
|
||||
|
||||
|
||||
function test_define() {
|
||||
$this->schema->addNamespace('Car');
|
||||
|
||||
|
||||
$this->schema->add('Car', 'Seats', 5, 'int', false);
|
||||
|
||||
|
||||
$this->assertIdentical($this->schema->defaults['Car']['Seats'], 5);
|
||||
$this->assertIdentical($this->schema->info['Car']['Seats']->type, HTMLPurifier_VarParser::INT);
|
||||
|
||||
|
||||
$this->schema->add('Car', 'Age', null, 'int', true);
|
||||
|
||||
|
||||
$this->assertIdentical($this->schema->defaults['Car']['Age'], null);
|
||||
$this->assertIdentical($this->schema->info['Car']['Age']->type, HTMLPurifier_VarParser::INT);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_defineAllowedValues() {
|
||||
$this->schema->addNamespace('QuantumNumber', 'D');
|
||||
$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);
|
||||
|
||||
|
||||
$this->schema->addAllowedValues( // okay, since default is null
|
||||
'QuantumNumber', 'Difficulty', array('easy' => true, 'medium' => true, 'hard' => true)
|
||||
);
|
||||
|
||||
|
||||
$this->assertIdentical($this->schema->defaults['QuantumNumber']['Difficulty'], null);
|
||||
$this->assertIdentical($this->schema->info['QuantumNumber']['Difficulty']->type, HTMLPurifier_VarParser::STRING);
|
||||
$this->assertIdentical($this->schema->info['QuantumNumber']['Difficulty']->allow_null, true);
|
||||
$this->assertIdentical($this->schema->info['QuantumNumber']['Difficulty']->allowed,
|
||||
$this->assertIdentical($this->schema->info['QuantumNumber']['Difficulty']->allowed,
|
||||
array(
|
||||
'easy' => true,
|
||||
'medium' => true,
|
||||
'hard' => true
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_defineValueAliases() {
|
||||
$this->schema->addNamespace('Abbrev', 'Stuff on abbreviations.');
|
||||
$this->schema->add('Abbrev', 'HTH', 'Happy to Help', 'string', false);
|
||||
@@ -74,10 +74,10 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
|
||||
'hail' => 'HAIL THE HAND!'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$this->assertIdentical($this->schema->defaults['Abbrev']['HTH'], 'Happy to Help');
|
||||
$this->assertIdentical($this->schema->info['Abbrev']['HTH']->type, HTMLPurifier_VarParser::STRING);
|
||||
$this->assertIdentical($this->schema->info['Abbrev']['HTH']->allowed,
|
||||
$this->assertIdentical($this->schema->info['Abbrev']['HTH']->allowed,
|
||||
array(
|
||||
'Happy to Help' => true,
|
||||
'Hope that Helps' => true,
|
||||
@@ -91,20 +91,20 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness
|
||||
'hail' => 'HAIL THE HAND!'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testAlias() {
|
||||
$this->schema->addNamespace('Home');
|
||||
$this->schema->add('Home', 'Rug', 3, 'int', false);
|
||||
$this->schema->addAlias('Home', 'Carpet', 'Home', 'Rug');
|
||||
|
||||
|
||||
$this->assertTrue(!isset($this->schema->defaults['Home']['Carpet']));
|
||||
$this->assertIdentical($this->schema->info['Home']['Carpet']->namespace, 'Home');
|
||||
$this->assertIdentical($this->schema->info['Home']['Carpet']->name, 'Rug');
|
||||
$this->assertIdentical($this->schema->info['Home']['Carpet']->isAlias, true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,19 +2,19 @@
|
||||
|
||||
class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
protected $schema;
|
||||
|
||||
|
||||
public function setUp() {
|
||||
// set up a dummy schema object for testing
|
||||
$this->schema = new HTMLPurifier_ConfigSchema();
|
||||
}
|
||||
|
||||
|
||||
// test functionality based on ConfigSchema
|
||||
|
||||
|
||||
function testNormal() {
|
||||
$this->schema->addNamespace('Element');
|
||||
|
||||
|
||||
$this->schema->add('Element', 'Abbr', 'H', 'string', false);
|
||||
$this->schema->add('Element', 'Name', 'hydrogen', 'istring', false);
|
||||
$this->schema->add('Element', 'Number', 1, 'int', false);
|
||||
@@ -24,10 +24,10 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
$this->schema->add('Element', 'Traits', array('nonmetallic', 'odorless', 'flammable'), 'list', false);
|
||||
$this->schema->add('Element', 'IsotopeNames', array(1 => 'protium', 2 => 'deuterium', 3 => 'tritium'), 'hash', false);
|
||||
$this->schema->add('Element', 'Object', new stdClass(), 'mixed', false);
|
||||
|
||||
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->autoFinalize = false;
|
||||
|
||||
|
||||
// test default value retrieval
|
||||
$this->assertIdentical($config->get('Element', 'Abbr'), 'H');
|
||||
$this->assertIdentical($config->get('Element', 'Name'), 'hydrogen');
|
||||
@@ -38,7 +38,7 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
$this->assertIdentical($config->get('Element', 'Traits'), array('nonmetallic', 'odorless', 'flammable'));
|
||||
$this->assertIdentical($config->get('Element', 'IsotopeNames'), array(1 => 'protium', 2 => 'deuterium', 3 => 'tritium'));
|
||||
$this->assertIdentical($config->get('Element', 'Object'), new stdClass());
|
||||
|
||||
|
||||
// test setting values
|
||||
$config->set('Element', 'Abbr', 'Pu');
|
||||
$config->set('Element', 'Name', 'PLUTONIUM'); // test decaps
|
||||
@@ -49,13 +49,13 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
$config->set('Element', 'Traits', 'nuclear, heavy, actinide'); // test parsing
|
||||
$config->set('Element', 'IsotopeNames', array(238 => 'Plutonium-238', 239 => 'Plutonium-239'));
|
||||
$config->set('Element', 'Object', false); // unmodeled
|
||||
|
||||
|
||||
$this->expectError('Cannot set undefined directive Element.Metal to value');
|
||||
$config->set('Element', 'Metal', true);
|
||||
|
||||
|
||||
$this->expectError('Value for Element.Radioactive is of invalid type, should be bool');
|
||||
$config->set('Element', 'Radioactive', 'very');
|
||||
|
||||
|
||||
// test value retrieval
|
||||
$this->assertIdentical($config->get('Element', 'Abbr'), 'Pu');
|
||||
$this->assertIdentical($config->get('Element', 'Name'), 'plutonium');
|
||||
@@ -66,16 +66,16 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
$this->assertIdentical($config->get('Element', 'Traits'), array('nuclear', 'heavy', 'actinide'));
|
||||
$this->assertIdentical($config->get('Element', 'IsotopeNames'), array(238 => 'Plutonium-238', 239 => 'Plutonium-239'));
|
||||
$this->assertIdentical($config->get('Element', 'Object'), false);
|
||||
|
||||
|
||||
$this->expectError('Cannot retrieve value of undefined directive Element.Metal');
|
||||
$config->get('Element', 'Metal');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testEnumerated() {
|
||||
|
||||
|
||||
$this->schema->addNamespace('Instrument', 'Of the musical type.');
|
||||
|
||||
|
||||
// case sensitive
|
||||
$this->schema->add('Instrument', 'Manufacturer', 'Yamaha', 'string', false);
|
||||
$this->schema->addAllowedValues('Instrument', 'Manufacturer', array(
|
||||
@@ -83,7 +83,7 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
'Laubin' => true, 'Buffet' => true, 'other' => true));
|
||||
$this->schema->addValueAliases('Instrument', 'Manufacturer', array(
|
||||
'Selmer' => 'Conn-Selmer'));
|
||||
|
||||
|
||||
// case insensitive
|
||||
$this->schema->add('Instrument', 'Family', 'woodwind', 'istring', false);
|
||||
$this->schema->addAllowedValues('Instrument', 'Family', array(
|
||||
@@ -91,89 +91,89 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
'string' => true, 'keyboard' => true, 'electronic' => true));
|
||||
$this->schema->addValueAliases('Instrument', 'Family', array(
|
||||
'synth' => 'electronic'));
|
||||
|
||||
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->autoFinalize = false;
|
||||
|
||||
|
||||
// case sensitive
|
||||
|
||||
|
||||
$config->set('Instrument', 'Manufacturer', 'Vandoren');
|
||||
$this->assertIdentical($config->get('Instrument', 'Manufacturer'), 'Vandoren');
|
||||
|
||||
|
||||
$config->set('Instrument', 'Manufacturer', 'Selmer');
|
||||
$this->assertIdentical($config->get('Instrument', 'Manufacturer'), 'Conn-Selmer');
|
||||
|
||||
|
||||
$this->expectError('Value not supported, valid values are: Yamaha, Conn-Selmer, Vandoren, Laubin, Buffet, other');
|
||||
$config->set('Instrument', 'Manufacturer', 'buffet');
|
||||
|
||||
|
||||
// case insensitive
|
||||
|
||||
|
||||
$config->set('Instrument', 'Family', 'brass');
|
||||
$this->assertIdentical($config->get('Instrument', 'Family'), 'brass');
|
||||
|
||||
|
||||
$config->set('Instrument', 'Family', 'PERCUSSION');
|
||||
$this->assertIdentical($config->get('Instrument', 'Family'), 'percussion');
|
||||
|
||||
|
||||
$config->set('Instrument', 'Family', 'synth');
|
||||
$this->assertIdentical($config->get('Instrument', 'Family'), 'electronic');
|
||||
|
||||
|
||||
$config->set('Instrument', 'Family', 'Synth');
|
||||
$this->assertIdentical($config->get('Instrument', 'Family'), 'electronic');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testNull() {
|
||||
|
||||
|
||||
$this->schema->addNamespace('ReportCard');
|
||||
$this->schema->add('ReportCard', 'English', null, 'string', true);
|
||||
$this->schema->add('ReportCard', 'Absences', 0, 'int', false);
|
||||
|
||||
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->autoFinalize = false;
|
||||
|
||||
|
||||
$config->set('ReportCard', 'English', 'B-');
|
||||
$this->assertIdentical($config->get('ReportCard', 'English'), 'B-');
|
||||
|
||||
|
||||
$config->set('ReportCard', 'English', null); // not yet graded
|
||||
$this->assertIdentical($config->get('ReportCard', 'English'), null);
|
||||
|
||||
|
||||
// error
|
||||
$this->expectError('Value for ReportCard.Absences is of invalid type, should be int');
|
||||
$config->set('ReportCard', 'Absences', null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testAliases() {
|
||||
|
||||
|
||||
$this->schema->addNamespace('Home');
|
||||
$this->schema->add('Home', 'Rug', 3, 'int', false);
|
||||
$this->schema->addAlias('Home', 'Carpet', 'Home', 'Rug');
|
||||
|
||||
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->autoFinalize = false;
|
||||
|
||||
|
||||
$this->assertIdentical($config->get('Home', 'Rug'), 3);
|
||||
|
||||
|
||||
$this->expectError('Cannot get value from aliased directive, use real name Home.Rug');
|
||||
$config->get('Home', 'Carpet');
|
||||
|
||||
|
||||
$this->expectError('Home.Carpet is an alias, preferred directive name is Home.Rug');
|
||||
$config->set('Home', 'Carpet', 999);
|
||||
$this->assertIdentical($config->get('Home', 'Rug'), 999);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// test functionality based on method
|
||||
|
||||
|
||||
function test_getBatch() {
|
||||
|
||||
|
||||
$this->schema->addNamespace('Variables');
|
||||
$this->schema->add('Variables', 'TangentialAcceleration', 'a_tan', 'string', false);
|
||||
$this->schema->add('Variables', 'AngularAcceleration', 'alpha', 'string', false);
|
||||
|
||||
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->autoFinalize = false;
|
||||
|
||||
|
||||
// grab a namespace
|
||||
$this->assertIdentical(
|
||||
$config->getBatch('Variables'),
|
||||
@@ -182,82 +182,82 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
'AngularAcceleration' => 'alpha'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
// grab a non-existant namespace
|
||||
$this->expectError('Cannot retrieve undefined namespace Constants');
|
||||
$config->getBatch('Constants');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_loadIni() {
|
||||
|
||||
|
||||
$this->schema->addNamespace('Shortcut', 'Keyboard shortcuts for commands');
|
||||
$this->schema->add('Shortcut', 'Copy', 'c', 'istring', false);
|
||||
$this->schema->add('Shortcut', 'Paste', 'v', 'istring', false);
|
||||
$this->schema->add('Shortcut', 'Cut', 'x', 'istring', false);
|
||||
|
||||
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->autoFinalize = false;
|
||||
|
||||
|
||||
$config->loadIni(dirname(__FILE__) . '/ConfigTest-loadIni.ini');
|
||||
|
||||
|
||||
$this->assertIdentical($config->get('Shortcut', 'Copy'), 'q');
|
||||
$this->assertIdentical($config->get('Shortcut', 'Paste'), 'p');
|
||||
$this->assertIdentical($config->get('Shortcut', 'Cut'), 't');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_getHTMLDefinition() {
|
||||
|
||||
|
||||
// we actually want to use the old copy, because the definition
|
||||
// generation routines have dependencies on configuration values
|
||||
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$config->set('HTML', 'Doctype', 'XHTML 1.0 Strict');
|
||||
$config->autoFinalize = false;
|
||||
|
||||
|
||||
$def = $config->getCSSDefinition();
|
||||
$this->assertIsA($def, 'HTMLPurifier_CSSDefinition');
|
||||
|
||||
|
||||
$def = $config->getHTMLDefinition();
|
||||
$def2 = $config->getHTMLDefinition();
|
||||
$this->assertIsA($def, 'HTMLPurifier_HTMLDefinition');
|
||||
$this->assertSame($def, $def2);
|
||||
$this->assertTrue($def->setup);
|
||||
|
||||
|
||||
$old_def = clone $def2;
|
||||
|
||||
|
||||
$config->set('HTML', 'Doctype', 'HTML 4.01 Transitional');
|
||||
$def = $config->getHTMLDefinition();
|
||||
$this->assertIsA($def, 'HTMLPurifier_HTMLDefinition');
|
||||
$this->assertNotEqual($def, $old_def);
|
||||
$this->assertTrue($def->setup);
|
||||
|
||||
|
||||
// test retrieval of raw definition
|
||||
$config->set('HTML', 'DefinitionID', 'HTMLPurifier_ConfigTest->test_getHTMLDefinition()');
|
||||
$config->set('HTML', 'DefinitionRev', 3);
|
||||
$def = $config->getHTMLDefinition(true);
|
||||
$this->assertNotEqual($def, $old_def);
|
||||
$this->assertEqual(false, $def->setup);
|
||||
|
||||
|
||||
// auto initialization
|
||||
$config->getHTMLDefinition();
|
||||
$this->assertTrue($def->setup);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
function test_getCSSDefinition() {
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
$def = $config->getCSSDefinition();
|
||||
$this->assertIsA($def, 'HTMLPurifier_CSSDefinition');
|
||||
}
|
||||
|
||||
|
||||
function test_getDefinition() {
|
||||
$this->schema->addNamespace('Cache', 'Cache stuff');
|
||||
$this->schema->add('Cache', 'DefinitionImpl', null, 'string', true);
|
||||
@@ -266,7 +266,7 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
$this->expectException(new HTMLPurifier_Exception("Definition of Crust type not supported"));
|
||||
$config->getDefinition('Crust');
|
||||
}
|
||||
|
||||
|
||||
function test_loadArray() {
|
||||
// setup a few dummy namespaces/directives for our testing
|
||||
$this->schema->addNamespace('Zoo');
|
||||
@@ -274,16 +274,16 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
$this->schema->add('Zoo', 'Boar', 0, 'int', false);
|
||||
$this->schema->add('Zoo', 'Camel', 0, 'int', false);
|
||||
$this->schema->add('Zoo', 'Others', array(), 'list', false);
|
||||
|
||||
|
||||
$config_manual = new HTMLPurifier_Config($this->schema);
|
||||
$config_loadabbr = new HTMLPurifier_Config($this->schema);
|
||||
$config_loadfull = new HTMLPurifier_Config($this->schema);
|
||||
|
||||
|
||||
$config_manual->set('Zoo', 'Aadvark', 3);
|
||||
$config_manual->set('Zoo', 'Boar', 5);
|
||||
$config_manual->set('Zoo', 'Camel', 2000); // that's a lotta camels!
|
||||
$config_manual->set('Zoo', 'Others', array('Peacock', 'Dodo')); // wtf!
|
||||
|
||||
|
||||
// condensed form
|
||||
$config_loadabbr->loadArray(array(
|
||||
'Zoo.Aadvark' => 3,
|
||||
@@ -291,7 +291,7 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
'Zoo.Camel' => 2000,
|
||||
'Zoo.Others' => array('Peacock', 'Dodo')
|
||||
));
|
||||
|
||||
|
||||
// fully expanded form
|
||||
$config_loadfull->loadArray(array(
|
||||
'Zoo' => array(
|
||||
@@ -301,62 +301,62 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
'Others' => array('Peacock', 'Dodo')
|
||||
)
|
||||
));
|
||||
|
||||
|
||||
$this->assertIdentical($config_manual, $config_loadabbr);
|
||||
$this->assertIdentical($config_manual, $config_loadfull);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_create() {
|
||||
|
||||
|
||||
$this->schema->addNamespace('Cake');
|
||||
$this->schema->add('Cake', 'Sprinkles', 666, 'int', false);
|
||||
$this->schema->add('Cake', 'Flavor', 'vanilla', 'string', false);
|
||||
|
||||
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->set('Cake', 'Sprinkles', 42);
|
||||
|
||||
|
||||
// test flat pass-through
|
||||
$created_config = HTMLPurifier_Config::create($config, $this->schema);
|
||||
$this->assertIdentical($config, $created_config);
|
||||
|
||||
|
||||
// test loadArray
|
||||
$created_config = HTMLPurifier_Config::create(array('Cake.Sprinkles' => 42), $this->schema);
|
||||
$this->assertIdentical($config, $created_config);
|
||||
|
||||
|
||||
// test loadIni
|
||||
$created_config = HTMLPurifier_Config::create(dirname(__FILE__) . '/ConfigTest-create.ini', $this->schema);
|
||||
$this->assertIdentical($config, $created_config);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_finalize() {
|
||||
|
||||
|
||||
// test finalization
|
||||
|
||||
|
||||
$this->schema->addNamespace('Poem');
|
||||
$this->schema->add('Poem', 'Meter', 'iambic', 'string', false);
|
||||
|
||||
|
||||
$config = new HTMLPurifier_Config($this->schema);
|
||||
$config->autoFinalize = false;
|
||||
|
||||
|
||||
$config->set('Poem', 'Meter', 'irregular');
|
||||
|
||||
|
||||
$config->finalize();
|
||||
|
||||
|
||||
$this->expectError('Cannot set directive after finalization');
|
||||
$config->set('Poem', 'Meter', 'vedic');
|
||||
|
||||
|
||||
$this->expectError('Cannot load directives after finalization');
|
||||
$config->loadArray(array('Poem.Meter' => 'octosyllable'));
|
||||
|
||||
|
||||
$this->expectError('Cannot load directives after finalization');
|
||||
$config->loadIni(dirname(__FILE__) . '/ConfigTest-finalize.ini');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_loadArrayFromForm() {
|
||||
|
||||
|
||||
$this->schema->addNamespace('Pancake');
|
||||
$this->schema->add('Pancake', 'Mix', 'buttermilk', 'string', false);
|
||||
$this->schema->add('Pancake', 'Served', true, 'bool', false);
|
||||
@@ -368,7 +368,7 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
$this->schema->add('Toppings', 'DefinitionID', null, 'string', true);
|
||||
$this->schema->add('Toppings', 'DefinitionRev', 1, 'int', false);
|
||||
$this->schema->add('Toppings', 'Protected', 1, 'int', false);
|
||||
|
||||
|
||||
$get = array(
|
||||
'breakfast' => array(
|
||||
'Pancake.Mix' => 'nasty',
|
||||
@@ -383,7 +383,7 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
'Toppings.Protected' => '4',
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$config_expect = HTMLPurifier_Config::create(array(
|
||||
'Pancake.Served' => false,
|
||||
'Toppings.Syrup' => false,
|
||||
@@ -391,19 +391,19 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
'Toppings.Strawberries' => 999,
|
||||
'Toppings.Calories' => null
|
||||
), $this->schema);
|
||||
|
||||
|
||||
$config_result = HTMLPurifier_Config::loadArrayFromForm(
|
||||
$get, 'breakfast',
|
||||
array('Pancake.Served', 'Toppings', '-Toppings.Protected'),
|
||||
false, // mq fix
|
||||
$this->schema
|
||||
);
|
||||
|
||||
|
||||
$this->assertEqual($config_expect, $config_result);
|
||||
|
||||
|
||||
/*
|
||||
MAGIC QUOTES NOT TESTED!!!
|
||||
|
||||
|
||||
$get = array(
|
||||
'breakfast' => array(
|
||||
'Pancake.Mix' => 'n\\asty'
|
||||
@@ -416,7 +416,7 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
$this->assertEqual($config_expect, $config_result);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
function test_getAllowedDirectivesForForm() {
|
||||
$this->schema->addNamespace('Unused');
|
||||
$this->schema->add('Unused', 'Unused', 'Foobar', 'string', false);
|
||||
@@ -428,17 +428,17 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
|
||||
$this->schema->add('All', 'Blacklisted', 'Foobar', 'string', false); // explicitly blacklisted
|
||||
$this->schema->add('All', 'DefinitionID', 'Foobar', 'string', true); // auto-blacklisted
|
||||
$this->schema->add('All', 'DefinitionRev', 2, 'int', false); // auto-blacklisted
|
||||
|
||||
|
||||
$input = array('Partial.Allowed', 'All', '-All.Blacklisted');
|
||||
$output = HTMLPurifier_Config::getAllowedDirectivesForForm($input, $this->schema);
|
||||
$expect = array(
|
||||
array('Partial', 'Allowed'),
|
||||
array('All', 'Allowed')
|
||||
);
|
||||
|
||||
|
||||
$this->assertEqual($output, $expect);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -3,81 +3,81 @@
|
||||
// mocks
|
||||
class HTMLPurifier_ContextTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
protected $context;
|
||||
|
||||
|
||||
public function setUp() {
|
||||
$this->context = new HTMLPurifier_Context();
|
||||
}
|
||||
|
||||
|
||||
function testStandardUsage() {
|
||||
|
||||
|
||||
generate_mock_once('HTMLPurifier_IDAccumulator');
|
||||
|
||||
|
||||
$this->assertFalse($this->context->exists('IDAccumulator'));
|
||||
|
||||
|
||||
$accumulator = new HTMLPurifier_IDAccumulatorMock();
|
||||
$this->context->register('IDAccumulator', $accumulator);
|
||||
$this->assertTrue($this->context->exists('IDAccumulator'));
|
||||
|
||||
|
||||
$accumulator_2 =& $this->context->get('IDAccumulator');
|
||||
$this->assertReference($accumulator, $accumulator_2);
|
||||
|
||||
|
||||
$this->context->destroy('IDAccumulator');
|
||||
$this->assertFalse($this->context->exists('IDAccumulator'));
|
||||
|
||||
|
||||
$this->expectError('Attempted to retrieve non-existent variable IDAccumulator');
|
||||
$accumulator_3 =& $this->context->get('IDAccumulator');
|
||||
$this->assertNull($accumulator_3);
|
||||
|
||||
|
||||
$this->expectError('Attempted to destroy non-existent variable IDAccumulator');
|
||||
$this->context->destroy('IDAccumulator');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testReRegister() {
|
||||
|
||||
|
||||
$var = true;
|
||||
$this->context->register('OnceOnly', $var);
|
||||
|
||||
|
||||
$this->expectError('Name OnceOnly produces collision, cannot re-register');
|
||||
$this->context->register('OnceOnly', $var);
|
||||
|
||||
|
||||
// destroy it, now registration is okay
|
||||
$this->context->destroy('OnceOnly');
|
||||
$this->context->register('OnceOnly', $var);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_loadArray() {
|
||||
|
||||
|
||||
// references can be *really* wonky!
|
||||
|
||||
|
||||
$context_manual = new HTMLPurifier_Context();
|
||||
$context_load = new HTMLPurifier_Context();
|
||||
|
||||
|
||||
$var1 = 1;
|
||||
$var2 = 2;
|
||||
|
||||
|
||||
$context_manual->register('var1', $var1);
|
||||
$context_manual->register('var2', $var2);
|
||||
|
||||
|
||||
// you MUST set up the references when constructing the array,
|
||||
// otherwise the registered version will be a copy
|
||||
$array = array(
|
||||
'var1' => &$var1,
|
||||
'var2' => &$var2
|
||||
);
|
||||
|
||||
|
||||
$context_load->loadArray($array);
|
||||
$this->assertIdentical($context_manual, $context_load);
|
||||
|
||||
|
||||
$var1 = 10;
|
||||
$var2 = 20;
|
||||
|
||||
|
||||
$this->assertIdentical($context_manual, $context_load);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -4,52 +4,52 @@ generate_mock_once('HTMLPurifier_DefinitionCache');
|
||||
|
||||
class HTMLPurifier_DefinitionCache_Decorator_CleanupTest extends HTMLPurifier_DefinitionCache_DecoratorHarness
|
||||
{
|
||||
|
||||
|
||||
function setup() {
|
||||
$this->cache = new HTMLPurifier_DefinitionCache_Decorator_Cleanup();
|
||||
parent::setup();
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
$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() {
|
||||
$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() {
|
||||
$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() {
|
||||
$this->setupMockForSuccess('set');
|
||||
$this->assertEqual($this->cache->set($this->def, $this->config), true);
|
||||
}
|
||||
|
||||
|
||||
function test_replace() {
|
||||
$this->setupMockForSuccess('replace');
|
||||
$this->assertEqual($this->cache->replace($this->def, $this->config), true);
|
||||
}
|
||||
|
||||
|
||||
function test_add() {
|
||||
$this->setupMockForSuccess('add');
|
||||
$this->assertEqual($this->cache->add($this->def, $this->config), true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -4,66 +4,66 @@ generate_mock_once('HTMLPurifier_DefinitionCache');
|
||||
|
||||
class HTMLPurifier_DefinitionCache_Decorator_MemoryTest extends HTMLPurifier_DefinitionCache_DecoratorHarness
|
||||
{
|
||||
|
||||
|
||||
function setup() {
|
||||
$this->cache = new HTMLPurifier_DefinitionCache_Decorator_Memory();
|
||||
parent::setup();
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
$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() {
|
||||
$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() {
|
||||
$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() {
|
||||
$this->setupMockForFailure('set', 'get');
|
||||
$this->assertEqual($this->cache->set($this->def, $this->config), false);
|
||||
$this->cache->get($this->config);
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$this->setupMockForFailure('replace', 'get');
|
||||
$this->assertEqual($this->cache->replace($this->def, $this->config), false);
|
||||
$this->cache->get($this->config);
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$this->setupMockForFailure('add', 'get');
|
||||
$this->assertEqual($this->cache->add($this->def, $this->config), false);
|
||||
$this->cache->get($this->config);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,7 @@ generate_mock_once('HTMLPurifier_DefinitionCache');
|
||||
|
||||
class HTMLPurifier_DefinitionCache_DecoratorHarness extends HTMLPurifier_DefinitionCacheHarness
|
||||
{
|
||||
|
||||
|
||||
function setup() {
|
||||
$this->mock = new HTMLPurifier_DefinitionCacheMock();
|
||||
$this->mock->type = 'Test';
|
||||
@@ -12,11 +12,11 @@ class HTMLPurifier_DefinitionCache_DecoratorHarness extends HTMLPurifier_Definit
|
||||
$this->def = $this->generateDefinition();
|
||||
$this->config = $this->generateConfigMock();
|
||||
}
|
||||
|
||||
|
||||
function teardown() {
|
||||
unset($this->mock);
|
||||
unset($this->cache);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,40 +2,40 @@
|
||||
|
||||
class HTMLPurifier_DefinitionCache_DecoratorTest extends HTMLPurifier_DefinitionCacheHarness
|
||||
{
|
||||
|
||||
|
||||
function test() {
|
||||
|
||||
|
||||
generate_mock_once('HTMLPurifier_DefinitionCache');
|
||||
$mock = new HTMLPurifier_DefinitionCacheMock();
|
||||
$mock->type = 'Test';
|
||||
|
||||
|
||||
$cache = new HTMLPurifier_DefinitionCache_Decorator();
|
||||
$cache = $cache->decorate($mock);
|
||||
|
||||
|
||||
$this->assertIdentical($cache->type, $mock->type);
|
||||
|
||||
|
||||
$def = $this->generateDefinition();
|
||||
$config = $this->generateConfigMock();
|
||||
|
||||
|
||||
$mock->expectOnce('add', array($def, $config));
|
||||
$cache->add($def, $config);
|
||||
|
||||
|
||||
$mock->expectOnce('set', array($def, $config));
|
||||
$cache->set($def, $config);
|
||||
|
||||
|
||||
$mock->expectOnce('replace', array($def, $config));
|
||||
$cache->replace($def, $config);
|
||||
|
||||
|
||||
$mock->expectOnce('get', array($config));
|
||||
$cache->get($config);
|
||||
|
||||
|
||||
$mock->expectOnce('flush', array($config));
|
||||
$cache->flush($config);
|
||||
|
||||
|
||||
$mock->expectOnce('cleanup', array($config));
|
||||
$cache->cleanup($config);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,164 +2,164 @@
|
||||
|
||||
class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_DefinitionCacheHarness
|
||||
{
|
||||
|
||||
|
||||
function test() {
|
||||
|
||||
|
||||
$cache = new HTMLPurifier_DefinitionCache_Serializer('Test');
|
||||
|
||||
|
||||
$config = $this->generateConfigMock('serial');
|
||||
$config->setReturnValue('get', 2, array('Test', 'DefinitionRev'));
|
||||
$config->version = '1.0.0';
|
||||
|
||||
|
||||
$config_md5 = '1.0.0,serial,2';
|
||||
|
||||
|
||||
$file = realpath(
|
||||
$rel_file = HTMLPURIFIER_PREFIX . '/HTMLPurifier/DefinitionCache/Serializer/Test/' .
|
||||
$config_md5 . '.ser'
|
||||
);
|
||||
if($file && file_exists($file)) unlink($file); // prevent previous failures from causing problems
|
||||
|
||||
|
||||
$this->assertIdentical($config_md5, $cache->generateKey($config));
|
||||
|
||||
|
||||
$def_original = $this->generateDefinition();
|
||||
|
||||
|
||||
$cache->add($def_original, $config);
|
||||
$this->assertFileExist($rel_file);
|
||||
|
||||
|
||||
$file_generated = $cache->generateFilePath($config);
|
||||
$this->assertIdentical(realpath($rel_file), realpath($file_generated));
|
||||
|
||||
|
||||
$def_1 = $cache->get($config);
|
||||
$this->assertIdentical($def_original, $def_1);
|
||||
|
||||
|
||||
$def_original->info_random = 'changed';
|
||||
|
||||
|
||||
$cache->set($def_original, $config);
|
||||
$def_2 = $cache->get($config);
|
||||
|
||||
|
||||
$this->assertIdentical($def_original, $def_2);
|
||||
$this->assertNotEqual ($def_original, $def_1);
|
||||
|
||||
|
||||
$def_original->info_random = 'did it change?';
|
||||
|
||||
|
||||
$this->assertFalse($cache->add($def_original, $config));
|
||||
$def_3 = $cache->get($config);
|
||||
|
||||
|
||||
$this->assertNotEqual ($def_original, $def_3); // did not change!
|
||||
$this->assertIdentical($def_3, $def_2);
|
||||
|
||||
|
||||
$cache->replace($def_original, $config);
|
||||
$def_4 = $cache->get($config);
|
||||
$this->assertIdentical($def_original, $def_4);
|
||||
|
||||
|
||||
$cache->remove($config);
|
||||
$this->assertFileNotExist($file);
|
||||
|
||||
|
||||
$this->assertFalse($cache->replace($def_original, $config));
|
||||
$def_5 = $cache->get($config);
|
||||
$this->assertFalse($def_5);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_errors() {
|
||||
$cache = new HTMLPurifier_DefinitionCache_Serializer('Test');
|
||||
$def = $this->generateDefinition();
|
||||
$def->setup = true;
|
||||
$def->type = 'NotTest';
|
||||
$config = $this->generateConfigMock('testfoo');
|
||||
|
||||
|
||||
$this->expectError('Cannot use definition of type NotTest in cache for Test');
|
||||
$cache->add($def, $config);
|
||||
|
||||
|
||||
$this->expectError('Cannot use definition of type NotTest in cache for Test');
|
||||
$cache->set($def, $config);
|
||||
|
||||
|
||||
$this->expectError('Cannot use definition of type NotTest in cache for Test');
|
||||
$cache->replace($def, $config);
|
||||
}
|
||||
|
||||
|
||||
function test_flush() {
|
||||
|
||||
|
||||
$cache = new HTMLPurifier_DefinitionCache_Serializer('Test');
|
||||
|
||||
|
||||
$config1 = $this->generateConfigMock('test1');
|
||||
$config2 = $this->generateConfigMock('test2');
|
||||
$config3 = $this->generateConfigMock('test3');
|
||||
|
||||
|
||||
$def1 = $this->generateDefinition(array('info_candles' => 1));
|
||||
$def2 = $this->generateDefinition(array('info_candles' => 2));
|
||||
$def3 = $this->generateDefinition(array('info_candles' => 3));
|
||||
|
||||
|
||||
$cache->add($def1, $config1);
|
||||
$cache->add($def2, $config2);
|
||||
$cache->add($def3, $config3);
|
||||
|
||||
|
||||
$this->assertEqual($def1, $cache->get($config1));
|
||||
$this->assertEqual($def2, $cache->get($config2));
|
||||
$this->assertEqual($def3, $cache->get($config3));
|
||||
|
||||
|
||||
$cache->flush($config1); // only essential directive is %Cache.SerializerPath
|
||||
|
||||
|
||||
$this->assertFalse($cache->get($config1));
|
||||
$this->assertFalse($cache->get($config2));
|
||||
$this->assertFalse($cache->get($config3));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testCleanup() {
|
||||
|
||||
|
||||
$cache = new HTMLPurifier_DefinitionCache_Serializer('Test');
|
||||
|
||||
|
||||
// in order of age, oldest first
|
||||
// note that configurations are all identical, but version/revision
|
||||
// are different
|
||||
|
||||
|
||||
$config1 = $this->generateConfigMock();
|
||||
$config1->version = '0.9.0';
|
||||
$config1->setReturnValue('get', 574, array('Test', 'DefinitionRev'));
|
||||
$def1 = $this->generateDefinition(array('info' => 1));
|
||||
|
||||
|
||||
$config2 = $this->generateConfigMock();
|
||||
$config2->version = '1.0.0beta';
|
||||
$config2->setReturnValue('get', 1, array('Test', 'DefinitionRev'));
|
||||
$def2 = $this->generateDefinition(array('info' => 3));
|
||||
|
||||
|
||||
$cache->set($def1, $config1);
|
||||
$cache->cleanup($config1);
|
||||
$this->assertEqual($def1, $cache->get($config1)); // no change
|
||||
|
||||
|
||||
$cache->cleanup($config2);
|
||||
$this->assertFalse($cache->get($config1));
|
||||
$this->assertFalse($cache->get($config2));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testCleanupOnlySameID() {
|
||||
|
||||
|
||||
$cache = new HTMLPurifier_DefinitionCache_Serializer('Test');
|
||||
|
||||
|
||||
$config1 = $this->generateConfigMock('serial1');
|
||||
$config1->version = '1.0.0';
|
||||
$config1->setReturnValue('get', 1, array('Test', 'DefinitionRev'));
|
||||
$def1 = $this->generateDefinition(array('info' => 1));
|
||||
|
||||
|
||||
$config2 = $this->generateConfigMock('serial2');
|
||||
$config2->version = '1.0.0';
|
||||
$config2->setReturnValue('get', 34, array('Test', 'DefinitionRev'));
|
||||
$def2 = $this->generateDefinition(array('info' => 3));
|
||||
|
||||
|
||||
$cache->set($def1, $config1);
|
||||
$cache->cleanup($config1);
|
||||
$this->assertEqual($def1, $cache->get($config1)); // no change
|
||||
|
||||
|
||||
$cache->set($def2, $config2);
|
||||
$cache->cleanup($config2);
|
||||
$this->assertEqual($def1, $cache->get($config1));
|
||||
$this->assertEqual($def2, $cache->get($config2));
|
||||
|
||||
|
||||
$cache->flush($config1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Asserts that a file exists, ignoring the stat cache
|
||||
*/
|
||||
@@ -167,31 +167,31 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio
|
||||
clearstatcache();
|
||||
$this->assertTrue(file_exists($file), 'Expected ' . $file . ' exists');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Asserts that a file does not exist, ignoring the stat cache
|
||||
*/
|
||||
function assertFileNotExist($file) {
|
||||
$this->assertFalse(file_exists($file), 'Expected ' . $file . ' does not exist');
|
||||
}
|
||||
|
||||
|
||||
function testAlternatePath() {
|
||||
|
||||
|
||||
$cache = new HTMLPurifier_DefinitionCache_Serializer('Test');
|
||||
$config = $this->generateConfigMock('serial');
|
||||
$config->version = '1.0.0';
|
||||
$config->setReturnValue('get', 1, array('Test', 'DefinitionRev'));
|
||||
$dir = dirname(__FILE__) . '/SerializerTest';
|
||||
$config->setReturnValue('get', $dir, array('Cache', 'SerializerPath'));
|
||||
|
||||
|
||||
$def_original = $this->generateDefinition();
|
||||
$cache->add($def_original, $config);
|
||||
$this->assertFileExist($dir . '/Test/1.0.0,serial,1.ser');
|
||||
|
||||
|
||||
unlink($dir . '/Test/1.0.0,serial,1.ser');
|
||||
rmdir( $dir . '/Test');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,26 +2,26 @@
|
||||
|
||||
class HTMLPurifier_DefinitionCacheFactoryTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
protected $factory;
|
||||
protected $oldFactory;
|
||||
|
||||
|
||||
public function setUp() {
|
||||
parent::setup();
|
||||
$this->factory = new HTMLPurifier_DefinitionCacheFactory();
|
||||
$this->oldFactory = HTMLPurifier_DefinitionCacheFactory::instance();
|
||||
HTMLPurifier_DefinitionCacheFactory::instance($this->factory);
|
||||
}
|
||||
|
||||
|
||||
public function tearDown() {
|
||||
HTMLPurifier_DefinitionCacheFactory::instance($this->oldFactory);
|
||||
}
|
||||
|
||||
|
||||
function test_create() {
|
||||
$cache = $this->factory->create('Test', $this->config);
|
||||
$this->assertEqual($cache, new HTMLPurifier_DefinitionCache_Serializer('Test'));
|
||||
}
|
||||
|
||||
|
||||
function test_create_withDecorator() {
|
||||
$this->factory->addDecorator('Memory');
|
||||
$cache = $this->factory->create('Test', $this->config);
|
||||
@@ -29,7 +29,7 @@ class HTMLPurifier_DefinitionCacheFactoryTest extends HTMLPurifier_Harness
|
||||
$cache_real = $cache_real->decorate(new HTMLPurifier_DefinitionCache_Serializer('Test'));
|
||||
$this->assertEqual($cache, $cache_real);
|
||||
}
|
||||
|
||||
|
||||
function test_create_withDecoratorObject() {
|
||||
$this->factory->addDecorator(new HTMLPurifier_DefinitionCache_Decorator_Memory());
|
||||
$cache = $this->factory->create('Test', $this->config);
|
||||
@@ -37,26 +37,26 @@ class HTMLPurifier_DefinitionCacheFactoryTest extends HTMLPurifier_Harness
|
||||
$cache_real = $cache_real->decorate(new HTMLPurifier_DefinitionCache_Serializer('Test'));
|
||||
$this->assertEqual($cache, $cache_real);
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$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() {
|
||||
$this->config->set('Cache', 'DefinitionImpl', null);
|
||||
$cache = $this->factory->create('Test', $this->config);
|
||||
$this->assertEqual($cache, new HTMLPurifier_DefinitionCache_Null('Test'));
|
||||
}
|
||||
|
||||
|
||||
function test_register() {
|
||||
generate_mock_once('HTMLPurifier_DefinitionCache');
|
||||
$this->config->set('Cache', 'DefinitionImpl', 'TestCache');
|
||||
@@ -64,6 +64,6 @@ class HTMLPurifier_DefinitionCacheFactoryTest extends HTMLPurifier_Harness
|
||||
$cache = $this->factory->create('Test', $this->config);
|
||||
$this->assertIsA($cache, $class);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
class HTMLPurifier_DefinitionCacheHarness extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Generate a configuration mock object that returns $values
|
||||
* to a getBatch() call
|
||||
@@ -15,7 +15,7 @@ class HTMLPurifier_DefinitionCacheHarness extends HTMLPurifier_Harness
|
||||
$config->version = '1.0.0';
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an anonymous def that has been setup and named Test
|
||||
*/
|
||||
@@ -28,6 +28,6 @@ class HTMLPurifier_DefinitionCacheHarness extends HTMLPurifier_Harness
|
||||
}
|
||||
return $def;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,30 +2,30 @@
|
||||
|
||||
class HTMLPurifier_DefinitionCacheTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
function test_isOld() {
|
||||
// using null subclass because parent is abstract
|
||||
$cache = new HTMLPurifier_DefinitionCache_Null('Test');
|
||||
|
||||
|
||||
generate_mock_once('HTMLPurifier_Config');
|
||||
$config = new HTMLPurifier_ConfigMock();
|
||||
$config->version = '1.0.0'; // hopefully no conflicts
|
||||
$config->setReturnValue('get', 10, array('Test', 'DefinitionRev'));
|
||||
$config->setReturnValue('getBatchSerial', 'hash', array('Test'));
|
||||
|
||||
|
||||
$this->assertIdentical($cache->isOld('1.0.0,hash,10', $config), false);
|
||||
$this->assertIdentical($cache->isOld('1.5.0,hash,1', $config), true);
|
||||
|
||||
|
||||
$this->assertIdentical($cache->isOld('0.9.0,hash,1', $config), true);
|
||||
$this->assertIdentical($cache->isOld('1.0.0,hash,1', $config), true);
|
||||
$this->assertIdentical($cache->isOld('1.0.0beta,hash,11', $config), true);
|
||||
|
||||
|
||||
$this->assertIdentical($cache->isOld('0.9.0,hash2,1', $config), true);
|
||||
$this->assertIdentical($cache->isOld('1.0.0,hash2,1', $config), false); // if hash is different, don't touch!
|
||||
$this->assertIdentical($cache->isOld('1.0.0beta,hash2,11', $config), true);
|
||||
$this->assertIdentical($cache->isOld('1.0.0-dev,hash2,11', $config), true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,11 +2,11 @@
|
||||
|
||||
class HTMLPurifier_DoctypeRegistryTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
function test_register() {
|
||||
|
||||
|
||||
$registry = new HTMLPurifier_DoctypeRegistry();
|
||||
|
||||
|
||||
$d = $registry->register(
|
||||
$name = 'XHTML 1.0 Transitional',
|
||||
$xml = true,
|
||||
@@ -14,63 +14,63 @@ class HTMLPurifier_DoctypeRegistryTest extends HTMLPurifier_Harness
|
||||
$tidyModules = array('lenient-module'),
|
||||
$aliases = array('X10T')
|
||||
);
|
||||
|
||||
|
||||
$d2 = new HTMLPurifier_Doctype($name, $xml, $modules, $tidyModules, $aliases);
|
||||
|
||||
|
||||
$this->assertIdentical($d, $d2);
|
||||
$this->assertSame($d, $registry->get('XHTML 1.0 Transitional'));
|
||||
|
||||
|
||||
// test shorthand
|
||||
$d = $registry->register(
|
||||
$name = 'XHTML 1.0 Strict', true, 'module', 'Tidy', 'X10S'
|
||||
);
|
||||
$d2 = new HTMLPurifier_Doctype($name, true, array('module'), array('Tidy'), array('X10S'));
|
||||
|
||||
|
||||
$this->assertIdentical($d, $d2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_get() {
|
||||
|
||||
|
||||
// see also alias and register tests
|
||||
|
||||
|
||||
$registry = new HTMLPurifier_DoctypeRegistry();
|
||||
|
||||
|
||||
$this->expectError('Doctype XHTML 2.0 does not exist');
|
||||
$registry->get('XHTML 2.0');
|
||||
|
||||
|
||||
// prevent XSS
|
||||
$this->expectError('Doctype <foo> does not exist');
|
||||
$registry->get('<foo>');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testAliases() {
|
||||
|
||||
|
||||
$registry = new HTMLPurifier_DoctypeRegistry();
|
||||
|
||||
|
||||
$d1 = $registry->register('Doc1', true, array(), array(), array('1'));
|
||||
|
||||
|
||||
$this->assertSame($d1, $registry->get('Doc1'));
|
||||
$this->assertSame($d1, $registry->get('1'));
|
||||
|
||||
|
||||
$d2 = $registry->register('Doc2', true, array(), array(), array('2'));
|
||||
|
||||
|
||||
$this->assertSame($d2, $registry->get('Doc2'));
|
||||
$this->assertSame($d2, $registry->get('2'));
|
||||
|
||||
|
||||
$d3 = $registry->register('1', true, array(), array(), array());
|
||||
|
||||
|
||||
// literal name overrides alias
|
||||
$this->assertSame($d3, $registry->get('1'));
|
||||
|
||||
|
||||
$d4 = $registry->register('One', true, array(), array(), array('1'));
|
||||
|
||||
|
||||
$this->assertSame($d4, $registry->get('One'));
|
||||
// still it overrides
|
||||
$this->assertSame($d3, $registry->get('1'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,19 +2,19 @@
|
||||
|
||||
class HTMLPurifier_ElementDefTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
function test_mergeIn() {
|
||||
|
||||
|
||||
$def1 = new HTMLPurifier_ElementDef();
|
||||
$def2 = new HTMLPurifier_ElementDef();
|
||||
$def3 = new HTMLPurifier_ElementDef();
|
||||
|
||||
|
||||
$old = 1;
|
||||
$new = 2;
|
||||
$overloaded_old = 3;
|
||||
$overloaded_new = 4;
|
||||
$removed = 5;
|
||||
|
||||
|
||||
$def1->standalone = true;
|
||||
$def1->attr = array(
|
||||
0 => array('old-include'),
|
||||
@@ -36,7 +36,7 @@ class HTMLPurifier_ElementDefTest extends HTMLPurifier_Harness
|
||||
'old' => true,
|
||||
'removed-old' => true
|
||||
);
|
||||
|
||||
|
||||
$def2->standalone = false;
|
||||
$def2->attr = array(
|
||||
0 => array('new-include'),
|
||||
@@ -44,7 +44,7 @@ class HTMLPurifier_ElementDefTest extends HTMLPurifier_Harness
|
||||
'overloaded-attr' => $overloaded_new,
|
||||
'removed-attr' => false,
|
||||
);
|
||||
$def2->attr_transform_pre =
|
||||
$def2->attr_transform_pre =
|
||||
$def2->attr_transform_post = array(
|
||||
'new-transform' => $new,
|
||||
'overloaded-transform' => $overloaded_new,
|
||||
@@ -58,10 +58,10 @@ class HTMLPurifier_ElementDefTest extends HTMLPurifier_Harness
|
||||
'new' => true,
|
||||
'removed-old' => false
|
||||
);
|
||||
|
||||
|
||||
$def1->mergeIn($def2);
|
||||
$def1->mergeIn($def3); // empty, has no effect
|
||||
|
||||
|
||||
$this->assertIdentical($def1->standalone, true);
|
||||
$this->assertIdentical($def1->attr, array(
|
||||
0 => array('old-include', 'new-include'),
|
||||
@@ -83,8 +83,8 @@ class HTMLPurifier_ElementDefTest extends HTMLPurifier_Harness
|
||||
'old' => true,
|
||||
'new' => true
|
||||
));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,20 +2,20 @@
|
||||
|
||||
class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
protected $_entity_lookup;
|
||||
|
||||
|
||||
function setUp() {
|
||||
$this->_entity_lookup = HTMLPurifier_EntityLookup::instance();
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$this->assertCleanUTF8('Normal string.');
|
||||
$this->assertCleanUTF8("Test\tAllowed\nControl\rCharacters");
|
||||
@@ -28,7 +28,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
|
||||
// invalid codepoints
|
||||
$this->assertCleanUTF8("\xED\xB0\x80", '');
|
||||
}
|
||||
|
||||
|
||||
function test_convertToUTF8_noConvert() {
|
||||
// UTF-8 means that we don't touch it
|
||||
$this->assertIdentical(
|
||||
@@ -37,7 +37,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
|
||||
'Expected identical [Binary: F6]'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_convertToUTF8_spuriousEncoding() {
|
||||
$this->config->set('Core', 'Encoding', 'utf99');
|
||||
$this->expectError('Invalid encoding utf99');
|
||||
@@ -46,7 +46,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_convertToUTF8_iso8859_1() {
|
||||
$this->config->set('Core', 'Encoding', 'ISO-8859-1');
|
||||
$this->assertIdentical(
|
||||
@@ -54,7 +54,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
|
||||
"\xC3\xB6"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_convertToUTF8_withoutIconv() {
|
||||
$this->config->set('Core', 'Encoding', 'ISO-8859-1');
|
||||
$this->config->set('Test', 'ForceNoIconv', true);
|
||||
@@ -62,13 +62,13 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
|
||||
HTMLPurifier_Encoder::convertToUTF8("\xF6", $this->config, $this->context),
|
||||
"\xC3\xB6"
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function getZhongWen() {
|
||||
return "\xE4\xB8\xAD\xE6\x96\x87 (Chinese)";
|
||||
}
|
||||
|
||||
|
||||
function test_convertFromUTF8_utf8() {
|
||||
// UTF-8 means that we don't touch it
|
||||
$this->assertIdentical(
|
||||
@@ -76,7 +76,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
|
||||
"\xC3\xB6"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_convertFromUTF8_iso8859_1() {
|
||||
$this->config->set('Core', 'Encoding', 'ISO-8859-1');
|
||||
$this->assertIdentical(
|
||||
@@ -85,7 +85,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
|
||||
'Expected identical [Binary: F6]'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_convertFromUTF8_iconvNoChars() {
|
||||
if (!function_exists('iconv')) return;
|
||||
$this->config->set('Core', 'Encoding', 'ISO-8859-1');
|
||||
@@ -94,7 +94,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
|
||||
" (Chinese)"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_convertFromUTF8_phpNormal() {
|
||||
// Plain PHP implementation has slightly different behavior
|
||||
$this->config->set('Core', 'Encoding', 'ISO-8859-1');
|
||||
@@ -105,7 +105,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
|
||||
'Expected identical [Binary: F6]'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_convertFromUTF8_phpNoChars() {
|
||||
$this->config->set('Core', 'Encoding', 'ISO-8859-1');
|
||||
$this->config->set('Test', 'ForceNoIconv', true);
|
||||
@@ -114,7 +114,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
|
||||
"?? (Chinese)"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_convertFromUTF8_withProtection() {
|
||||
// Preserve the characters!
|
||||
$this->config->set('Core', 'Encoding', 'ISO-8859-1');
|
||||
@@ -123,30 +123,30 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
|
||||
HTMLPurifier_Encoder::convertFromUTF8($this->getZhongWen(), $this->config, $this->context),
|
||||
"中文 (Chinese)"
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_convertToASCIIDumbLossless() {
|
||||
|
||||
|
||||
// Uppercase thorn letter
|
||||
$this->assertIdentical(
|
||||
HTMLPurifier_Encoder::convertToASCIIDumbLossless("\xC3\x9Eorn"),
|
||||
"Þorn"
|
||||
);
|
||||
|
||||
|
||||
$this->assertIdentical(
|
||||
HTMLPurifier_Encoder::convertToASCIIDumbLossless("an"),
|
||||
"an"
|
||||
);
|
||||
|
||||
|
||||
// test up to four bytes
|
||||
$this->assertIdentical(
|
||||
HTMLPurifier_Encoder::convertToASCIIDumbLossless("\xF3\xA0\x80\xA0"),
|
||||
"󠀠"
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function assertASCIISupportCheck($enc, $ret) {
|
||||
$test = HTMLPurifier_Encoder::testEncodingSupportsASCII($enc, true);
|
||||
if ($test === false) return;
|
||||
@@ -159,14 +159,14 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
|
||||
$ret
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_testEncodingSupportsASCII() {
|
||||
$this->assertASCIISupportCheck('Shift_JIS', array("\xC2\xA5" => '\\', "\xE2\x80\xBE" => '~'));
|
||||
$this->assertASCIISupportCheck('JOHAB', array("\xE2\x82\xA9" => '\\'));
|
||||
$this->assertASCIISupportCheck('ISO-8859-1', array());
|
||||
$this->assertASCIISupportCheck('dontexist', array()); // canary
|
||||
}
|
||||
|
||||
|
||||
function testShiftJIS() {
|
||||
if (!function_exists('iconv')) return;
|
||||
$this->config->set('Core', 'Encoding', 'Shift_JIS');
|
||||
@@ -180,6 +180,6 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
|
||||
'\\~'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -4,23 +4,23 @@
|
||||
|
||||
class HTMLPurifier_EntityLookupTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
function test() {
|
||||
|
||||
|
||||
$lookup = HTMLPurifier_EntityLookup::instance();
|
||||
|
||||
|
||||
// latin char
|
||||
$this->assertIdentical('â', $lookup->table['acirc']);
|
||||
|
||||
|
||||
// special char
|
||||
$this->assertIdentical('"', $lookup->table['quot']);
|
||||
$this->assertIdentical('“', $lookup->table['ldquo']);
|
||||
$this->assertIdentical('<', $lookup->table['lt']); // expressed strangely in source file
|
||||
|
||||
|
||||
// symbol char
|
||||
$this->assertIdentical('θ', $lookup->table['theta']);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,21 +2,21 @@
|
||||
|
||||
class HTMLPurifier_EntityParserTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
protected $EntityParser;
|
||||
|
||||
|
||||
public function setUp() {
|
||||
$this->EntityParser = new HTMLPurifier_EntityParser();
|
||||
$this->_entity_lookup = HTMLPurifier_EntityLookup::instance();
|
||||
}
|
||||
|
||||
|
||||
function test_substituteNonSpecialEntities() {
|
||||
$char_theta = $this->_entity_lookup->table['theta'];
|
||||
$this->assertIdentical($char_theta,
|
||||
$this->EntityParser->substituteNonSpecialEntities('θ') );
|
||||
$this->assertIdentical('"',
|
||||
$this->EntityParser->substituteNonSpecialEntities('"') );
|
||||
|
||||
|
||||
// numeric tests, adapted from Feyd
|
||||
$args = array();
|
||||
$args[] = array(1114112,false );
|
||||
@@ -45,8 +45,8 @@ class HTMLPurifier_EntityParserTest extends HTMLPurifier_Harness
|
||||
$args[] = array(20108, 'E4BA8C' ); // 0x00004E8C
|
||||
$args[] = array(77, '4D' ); // 0x0000004D
|
||||
$args[] = array(66306, 'F0908C82'); // 0x00010302
|
||||
$args[] = array(1072, 'D0B0' ); // 0x00000430
|
||||
|
||||
$args[] = array(1072, 'D0B0' ); // 0x00000430
|
||||
|
||||
foreach ($args as $arg) {
|
||||
$string = '&#' . $arg[0] . ';' . // decimal
|
||||
'&#x' . dechex($arg[0]) . ';'; // hex
|
||||
@@ -70,15 +70,15 @@ class HTMLPurifier_EntityParserTest extends HTMLPurifier_Harness
|
||||
'Identical expectation [Hex: '. dechex($arg[0]) .']'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_substituteSpecialEntities() {
|
||||
$this->assertIdentical(
|
||||
"'",
|
||||
$this->EntityParser->substituteSpecialEntities(''')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -7,28 +7,28 @@ generate_mock_once('HTMLPurifier_ErrorCollector');
|
||||
*/
|
||||
class HTMLPurifier_ErrorCollectorEMock extends HTMLPurifier_ErrorCollectorMock
|
||||
{
|
||||
|
||||
|
||||
private $_context;
|
||||
private $_expected_context = array();
|
||||
private $_expected_context_at = array();
|
||||
|
||||
|
||||
public function prepare($context) {
|
||||
$this->_context = $context;
|
||||
}
|
||||
|
||||
|
||||
public function expectContext($key, $value) {
|
||||
$this->_expected_context[$key] = $value;
|
||||
}
|
||||
public function expectContextAt($step, $key, $value) {
|
||||
$this->_expected_context_at[$step][$key] = $value;
|
||||
}
|
||||
|
||||
|
||||
public function send($v1, $v2) {
|
||||
// test for context
|
||||
$context = SimpleTest::getContext();
|
||||
$test = $context->getTest();
|
||||
$mock = $this->mock;
|
||||
|
||||
|
||||
foreach ($this->_expected_context as $key => $value) {
|
||||
$test->assertEqual($value, $this->_context->get($key));
|
||||
}
|
||||
@@ -42,6 +42,6 @@ class HTMLPurifier_ErrorCollectorEMock extends HTMLPurifier_ErrorCollectorMock
|
||||
$args = func_get_args();
|
||||
$mock->invoke('send', $args);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -5,10 +5,10 @@
|
||||
*/
|
||||
class HTMLPurifier_ErrorCollectorTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
protected $language, $generator, $line;
|
||||
protected $collector;
|
||||
|
||||
|
||||
public function setup() {
|
||||
generate_mock_once('HTMLPurifier_Language');
|
||||
generate_mock_once('HTMLPurifier_Generator');
|
||||
@@ -25,113 +25,113 @@ class HTMLPurifier_ErrorCollectorTest extends HTMLPurifier_Harness
|
||||
$this->context->register('Generator', $this->generator);
|
||||
$this->collector = new HTMLPurifier_ErrorCollector($this->context);
|
||||
}
|
||||
|
||||
|
||||
function test() {
|
||||
|
||||
|
||||
$language = $this->language;
|
||||
$language->setReturnValue('getMessage', 'Message 1', array('message-1'));
|
||||
$language->setReturnValue('formatMessage', 'Message 2', array('message-2', array(1 => 'param')));
|
||||
$language->setReturnValue('formatMessage', ' at line 23', array('ErrorCollector: At line', array('line' => 23)));
|
||||
$language->setReturnValue('formatMessage', ' at line 3', array('ErrorCollector: At line', array('line' => 3)));
|
||||
|
||||
|
||||
$this->line = 23;
|
||||
$this->collector->send(E_ERROR, 'message-1');
|
||||
|
||||
|
||||
$this->line = 3;
|
||||
$this->collector->send(E_WARNING, 'message-2', 'param');
|
||||
|
||||
|
||||
$result = array(
|
||||
0 => array(23, E_ERROR, 'Message 1', array()),
|
||||
1 => array(3, E_WARNING, 'Message 2', array())
|
||||
);
|
||||
|
||||
|
||||
$this->assertIdentical($this->collector->getRaw(), $result);
|
||||
|
||||
|
||||
/*
|
||||
$formatted_result =
|
||||
$formatted_result =
|
||||
'<ul><li><strong>Warning</strong>: Message 2 at line 3</li>'.
|
||||
'<li><strong>Error</strong>: Message 1 at line 23</li></ul>';
|
||||
|
||||
|
||||
$this->assertIdentical($this->collector->getHTMLFormatted($this->config), $formatted_result);
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testNoErrors() {
|
||||
$this->language->setReturnValue('getMessage', 'No errors', array('ErrorCollector: No errors'));
|
||||
|
||||
|
||||
$formatted_result = '<p>No errors</p>';
|
||||
$this->assertIdentical(
|
||||
$this->collector->getHTMLFormatted($this->config),
|
||||
$formatted_result
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testNoLineNumbers() {
|
||||
$this->language->setReturnValue('getMessage', 'Message 1', array('message-1'));
|
||||
$this->language->setReturnValue('getMessage', 'Message 2', array('message-2'));
|
||||
|
||||
|
||||
$this->collector->send(E_ERROR, 'message-1');
|
||||
$this->collector->send(E_ERROR, 'message-2');
|
||||
|
||||
|
||||
$result = array(
|
||||
0 => array(false, E_ERROR, 'Message 1', array()),
|
||||
1 => array(false, E_ERROR, 'Message 2', array())
|
||||
);
|
||||
$this->assertIdentical($this->collector->getRaw(), $result);
|
||||
|
||||
|
||||
/*
|
||||
$formatted_result =
|
||||
$formatted_result =
|
||||
'<ul><li><strong>Error</strong>: Message 1</li>'.
|
||||
'<li><strong>Error</strong>: Message 2</li></ul>';
|
||||
$this->assertIdentical($this->collector->getHTMLFormatted($this->config), $formatted_result);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
function testContextSubstitutions() {
|
||||
|
||||
|
||||
$current_token = false;
|
||||
$this->context->register('CurrentToken', $current_token);
|
||||
|
||||
|
||||
// 0
|
||||
$current_token = new HTMLPurifier_Token_Start('a', array('href' => 'http://example.com'), 32);
|
||||
$this->language->setReturnValue('formatMessage', 'Token message',
|
||||
array('message-data-token', array('CurrentToken' => $current_token)));
|
||||
$this->collector->send(E_NOTICE, 'message-data-token');
|
||||
|
||||
|
||||
$current_attr = 'href';
|
||||
$this->language->setReturnValue('formatMessage', '$CurrentAttr.Name => $CurrentAttr.Value',
|
||||
array('message-attr', array('CurrentToken' => $current_token)));
|
||||
|
||||
|
||||
// 1
|
||||
$this->collector->send(E_NOTICE, 'message-attr'); // test when context isn't available
|
||||
|
||||
|
||||
// 2
|
||||
$this->context->register('CurrentAttr', $current_attr);
|
||||
$this->collector->send(E_NOTICE, 'message-attr');
|
||||
|
||||
|
||||
$result = array(
|
||||
0 => array(32, E_NOTICE, 'Token message', array()),
|
||||
1 => array(32, E_NOTICE, '$CurrentAttr.Name => $CurrentAttr.Value', array()),
|
||||
2 => array(32, E_NOTICE, 'href => http://example.com', array())
|
||||
);
|
||||
$this->assertIdentical($this->collector->getRaw(), $result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
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')));
|
||||
$this->language->setReturnValue('formatMessage', ' at line 4', array('ErrorCollector: At line', array('line' => 4)));
|
||||
|
||||
|
||||
$this->line = 4;
|
||||
$this->collector->start();
|
||||
$this->collector->send(E_WARNING, 'message-1');
|
||||
$this->collector->send(E_NOTICE, 'message-2');
|
||||
$this->collector->end(E_NOTICE, 'end-message', 'param');
|
||||
|
||||
|
||||
$expect = array(
|
||||
0 => array(4, E_NOTICE, 'End Message', array(
|
||||
0 => array(4, E_WARNING, 'Message 1', array()),
|
||||
@@ -140,7 +140,7 @@ class HTMLPurifier_ErrorCollectorTest extends HTMLPurifier_Harness
|
||||
);
|
||||
$result = $this->collector->getRaw();
|
||||
$this->assertIdentical($result, $expect);
|
||||
|
||||
|
||||
$formatted_expect =
|
||||
'<ul><li><strong>Notice</strong>: End Message at line 4<ul>'.
|
||||
'<li><strong>Warning</strong>: Message 1 at line 4</li>'.
|
||||
@@ -148,9 +148,9 @@ class HTMLPurifier_ErrorCollectorTest extends HTMLPurifier_Harness
|
||||
'</li></ul>';
|
||||
$formatted_result = $this->collector->getHTMLFormatted($this->config);
|
||||
$this->assertIdentical($formatted_result, $formatted_expect);
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -6,10 +6,10 @@
|
||||
*/
|
||||
class HTMLPurifier_ErrorsHarness extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
protected $config, $context;
|
||||
protected $collector, $generator, $callCount;
|
||||
|
||||
|
||||
public function setup() {
|
||||
$this->config = HTMLPurifier_Config::create(array('Core.CollectErrors' => true));
|
||||
$this->context = new HTMLPurifier_Context();
|
||||
@@ -19,19 +19,19 @@ class HTMLPurifier_ErrorsHarness extends HTMLPurifier_Harness
|
||||
$this->context->register('ErrorCollector', $this->collector);
|
||||
$this->callCount = 0;
|
||||
}
|
||||
|
||||
|
||||
protected function expectNoErrorCollection() {
|
||||
$this->collector->expectNever('send');
|
||||
}
|
||||
|
||||
|
||||
protected function expectErrorCollection() {
|
||||
$args = func_get_args();
|
||||
$this->collector->expectOnce('send', $args);
|
||||
}
|
||||
|
||||
|
||||
protected function expectContext($key, $value) {
|
||||
$this->collector->expectContext($key, $value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
// usual use case:
|
||||
function test_tokenizeHTML_extractStyleBlocks() {
|
||||
$this->config->set('Filter', 'ExtractStyleBlocks', true);
|
||||
@@ -19,7 +19,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function assertExtractStyleBlocks($html, $expect = true, $styles = array()) {
|
||||
$filter = new HTMLPurifier_Filter_ExtractStyleBlocks(); // disable cleaning
|
||||
if ($expect === true) $expect = $html;
|
||||
@@ -28,15 +28,15 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
|
||||
$this->assertIdentical($result, $expect);
|
||||
$this->assertIdentical($this->context->get('StyleBlocks'), $styles);
|
||||
}
|
||||
|
||||
|
||||
function test_extractStyleBlocks_preserve() {
|
||||
$this->assertExtractStyleBlocks('Foobar');
|
||||
}
|
||||
|
||||
|
||||
function test_extractStyleBlocks_allStyle() {
|
||||
$this->assertExtractStyleBlocks('<style>foo</style>', '', array('foo'));
|
||||
}
|
||||
|
||||
|
||||
function test_extractStyleBlocks_multipleBlocks() {
|
||||
$this->assertExtractStyleBlocks(
|
||||
"<style>1</style><style>2</style>NOP<style>4</style>",
|
||||
@@ -44,7 +44,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
|
||||
array('1', '2', '4')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_extractStyleBlocks_blockWithAttributes() {
|
||||
$this->assertExtractStyleBlocks(
|
||||
'<style type="text/css">css</style>',
|
||||
@@ -52,7 +52,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
|
||||
array('css')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_extractStyleBlocks_styleWithPadding() {
|
||||
$this->assertExtractStyleBlocks(
|
||||
"Alas<styled>Awesome</styled>\n<style>foo</style> Trendy!",
|
||||
@@ -60,7 +60,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
|
||||
array('foo')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function assertCleanCSS($input, $expect = true) {
|
||||
$filter = new HTMLPurifier_Filter_ExtractStyleBlocks();
|
||||
if ($expect === true) $expect = $input;
|
||||
@@ -69,22 +69,22 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
|
||||
$result = $filter->cleanCSS($input, $this->config, $this->context);
|
||||
$this->assertIdentical($result, $expect);
|
||||
}
|
||||
|
||||
|
||||
function test_cleanCSS_malformed() {
|
||||
$this->assertCleanCSS('</style>', '');
|
||||
}
|
||||
|
||||
|
||||
function test_cleanCSS_selector() {
|
||||
$this->assertCleanCSS("a .foo #id div.cl#foo {\nfont-weight:700;\n}");
|
||||
}
|
||||
|
||||
|
||||
function test_cleanCSS_angledBrackets() {
|
||||
$this->assertCleanCSS(
|
||||
".class {\nfont-family:'</style>';\n}",
|
||||
".class {\nfont-family:'\\3C /style\\3E ';\n}"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_cleanCSS_angledBrackets2() {
|
||||
// CSSTidy's behavior in this case is wrong, and should be fixed
|
||||
//$this->assertCleanCSS(
|
||||
@@ -92,24 +92,24 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
|
||||
// "span[title=\"\\3C /style\\3E \"] {\nfont-size:12pt;\n}"
|
||||
//);
|
||||
}
|
||||
|
||||
|
||||
function test_cleanCSS_bogus() {
|
||||
$this->assertCleanCSS("div {bogus:tree;}", "div {\n}");
|
||||
}
|
||||
|
||||
|
||||
function test_cleanCSS_escapeCodes() {
|
||||
$this->assertCleanCSS(
|
||||
".class {\nfont-family:'\\3C /style\\3E ';\n}"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_cleanCSS_noEscapeCodes() {
|
||||
$this->config->set('FilterParam', 'ExtractStyleBlocksEscaping', false);
|
||||
$this->assertCleanCSS(
|
||||
".class {\nfont-family:'</style>';\n}"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_cleanCSS_scope() {
|
||||
$this->config->set('FilterParam', 'ExtractStyleBlocksScope', '#foo');
|
||||
$this->assertCleanCSS(
|
||||
@@ -117,7 +117,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
|
||||
"#foo p {\ntext-indent:1em;\n}"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_cleanCSS_scopeWithSelectorCommas() {
|
||||
$this->config->set('FilterParam', 'ExtractStyleBlocksScope', '#foo');
|
||||
$this->assertCleanCSS(
|
||||
@@ -125,17 +125,17 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
|
||||
"#foo b, #foo i {\ntext-decoration:underline;\n}"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_cleanCSS_scopeWithNaughtySelector() {
|
||||
$this->config->set('FilterParam', 'ExtractStyleBlocksScope', '#foo');
|
||||
$this->assertCleanCSS(" + p {\ntext-indent:1em;\n}", '');
|
||||
}
|
||||
|
||||
|
||||
function test_cleanCSS_scopeWithMultipleNaughtySelectors() {
|
||||
$this->config->set('FilterParam', 'ExtractStyleBlocksScope', '#foo');
|
||||
$this->assertCleanCSS(" ++ ++ p {\ntext-indent:1em;\n}", '');
|
||||
}
|
||||
|
||||
|
||||
function test_cleanCSS_scopeWithCommas() {
|
||||
$this->config->set('FilterParam', 'ExtractStyleBlocksScope', '#foo, .bar');
|
||||
$this->assertCleanCSS(
|
||||
@@ -143,7 +143,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
|
||||
"#foo p, .bar p {\ntext-indent:1em;\n}"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_cleanCSS_scopeAllWithCommas() {
|
||||
$this->config->set('FilterParam', 'ExtractStyleBlocksScope', '#foo, .bar');
|
||||
$this->assertCleanCSS(
|
||||
@@ -151,7 +151,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
|
||||
"#foo p, #foo div, .bar p, .bar div {\ntext-indent:1em;\n}"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_cleanCSS_scopeWithConflicts() {
|
||||
$this->config->set('FilterParam', 'ExtractStyleBlocksScope', 'p');
|
||||
$this->assertCleanCSS(
|
||||
@@ -172,7 +172,7 @@ text-align:left;
|
||||
}"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_removeComments() {
|
||||
$this->assertCleanCSS(
|
||||
"<!--
|
||||
@@ -185,5 +185,5 @@ text-align:right;
|
||||
}"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -2,42 +2,42 @@
|
||||
|
||||
class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Entity lookup table to help for a few tests.
|
||||
*/
|
||||
private $_entity_lookup;
|
||||
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->_entity_lookup = HTMLPurifier_EntityLookup::instance();
|
||||
}
|
||||
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->config->set('Output', 'Newline', "\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a generator based on config and context member variables.
|
||||
*/
|
||||
protected function createGenerator() {
|
||||
return new HTMLPurifier_Generator($this->config, $this->context);
|
||||
}
|
||||
|
||||
|
||||
protected function assertGenerateFromToken($token, $html) {
|
||||
$generator = $this->createGenerator();
|
||||
$result = $generator->generateFromToken($token);
|
||||
$this->assertIdentical($result, $html);
|
||||
}
|
||||
|
||||
|
||||
function test_generateFromToken_text() {
|
||||
$this->assertGenerateFromToken(
|
||||
new HTMLPurifier_Token_Text('Foobar.<>'),
|
||||
'Foobar.<>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_generateFromToken_startWithAttr() {
|
||||
$this->assertGenerateFromToken(
|
||||
new HTMLPurifier_Token_Start('a',
|
||||
@@ -46,14 +46,14 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
||||
'<a href="dyn?a=foo&b=bar">'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_generateFromToken_end() {
|
||||
$this->assertGenerateFromToken(
|
||||
new HTMLPurifier_Token_End('b'),
|
||||
'</b>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_generateFromToken_emptyWithAttr() {
|
||||
$this->assertGenerateFromToken(
|
||||
new HTMLPurifier_Token_Empty('br',
|
||||
@@ -62,26 +62,26 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
||||
'<br style="font-family:"Courier New";" />'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_generateFromToken_startNoAttr() {
|
||||
$this->assertGenerateFromToken(
|
||||
new HTMLPurifier_Token_Start('asdf'),
|
||||
'<asdf>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_generateFromToken_emptyNoAttr() {
|
||||
$this->assertGenerateFromToken(
|
||||
new HTMLPurifier_Token_Empty('br'),
|
||||
'<br />'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_generateFromToken_error() {
|
||||
$this->expectError('Cannot generate HTML from non-HTMLPurifier_Token object');
|
||||
$this->assertGenerateFromToken( null, '' );
|
||||
}
|
||||
|
||||
|
||||
function test_generateFromToken_() {
|
||||
$theta_char = $this->_entity_lookup->table['theta'];
|
||||
$this->assertGenerateFromToken(
|
||||
@@ -89,45 +89,45 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
||||
$theta_char
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function assertGenerateAttributes($attr, $expect, $element = false) {
|
||||
$generator = $this->createGenerator();
|
||||
$result = $generator->generateAttributes($attr, $element);
|
||||
$this->assertIdentical($result, $expect);
|
||||
}
|
||||
|
||||
|
||||
function test_generateAttributes_blank() {
|
||||
$this->assertGenerateAttributes(array(), '');
|
||||
}
|
||||
|
||||
|
||||
function test_generateAttributes_basic() {
|
||||
$this->assertGenerateAttributes(
|
||||
array('href' => 'dyn?a=foo&b=bar'),
|
||||
'href="dyn?a=foo&b=bar"'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_generateAttributes_doubleQuote() {
|
||||
$this->assertGenerateAttributes(
|
||||
array('style' => 'font-family:"Courier New";'),
|
||||
'style="font-family:"Courier New";"'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_generateAttributes_singleQuote() {
|
||||
$this->assertGenerateAttributes(
|
||||
array('style' => 'font-family:\'Courier New\';'),
|
||||
'style="font-family:\'Courier New\';"'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_generateAttributes_multiple() {
|
||||
$this->assertGenerateAttributes(
|
||||
array('src' => 'picture.jpg', 'alt' => 'Short & interesting'),
|
||||
'src="picture.jpg" alt="Short & interesting"'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_generateAttributes_specialChar() {
|
||||
$theta_char = $this->_entity_lookup->table['theta'];
|
||||
$this->assertGenerateAttributes(
|
||||
@@ -135,17 +135,17 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
||||
'title="Theta is ' . $theta_char . '"'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function test_generateAttributes_minimized() {
|
||||
$this->config->set('HTML', 'Doctype', 'HTML 4.01 Transitional');
|
||||
$this->assertGenerateAttributes(
|
||||
array('compact' => 'compact'), 'compact', 'menu'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_generateFromTokens() {
|
||||
|
||||
|
||||
$this->assertGeneration(
|
||||
array(
|
||||
new HTMLPurifier_Token_Start('b'),
|
||||
@@ -154,15 +154,15 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
||||
),
|
||||
'<b>Foobar!</b>'
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$this->assertGeneration(
|
||||
array(
|
||||
@@ -173,7 +173,7 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
||||
"<script><!--//--><![CDATA[//><!--\nalert(3 < 5);\n//--><!]]></script>"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_generateFromTokens_Scripting_missingCloseTag() {
|
||||
$this->assertGeneration(
|
||||
array(
|
||||
@@ -183,7 +183,7 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
||||
"<script>alert(3 < 5);"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_generateFromTokens_Scripting_doubleBlock() {
|
||||
$this->assertGeneration(
|
||||
array(
|
||||
@@ -195,7 +195,7 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
||||
"<script>alert(3 < 5);foo();</script>"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_generateFromTokens_Scripting_disableWrapper() {
|
||||
$this->config->set('Output', 'CommentScriptContents', false);
|
||||
$this->assertGeneration(
|
||||
@@ -207,38 +207,38 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
||||
"<script>alert(3 < 5);</script>"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_generateFromTokens_XHTMLoff() {
|
||||
$this->config->set('HTML', 'XHTML', false);
|
||||
|
||||
|
||||
// omit trailing slash
|
||||
$this->assertGeneration(
|
||||
array( new HTMLPurifier_Token_Empty('br') ),
|
||||
'<br>'
|
||||
);
|
||||
|
||||
|
||||
// there should be a test for attribute minimization, but it is
|
||||
// impossible for something like that to happen due to our current
|
||||
// definitions! fix it later
|
||||
|
||||
|
||||
// namespaced attributes must be dropped
|
||||
$this->assertGeneration(
|
||||
array( new HTMLPurifier_Token_Start('p', array('xml:lang'=>'fr')) ),
|
||||
'<p>'
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_generateFromTokens_TidyFormat() {
|
||||
// abort test if tidy isn't loaded
|
||||
if (!extension_loaded('tidy')) return;
|
||||
|
||||
|
||||
// just don't test; Tidy is exploding on me.
|
||||
return;
|
||||
|
||||
|
||||
$this->config->set('Core', 'TidyFormat', true);
|
||||
$this->config->set('Output', 'Newline', "\n");
|
||||
|
||||
|
||||
// nice wrapping please
|
||||
$this->assertGeneration(
|
||||
array(
|
||||
@@ -248,18 +248,18 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness
|
||||
),
|
||||
"<div>\n Text\n</div>\n"
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_generateFromTokens_sortAttr() {
|
||||
$this->config->set('Output', 'SortAttr', true);
|
||||
|
||||
|
||||
$this->assertGeneration(
|
||||
array( new HTMLPurifier_Token_Start('p', array('b'=>'c', 'a'=>'d')) ),
|
||||
'<p a="d" b="c">'
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,53 +2,53 @@
|
||||
|
||||
class HTMLPurifier_HTMLDefinitionTest extends HTMLPurifier_Harness
|
||||
{
|
||||
|
||||
|
||||
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() {
|
||||
|
||||
|
||||
$def = new HTMLPurifier_HTMLDefinition();
|
||||
|
||||
// note: this is case-sensitive, but its config schema
|
||||
|
||||
// note: this is case-sensitive, but its config schema
|
||||
// counterpart is not. This is generally a good thing for users,
|
||||
// but it's a slight internal inconsistency
|
||||
|
||||
|
||||
$this->assertEqual(
|
||||
$def->parseTinyMCEAllowedList(''),
|
||||
array(array(), array())
|
||||
);
|
||||
|
||||
|
||||
$this->assertEqual(
|
||||
$def->parseTinyMCEAllowedList('a,b,c'),
|
||||
array(array('a' => true, 'b' => true, 'c' => true), array())
|
||||
);
|
||||
|
||||
|
||||
$this->assertEqual(
|
||||
$def->parseTinyMCEAllowedList('a[x|y|z]'),
|
||||
array(array('a' => true), array('a.x' => true, 'a.y' => true, 'a.z' => true))
|
||||
);
|
||||
|
||||
|
||||
$this->assertEqual(
|
||||
$def->parseTinyMCEAllowedList('*[id]'),
|
||||
array(array(), array('*.id' => true))
|
||||
);
|
||||
|
||||
|
||||
$this->assertEqual(
|
||||
$def->parseTinyMCEAllowedList('a[*]'),
|
||||
array(array('a' => true), array('a.*' => true))
|
||||
);
|
||||
|
||||
|
||||
$this->assertEqual(
|
||||
$def->parseTinyMCEAllowedList('span[style],strong,a[href|title]'),
|
||||
array(array('span' => true, 'strong' => true, 'a' => true),
|
||||
array('span.style' => true, 'a.href' => true, 'a.title' => true))
|
||||
);
|
||||
|
||||
|
||||
$this->assertEqual(
|
||||
// alternate form:
|
||||
$def->parseTinyMCEAllowedList(
|
||||
@@ -59,100 +59,100 @@ a[href|title]
|
||||
$val = array(array('span' => true, 'strong' => true, 'a' => true),
|
||||
array('span.style' => true, 'a.href' => true, 'a.title' => true))
|
||||
);
|
||||
|
||||
|
||||
$this->assertEqual(
|
||||
$def->parseTinyMCEAllowedList(' span [ style ], strong'."\n\t".'a[href | title]'),
|
||||
$val
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_Allowed() {
|
||||
|
||||
|
||||
$config1 = HTMLPurifier_Config::create(array(
|
||||
'HTML.AllowedElements' => array('b', 'i', 'p', 'a'),
|
||||
'HTML.AllowedAttributes' => array('a@href', '*@id')
|
||||
));
|
||||
|
||||
|
||||
$config2 = HTMLPurifier_Config::create(array(
|
||||
'HTML.Allowed' => 'b,i,p,a[href],*[id]'
|
||||
));
|
||||
|
||||
|
||||
$this->assertEqual($config1->getHTMLDefinition(), $config2->getHTMLDefinition());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function assertPurification_AllowedElements_p() {
|
||||
$this->assertPurification('<p><b>Jelly</b></p>', '<p>Jelly</p>');
|
||||
}
|
||||
|
||||
|
||||
function test_AllowedElements() {
|
||||
$this->config->set('HTML', 'AllowedElements', 'p');
|
||||
$this->assertPurification_AllowedElements_p();
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$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() {
|
||||
$this->config->set('HTML', 'AllowedElements', '<script>,p');
|
||||
$this->expectError(new PatternExpectation("/Element '<script>' is not supported/"));
|
||||
$this->assertPurification_AllowedElements_p();
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$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() {
|
||||
$this->config->set('HTML', 'AllowedAttributes', 'style');
|
||||
$this->assertPurification_AllowedAttributes_global_style();
|
||||
}
|
||||
|
||||
|
||||
function test_AllowedAttributes_global_verboseSyntax() {
|
||||
$this->config->set('HTML', 'AllowedAttributes', '*@style');
|
||||
$this->assertPurification_AllowedAttributes_global_style();
|
||||
}
|
||||
|
||||
|
||||
function test_AllowedAttributes_global_discouragedSyntax() {
|
||||
// Emit errors eventually
|
||||
$this->config->set('HTML', 'AllowedAttributes', '*.style');
|
||||
$this->assertPurification_AllowedAttributes_global_style();
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$this->config->set('HTML', 'AllowedAttributes', 'p@style');
|
||||
$this->assertPurification_AllowedAttributes_local_p_style();
|
||||
}
|
||||
|
||||
|
||||
function test_AllowedAttributes_local_discouragedSyntax() {
|
||||
$this->config->set('HTML', 'AllowedAttributes', 'p.style');
|
||||
$this->assertPurification_AllowedAttributes_local_p_style();
|
||||
}
|
||||
|
||||
|
||||
function test_AllowedAttributes_multiple() {
|
||||
$this->config->set('HTML', 'AllowedAttributes', 'p@style,br@class,title');
|
||||
$this->assertPurification(
|
||||
@@ -160,192 +160,192 @@ a[href|title]
|
||||
'<p style="font-weight:bold;" title="foo">Jelly</p><br class="foo" title="foo" />'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_AllowedAttributes_local_invalidAttribute() {
|
||||
$this->config->set('HTML', 'AllowedAttributes', array('p@style', 'p@<foo>'));
|
||||
$this->expectError(new PatternExpectation("/Attribute '<foo>' in element 'p' not supported/"));
|
||||
$this->assertPurification_AllowedAttributes_local_p_style();
|
||||
}
|
||||
|
||||
|
||||
function test_AllowedAttributes_global_invalidAttribute() {
|
||||
$this->config->set('HTML', 'AllowedAttributes', array('style', '<foo>'));
|
||||
$this->expectError(new PatternExpectation("/Global attribute '<foo>' is not supported in any elements/"));
|
||||
$this->assertPurification_AllowedAttributes_global_style();
|
||||
}
|
||||
|
||||
|
||||
function test_AllowedAttributes_local_invalidAttributeDueToMissingElement() {
|
||||
$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() {
|
||||
$this->config->set('HTML', 'AllowedAttributes', 'p.style,p@style');
|
||||
$this->assertPurification_AllowedAttributes_local_p_style();
|
||||
}
|
||||
|
||||
|
||||
function test_AllowedAttributes_multipleErrors() {
|
||||
$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/"));
|
||||
$this->expectError(new PatternExpectation("/Global attribute '<foo>' is not supported in any elements/"));
|
||||
$this->assertPurification_AllowedAttributes_local_p_style();
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$this->config->set('HTML', 'ForbiddenElements', 'obviously_incorrect');
|
||||
// no error!
|
||||
$this->assertPurification('<i>i</i>');
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$this->config->set('HTML', 'ForbiddenAttributes', 'b@style');
|
||||
$this->assertPurification_ForbiddenAttributes_b_style();
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
$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() {
|
||||
$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() {
|
||||
$this->config->set('HTML', 'ForbiddenAttributes', 'style');
|
||||
$this->assertPurification_ForbiddenAttributes_style();
|
||||
}
|
||||
|
||||
|
||||
function test_ForbiddenAttributes_globalVerboseFormat() {
|
||||
$this->config->set('HTML', 'ForbiddenAttributes', '*@style');
|
||||
$this->assertPurification_ForbiddenAttributes_style();
|
||||
}
|
||||
|
||||
|
||||
function test_addAttribute() {
|
||||
|
||||
|
||||
$config = HTMLPurifier_Config::create(array(
|
||||
'HTML.DefinitionID' => 'HTMLPurifier_HTMLDefinitionTest->test_addAttribute'
|
||||
));
|
||||
$def = $config->getHTMLDefinition(true);
|
||||
$def->addAttribute('span', 'custom', 'Enum#attribute');
|
||||
|
||||
|
||||
$purifier = new HTMLPurifier($config);
|
||||
$input = '<span custom="attribute">Custom!</span>';
|
||||
$output = $purifier->purify($input);
|
||||
$this->assertIdentical($input, $output);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_addAttribute_multiple() {
|
||||
|
||||
|
||||
$config = HTMLPurifier_Config::create(array(
|
||||
'HTML.DefinitionID' => 'HTMLPurifier_HTMLDefinitionTest->test_addAttribute_multiple'
|
||||
));
|
||||
$def = $config->getHTMLDefinition(true);
|
||||
$def->addAttribute('span', 'custom', 'Enum#attribute');
|
||||
$def->addAttribute('span', 'foo', 'Text');
|
||||
|
||||
|
||||
$purifier = new HTMLPurifier($config);
|
||||
$input = '<span custom="attribute" foo="asdf">Custom!</span>';
|
||||
$output = $purifier->purify($input);
|
||||
$this->assertIdentical($input, $output);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_addElement() {
|
||||
|
||||
|
||||
$config = HTMLPurifier_Config::create(array(
|
||||
'HTML.DefinitionID' => 'HTMLPurifier_HTMLDefinitionTest->test_addElement'
|
||||
));
|
||||
$def = $config->getHTMLDefinition(true);
|
||||
$def->addElement('marquee', 'Inline', 'Inline', 'Common', array('width' => 'Length'));
|
||||
|
||||
|
||||
$purifier = new HTMLPurifier($config);
|
||||
$input = '<span><marquee width="50">Foobar</marquee></span>';
|
||||
$output = $purifier->purify($input);
|
||||
$this->assertIdentical($input, $output);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_injector() {
|
||||
$this->config->set('HTML', 'DefinitionID', 'HTMLPurifier_HTMLDefinitionTest->test_injector');
|
||||
|
||||
|
||||
generate_mock_once('HTMLPurifier_Injector');
|
||||
$injector = new HTMLPurifier_InjectorMock();
|
||||
$injector->name = 'MyInjector';
|
||||
$injector->setReturnValue('checkNeeded', false);
|
||||
|
||||
|
||||
$module = $this->config->getHTMLDefinition(true)->getAnonymousModule();
|
||||
$module->info_injector[] = $injector;
|
||||
|
||||
|
||||
$this->assertIdentical($this->config->getHTMLDefinition()->info_injector,
|
||||
array(
|
||||
'MyInjector' => $injector,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_injectorMissingNeeded() {
|
||||
$this->config->set('HTML', 'DefinitionID', 'HTMLPurifier_HTMLDefinitionTest->test_injectorMissingNeeded');
|
||||
|
||||
|
||||
generate_mock_once('HTMLPurifier_Injector');
|
||||
$injector = new HTMLPurifier_InjectorMock();
|
||||
$injector->name = 'MyInjector';
|
||||
$injector->setReturnValue('checkNeeded', 'a');
|
||||
|
||||
|
||||
$module = $this->config->getHTMLDefinition(true)->getAnonymousModule();
|
||||
$module->info_injector[] = $injector;
|
||||
|
||||
|
||||
$this->assertIdentical($this->config->getHTMLDefinition()->info_injector,
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_injectorIntegration() {
|
||||
$this->config->set('HTML', 'DefinitionID', 'HTMLPurifier_HTMLDefinitionTest->test_injectorIntegration');
|
||||
|
||||
|
||||
$module = $this->config->getHTMLDefinition(true)->getAnonymousModule();
|
||||
$module->info_injector[] = 'Linkify';
|
||||
|
||||
|
||||
$this->assertIdentical(
|
||||
$this->config->getHTMLDefinition()->info_injector,
|
||||
array('Linkify' => new HTMLPurifier_Injector_Linkify())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function test_injectorIntegrationFail() {
|
||||
$this->config->set('HTML', 'DefinitionID', 'HTMLPurifier_HTMLDefinitionTest->test_injectorIntegrationFail');
|
||||
|
||||
|
||||
$this->config->set('HTML', 'Allowed', 'p');
|
||||
|
||||
|
||||
$module = $this->config->getHTMLDefinition(true)->getAnonymousModule();
|
||||
$module->info_injector[] = 'Linkify';
|
||||
|
||||
|
||||
$this->assertIdentical(
|
||||
$this->config->getHTMLDefinition()->info_injector,
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,14 +2,14 @@
|
||||
|
||||
class HTMLPurifier_HTMLModule_FormsTest extends HTMLPurifier_HTMLModuleHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->config->set('HTML', 'Trusted', true);
|
||||
$this->config->set('Attr', 'EnableID', true);
|
||||
$this->config->set('Cache', 'DefinitionImpl', null);
|
||||
}
|
||||
|
||||
|
||||
function testBasicUse() {
|
||||
$this->assertResult( // need support for label for later
|
||||
'
|
||||
@@ -28,7 +28,7 @@ class HTMLPurifier_HTMLModule_FormsTest extends HTMLPurifier_HTMLModuleHarness
|
||||
</form>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testSelectOption() {
|
||||
$this->assertResult('
|
||||
<form action="http://somesite.com/prog/component-select" method="post">
|
||||
@@ -47,7 +47,7 @@ class HTMLPurifier_HTMLModule_FormsTest extends HTMLPurifier_HTMLModuleHarness
|
||||
</form>
|
||||
');
|
||||
}
|
||||
|
||||
|
||||
function testSelectOptgroup() {
|
||||
$this->assertResult('
|
||||
<form action="http://somesite.com/prog/someprog" method="post">
|
||||
@@ -72,7 +72,7 @@ class HTMLPurifier_HTMLModule_FormsTest extends HTMLPurifier_HTMLModuleHarness
|
||||
</form>
|
||||
');
|
||||
}
|
||||
|
||||
|
||||
function testTextarea() {
|
||||
$this->assertResult('
|
||||
<form action="http://somesite.com/prog/text-read" method="post">
|
||||
@@ -86,9 +86,9 @@ class HTMLPurifier_HTMLModule_FormsTest extends HTMLPurifier_HTMLModuleHarness
|
||||
</form>
|
||||
');
|
||||
}
|
||||
|
||||
|
||||
// label tests omitted
|
||||
|
||||
|
||||
function testFieldset() {
|
||||
$this->assertResult('
|
||||
<form action="..." method="post">
|
||||
@@ -109,7 +109,7 @@ class HTMLPurifier_HTMLModule_FormsTest extends HTMLPurifier_HTMLModuleHarness
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Current Medication</legend>
|
||||
Are you currently taking any medication?
|
||||
Are you currently taking any medication?
|
||||
<input name="medication_now" type="radio" value="Yes" tabindex="35" />Yes
|
||||
<input name="medication_now" type="radio" value="No" tabindex="35" />No
|
||||
|
||||
@@ -120,18 +120,18 @@ class HTMLPurifier_HTMLModule_FormsTest extends HTMLPurifier_HTMLModuleHarness
|
||||
</form>
|
||||
');
|
||||
}
|
||||
|
||||
|
||||
function testInputTransform() {
|
||||
$this->assertResult('<input type="checkbox" />', '<input type="checkbox" value="" />');
|
||||
}
|
||||
|
||||
|
||||
function testTextareaTransform() {
|
||||
$this->assertResult('<textarea></textarea>', '<textarea cols="22" rows="3"></textarea>');
|
||||
}
|
||||
|
||||
|
||||
function testTextInFieldset() {
|
||||
$this->assertResult('<fieldset> <legend></legend>foo</fieldset>');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,26 +2,26 @@
|
||||
|
||||
class HTMLPurifier_HTMLModule_ImageTest extends HTMLPurifier_HTMLModuleHarness
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
function testNormal() {
|
||||
$this->assertResult('<img height="40" width="40" src="" alt="" />');
|
||||
}
|
||||
|
||||
|
||||
function testLengthTooLarge() {
|
||||
$this->assertResult(
|
||||
'<img height="40000" width="40000" src="" alt="" />',
|
||||
'<img height="1200" width="1200" src="" alt="" />'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testLengthPercentage() {
|
||||
$this->assertResult(
|
||||
'<img height="100%" width="100%" src="" alt="" />',
|
||||
'<img src="" alt="" />'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testLengthCustomMax() {
|
||||
$this->config->set('HTML', 'MaxImgLength', 20);
|
||||
$this->assertResult(
|
||||
@@ -29,7 +29,7 @@ class HTMLPurifier_HTMLModule_ImageTest extends HTMLPurifier_HTMLModuleHarness
|
||||
'<img height="20" width="20" src="" alt="" />'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testLengthCrashFixDisabled() {
|
||||
$this->config->set('HTML', 'MaxImgLength', null);
|
||||
$this->assertResult(
|
||||
@@ -39,7 +39,7 @@ class HTMLPurifier_HTMLModule_ImageTest extends HTMLPurifier_HTMLModuleHarness
|
||||
'<img height="40000" width="40000" src="" alt="" />'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testLengthTrusted() {
|
||||
$this->config->set('HTML', 'Trusted', true);
|
||||
$this->assertResult(
|
||||
@@ -49,6 +49,6 @@ class HTMLPurifier_HTMLModule_ImageTest extends HTMLPurifier_HTMLModuleHarness
|
||||
'<img height="40000" width="40000" src="" alt="" />'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,23 +2,23 @@
|
||||
|
||||
class HTMLPurifier_HTMLModule_ObjectTest extends HTMLPurifier_HTMLModuleHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->config->set('HTML', 'Trusted', true);
|
||||
}
|
||||
|
||||
|
||||
function testDefaultRemoval() {
|
||||
$this->config->set('HTML', 'Trusted', false);
|
||||
$this->assertResult(
|
||||
'<object></object>', ''
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testMinimal() {
|
||||
$this->assertResult('<object></object>');
|
||||
}
|
||||
|
||||
|
||||
function testStandardUseCase() {
|
||||
$this->assertResult(
|
||||
'<object type="video/x-ms-wmv" data="http://domain.com/video.wmv" width="320" height="256">
|
||||
@@ -30,8 +30,8 @@ class HTMLPurifier_HTMLModule_ObjectTest extends HTMLPurifier_HTMLModuleHarness
|
||||
</object>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// more test-cases?
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,12 +2,12 @@
|
||||
|
||||
class HTMLPurifier_HTMLModule_ProprietaryTest extends HTMLPurifier_HTMLModuleHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->config->set('HTML', 'Proprietary', true);
|
||||
}
|
||||
|
||||
|
||||
function testMarquee() {
|
||||
$this->assertResult(
|
||||
'<span><marquee
|
||||
@@ -24,6 +24,6 @@ class HTMLPurifier_HTMLModule_ProprietaryTest extends HTMLPurifier_HTMLModuleHar
|
||||
><div>Block</div><span>Inline</span>Text</marquee></span>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,24 +2,24 @@
|
||||
|
||||
class HTMLPurifier_HTMLModule_RubyTest extends HTMLPurifier_HTMLModuleHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->config->set('HTML', 'Doctype', 'XHTML 1.1');
|
||||
}
|
||||
|
||||
|
||||
function testBasicUse() {
|
||||
$this->assertResult(
|
||||
'<ruby><rb>WWW</rb><rt>World Wide Web</rt></ruby>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testRPUse() {
|
||||
$this->assertResult(
|
||||
'<ruby><rb>WWW</rb><rp>(</rp><rt>World Wide Web</rt><rp>)</rp></ruby>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testComplexUse() {
|
||||
$this->assertResult(
|
||||
'<ruby>
|
||||
@@ -38,7 +38,7 @@ class HTMLPurifier_HTMLModule_RubyTest extends HTMLPurifier_HTMLModuleHarness
|
||||
</rtc>
|
||||
</ruby>'
|
||||
);
|
||||
|
||||
|
||||
/* not implemented
|
||||
function testBackwardsCompat() {
|
||||
$this->assertResult(
|
||||
@@ -47,8 +47,8 @@ class HTMLPurifier_HTMLModule_RubyTest extends HTMLPurifier_HTMLModuleHarness
|
||||
);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,40 +2,40 @@
|
||||
|
||||
class HTMLPurifier_HTMLModule_SafeEmbedTest extends HTMLPurifier_HTMLModuleHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->config->set('HTML', 'DefinitionID', 'HTMLPurifier_HTMLModule_SafeEmbedTest');
|
||||
$def = $this->config->getHTMLDefinition(true);
|
||||
$def->manager->addModule('SafeEmbed');
|
||||
}
|
||||
|
||||
|
||||
function testMinimal() {
|
||||
$this->assertResult(
|
||||
'<embed src="http://www.youtube.com/v/RVtEQxH7PWA&hl=en" />',
|
||||
'<embed src="http://www.youtube.com/v/RVtEQxH7PWA&hl=en" allowscriptaccess="never" allownetworking="internal" type="application/x-shockwave-flash" />'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testYouTube() {
|
||||
$this->assertResult(
|
||||
'<embed src="http://www.youtube.com/v/RVtEQxH7PWA&hl=en" type="application/x-shockwave-flash" width="425" height="344"></embed>',
|
||||
'<embed src="http://www.youtube.com/v/RVtEQxH7PWA&hl=en" type="application/x-shockwave-flash" width="425" height="344" allowscriptaccess="never" allownetworking="internal" />'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testMalicious() {
|
||||
$this->assertResult(
|
||||
'<embed src="http://example.com/bad.swf" type="application/x-shockwave-flash" width="9999999" height="3499994" allowscriptaccess="always" allownetworking="always" />',
|
||||
'<embed src="http://example.com/bad.swf" type="application/x-shockwave-flash" width="1200" height="1200" allowscriptaccess="never" allownetworking="internal" />'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testFull() {
|
||||
$this->assertResult(
|
||||
'<b><embed src="http://www.youtube.com/v/RVtEQxH7PWA&hl=en" type="application/x-shockwave-flash" width="24" height="23" allowscriptaccess="never" allownetworking="internal" wmode="window" /></b>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,21 +2,21 @@
|
||||
|
||||
class HTMLPurifier_HTMLModule_SafeObjectTest extends HTMLPurifier_HTMLModuleHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->config->set('HTML', 'DefinitionID', 'HTMLPurifier_HTMLModule_SafeObjectTest');
|
||||
$def = $this->config->getHTMLDefinition(true);
|
||||
$def->manager->addModule('SafeObject');
|
||||
}
|
||||
|
||||
|
||||
function testMinimal() {
|
||||
$this->assertResult(
|
||||
'<object></object>',
|
||||
'<object type="application/x-shockwave-flash"><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testYouTube() {
|
||||
// embed is purposely removed
|
||||
$this->assertResult(
|
||||
@@ -24,19 +24,19 @@ class HTMLPurifier_HTMLModule_SafeObjectTest extends HTMLPurifier_HTMLModuleHarn
|
||||
'<object width="425" height="344" data="http://www.youtube.com/v/RVtEQxH7PWA&hl=en" type="application/x-shockwave-flash"><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><param name="movie" value="http://www.youtube.com/v/RVtEQxH7PWA&hl=en" /></object>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testMalicious() {
|
||||
$this->assertResult(
|
||||
'<object width="9999999" height="9999999"><param name="allowScriptAccess" value="always" /><param name="movie" value="http://example.com/attack.swf" /></object>',
|
||||
'<object width="1200" height="1200" data="http://example.com/attack.swf" type="application/x-shockwave-flash"><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><param name="movie" value="http://example.com/attack.swf" /></object>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testFull() {
|
||||
$this->assertResult(
|
||||
'<b><object width="425" height="344" type="application/x-shockwave-flash" data="Foobar"><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><param name="movie" value="http://www.youtube.com/v/RVtEQxH7PWA&hl=en" /><param name="wmode" value="window" /></object></b>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,26 +2,26 @@
|
||||
|
||||
class HTMLPurifier_HTMLModule_ScriptingTest extends HTMLPurifier_HTMLModuleHarness
|
||||
{
|
||||
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->config->set('HTML', 'Trusted', true);
|
||||
$this->config->set('Output', 'CommentScriptContents', false);
|
||||
}
|
||||
|
||||
|
||||
function testDefaultRemoval() {
|
||||
$this->config->set('HTML', 'Trusted', false);
|
||||
$this->assertResult(
|
||||
'<script type="text/javascript">foo();</script>', ''
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testPreserve() {
|
||||
$this->assertResult(
|
||||
'<script type="text/javascript">foo();</script>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testCDATAEnclosure() {
|
||||
$this->assertResult(
|
||||
'<script type="text/javascript">//<![CDATA[
|
||||
@@ -29,7 +29,7 @@ alert("<This is compatible with XHTML>");
|
||||
//]]></script>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testAllAttributes() {
|
||||
$this->assertResult(
|
||||
'<script
|
||||
@@ -39,7 +39,7 @@ alert("<This is compatible with XHTML>");
|
||||
>PCDATA</script>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function testUnsupportedAttributes() {
|
||||
$this->assertResult(
|
||||
'<script
|
||||
@@ -49,6 +49,6 @@ alert("<This is compatible with XHTML>");
|
||||
'<script type="text/javascript">PCDATA</script>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user