3 class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest
extends HTMLPurifier_StrategyHarness
6 public function setUp()
9 $this->obj
= new HTMLPurifier_Strategy_MakeWellFormed();
10 $this->config
->set('AutoFormat.AutoParagraph', true);
11 $this->config
->set('AutoFormat.Linkify', true);
12 $this->config
->set('AutoFormat.RemoveEmpty', true);
13 generate_mock_once('HTMLPurifier_Injector');
16 public function testEndHandler()
18 $mock = new HTMLPurifier_InjectorMock();
19 $b = new HTMLPurifier_Token_End('b');
20 $b->skip
= array(0 => true);
21 $b->start
= new HTMLPurifier_Token_Start('b');
22 $b->start
->skip
= array(0 => true, 1 => true);
23 $mock->expectAt(0, 'handleEnd', array($b));
24 $i = new HTMLPurifier_Token_End('i');
25 $i->start
= new HTMLPurifier_Token_Start('i');
26 $i->skip
= array(0 => true);
27 $i->start
->skip
= array(0 => true, 1 => true);
28 $mock->expectAt(1, 'handleEnd', array($i));
29 $mock->expectCallCount('handleEnd', 2);
30 $mock->returns('getRewindOffset', false);
31 $this->config
->set('AutoFormat.AutoParagraph', false);
32 $this->config
->set('AutoFormat.Linkify', false);
33 $this->config
->set('AutoFormat.Custom', array($mock));
34 $this->assertResult('<i><b>asdf</b>', '<i><b>asdf</b></i>');
37 public function testErrorRequiredElementNotAllowed()
39 $this->config
->set('HTML.Allowed', '');
40 $this->expectError('Cannot enable AutoParagraph injector because p is not allowed');
41 $this->expectError('Cannot enable Linkify injector because a is not allowed');
42 $this->assertResult('Foobar');
45 public function testErrorRequiredAttributeNotAllowed()
47 $this->config
->set('HTML.Allowed', 'a,p');
48 $this->expectError('Cannot enable Linkify injector because a.href is not allowed');
49 $this->assertResult('<p>http://example.com</p>');
52 public function testOnlyAutoParagraph()
60 public function testParagraphWrappingOnlyLink()
64 '<p><a href="http://example.com">http://example.com</a></p>'
68 public function testParagraphWrappingNodeContainingLink()
71 '<b>http://example.com</b>',
72 '<p><b><a href="http://example.com">http://example.com</a></b></p>'
76 public function testParagraphWrappingPoorlyFormedNodeContainingLink()
79 '<b>http://example.com',
80 '<p><b><a href="http://example.com">http://example.com</a></b></p>'
84 public function testTwoParagraphsContainingOnlyOneLink()
87 "http://example.com\n\nhttp://dev.example.com",
88 '<p><a href="http://example.com">http://example.com</a></p>
90 <p><a href="http://dev.example.com">http://dev.example.com</a></p>'
94 public function testParagraphNextToDivWithLinks()
97 'http://example.com <div>http://example.com</div>',
98 '<p><a href="http://example.com">http://example.com</a> </p>
100 <div><a href="http://example.com">http://example.com</a></div>'
104 public function testRealisticLinkInSentence()
107 'This URL http://example.com is what you need',
108 '<p>This URL <a href="http://example.com">http://example.com</a> is what you need</p>'
112 public function testParagraphAfterLinkifiedURL()
118 "<p><a href=\"http://google.com\">http://google.com</a></p>
124 public function testEmptyAndParagraph()
126 // This is a fairly degenerate case, but it demonstrates that
127 // the two don't error out together, at least.
128 // Change this behavior!
143 public function testRewindAndParagraph()
163 // vim: et sw=4 sts=4