1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.util;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.junit.Test;
20 import org.kuali.rice.kns.util.WebUtils;
21 import org.kuali.test.KRADTestCase;
22
23 import static org.junit.Assert.*;
24
25
26
27
28
29
30
31 public class WebUtilsTest extends KRADTestCase {
32
33
34
35
36
37 @Test
38 public void testButtonImageUrl() {
39 final String test1 = "test1";
40 final String test2 = "test2";
41
42 final String test2Image = WebUtils.getButtonImageUrl(test2);
43 final String test2DefaultImage = WebUtils.getDefaultButtonImageUrl(test2);
44 assertEquals("test2 image did not equal default for test2", test2Image, test2DefaultImage);
45
46 final String test1Image = WebUtils.getButtonImageUrl(test1);
47 final String test1DefaultImage = WebUtils.getDefaultButtonImageUrl(test1);
48 assertNotSame("the test1 image should not be the default", test1Image, test1DefaultImage);
49 assertEquals("/test/images/test1.png", test1Image);
50 }
51
52
53
54
55 @Test
56 public void testFilterHtmlAndReplaceRiceMarkup() {
57 String questionText = "";
58
59
60 questionText = "<script> function () </script>";
61 String filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
62 assertTrue("Script tags not filtered out", !StringUtils.equals(questionText, filteredText));
63
64
65 questionText = "[p][/p]";
66 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
67 assertEquals("Paragraph tag not translated to markup", "<p></p>", filteredText);
68
69 questionText = "[b][/b]";
70 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
71 assertEquals("Bold tag not translated to markup", "<b></b>", filteredText);
72
73 questionText = "[br][/br]";
74 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
75 assertEquals("Break tag not translated to markup", "<br></br>", filteredText);
76
77 questionText = "[tr][/tr]";
78 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
79 assertEquals("Table row tag not translated to markup", "<tr></tr>", filteredText);
80
81 questionText = "[td][/td]";
82 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
83 assertEquals("Table cell tag not translated to markup", "<td></td>", filteredText);
84
85 questionText = "[font #000000][/font]";
86 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
87 assertEquals("Font with hex color tag not translated to markup", "<font color=\"#000000\"></font>", filteredText);
88
89 questionText = "[font red][/font]";
90 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
91 assertEquals("Font with color name tag not translated to markup", "<font color=\"red\"></font>", filteredText);
92
93 questionText = "[table][/table]";
94 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
95 assertEquals("Table tag not translated to markup", "<table></table>", filteredText);
96
97 questionText = "[table questionTable][/table]";
98 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
99 assertEquals("Table with class tag not translated to markup", "<table class=\"questionTable\"></table>", filteredText);
100
101 questionText = "[td leftTd][/td]";
102 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
103 assertEquals("Table cell with class tag not translated to markup", "<td class=\"leftTd\"></td>", filteredText);
104 }
105
106 @Test
107 public void testToAbsoluteURL() {
108 assertEquals("base/relative", WebUtils.toAbsoluteURL("base", "/relative"));
109 assertEquals("http://base/relative", WebUtils.toAbsoluteURL("http://base", "/relative"));
110 assertEquals("http://absolute", WebUtils.toAbsoluteURL("http://base", "http://absolute"));
111 assertEquals("https://absolute", WebUtils.toAbsoluteURL("http://base", "https://absolute"));
112 assertEquals("https://absolute", WebUtils.toAbsoluteURL(null, "https://absolute"));
113 assertEquals("", WebUtils.toAbsoluteURL("", ""));
114 assertEquals("base", WebUtils.toAbsoluteURL("base", ""));
115 assertEquals("base", WebUtils.toAbsoluteURL("base", null));
116 }
117 }