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() {
|
|
|
|
// uses $CurrentToken.Serialized
|
|
|
|
$this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Tag transform', 'center');
|
|
|
|
$this->invoke('<center>');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testMissingRequiredAttr() {
|
|
|
|
// a little fragile, since img has two required attributes
|
|
|
|
$this->expectErrorCollection(E_ERROR, 'Strategy_RemoveForeignElements: Missing required attribute', 'img', 'alt');
|
|
|
|
$this->invoke('<img />');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testForeignElementToText() {
|
2007-06-26 15:07:07 +00:00
|
|
|
// uses $CurrentToken.Serialized
|
2007-06-26 02:49:21 +00:00
|
|
|
$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 02:49:21 +00:00
|
|
|
$this->invoke('<cannot-possibly-exist-element>');
|
|
|
|
}
|
|
|
|
|
|
|
|
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 02:49:21 +00:00
|
|
|
$this->invoke('<cannot-possibly-exist-element>');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCommentRemoved() {
|
2007-06-26 03:22:07 +00:00
|
|
|
$this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Comment removed', ' test ');
|
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'));
|
|
|
|
$this->collector->expectAt(1, 'send', array(E_ERROR, 'Strategy_RemoveForeignElements: Token removed to end', 'script'));
|
|
|
|
$this->invoke('<script>asdf');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|