Search in sources :

Example 36 with WButton

use of com.github.bordertech.wcomponents.WButton in project wcomponents by BorderTech.

the class WButtonRenderer_Test method testAllOptions.

@Test
public void testAllOptions() throws IOException, SAXException, XpathException {
    WButton button = new WButton("All");
    button.setDisabled(true);
    setFlag(button, ComponentModel.HIDE_FLAG, true);
    button.setToolTip("Title");
    button.setAccessKey('T');
    button.setImageUrl("http://localhost/image.png");
    button.setImagePosition(ImagePosition.EAST);
    button.setRenderAsLink(true);
    button.setAjaxTarget(new WTextField());
    button.setPopupTrigger(true);
    setActiveContext(createUIContext());
    WPanel validationComponent = new WPanel();
    button.setAction(new ValidatingAction(new WValidationErrors(), validationComponent) {

        @Override
        public void executeOnValid(final ActionEvent event) {
        // Do nothing
        }
    });
    WContainer root = new WContainer();
    root.add(button);
    root.add(validationComponent);
    assertXpathExists("//html:button[@id]", button);
    assertXpathExists("//html:button[contains(@class, 'wc-linkbutton')]", button);
    assertXpathEvaluatesTo(button.getText(), "//html:button", button);
    assertXpathEvaluatesTo("disabled", "//html:button/@disabled", button);
    assertXpathEvaluatesTo("hidden", "//html:button/@hidden", button);
    assertXpathEvaluatesTo(button.getToolTip(), "//html:button/@title", button);
    assertXpathUrlEvaluatesTo(button.getImageUrl(), "//html:button//html:img/@src", button);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imge')]", button);
    assertXpathEvaluatesTo(button.getAccessKeyAsString(), "//html:button/@accesskey", button);
    assertXpathEvaluatesTo("true", "//html:button/@aria-haspopup", button);
    assertXpathEvaluatesTo(validationComponent.getId(), "//html:button/@data-wc-validate", button);
    assertXpathEvaluatesTo(button.getId(), "//ui:ajaxtrigger/@triggerId", button);
    button.setImagePosition(ImagePosition.NORTH);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgn')]", button);
    button.setImagePosition(ImagePosition.SOUTH);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgs')]", button);
    button.setImagePosition(ImagePosition.WEST);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgw')]", button);
    button.setClientCommandOnly(true);
    assertXpathEvaluatesTo("button", "//html:button/@type", button);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) WValidationErrors(com.github.bordertech.wcomponents.validation.WValidationErrors) WButton(com.github.bordertech.wcomponents.WButton) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 37 with WButton

use of com.github.bordertech.wcomponents.WButton in project wcomponents by BorderTech.

the class WButtonRenderer_Test method testRendererCorrectlyConfigured.

/**
 * Test the Layout is correctly configured.
 */
@Test
public void testRendererCorrectlyConfigured() {
    WButton component = new WButton();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(component) instanceof WButtonRenderer);
}
Also used : WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 38 with WButton

use of com.github.bordertech.wcomponents.WButton in project wcomponents by BorderTech.

