3 class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest
extends HTMLPurifier_StrategyHarness
8 $this->obj
= new HTMLPurifier_Strategy_MakeWellFormed();
9 $this->config
->set('AutoFormat', 'AutoParagraph', true);
10 $this->config
->set('AutoFormat', 'Linkify', true);
11 $this->config
->set('AutoFormat', 'RemoveEmpty', true);
12 generate_mock_once('HTMLPurifier_Injector');
15 function testEndHandler() {
16 $mock = new HTMLPurifier_InjectorMock();
17 $b = new HTMLPurifier_Token_End('b');
18 $b->skip
= array(0 => true);
19 $b->start
= new HTMLPurifier_Token_Start('b');
20 $b->start
->skip
= array(0 => true, 1 => true);
21 $mock->expectAt(0, 'handleEnd', array($b));
22 $i = new HTMLPurifier_Token_End('i');
23 $i->start
= new HTMLPurifier_Token_Start('i');
24 $i->skip
= array(0 => true);
25 $i->start
->skip
= array(0 => true, 1 => true);
26 $mock->expectAt(1, 'handleEnd', array($i));
27 $mock->expectCallCount('handleEnd', 2);
28 $mock->setReturnValue('getRewind', false);
29 $this->config
->set('AutoFormat', 'AutoParagraph', false);
30 $this->config
->set('AutoFormat', 'Linkify', false);
31 $this->config
->set('AutoFormat', 'Custom', array($mock));
32 $this->assertResult('<i><b>asdf</b>', '<i><b>asdf</b></i>');
35 function testErrorRequiredElementNotAllowed() {
36 $this->config
->set('HTML', 'Allowed', '');
37 $this->expectError('Cannot enable AutoParagraph injector because p is not allowed');
38 $this->expectError('Cannot enable Linkify injector because a is not allowed');
39 $this->assertResult('Foobar');
42 function testErrorRequiredAttributeNotAllowed() {
43 $this->config
->set('HTML', 'Allowed', 'a,p');
44 $this->expectError('Cannot enable Linkify injector because a.href is not allowed');
45 $this->assertResult('<p>http://example.com</p>');
48 function testOnlyAutoParagraph() {
55 function testParagraphWrappingOnlyLink() {
58 '<p><a href="http://example.com">http://example.com</a></p>'
62 function testParagraphWrappingNodeContainingLink() {
64 '<b>http://example.com</b>',
65 '<p><b><a href="http://example.com">http://example.com</a></b></p>'
69 function testParagraphWrappingPoorlyFormedNodeContainingLink() {
71 '<b>http://example.com',
72 '<p><b><a href="http://example.com">http://example.com</a></b></p>'
76 function testTwoParagraphsContainingOnlyOneLink() {
78 "http://example.com\n\nhttp://dev.example.com",
79 '<p><a href="http://example.com">http://example.com</a></p>
81 <p><a href="http://dev.example.com">http://dev.example.com</a></p>'
85 function testParagraphNextToDivWithLinks() {
87 'http://example.com <div>http://example.com</div>',
88 '<p><a href="http://example.com">http://example.com</a> </p>
90 <div><a href="http://example.com">http://example.com</a></div>'
94 function testRealisticLinkInSentence() {
96 'This URL http://example.com is what you need',
97 '<p>This URL <a href="http://example.com">http://example.com</a> is what you need</p>'
101 function testParagraphAfterLinkifiedURL() {
106 "<p><a href=\"http://google.com\">http://google.com</a></p>
112 function testEmptyAndParagraph() {
113 // This is a fairly degenerate case, but it demonstrates that
114 // the two don't error out together, at least.
115 // Change this behavior!
132 function testRewindAndParagraph() {