/////////////////////////////////////////////////////////////////////////////
//
// Project ProjectForge Community Edition
// www.projectforge.org
//
// Copyright (C) 2001-2014 Kai Reinhard (k.reinhard@micromata.de)
//
// ProjectForge is dual-licensed.
//
// This community edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published
// by the Free Software Foundation; version 3 of the License.
//
// This community edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, see http://www.gnu.org/licenses/.
//
/////////////////////////////////////////////////////////////////////////////
package org.projectforge.web;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Test;
public class HtmlHelperTest
{
@Test
public void testAttribute()
{
final HtmlHelper htmlHelper = new HtmlHelper();
assertEquals(" hallo=\"test\"", htmlHelper.attribute("hallo", "test"));
}
@Test
public void testAppendAncorOnClickSubmitEventStartTag()
{
final HtmlHelper htmlHelper = new HtmlHelper();
StringBuffer buf = new StringBuffer();
htmlHelper.appendAncorOnClickSubmitEventStartTag(buf, "submitEvent", "select.task");
assertEquals("<a href=\"#\" onclick=\"javascript:submitEvent('select.task')\">", buf.toString());
buf = new StringBuffer();
htmlHelper.appendAncorOnClickSubmitEventStartTag(buf, "submitSelectedEvent", "selectTask", "4");
assertEquals("<a href=\"#\" onclick=\"javascript:submitSelectedEvent('selectTask', '4')\">", buf.toString());
}
@Test
public void testFormatText()
{
assertEquals("", HtmlHelper.formatText(null, true));
assertEquals("", HtmlHelper.formatText("", true));
assertEquals("<br/>", HtmlHelper.formatText("\n", true));
assertEquals(" ", HtmlHelper.formatText("\t ", true));
assertEquals(
"Name: Reinhard<br/>Vorname: Kai<br/>Test ",
HtmlHelper.formatText("Name:\tReinhard\r\nVorname:\tKai\nTest ", true));
}
@Test
public void escapeHtml()
{
assertNull(HtmlHelper.escapeHtml(null, true));
assertNull(HtmlHelper.escapeHtml(null, false));
assertEquals("", HtmlHelper.escapeHtml("", true));
assertEquals("", HtmlHelper.escapeHtml("", false));
assertEquals("Stéphanie<<br/>\n", HtmlHelper.escapeHtml("Stéphanie<\n", true));
assertEquals("Stéphanie<\n", HtmlHelper.escapeHtml("Stéphanie<\n", false));
assertEquals("Stéphanie<<br/>\nGermany", HtmlHelper.escapeHtml("Stéphanie<\nGermany", true));
assertEquals("Stéphanie<\nGermany", HtmlHelper.escapeHtml("Stéphanie<\nGermany", false));
assertEquals("Stéphanie<<br/>\r\n", HtmlHelper.escapeHtml("Stéphanie<\r\n", true));
assertEquals("Stéphanie<\r\n", HtmlHelper.escapeHtml("Stéphanie<\r\n", false));
assertEquals("Test\nStéphanie<<br/>\r\nGermany", HtmlHelper.escapeHtml("Test\nStéphanie<\r\nGermany", true));
assertEquals("Stéphanie<\r\nGermany", HtmlHelper.escapeHtml("Stéphanie<\r\nGermany", false));
}
}