diff --git a/tests/HTMLPurifier/Strategy/FixNestingTest.php b/tests/HTMLPurifier/Strategy/FixNestingTest.php index 6022fcd6..e67a3e44 100644 --- a/tests/HTMLPurifier/Strategy/FixNestingTest.php +++ b/tests/HTMLPurifier/Strategy/FixNestingTest.php @@ -109,7 +109,7 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness function testInvalidParentError() { // test fallback to div $this->config->set('HTML', 'Parent', 'obviously-impossible'); - $this->expectError('Cannot use unrecognized element as parent.'); + $this->expectError('Cannot use unrecognized element as parent'); $this->assertResult('
Accept
'); } diff --git a/tests/HTMLPurifier/Strategy/MakeWellFormed_InjectorTest.php b/tests/HTMLPurifier/Strategy/MakeWellFormed_InjectorTest.php new file mode 100644 index 00000000..e8e6c797 --- /dev/null +++ b/tests/HTMLPurifier/Strategy/MakeWellFormed_InjectorTest.php @@ -0,0 +1,65 @@ +obj = new HTMLPurifier_Strategy_MakeWellFormed(); + $this->config->set('AutoFormat', 'AutoParagraph', true); + $this->config->set('AutoFormat', 'Linkify', true); + } + + function testOnlyAutoParagraph() { + $this->assertResult( + 'Foobar', + '

Foobar

' + ); + } + + function testParagraphWrappingOnlyLink() { + $this->assertResult( + 'http://example.com', + '

http://example.com

' + ); + } + + function testParagraphWrappingNodeContainingLink() { + $this->assertResult( + 'http://example.com', + '

http://example.com

' + ); + } + + function testParagraphWrappingPoorlyFormedNodeContainingLink() { + $this->assertResult( + 'http://example.com', + '

http://example.com

' + ); + } + + function testTwoParagraphsContainingOnlyOneLink() { + $this->assertResult( + "http://example.com\n\nhttp://dev.example.com", + '

http://example.com

http://dev.example.com

' + ); + } + + function testParagraphNextToDivWithLinks() { + $this->assertResult( + 'http://example.com
http://example.com
', + '

http://example.com

http://example.com
' + ); + } + + function testRealisticLinkInSentence() { + $this->assertResult( + 'This URL http://example.com is what you need', + '

This URL http://example.com is what you need

' + ); + } + +} diff --git a/tests/HTMLPurifier/Strategy/RemoveForeignElements_TidyTest.php b/tests/HTMLPurifier/Strategy/RemoveForeignElements_TidyTest.php new file mode 100644 index 00000000..8071d2ab --- /dev/null +++ b/tests/HTMLPurifier/Strategy/RemoveForeignElements_TidyTest.php @@ -0,0 +1,46 @@ +obj = new HTMLPurifier_Strategy_RemoveForeignElements(); + $this->config->set('HTML', 'TidyLevel', 'heavy'); + } + + function testCenterTransform() { + $this->assertResult( + '
Look I am Centered!
', + '
Look I am Centered!
' + ); + } + + function testFontTransform() { + $this->assertResult( + 'Big Warning!', + 'Big'. + ' Warning!' + ); + } + + function testTransformToForbiddenElement() { + $this->config->set('HTML', 'Allowed', 'div'); + $this->assertResult( + 'Big Warning!', + 'Big Warning!' + ); + } + + function testMenuTransform() { + $this->assertResult( + '
  • Item 1
  • ', + '' + ); + } + +} diff --git a/tests/HTMLPurifier/Strategy/ValidateAttributes_IDTest.php b/tests/HTMLPurifier/Strategy/ValidateAttributes_IDTest.php new file mode 100644 index 00000000..d73b0ebd --- /dev/null +++ b/tests/HTMLPurifier/Strategy/ValidateAttributes_IDTest.php @@ -0,0 +1,65 @@ +obj = new HTMLPurifier_Strategy_ValidateAttributes(); + $this->config->set('HTML', 'EnableAttrID', true); + } + + + function testPreserveIDWhenEnabled() { + $this->assertResult('
    Preserve the ID.
    '); + } + + function testRemoveInvalidID() { + $this->assertResult( + '
    Kill the ID.
    ', + '
    Kill the ID.
    ' + ); + } + + function testRemoveDuplicateID() { + $this->assertResult( + '
    Valid
    Invalid
    ', + '
    Valid
    Invalid
    ' + ); + } + + function testAttributeKeyCaseInsensitivity() { + $this->assertResult( + '
    Convert ID to lowercase.
    ', + '
    Convert ID to lowercase.
    ' + ); + } + + function testTrimWhitespace() { + $this->assertResult( + '
    Trim whitespace.
    ', + '
    Trim whitespace.
    ' + ); + } + + function testIDBlacklist() { + $this->config->set('Attr', 'IDBlacklist', array('invalid')); + $this->assertResult( + '
    Invalid
    ', + '
    Invalid
    ' + ); + } + + function testNameConvertedToID() { + $this->config->set('HTML', 'TidyLevel', 'heavy'); + $this->assertResult( + '', + '' + ); + } + +} + diff --git a/tests/HTMLPurifier/Strategy/ValidateAttributes_TidyTest.php b/tests/HTMLPurifier/Strategy/ValidateAttributes_TidyTest.php new file mode 100644 index 00000000..1f0e21ba --- /dev/null +++ b/tests/HTMLPurifier/Strategy/ValidateAttributes_TidyTest.php @@ -0,0 +1,353 @@ +obj = new HTMLPurifier_Strategy_ValidateAttributes(); + $this->config->set('HTML', 'TidyLevel', 'heavy'); + } + + function testConvertCenterAlign() { + $this->assertResult( + '

    Centered Headline

    ', + '

    Centered Headline

    ' + ); + } + + function testConvertRightAlign() { + $this->assertResult( + '

    Right-aligned Headline

    ', + '

    Right-aligned Headline

    ' + ); + } + + function testConvertLeftAlign() { + $this->assertResult( + '

    Left-aligned Headline

    ', + '

    Left-aligned Headline

    ' + ); + } + + function testConvertJustifyAlign() { + $this->assertResult( + '

    Justified Paragraph

    ', + '

    Justified Paragraph

    ' + ); + } + + function testRemoveInvalidAlign() { + $this->assertResult( + '

    Invalid Headline

    ', + '

    Invalid Headline

    ' + ); + } + + function testConvertTableLengths() { + $this->assertResult( + '
    ', + '
    ' + ); + } + + function testTdConvertNowrap() { + $this->assertResult( + '', + '' + ); + } + + function testCaptionConvertAlignLeft() { + $this->assertResult( + '', + '' + ); + } + + function testCaptionConvertAlignRight() { + $this->assertResult( + '', + '' + ); + } + + function testCaptionConvertAlignTop() { + $this->assertResult( + '', + '' + ); + } + + function testCaptionConvertAlignBottom() { + $this->assertResult( + '', + '' + ); + } + + function testCaptionRemoveInvalidAlign() { + $this->assertResult( + '', + '' + ); + } + + function testTableConvertAlignLeft() { + $this->assertResult( + '', + '
    ' + ); + } + + function testTableConvertAlignCenter() { + $this->assertResult( + '
    ', + '
    ' + ); + } + + function testTableConvertAlignRight() { + $this->assertResult( + '
    ', + '
    ' + ); + } + + function testTableRemoveInvalidAlign() { + $this->assertResult( + '
    ', + '
    ' + ); + } + + function testImgConvertAlignLeft() { + $this->assertResult( + 'foobar', + 'foobar' + ); + } + + function testImgConvertAlignRight() { + $this->assertResult( + 'foobar', + 'foobar' + ); + } + + function testImgConvertAlignBottom() { + $this->assertResult( + 'foobar', + 'foobar' + ); + } + + function testImgConvertAlignMiddle() { + $this->assertResult( + 'foobar', + 'foobar' + ); + } + + function testImgConvertAlignTop() { + $this->assertResult( + 'foobar', + 'foobar' + ); + } + + function testImgRemoveInvalidAlign() { + $this->assertResult( + 'foobar', + 'foobar' + ); + } + + function testBorderConvertHVSpace() { + $this->assertResult( + 'foo', + 'foo' + ); + } + + function testHrConvertSize() { + $this->assertResult( + '
    ', + '
    ' + ); + } + + function testHrConvertNoshade() { + $this->assertResult( + '
    ', + '
    ' + ); + } + + function testHrConvertAlignLeft() { + $this->assertResult( + '
    ', + '
    ' + ); + } + + function testHrConvertAlignCenter() { + $this->assertResult( + '
    ', + '
    ' + ); + } + + function testHrConvertAlignRight() { + $this->assertResult( + '
    ', + '
    ' + ); + } + + function testHrRemoveInvalidAlign() { + $this->assertResult( + '
    ', + '
    ' + ); + } + + function testBrConvertClearLeft() { + $this->assertResult( + '
    ', + '
    ' + ); + } + + function testBrConvertClearRight() { + $this->assertResult( + '
    ', + '
    ' + ); + } + + function testBrConvertClearAll() { + $this->assertResult( + '
    ', + '
    ' + ); + } + + function testBrConvertClearNone() { + $this->assertResult( + '
    ', + '
    ' + ); + } + + function testBrRemoveInvalidClear() { + $this->assertResult( + '
    ', + '
    ' + ); + } + + function testUlConvertTypeDisc() { + $this->assertResult( + '