Search in sources :

Example 1 with WToggleButton

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);
}
Also used : WToggleButton(com.github.bordertech.wcomponents.WToggleButton) Test(org.junit.Test)

Example 2 with WToggleButton

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);
}
Also used : WToggleButton(com.github.bordertech.wcomponents.WToggleButton) Test(org.junit.Test)

Example 3 with WToggleButton

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");
}
Also used : WToggleButton(com.github.bordertech.wcomponents.WToggleButton) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WCheckBox(com.github.bordertech.wcomponents.WCheckBox)

Example 4 with WToggleButton

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);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WToggleButton(com.github.bordertech.wcomponents.WToggleButton) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 5 with WToggleButton

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);
}
Also used : WToggleButton(com.github.bordertech.wcomponents.WToggleButton) Test(org.junit.Test)

Aggregations

WToggleButton (com.github.bordertech.wcomponents.WToggleButton)5 Test (org.junit.Test)4 WButton (com.github.bordertech.wcomponents.WButton)1 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)1 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)1 WContainer (com.github.bordertech.wcomponents.WContainer)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1