Fix newline issues in tests.
[htmlpurifier/darkodev.git] / tests / HTMLPurifier / Strategy / MakeWellFormed_InjectorTest.php
blob212b2d4ce6cdba4cc6b606013459f38c18b97c17
1 <?php
3 class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_StrategyHarness
6 function setUp() {
7 parent::setUp();
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() {
49 $this->assertResult(
50 'Foobar',
51 '<p>Foobar</p>'
55 function testParagraphWrappingOnlyLink() {
56 $this->assertResult(
57 'http://example.com',
58 '<p><a href="http://example.com">http://example.com</a></p>'
62 function testParagraphWrappingNodeContainingLink() {
63 $this->assertResult(
64 '<b>http://example.com</b>',
65 '<p><b><a href="http://example.com">http://example.com</a></b></p>'
69 function testParagraphWrappingPoorlyFormedNodeContainingLink() {
70 $this->assertResult(
71 '<b>http://example.com',
72 '<p><b><a href="http://example.com">http://example.com</a></b></p>'
76 function testTwoParagraphsContainingOnlyOneLink() {
77 $this->assertResult(
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() {
86 $this->assertResult(
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() {
95 $this->assertResult(
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() {
102 $this->assertResult(
103 "http://google.com
105 <b>b</b>",
106 "<p><a href=\"http://google.com\">http://google.com</a></p>
108 <p><b>b</b></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!
116 $this->assertResult(
117 "<p>asdf
119 asdf<b></b></p>
121 <p></p><i></i>",
122 "<p>asdf</p>
124 <p>asdf</p>
132 function testRewindAndParagraph() {
133 $this->assertResult(
134 "bar
136 <p><i></i>
138 </p>
140 foo",
141 "<p>bar</p>
145 <p>foo</p>"