the class WDataTableRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WDataTable table = new WDataTable();
    table.addColumn(new WTableColumn(getMaliciousContent(), WText.class));
    table.addColumn(new WTableColumn(getMaliciousContent(), WText.class));
    table.addColumn(new WTableColumn(getMaliciousContent(), WText.class));
    table.setNoDataMessage(getMaliciousAttribute("ui:table"));
    UIContext uic = createUIContext();
    assertSafeContent(table);
    WButton button = new WButton("dummy");
    table.addAction(button);
    table.addActionConstraint(button, new ActionConstraint(0, 1, false, getMaliciousAttribute("ui:action")));
    assertSafeContent(table);
    TableDataModel tableModel = createTableModel();
    table.setDataModel(tableModel);
    // clear out cached data from previous renders
    uic.clearScratchMap();
    assertSafeContent(table);
    table.setCaption(getMaliciousAttribute("ui:table"));
    assertSafeContent(table);
    table.setSummary(getMaliciousAttribute("ui:table"));
    assertSafeContent(table);
    table.setSelectGroup(getMaliciousAttribute("ui:rowselection"));
    assertSafeContent(table);
    table.setActiveFilters(Arrays.asList(new String[] { getMaliciousAttribute("ui:table") }));
}
Also used : WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WText(com.github.bordertech.wcomponents.WText) UIContext(com.github.bordertech.wcomponents.UIContext) WDataTable(com.github.bordertech.wcomponents.WDataTable) ActionConstraint(com.github.bordertech.wcomponents.WDataTable.ActionConstraint) SimpleTableDataModel(com.github.bordertech.wcomponents.SimpleTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 39 with WButton

use of com.github.bordertech.wcomponents.WButton in project wcomponents by BorderTech.

the class WDataTableRenderer_Test method testDoPaintTableActionsWithConstraints.

@Test
public void testDoPaintTableActionsWithConstraints() throws IOException, SAXException, XpathException {
    final int minSelectedRowCount1 = 1;
    final int maxSelectedRowCount1 = 2;
    final String message1 = "message1";
    final int minSelectedRowCount2 = 1;
    final int maxSelectedRowCount2 = 2;
    final String message2 = "message2";
    WDataTable component = new WDataTable();
    component.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class));
    component.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class));
    component.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class));
    TableDataModel tableModel = createTableModel();
    component.setDataModel(tableModel);
    component.setVisible(true);
    WButton buttonOne = new WButton(TEST_ACTION_ONE);
    WButton buttonTwo = new WButton(TEST_ACTION_TWO);
    component.addAction(buttonOne);
    component.addAction(buttonTwo);
    component.addActionConstraint(buttonOne, new ActionConstraint(minSelectedRowCount1, maxSelectedRowCount1, true, message1));
    component.addActionConstraint(buttonTwo, new ActionConstraint(minSelectedRowCount2, maxSelectedRowCount2, false, message2));
    assertXpathExists("//ui:table/ui:actions", component);
    assertXpathEvaluatesTo(TEST_ACTION_ONE, "//ui:table/ui:actions/ui:action[1]/html:button", component);
    assertXpathEvaluatesTo(TEST_ACTION_TWO, "//ui:table/ui:actions/ui:action[2]/html:button", component);
    String expectedWarning = "error";
    assertXpathEvaluatesTo(((new Integer(minSelectedRowCount1))).toString(), "//ui:table/ui:actions/ui:action[1]/ui:condition/@minSelectedRows", component);
    assertXpathEvaluatesTo(((new Integer(maxSelectedRowCount1))).toString(), "//ui:table/ui:actions/ui:action[1]/ui:condition/@maxSelectedRows", component);
    assertXpathEvaluatesTo(expectedWarning, "//ui:table/ui:actions/ui:action[1]/ui:condition/@type", component);
    assertXpathEvaluatesTo(message1, "//ui:table/ui:actions/ui:action[1]/ui:condition/@message", component);
    expectedWarning = "warning";
    assertXpathEvaluatesTo(((new Integer(minSelectedRowCount2))).toString(), "//ui:table/ui:actions/ui:action[2]/ui:condition/@minSelectedRows", component);
    assertXpathEvaluatesTo(((new Integer(maxSelectedRowCount2))).toString(), "//ui:table/ui:actions/ui:action[2]/ui:condition/@maxSelectedRows", component);
    assertXpathEvaluatesTo(expectedWarning, "//ui:table/ui:actions/ui:action[2]/ui:condition/@type", component);
    assertXpathEvaluatesTo(message2, "//ui:table/ui:actions/ui:action[2]/ui:condition/@message", component);
}
Also used : WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WDataTable(com.github.bordertech.wcomponents.WDataTable) ActionConstraint(com.github.bordertech.wcomponents.WDataTable.ActionConstraint) SimpleTableDataModel(com.github.bordertech.wcomponents.SimpleTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) ActionConstraint(com.github.bordertech.wcomponents.WDataTable.ActionConstraint) Test(org.junit.Test)

Example 40 with WButton

use of com.github.bordertech.wcomponents.WButton in project wcomponents by BorderTech.

the class WPanelRenderer_Test method testRenderedFormatWithButton.

@Test
public void testRenderedFormatWithButton() throws IOException, SAXException, XpathException {
    WPanel panel = new WPanel();
    WButton button = new WButton("submit");
    panel.add(button);
    panel.setDefaultSubmitButton(button);
    assertSchemaMatch(panel);
    assertXpathEvaluatesTo(button.getId(), "//ui:panel/@buttonId", panel);
}
Also used : WPanel(com.github.bordertech.wcomponents.WPanel) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Aggregations

WButton (com.github.bordertech.wcomponents.WButton)76 Test (org.junit.Test)39 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)25 Action (com.github.bordertech.wcomponents.Action)20 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)18 WTextField (com.github.bordertech.wcomponents.WTextField)17 WHeading (com.github.bordertech.wcomponents.WHeading)16 WContainer (com.github.bordertech.wcomponents.WContainer)14 WPanel (com.github.bordertech.wcomponents.WPanel)13 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)11 ValidatingAction (com.github.bordertech.wcomponents.validation.ValidatingAction)10 WLabel (com.github.bordertech.wcomponents.WLabel)9 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)8 UIContext (com.github.bordertech.wcomponents.UIContext)7 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)7 WText (com.github.bordertech.wcomponents.WText)6 WDataTable (com.github.bordertech.wcomponents.WDataTable)5 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)5 WTable (com.github.bordertech.wcomponents.WTable)5 AdapterBasicTableModel (com.github.bordertech.wcomponents.AdapterBasicTableModel)4