001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.krad.util;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.junit.Test;
020 import org.kuali.rice.kns.util.WebUtils;
021 import org.kuali.test.KRADTestCase;
022
023 import static org.junit.Assert.*;
024
025 /**
026 * Unit tests for the KNS WebUtils
027 *
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 *
030 */
031 public class WebUtilsTest extends KRADTestCase {
032
033 /**
034 * Tests WebUtils.getButtonImageUrl()
035 *
036 */
037 @Test
038 public void testButtonImageUrl() {
039 final String test1 = "test1";
040 final String test2 = "test2";
041
042 final String test2Image = WebUtils.getButtonImageUrl(test2);
043 final String test2DefaultImage = WebUtils.getDefaultButtonImageUrl(test2);
044 assertEquals("test2 image did not equal default for test2", test2Image, test2DefaultImage);
045
046 final String test1Image = WebUtils.getButtonImageUrl(test1);
047 final String test1DefaultImage = WebUtils.getDefaultButtonImageUrl(test1);
048 assertNotSame("the test1 image should not be the default", test1Image, test1DefaultImage);
049 assertEquals("/test/images/test1.png", test1Image);
050 }
051
052 /**
053 * Tests the filterHtmlAndReplaceRiceMarkup method
054 */
055 @Test
056 public void testFilterHtmlAndReplaceRiceMarkup() {
057 String questionText = "";
058
059 // verify script markup does not make it through
060 questionText = "<script> function () </script>";
061 String filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
062 assertTrue("Script tags not filtered out", !StringUtils.equals(questionText, filteredText));
063
064 // verify supported tags get translated
065 questionText = "[p][/p]";
066 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
067 assertEquals("Paragraph tag not translated to markup", "<p></p>", filteredText);
068
069 questionText = "[b][/b]";
070 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
071 assertEquals("Bold tag not translated to markup", "<b></b>", filteredText);
072
073 questionText = "[br][/br]";
074 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
075 assertEquals("Break tag not translated to markup", "<br></br>", filteredText);
076
077 questionText = "[tr][/tr]";
078 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
079 assertEquals("Table row tag not translated to markup", "<tr></tr>", filteredText);
080
081 questionText = "[td][/td]";
082 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
083 assertEquals("Table cell tag not translated to markup", "<td></td>", filteredText);
084
085 questionText = "[font #000000][/font]";
086 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
087 assertEquals("Font with hex color tag not translated to markup", "<font color=\"#000000\"></font>", filteredText);
088
089 questionText = "[font red][/font]";
090 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
091 assertEquals("Font with color name tag not translated to markup", "<font color=\"red\"></font>", filteredText);
092
093 questionText = "[table][/table]";
094 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
095 assertEquals("Table tag not translated to markup", "<table></table>", filteredText);
096
097 questionText = "[table questionTable][/table]";
098 filteredText = WebUtils.filterHtmlAndReplaceRiceMarkup(questionText);
099 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 }