From 7b46cf02bfd62a7e7adaf85c42d326f801c6c21c Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Sat, 17 Oct 2026 16:02:03 +0200 Subject: [PATCH] WW-3792 test(core): pin css_xhtml checkbox left-label wrappers to match other controls Under css_xhtml every control wraps its label and control in
for labelPosition="top" and otherwise. Pins that a checkbox with labelPosition="left" uses the same wrapper elements as a textfield. Co-Authored-By: Claude Opus 5.5 --- .../struts2/views/jsp/ui/CheckboxTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/CheckboxTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/CheckboxTest.java index e7da044ca7..ead4812794 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ui/CheckboxTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/CheckboxTest.java @@ -25,6 +25,8 @@ import org.apache.struts2.views.jsp.AbstractUITagTest; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class CheckboxTest extends AbstractUITagTest { @@ -233,6 +235,41 @@ public void testCheckedWithLeftLabelPosition_clearTagStateSet() throws Exception strutsBodyTagsAreReflectionEqual(tag, freshTag)); } + public void testCssXhtmlLeftLabelPositionWrapsLikeTextfield() throws Exception { + TextFieldTag textfield = new TextFieldTag(); + textfield.setPageContext(pageContext); + textfield.setId("textId"); + textfield.setLabel("mylabel"); + textfield.setName("foo"); + textfield.setTheme("css_xhtml"); + textfield.setLabelPosition("left"); + textfield.doStartTag(); + textfield.doEndTag(); + String textfieldOutput = writer.toString(); + writer.getBuffer().setLength(0); + + CheckboxTag checkbox = new CheckboxTag(); + checkbox.setPageContext(pageContext); + checkbox.setId("checkboxId"); + checkbox.setLabel("mylabel"); + checkbox.setName("foo"); + checkbox.setFieldValue("baz"); + checkbox.setTheme("css_xhtml"); + checkbox.setLabelPosition("left"); + checkbox.doStartTag(); + checkbox.doEndTag(); + String checkboxOutput = writer.toString(); + + assertEquals(wrapperElement(textfieldOutput, "wwlbl_textId"), wrapperElement(checkboxOutput, "wwlbl_checkboxId")); + assertEquals(wrapperElement(textfieldOutput, "wwctrl_textId"), wrapperElement(checkboxOutput, "wwctrl_checkboxId")); + } + + private static String wrapperElement(String html, String id) { + Matcher matcher = Pattern.compile("<(\\w+)\\s+id=\"" + id + "\"").matcher(html); + assertTrue("No element with id " + id + " in: " + html, matcher.find()); + return matcher.group(1); + } + public void testCheckedWithError() throws Exception { TestAction testAction = (TestAction) action; testAction.setFoo("true");