Fix autoparagraph bug with non-inline elements.
[htmlpurifier.git] / tests / HTMLPurifier / Strategy / RemoveForeignElements_ErrorsTest.php
blob98eb0b4ed99a8cf75c3e214c2bd86c05ae036ce1
1 <?php
3 class HTMLPurifier_Strategy_RemoveForeignElements_ErrorsTest extends HTMLPurifier_Strategy_ErrorsHarness
6 public function setup() {
7 parent::setup();
8 $this->config->set('HTML.TidyLevel', 'heavy');
11 protected function getStrategy() {
12 return new HTMLPurifier_Strategy_RemoveForeignElements();
15 function testTagTransform() {
16 $this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Tag transform', 'center');
17 $this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('div', array('style' => 'text-align:center;'), 1));
18 $this->invoke('<center>');
21 function testMissingRequiredAttr() {
22 // a little fragile, since img has two required attributes
23 $this->expectErrorCollection(E_ERROR, 'Strategy_RemoveForeignElements: Missing required attribute', 'alt');
24 $this->expectContext('CurrentToken', new HTMLPurifier_Token_Empty('img', array(), 1));
25 $this->invoke('<img />');
28 function testForeignElementToText() {
29 $this->config->set('Core.EscapeInvalidTags', true);
30 $this->expectErrorCollection(E_WARNING, 'Strategy_RemoveForeignElements: Foreign element to text');
31 $this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('invalid', array(), 1));
32 $this->invoke('<invalid>');
35 function testForeignElementRemoved() {
36 // uses $CurrentToken.Serialized
37 $this->expectErrorCollection(E_ERROR, 'Strategy_RemoveForeignElements: Foreign element removed');
38 $this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('invalid', array(), 1));
39 $this->invoke('<invalid>');
42 function testCommentRemoved() {
43 $this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Comment removed');
44 $this->expectContext('CurrentToken', new HTMLPurifier_Token_Comment(' test ', 1));
45 $this->invoke('<!-- test -->');
48 function testTrailingHyphenInCommentRemoved() {
49 $this->config->set('HTML.Trusted', true);
50 $this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Trailing hyphen in comment removed');
51 $this->expectContext('CurrentToken', new HTMLPurifier_Token_Comment(' test --', 1));
52 $this->invoke('<!-- test ---->');
55 function testDoubleHyphenInCommentRemoved() {
56 $this->config->set('HTML.Trusted', true);
57 $this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Hyphens in comment collapsed');
58 $this->expectContext('CurrentToken', new HTMLPurifier_Token_Comment(' test --- test -- test ', 1));
59 $this->invoke('<!-- test --- test -- test -->');
62 function testForeignMetaElementRemoved() {
63 $this->collector->expectAt(0, 'send', array(E_ERROR, 'Strategy_RemoveForeignElements: Foreign meta element removed'));
64 $this->collector->expectContextAt(0, 'CurrentToken', new HTMLPurifier_Token_Start('script', array(), 1));
65 $this->collector->expectAt(1, 'send', array(E_ERROR, 'Strategy_RemoveForeignElements: Token removed to end', 'script'));
66 $this->invoke('<script>asdf');
71 // vim: et sw=4 sts=4