2007-06-26 02:49:21 +00:00
|
|
|
<?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
|
|
|
{
|
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
public function setup() {
|
2007-06-26 02:49:21 +00:00
|
|
|
parent::setup();
|
|
|
|
$this->config->set('HTML', 'TidyLevel', 'heavy');
|
|
|
|
}
|
|
|
|
|
2008-04-21 15:24:18 +00:00
|
|
|
protected function getStrategy() {
|
2007-06-26 15:07:07 +00:00
|
|
|
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 -->');
|
|
|
|
}
|
|
|
|
|
2008-06-26 03:12:19 +00:00
|
|
|
function testTrailingHyphenInCommentRemoved() {
|
|
|
|
$this->config->set('HTML', 'Trusted', true);
|
|
|
|
$this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Trailing hyphen in comment removed');
|
|
|
|
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Comment(' test --', 1));
|
|
|
|
$this->invoke('<!-- test ---->');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDoubleHyphenInCommentRemoved() {
|
|
|
|
$this->config->set('HTML', 'Trusted', true);
|
|
|
|
$this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Hyphens in comment collapsed');
|
|
|
|
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Comment(' test --- test -- test ', 1));
|
|
|
|
$this->invoke('<!-- test --- test -- test -->');
|
|
|
|
}
|
|
|
|
|
2007-07-11 20:42:58 +00:00
|
|
|
function testForeignMetaElementRemoved() {
|
|
|
|
$this->collector->expectAt(0, 'send', array(E_ERROR, 'Strategy_RemoveForeignElements: Foreign meta element 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');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|