mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-02 20:27:40 +02:00
[1.7.0] Add some module unit tests for Edit, Hypertext, Image and Legacy (incomplete). Remove redundant img scaffolding.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1050 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -14,8 +14,6 @@ class HTMLPurifier_HTMLModule_Image extends HTMLPurifier_HTMLModule
|
|||||||
{
|
{
|
||||||
|
|
||||||
var $name = 'Image';
|
var $name = 'Image';
|
||||||
var $elements = array('img');
|
|
||||||
var $content_sets = array('Inline' => 'img');
|
|
||||||
|
|
||||||
function HTMLPurifier_HTMLModule_Image() {
|
function HTMLPurifier_HTMLModule_Image() {
|
||||||
$img =& $this->addElement(
|
$img =& $this->addElement(
|
||||||
|
@@ -7,6 +7,7 @@ class HTMLPurifier_HTMLModule_BdoTest extends HTMLPurifier_HTMLModuleHarness
|
|||||||
|
|
||||||
function test() {
|
function test() {
|
||||||
|
|
||||||
|
// max
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<span>
|
'<span>
|
||||||
<bdo
|
<bdo
|
||||||
@@ -23,6 +24,23 @@ class HTMLPurifier_HTMLModule_BdoTest extends HTMLPurifier_HTMLModuleHarness
|
|||||||
</span>', true, array('Attr.EnableID' => true)
|
</span>', true, array('Attr.EnableID' => true)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// min
|
||||||
|
$this->assertResult(
|
||||||
|
'<bdo></bdo>', '<bdo dir="ltr"></bdo>'
|
||||||
|
);
|
||||||
|
|
||||||
|
// children
|
||||||
|
$this->assertResult(
|
||||||
|
'<bdo dir="rtl">Text<span></span><div></div></bdo>',
|
||||||
|
'<bdo dir="rtl">Text<span></span></bdo>'
|
||||||
|
);
|
||||||
|
|
||||||
|
// global attr
|
||||||
|
$this->assertResult(
|
||||||
|
'<br dir="ltr" /><span dir="ltr"></span>',
|
||||||
|
'<br /><span dir="ltr"></span>'
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
58
tests/HTMLPurifier/HTMLModule/EditTest.php
Normal file
58
tests/HTMLPurifier/HTMLModule/EditTest.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/HTMLModuleHarness.php';
|
||||||
|
|
||||||
|
class HTMLPurifier_HTMLModule_EditTest extends HTMLPurifier_HTMLModuleHarness
|
||||||
|
{
|
||||||
|
|
||||||
|
function test() {
|
||||||
|
|
||||||
|
// max
|
||||||
|
$this->assertResult(
|
||||||
|
'<span>
|
||||||
|
<ins cite="http://www.example.com/">
|
||||||
|
#PCDATA <span></span>
|
||||||
|
</ins>
|
||||||
|
<del cite="http://www.example.com/">
|
||||||
|
#PCDATA <span></span>
|
||||||
|
</del>
|
||||||
|
</span>
|
||||||
|
<div>
|
||||||
|
<ins cite="http://www.example.com/">
|
||||||
|
#PCDATA <div></div> <span></span>
|
||||||
|
</ins>
|
||||||
|
<del cite="http://www.example.com/">
|
||||||
|
#PCDATA <div></div> <span></span>
|
||||||
|
</del>
|
||||||
|
</div>'
|
||||||
|
);
|
||||||
|
|
||||||
|
// inline removal
|
||||||
|
$this->assertResult(
|
||||||
|
'<span>
|
||||||
|
<ins><div></div></ins>
|
||||||
|
<del><div></div></del>
|
||||||
|
</span>',
|
||||||
|
'<span>
|
||||||
|
<ins></ins>
|
||||||
|
<del></del>
|
||||||
|
</span>'
|
||||||
|
);
|
||||||
|
|
||||||
|
// unsupported attributes
|
||||||
|
$this->assertResult(
|
||||||
|
'<ins
|
||||||
|
datetime="1994-11-05T13:15:30Z"
|
||||||
|
></ins>
|
||||||
|
<del
|
||||||
|
datetime="1994-11-05T13:15:30Z"
|
||||||
|
></del>',
|
||||||
|
'<ins></ins>
|
||||||
|
<del></del>'
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
52
tests/HTMLPurifier/HTMLModule/HypertextTest.php
Normal file
52
tests/HTMLPurifier/HTMLModule/HypertextTest.php
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/HTMLModuleHarness.php';
|
||||||
|
|
||||||
|
class HTMLPurifier_HTMLModule_HypertextTest extends HTMLPurifier_HTMLModuleHarness
|
||||||
|
{
|
||||||
|
|
||||||
|
function test() {
|
||||||
|
|
||||||
|
// max
|
||||||
|
$this->assertResult(
|
||||||
|
'<span>
|
||||||
|
<a
|
||||||
|
href="http://www.example.com/"
|
||||||
|
rel="nofollow"
|
||||||
|
rev="index"
|
||||||
|
>
|
||||||
|
#PCDATA <span>Inline</span>
|
||||||
|
</a>
|
||||||
|
</span>', true, array(
|
||||||
|
'Attr.AllowedRel' => 'nofollow',
|
||||||
|
'Attr.AllowedRev' => 'index'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// invalid children
|
||||||
|
$this->assertResult(
|
||||||
|
'<a>Text<span><a></a></span><div></div><a></a></a>',
|
||||||
|
'<a>Text<span></span></a>'
|
||||||
|
);
|
||||||
|
|
||||||
|
// unsupported attributes
|
||||||
|
$this->assertResult(
|
||||||
|
'<a
|
||||||
|
charset="utf-8"
|
||||||
|
type="text/html"
|
||||||
|
hreflang="en"
|
||||||
|
accesskey="f"
|
||||||
|
shape="rect"
|
||||||
|
coords="0,0,20,0"
|
||||||
|
tabindex="3"
|
||||||
|
onfocus="foo();"
|
||||||
|
onblur="bar();"
|
||||||
|
></a>',
|
||||||
|
'<a></a>'
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
50
tests/HTMLPurifier/HTMLModule/ImageTest.php
Normal file
50
tests/HTMLPurifier/HTMLModule/ImageTest.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/HTMLModuleHarness.php';
|
||||||
|
|
||||||
|
class HTMLPurifier_HTMLModule_ImageTest extends HTMLPurifier_HTMLModuleHarness
|
||||||
|
{
|
||||||
|
|
||||||
|
function test() {
|
||||||
|
|
||||||
|
// max
|
||||||
|
$this->assertResult(
|
||||||
|
'<span>
|
||||||
|
<img
|
||||||
|
src="example.png"
|
||||||
|
alt="Example image"
|
||||||
|
longdesc="example.description.txt"
|
||||||
|
height="42"
|
||||||
|
width="42"
|
||||||
|
/>
|
||||||
|
</span>'
|
||||||
|
);
|
||||||
|
|
||||||
|
// required attributes
|
||||||
|
$this->assertResult(
|
||||||
|
'<img src="foo.png" />',
|
||||||
|
'<img src="foo.png" alt="foo.png" />'
|
||||||
|
);
|
||||||
|
|
||||||
|
// empty
|
||||||
|
$this->assertResult(
|
||||||
|
'<img src="foo.png" alt="foo">',
|
||||||
|
'<img src="foo.png" alt="foo" />'
|
||||||
|
);
|
||||||
|
|
||||||
|
// unsupported attributes
|
||||||
|
$this->assertResult(
|
||||||
|
'<img
|
||||||
|
src="example.png"
|
||||||
|
alt="Example"
|
||||||
|
usemap="#foo"
|
||||||
|
ismap="ismap"
|
||||||
|
/>',
|
||||||
|
'<img src="example.png" alt="Example" />'
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
32
tests/HTMLPurifier/HTMLModule/LegacyTest.php
Normal file
32
tests/HTMLPurifier/HTMLModule/LegacyTest.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/HTMLModuleHarness.php';
|
||||||
|
|
||||||
|
class HTMLPurifier_HTMLModule_LegacyTest extends HTMLPurifier_HTMLModuleHarness
|
||||||
|
{
|
||||||
|
|
||||||
|
function test() {
|
||||||
|
|
||||||
|
// max
|
||||||
|
$this->assertResult(
|
||||||
|
'<span>
|
||||||
|
<u>Text<span></span></u>
|
||||||
|
<s>Text<span></span></s>
|
||||||
|
<strike>Text<span></span></strike>
|
||||||
|
</span>'
|
||||||
|
);
|
||||||
|
|
||||||
|
// redefinitions
|
||||||
|
/*$this->assertResult(
|
||||||
|
'<ol start="3">
|
||||||
|
<li value="2">Foo</li>
|
||||||
|
</ol>
|
||||||
|
<address>Text<span></span><p></p></address>
|
||||||
|
<blockquote>Text<span></span><div></div></blockquote>'
|
||||||
|
);*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@@ -63,6 +63,10 @@ $test_files[] = 'GeneratorTest.php';
|
|||||||
$test_files[] = 'HTMLModuleManagerTest.php';
|
$test_files[] = 'HTMLModuleManagerTest.php';
|
||||||
$test_files[] = 'HTMLModuleTest.php';
|
$test_files[] = 'HTMLModuleTest.php';
|
||||||
$test_files[] = 'HTMLModule/BdoTest.php';
|
$test_files[] = 'HTMLModule/BdoTest.php';
|
||||||
|
$test_files[] = 'HTMLModule/EditTest.php';
|
||||||
|
$test_files[] = 'HTMLModule/HypertextTest.php';
|
||||||
|
$test_files[] = 'HTMLModule/ImageTest.php';
|
||||||
|
$test_files[] = 'HTMLModule/LegacyTest.php';
|
||||||
$test_files[] = 'IDAccumulatorTest.php';
|
$test_files[] = 'IDAccumulatorTest.php';
|
||||||
$test_files[] = 'LanguageFactoryTest.php';
|
$test_files[] = 'LanguageFactoryTest.php';
|
||||||
$test_files[] = 'LanguageTest.php';
|
$test_files[] = 'LanguageTest.php';
|
||||||
|
Reference in New Issue
Block a user