Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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");
Expand Down
Loading