1 9 package org.jboss.portal.test.format; 10 11 import java.io.IOException ; 12 import java.io.StringWriter ; 13 14 import org.jboss.portal.format.render.bbcodehtml.ToTextRenderer; 15 import org.jboss.portal.format.template.BuildException; 16 17 20 public class BBCodeHTML2TextTestCase 21 extends junit.framework.TestCase 22 { 23 24 public ToTextRenderer toTextRenderer; 25 26 public StringWriter stringWriter; 27 28 public void setUp() 29 { 30 String location = "org/jboss/portal/test/format/template"; 31 32 toTextRenderer = new ToTextRenderer(); 33 stringWriter = new StringWriter (); 34 toTextRenderer.setWriter(stringWriter); 35 } 36 37 public void tearDown() 38 { 39 stringWriter.flush(); 40 } 41 42 public void testBlah() 43 { 44 45 } 46 47 public void testXMLCharacterEntityReference() 48 { 49 String text = "[code]A[/code]"; 50 toTextRenderer.render(text.toCharArray(), 0, text.length()); 51 assertTrue(stringWriter.toString().indexOf("A") != -1); 52 } 53 54 public void testHTML01() 55 { 56 String text = "<b>bold</b>"; 57 toTextRenderer.render(text.toCharArray(), 0, text.length()); 58 assertEquals("bold", stringWriter.toString()); 59 } 60 61 public void testHTML02() 62 { 63 String text = "<i><b>bold</b></i>"; 64 toTextRenderer.render(text.toCharArray(), 0, text.length()); 65 assertEquals("bold", stringWriter.toString()); 66 } 67 68 public void testBBCodeBold() 69 { 70 String text = "[b]bold[/b]"; 71 toTextRenderer.render(text.toCharArray(), 0, text.length()); 72 assertEquals("*bold*", stringWriter.toString()); 73 } 74 75 public void testBBCodeItalic() 76 { 77 String text = "[i]italic[/i]"; 78 toTextRenderer.render(text.toCharArray(), 0, text.length()); 79 assertEquals("italic", stringWriter.toString()); 80 } 81 82 public void testBBCodeUnderline() 83 { 84 String text = "[u]underline[/u]"; 85 toTextRenderer.render(text.toCharArray(), 0, text.length()); 86 assertEquals("underline", stringWriter.toString()); 87 } 88 89 public void testBBCodeColor() 90 { 91 String text = "[color=blue]color[/color]"; 92 toTextRenderer.render(text.toCharArray(), 0, text.length()); 93 assertEquals("color", stringWriter.toString()); 94 } 95 96 public void testBBCodeSize() 97 { 98 String text = "[size=4]size[/size]"; 99 toTextRenderer.render(text.toCharArray(), 0, text.length()); 100 assertEquals("size", stringWriter.toString()); 101 } 102 103 public void testBBCodeQuote() 104 { 105 String text = "[quote=theute]myquote[/quote]"; 106 toTextRenderer.render(text.toCharArray(), 0, text.length()); 107 assertEquals("theute wrote : myquote", stringWriter.toString()); 108 } 109 110 public void testBBCodeQuoteMultiline() 111 { 112 String text = "[quote=theute]myquote\nis a good quote\nisn't it ?[/quote]"; 113 toTextRenderer.render(text.toCharArray(), 0, text.length()); 114 assertEquals( 115 "theute wrote : myquote\n | is a good quote\n | isn't it ?", 116 stringWriter.toString()); 117 } 118 119 public void testBBCodeMultiQuoteMultiline() 120 { 121 String text = "[quote=theute]myquote\nanother\n[quote=bob]quote of\nanother\ndude[/quote]\nNice quote\nisn't it ?[/quote]"; 122 toTextRenderer.render(text.toCharArray(), 0, text.length()); 123 assertEquals( 124 "theute wrote : myquote\n | another\n | bob wrote : quote of\n | | another\n | | dude\n | Nice quote\n | isn't it ?", 125 stringWriter.toString()); 126 } 127 128 public void testBBCodeQuoteAnonymous() 129 { 130 String text = "[quote]myquote[/quote]"; 131 toTextRenderer.render(text.toCharArray(), 0, text.length()); 132 assertEquals("anonymous wrote : myquote", stringWriter.toString()); 133 } 134 135 public void testBBCodeList() 136 { 137 String text = "[list]list[/list]</b>"; 138 toTextRenderer.render(text.toCharArray(), 0, text.length()); 139 assertEquals("list", stringWriter.toString()); 140 } 141 142 public void testBBCodeListItem() 143 { 144 String text = "[list][*]foo[/list]</b>"; 145 toTextRenderer.render(text.toCharArray(), 0, text.length()); 146 assertEquals("-> foo", stringWriter.toString()); 147 } 148 149 public void testBBCodeListItems() 150 { 151 String text = "[list][*]foo[*]bar[/list]</b>"; 152 toTextRenderer.render(text.toCharArray(), 0, text.length()); 153 assertEquals("-> foo-> bar", stringWriter.toString()); 154 } 155 156 public void testBBCodeList1() 157 { 158 String text = "[list=1]list1[/list]</b>"; 159 toTextRenderer.render(text.toCharArray(), 0, text.length()); 160 assertEquals("list1", stringWriter.toString()); 161 } 162 163 public void testBBCodeList1Item() 164 { 165 String text = "[list=1][*]foo[/list]</b>"; 166 toTextRenderer.render(text.toCharArray(), 0, text.length()); 167 assertEquals("-> foo", stringWriter.toString()); 168 } 169 170 public void testBBCodeList1Items() 171 { 172 String text = "[list=1][*]foo[*]bar[/list]</b>"; 173 toTextRenderer.render(text.toCharArray(), 0, text.length()); 174 assertEquals("-> foo-> bar", stringWriter.toString()); 175 } 176 177 public void testBBCodeListA() 178 { 179 String text = "[list=a]listA[/list]</b>"; 180 toTextRenderer.render(text.toCharArray(), 0, text.length()); 181 assertEquals("listA", stringWriter.toString()); 182 } 183 184 public void testBBCodeListAItem() 185 { 186 String text = "[list=a][*]foo[/list]</b>"; 187 toTextRenderer.render(text.toCharArray(), 0, text.length()); 188 assertEquals("-> foo", stringWriter.toString()); 189 } 190 191 public void testBBCodeListAItems() throws BuildException, IOException 192 { 193 String text = "[list=a][*]foo[*]bar[/list]</b>"; 194 toTextRenderer.render(text.toCharArray(), 0, text.length()); 195 assertEquals("-> foo-> bar", stringWriter.toString()); 196 } 197 198 public void testBBCodeURL() 199 { 200 String text = "[url]http://www.jboss.org[/url]"; 201 toTextRenderer.render(text.toCharArray(), 0, text.length()); 202 assertEquals("[ http://www.jboss.org ]", stringWriter.toString()); 203 } 204 205 public void testBBCode2URL() 206 { 207 String text = "[url]http://www.jboss.com[/url][url]http://www.jboss.org[/url]"; 208 toTextRenderer.render(text.toCharArray(), 0, text.length()); 209 assertEquals("[ http://www.jboss.com ][ http://www.jboss.org ]", 210 stringWriter.toString()); 211 } 212 213 public void testBBCodeCode() 214 { 215 String text = "[code][b]BBBold[/b] <b>HTMLBold</b>[/code]"; 216 toTextRenderer.render(text.toCharArray(), 0, text.length()); 217 assertEquals(" | BBBold <b>HTMLBold</b>", stringWriter.toString()); 218 } 219 220 223 public void testBBCodeCodeMultiLine() 224 { 225 String text = "[code][b]BBBold[/b]\n<b>HTMLBold</b>\nnormal[/code]"; 226 toTextRenderer.render(text.toCharArray(), 0, text.length()); 227 assertEquals(" | BBBold\n | <b>HTMLBold</b>\n | normal", stringWriter 228 .toString()); 229 } 230 } 231 | Popular Tags |