PSR-2 reformatting PHPDoc corrections
[htmlpurifier.git] / tests / HTMLPurifier / Strategy / RemoveForeignElements_ErrorsTest.php
blobfcc7c7c88e09777e80c78fcfc1ecfa40f53f891b
1 <?php
3 class HTMLPurifier_Strategy_RemoveForeignElements_ErrorsTest extends HTMLPurifier_Strategy_ErrorsHarness
6 public function setup()
8 parent::setup();
9 $this->config->set('HTML.TidyLevel', 'heavy');
12 protected function getStrategy()
14 return new HTMLPurifier_Strategy_RemoveForeignElements();
17 public function testTagTransform()
19 $this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Tag transform', 'center');
20 $this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('div', array('style' => 'text-align:center;'), 1));
21 $this->invoke('<center>');
24 public function testMissingRequiredAttr()
26 // a little fragile, since img has two required attributes
27 $this->expectErrorCollection(E_ERROR, 'Strategy_RemoveForeignElements: Missing required attribute', 'alt');
28 $this->expectContext('CurrentToken', new HTMLPurifier_Token_Empty('img', array(), 1));
29 $this->invoke('<img />');
32 public function testForeignElementToText()
34 $this->config->set('Core.EscapeInvalidTags', true);
35 $this->expectErrorCollection(E_WARNING, 'Strategy_RemoveForeignElements: Foreign element to text');
36 $this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('invalid', array(), 1));
37 $this->invoke('<invalid>');
40 public function testForeignElementRemoved()
42 // uses $CurrentToken.Serialized
43 $this->expectErrorCollection(E_ERROR, 'Strategy_RemoveForeignElements: Foreign element removed');
44 $this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('invalid', array(), 1));
45 $this->invoke('<invalid>');
48 public function testCommentRemoved()
50 $this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Comment removed');
51 $this->expectContext('CurrentToken', new HTMLPurifier_Token_Comment(' test ', 1));
52 $this->invoke('<!-- test -->');
55 public function testTrailingHyphenInCommentRemoved()
57 $this->config->set('HTML.Trusted', true);
58 $this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Trailing hyphen in comment removed');
59 $this->expectContext('CurrentToken', new HTMLPurifier_Token_Comment(' test ', 1));
60 $this->invoke('<!-- test ---->');
63 public function testDoubleHyphenInCommentRemoved()
65 $this->config->set('HTML.Trusted', true);
66 $this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Hyphens in comment collapsed');
67 $this->expectContext('CurrentToken', new HTMLPurifier_Token_Comment(' test - test - test ', 1));
68 $this->invoke('<!-- test --- test -- test -->');
71 public function testForeignMetaElementRemoved()
73 $this->collector->expectAt(0, 'send', array(E_ERROR, 'Strategy_RemoveForeignElements: Foreign meta element removed'));
74 $this->collector->expectContextAt(0, 'CurrentToken', new HTMLPurifier_Token_Start('script', array(), 1));
75 $this->collector->expectAt(1, 'send', array(E_ERROR, 'Strategy_RemoveForeignElements: Token removed to end', 'script'));
76 $this->invoke('<script>asdf');
81 // vim: et sw=4 sts=4