Whoops, forgot to edit WHATSNEW
[htmlpurifier.git] / tests / HTMLPurifier / Strategy / MakeWellFormed_InjectorTest.php
blob4dd031c43ea96770409decf4dd5f39cdd4eada44
1 <?php
3 class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_StrategyHarness
6 public function setUp()
8 parent::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()
54 $this->assertResult(
55 'Foobar',
56 '<p>Foobar</p>'
60 public function testParagraphWrappingOnlyLink()
62 $this->assertResult(
63 'http://example.com',
64 '<p><a href="http://example.com">http://example.com</a></p>'
68 public function testParagraphWrappingNodeContainingLink()
70 $this->assertResult(
71 '<b>http://example.com</b>',
72 '<p><b><a href="http://example.com">http://example.com</a></b></p>'
76 public function testParagraphWrappingPoorlyFormedNodeContainingLink()
78 $this->assertResult(
79 '<b>http://example.com',
80 '<p><b><a href="http://example.com">http://example.com</a></b></p>'
84 public function testTwoParagraphsContainingOnlyOneLink()
86 $this->assertResult(
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()
96 $this->assertResult(
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()
106 $this->assertResult(
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()
114 $this->assertResult(
115 "http://google.com
117 <b>b</b>",
118 "<p><a href=\"http://google.com\">http://google.com</a></p>
120 <p><b>b</b></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!
129 $this->assertResult(
130 "<p>asdf
132 asdf<b></b></p>
134 <p></p><i></i>",
135 "<p>asdf</p>
137 <p>asdf</p>
143 public function testRewindAndParagraph()
145 $this->assertResult(
146 "bar
148 <p><i></i>
150 </p>
152 foo",
153 "<p>bar</p>
157 <p>foo</p>"
163 // vim: et sw=4 sts=4