2007-06-26 02:49:21 +00:00
|
|
|
<?php
|
|
|
|
|
2007-06-26 15:07:07 +00:00
|
|
|
require_once 'HTMLPurifier/Strategy/ErrorsHarness.php';
|
2007-06-26 02:49:21 +00:00
|
|
|
require_once 'HTMLPurifier/Strategy/RemoveForeignElements.php';
|
|
|
|
|
2007-06-26 15:07:07 +00:00
|
|
|
class HTMLPurifier_Strategy_RemoveForeignElements_ErrorsTest extends HTMLPurifier_Strategy_ErrorsHarness
|
2007-06-26 02:49:21 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
function setup() {
|
|
|
|
parent::setup();
|
|
|
|
$this->config->set('HTML', 'TidyLevel', 'heavy');
|
|
|
|
}
|
|
|
|
|
2007-06-26 15:07:07 +00:00
|
|
|
function getStrategy() {
|
|
|
|
return new HTMLPurifier_Strategy_RemoveForeignElements();
|
2007-06-26 02:49:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testTagTransform() {
|
|
|
|
$this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Tag transform', 'center');
|
2007-06-26 19:33:37 +00:00
|
|
|
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('div', array('style' => 'text-align:center;'), 1));
|
2007-06-26 02:49:21 +00:00
|
|
|
$this->invoke('<center>');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testMissingRequiredAttr() {
|
|
|
|
// a little fragile, since img has two required attributes
|
2007-06-26 19:33:37 +00:00
|
|
|
$this->expectErrorCollection(E_ERROR, 'Strategy_RemoveForeignElements: Missing required attribute', 'alt');
|
|
|
|
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Empty('img', array(), 1));
|
2007-06-26 02:49:21 +00:00
|
|
|
$this->invoke('<img />');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testForeignElementToText() {
|
|
|
|
$this->config->set('Core', 'EscapeInvalidTags', true);
|
2007-06-26 15:40:04 +00:00
|
|
|
$this->expectErrorCollection(E_WARNING, 'Strategy_RemoveForeignElements: Foreign element to text');
|
2007-06-26 19:33:37 +00:00
|
|
|
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('invalid', array(), 1));
|
|
|
|
$this->invoke('<invalid>');
|
2007-06-26 02:49:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testForeignElementRemoved() {
|
2007-06-26 15:07:07 +00:00
|
|
|
// uses $CurrentToken.Serialized
|
2007-06-26 15:40:04 +00:00
|
|
|
$this->expectErrorCollection(E_ERROR, 'Strategy_RemoveForeignElements: Foreign element removed');
|
2007-06-26 19:33:37 +00:00
|
|
|
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('invalid', array(), 1));
|
|
|
|
$this->invoke('<invalid>');
|
2007-06-26 02:49:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testCommentRemoved() {
|
2007-06-26 19:33:37 +00:00
|
|
|
$this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Comment removed');
|
|
|
|
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Comment(' test ', 1));
|
2007-06-26 02:49:21 +00:00
|
|
|
$this->invoke('<!-- test -->');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testScriptRemoved() {
|
|
|
|
$this->collector->expectAt(0, 'send', array(E_ERROR, 'Strategy_RemoveForeignElements: Script removed'));
|
2007-06-26 19:33:37 +00:00
|
|
|
$this->collector->expectContextAt(0, 'CurrentToken', new HTMLPurifier_Token_Start('script', array(), 1));
|
2007-06-26 02:49:21 +00:00
|
|
|
$this->collector->expectAt(1, 'send', array(E_ERROR, 'Strategy_RemoveForeignElements: Token removed to end', 'script'));
|
|
|
|
$this->invoke('<script>asdf');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|