Author: husted Date: Mon Mar 19 20:18:23 2007 New Revision: 520249 URL: http://svn.apache.org/viewvc?view=rev&rev=520249 Log: WW-1825 "Anchor tag inserts newline at end of tag" apply patch submitted by Claus Ibsen
Modified: struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/template/simple/a-close.ftl struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/template/simple/a.ftl struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/template/simple/common-attributes.ftl struts/struts2/branches/STRUTS_2_0_X/core/src/test/java/org/apache/struts2/views/jsp/AnchorTagTest.java Modified: struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/template/simple/a-close.ftl URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/template/simple/a-close.ftl?view=diff&rev=520249&r1=520248&r2=520249 ============================================================================== --- struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/template/simple/a-close.ftl (original) +++ struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/template/simple/a-close.ftl Mon Mar 19 20:18:23 2007 @@ -1 +1 @@ -</a> +</a><#rt/> Modified: struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/template/simple/a.ftl URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/template/simple/a.ftl?view=diff&rev=520249&r1=520248&r2=520249 ============================================================================== --- struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/template/simple/a.ftl (original) +++ struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/template/simple/a.ftl Mon Mar 19 20:18:23 2007 @@ -19,4 +19,4 @@ </#if> <#include "/${parameters.templateDir}/simple/scripting-events.ftl" /> <#include "/${parameters.templateDir}/simple/common-attributes.ftl" /> -> +><#rt/> Modified: struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/template/simple/common-attributes.ftl URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/template/simple/common-attributes.ftl?view=diff&rev=520249&r1=520248&r2=520249 ============================================================================== --- struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/template/simple/common-attributes.ftl (original) +++ struts/struts2/branches/STRUTS_2_0_X/core/src/main/resources/template/simple/common-attributes.ftl Mon Mar 19 20:18:23 2007 @@ -1,3 +1,3 @@ <#if parameters.accesskey?exists> - accesskey="${parameters.accesskey?html}" -</#if> \ No newline at end of file + accesskey="${parameters.accesskey?html}"<#rt/> +</#if> Modified: struts/struts2/branches/STRUTS_2_0_X/core/src/test/java/org/apache/struts2/views/jsp/AnchorTagTest.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_2_0_X/core/src/test/java/org/apache/struts2/views/jsp/AnchorTagTest.java?view=diff&rev=520249&r1=520248&r2=520249 ============================================================================== --- struts/struts2/branches/STRUTS_2_0_X/core/src/test/java/org/apache/struts2/views/jsp/AnchorTagTest.java (original) +++ struts/struts2/branches/STRUTS_2_0_X/core/src/test/java/org/apache/struts2/views/jsp/AnchorTagTest.java Mon Mar 19 20:18:23 2007 @@ -22,7 +22,6 @@ import java.io.StringWriter; -import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import org.apache.struts2.views.jsp.ui.AnchorTag; @@ -30,41 +29,12 @@ /** - * + * Unit test for {@ link AnchorTag}. */ public class AnchorTagTest extends AbstractUITagTest { private StringWriter writer = new StringWriter(); private AnchorTag tag; - public void testActionURL() { - tag.setHref("TestAction.action"); - try { - tag.doStartTag(); - tag.doEndTag(); - assertTrue( writer.toString().indexOf("href=\"TestAction.action\"") > -1); - } catch (JspException ex) { - ex.printStackTrace(); - fail(); - } - } - - public void testAddParameters() { - tag.setHref("/TestAction.action"); - String bodyText = "<img src=\"#\"/>"; - try { - StrutsBodyContent bodyContent = new StrutsBodyContent(null); - bodyContent.print(bodyText); - tag.setBodyContent(bodyContent); - - tag.doStartTag(); - tag.doEndTag(); - } catch (Exception ex) { - ex.printStackTrace(); - fail(); - } - } - - protected void setUp() throws Exception { super.setUp(); @@ -76,6 +46,87 @@ tag.setPageContext(pageContext); JspWriter jspWriter = new StrutsMockJspWriter(writer); pageContext.setJspWriter(jspWriter); + } + + public void testActionURL() throws Exception { + tag.setHref("TestAction.action"); + tag.doStartTag(); + tag.doEndTag(); + assertTrue(writer.toString().indexOf("href=\"TestAction.action\"") > -1); + assertEquals("<a href=\"TestAction.action\"></a>", writer.toString()); + } + + public void testNoNewLineAtEnd() throws Exception { + tag.setHref("TestAction.action"); + tag.doStartTag(); + tag.doEndTag(); + assertFalse(writer.toString().endsWith("\n")); + } + + public void testAccessKey() throws Exception { + tag.setHref("TestAction.action"); + tag.setAccesskey("T"); + tag.doStartTag(); + tag.doEndTag(); + assertTrue(writer.toString().indexOf("accesskey=\"T\"") > -1); + assertFalse(writer.toString().endsWith("\n")); + } + + public void testId() throws Exception { + tag.setId("home&improvements"); + tag.doStartTag(); + tag.doEndTag(); + assertEquals("<a id=\"home&improvements\"></a>", writer.toString()); + assertFalse(writer.toString().endsWith("\n")); + } + + public void testTitle() throws Exception { + tag.setHref("home.ftl"); + tag.setTitle("home & improvements"); + tag.doStartTag(); + tag.doEndTag(); + assertEquals("<a href=\"home.ftl\" title=\"home & improvements\"></a>", writer.toString()); + assertFalse(writer.toString().endsWith("\n")); + } + + public void testOnMouseOver() throws Exception { + tag.setHref("TestAction.action"); + tag.setOnmouseover("over"); + tag.doStartTag(); + tag.doEndTag(); + assertTrue(writer.toString().indexOf("onmouseover=\"over\"") > -1); + assertFalse(writer.toString().endsWith("\n")); + } + + public void testOnMouseOverAndFocus() throws Exception { + tag.setHref("TestAction.action"); + tag.setOnmouseover("overme"); + tag.setOnfocus("focusme"); + tag.doStartTag(); + tag.doEndTag(); + assertTrue(writer.toString().indexOf("onmouseover=\"overme\"") > -1); + assertTrue(writer.toString().indexOf("onfocus=\"focusme\"") > -1); + assertFalse(writer.toString().endsWith("\n")); + } + + public void testWithContent() throws Exception { + tag.setHref("TestAction.action"); + tag.doStartTag(); + writer.write("Home"); + tag.doEndTag(); + assertEquals("<a href=\"TestAction.action\">Home</a>", writer.toString()); + assertFalse(writer.toString().endsWith("\n")); + } + + public void testAddParameters() throws Exception { + tag.setHref("/TestAction.action"); + String bodyText = "<img src=\"#\"/>"; + StrutsBodyContent bodyContent = new StrutsBodyContent(null); + bodyContent.print(bodyText); + tag.setBodyContent(bodyContent); + + tag.doStartTag(); + tag.doEndTag(); } }