use of com.github.bordertech.wcomponents.WToggleButton in project wcomponents by BorderTech.
the class WToggleButtonRenderer_Test method testRendererCorrectlyConfigured.
@Test
public void testRendererCorrectlyConfigured() {
WToggleButton component = new WToggleButton();
Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(component) instanceof WToggleButtonRenderer);
}
use of com.github.bordertech.wcomponents.WToggleButton in project wcomponents by BorderTech.
the class WToggleButtonRenderer_Test method textReadOnly.
@Test
public void textReadOnly() throws IOException, SAXException, XpathException {
WToggleButton toggle = new WToggleButton();
// Check readOnly
assertXpathNotExists("//ui:togglebutton/@readOnly", toggle);
toggle.setReadOnly(true);
assertSchemaMatch(toggle);
assertXpathEvaluatesTo("true", "//ui:togglebutton/@readOnly", toggle);
}
use of com.github.bordertech.wcomponents.WToggleButton in project wcomponents by BorderTech.
the class WToggleButtonRenderer method doRender.
/**
* Paints the given WCheckBox.
*
* @param component the WCheckBox to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WToggleButton toggle = (WToggleButton) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean readOnly = toggle.isReadOnly();
xml.appendTagOpen("ui:togglebutton");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", toggle.isHidden(), "true");
xml.appendOptionalAttribute("selected", toggle.isSelected(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
WComponentGroup<WCheckBox> group = toggle.getGroup();
String groupName = group == null ? null : group.getId();
xml.appendOptionalAttribute("groupName", groupName);
xml.appendOptionalAttribute("disabled", toggle.isDisabled(), "true");
xml.appendOptionalAttribute("submitOnChange", toggle.isSubmitOnChange(), "true");
xml.appendOptionalAttribute("toolTip", toggle.getToolTip());
xml.appendOptionalAttribute("accessibleText", toggle.getAccessibleText());
}
xml.appendClose();
String text = toggle.getText();
if (text != null) {
xml.appendEscaped(text);
}
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(toggle, renderContext);
}
xml.appendEndTag("ui:togglebutton");
}
use of com.github.bordertech.wcomponents.WToggleButton in project wcomponents by BorderTech.
the class WToggleButtonRenderer_Test method testDoPaint.
@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
WToggleButton toggle = new WToggleButton();
WComponentGroup<WToggleButton> group = new WComponentGroup<>();
WButton button = new WButton("test");
WContainer root = new WContainer();
root.add(toggle);
root.add(group);
root.add(button);
setActiveContext(createUIContext());
assertSchemaMatch(toggle);
assertXpathExists("//ui:togglebutton", toggle);
assertXpathEvaluatesTo(toggle.getId(), "//ui:togglebutton/@id", toggle);
// Check disabled
assertXpathNotExists("//ui:togglebutton/@disabled", toggle);
toggle.setDisabled(true);
assertSchemaMatch(toggle);
assertXpathEvaluatesTo("true", "//ui:togglebutton/@disabled", toggle);
// Check hidden
assertXpathNotExists("//ui:togglebutton/@hidden", toggle);
setFlag(toggle, ComponentModel.HIDE_FLAG, true);
assertSchemaMatch(toggle);
assertXpathEvaluatesTo("true", "//ui:togglebutton/@hidden", toggle);
// Check selected
assertXpathNotExists("//ui:togglebutton/@selected", toggle);
toggle.setSelected(true);
assertSchemaMatch(toggle);
assertXpathEvaluatesTo("true", "//ui:togglebutton/@selected", toggle);
// Check toolTip
assertXpathNotExists("//ui:togglebutton/@toolTip", toggle);
toggle.setToolTip("WCheckBox_Test.testRenderedFormat.title");
assertSchemaMatch(toggle);
assertXpathEvaluatesTo(toggle.getToolTip(), "//ui:togglebutton/@toolTip", toggle);
// Check accessibleText
assertXpathNotExists("//ui:togglebutton/@accessibleText", toggle);
toggle.setAccessibleText("WCheckBox_Test.testRenderedFormat.accessibleText");
assertSchemaMatch(toggle);
assertXpathEvaluatesTo(toggle.getAccessibleText(), "//ui:togglebutton/@accessibleText", toggle);
}
use of com.github.bordertech.wcomponents.WToggleButton in project wcomponents by BorderTech.
the class WToggleButtonRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
WToggleButton checkBox = new WToggleButton();
assertSafeContent(checkBox);
checkBox.setToolTip(getMaliciousAttribute());
assertSafeContent(checkBox);
checkBox.setAccessibleText(getMaliciousAttribute());
assertSafeContent(checkBox);
}
Aggregations