0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-14 01:08:41 +00:00
htmlpurifier/tests/HTMLPurifier/Strategy/RemoveForeignElements_ErrorsTest.php
Edward Z. Yang fbc595ebed Remove includes from unit tests.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1569 48356398-32a2-884e-a903-53898d9a118a
2008-02-18 04:41:42 +00:00

57 lines
2.4 KiB
PHP

<?php
class HTMLPurifier_Strategy_RemoveForeignElements_ErrorsTest extends HTMLPurifier_Strategy_ErrorsHarness
{
function setup() {
parent::setup();
$this->config->set('HTML', 'TidyLevel', 'heavy');
}
function getStrategy() {
return new HTMLPurifier_Strategy_RemoveForeignElements();
}
function testTagTransform() {
$this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Tag transform', 'center');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('div', array('style' => 'text-align:center;'), 1));
$this->invoke('<center>');
}
function testMissingRequiredAttr() {
// a little fragile, since img has two required attributes
$this->expectErrorCollection(E_ERROR, 'Strategy_RemoveForeignElements: Missing required attribute', 'alt');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Empty('img', array(), 1));
$this->invoke('<img />');
}
function testForeignElementToText() {
$this->config->set('Core', 'EscapeInvalidTags', true);
$this->expectErrorCollection(E_WARNING, 'Strategy_RemoveForeignElements: Foreign element to text');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('invalid', array(), 1));
$this->invoke('<invalid>');
}
function testForeignElementRemoved() {
// uses $CurrentToken.Serialized
$this->expectErrorCollection(E_ERROR, 'Strategy_RemoveForeignElements: Foreign element removed');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('invalid', array(), 1));
$this->invoke('<invalid>');
}
function testCommentRemoved() {
$this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Comment removed');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Comment(' test ', 1));
$this->invoke('<!-- test -->');
}
function testForeignMetaElementRemoved() {
$this->collector->expectAt(0, 'send', array(E_ERROR, 'Strategy_RemoveForeignElements: Foreign meta element removed'));
$this->collector->expectContextAt(0, 'CurrentToken', new HTMLPurifier_Token_Start('script', array(), 1));
$this->collector->expectAt(1, 'send', array(E_ERROR, 'Strategy_RemoveForeignElements: Token removed to end', 'script'));
$this->invoke('<script>asdf');
}
}