2007-06-26 15:07:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class HTMLPurifier_Strategy_MakeWellFormed_ErrorsTest extends HTMLPurifier_Strategy_ErrorsHarness
|
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
protected function getStrategy()
|
|
|
|
{
|
2007-06-26 15:07:07 +00:00
|
|
|
return new HTMLPurifier_Strategy_MakeWellFormed();
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testUnnecessaryEndTagRemoved()
|
|
|
|
{
|
2007-06-26 19:33:37 +00:00
|
|
|
$this->expectErrorCollection(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag removed');
|
2008-09-01 18:10:10 +00:00
|
|
|
$this->expectContext('CurrentToken', new HTMLPurifier_Token_End('b', array(), 1, 0));
|
2007-06-26 15:07:07 +00:00
|
|
|
$this->invoke('</b>');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testUnnecessaryEndTagToText()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Core.EscapeInvalidTags', true);
|
2007-06-26 19:33:37 +00:00
|
|
|
$this->expectErrorCollection(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag to text');
|
2008-09-01 18:10:10 +00:00
|
|
|
$this->expectContext('CurrentToken', new HTMLPurifier_Token_End('b', array(), 1, 0));
|
2007-06-26 15:07:07 +00:00
|
|
|
$this->invoke('</b>');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testTagAutoclose()
|
|
|
|
{
|
2008-12-20 18:06:00 +00:00
|
|
|
$this->expectErrorCollection(E_NOTICE, 'Strategy_MakeWellFormed: Tag auto closed', new HTMLPurifier_Token_Start('p', array(), 1, 0));
|
|
|
|
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('div', array(), 1, 6));
|
|
|
|
$this->invoke('<p>Foo<div>Bar</div>');
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testTagCarryOver()
|
|
|
|
{
|
2008-12-20 18:06:00 +00:00
|
|
|
$b = new HTMLPurifier_Token_Start('b', array(), 1, 0);
|
|
|
|
$this->expectErrorCollection(E_NOTICE, 'Strategy_MakeWellFormed: Tag carryover', $b);
|
2008-09-01 18:10:10 +00:00
|
|
|
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('div', array(), 1, 6));
|
2007-06-26 19:33:37 +00:00
|
|
|
$this->invoke('<b>Foo<div>Bar</div>');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testStrayEndTagRemoved()
|
|
|
|
{
|
2007-06-26 19:33:37 +00:00
|
|
|
$this->expectErrorCollection(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag removed');
|
2008-09-01 18:10:10 +00:00
|
|
|
$this->expectContext('CurrentToken', new HTMLPurifier_Token_End('b', array(), 1, 3));
|
2007-06-26 15:07:07 +00:00
|
|
|
$this->invoke('<i></b></i>');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testStrayEndTagToText()
|
|
|
|
{
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Core.EscapeInvalidTags', true);
|
2007-06-26 19:33:37 +00:00
|
|
|
$this->expectErrorCollection(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag to text');
|
2008-09-01 18:10:10 +00:00
|
|
|
$this->expectContext('CurrentToken', new HTMLPurifier_Token_End('b', array(), 1, 3));
|
2007-06-26 15:07:07 +00:00
|
|
|
$this->invoke('<i></b></i>');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testTagClosedByElementEnd()
|
|
|
|
{
|
2008-09-01 18:10:10 +00:00
|
|
|
$this->expectErrorCollection(E_NOTICE, 'Strategy_MakeWellFormed: Tag closed by element end', new HTMLPurifier_Token_Start('b', array(), 1, 3));
|
|
|
|
$this->expectContext('CurrentToken', new HTMLPurifier_Token_End('i', array(), 1, 12));
|
2007-06-26 15:07:07 +00:00
|
|
|
$this->invoke('<i><b>Foobar</i>');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testTagClosedByDocumentEnd()
|
|
|
|
{
|
2008-09-01 18:10:10 +00:00
|
|
|
$this->expectErrorCollection(E_NOTICE, 'Strategy_MakeWellFormed: Tag closed by document end', new HTMLPurifier_Token_Start('b', array(), 1, 0));
|
2007-06-26 15:07:07 +00:00
|
|
|
$this->invoke('<b>Foobar');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-26 15:07:07 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|