2009-08-28 00:42:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class HTMLPurifier_Injector_RemoveSpansWithoutAttributesTest extends HTMLPurifier_InjectorHarness
|
|
|
|
{
|
2013-07-16 11:56:14 +00:00
|
|
|
public function setup()
|
|
|
|
{
|
2009-08-28 00:42:09 +00:00
|
|
|
parent::setup();
|
|
|
|
$this->config->set('HTML.Allowed', 'span[class],div,p,strong,em');
|
|
|
|
$this->config->set('AutoFormat.RemoveSpansWithoutAttributes', true);
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testSingleSpan()
|
|
|
|
{
|
2009-08-28 00:42:09 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<span>foo</span>',
|
|
|
|
'foo'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testSingleSpanWithAttributes()
|
|
|
|
{
|
2009-08-28 00:42:09 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<span class="bar">foo</span>',
|
|
|
|
'<span class="bar">foo</span>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testSingleNestedSpan()
|
|
|
|
{
|
2009-08-28 00:42:09 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<p><span>foo</span></p>',
|
|
|
|
'<p>foo</p>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testSingleNestedSpanWithAttributes()
|
|
|
|
{
|
2009-08-28 00:42:09 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<p><span class="bar">foo</span></p>',
|
|
|
|
'<p><span class="bar">foo</span></p>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testSpanWithChildren()
|
|
|
|
{
|
2009-08-28 00:42:09 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<span>foo <strong>bar</strong> <em>baz</em></span>',
|
|
|
|
'foo <strong>bar</strong> <em>baz</em>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testSpanWithSiblings()
|
|
|
|
{
|
2009-08-28 00:42:09 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<p>before <span>inside</span> <strong>after</strong></p>',
|
|
|
|
'<p>before inside <strong>after</strong></p>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testNestedSpanWithSiblingsAndChildren()
|
|
|
|
{
|
2009-08-28 00:42:09 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<p>a <span>b <em>c</em> d</span> e</p>',
|
|
|
|
'<p>a b <em>c</em> d e</p>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testNestedSpansWithoutAttributes()
|
|
|
|
{
|
2009-08-28 00:42:09 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<span>one<span>two<span>three</span></span></span>',
|
|
|
|
'onetwothree'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testDeeplyNestedSpan()
|
|
|
|
{
|
2009-08-28 00:42:09 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div><div><div><span class="a">a <span>b</span> c</span></div></div></div>',
|
|
|
|
'<div><div><div><span class="a">a b c</span></div></div></div>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testSpanWithInvalidAttributes()
|
|
|
|
{
|
2009-08-28 00:42:09 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<p><span snorkel buzzer="emu">foo</span></p>',
|
|
|
|
'<p>foo</p>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testNestedAlternateSpans()
|
|
|
|
{
|
2009-08-28 00:42:09 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<span>a <span class="x">b <span>c <span class="y">d <span>e <span class="z">f
|
|
|
|
</span></span></span></span></span></span>',
|
|
|
|
'a <span class="x">b c <span class="y">d e <span class="z">f
|
|
|
|
</span></span></span>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testSpanWithSomeInvalidAttributes()
|
|
|
|
{
|
2009-08-28 00:42:09 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<p><span buzzer="emu" class="bar">foo</span></p>',
|
|
|
|
'<p><span class="bar">foo</span></p>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// vim: et sw=4 sts=4
|