Search in sources :

Example 31 with WButton

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

the class WAjaxControlRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WAjaxControl component = new WAjaxControl(new WButton("x"));
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(component) instanceof WAjaxControlRenderer);
}
Also used : WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 32 with WButton

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

the class WTableRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WTable table = new WTable();
    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);
    TableModel tableModel = createTableModel();
    table.setTableModel(tableModel);
    // clear out cached data from previous renders
    uic.clearScratchMap();
    assertSafeContent(table);
    table.setCaption(getMaliciousAttribute("ui:table"));
    assertSafeContent(table);
}
Also used : WTable(com.github.bordertech.wcomponents.WTable) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) WText(com.github.bordertech.wcomponents.WText) UIContext(com.github.bordertech.wcomponents.UIContext) ActionConstraint(com.github.bordertech.wcomponents.WTable.ActionConstraint) WButton(com.github.bordertech.wcomponents.WButton) TableModel(com.github.bordertech.wcomponents.WTable.TableModel) AdapterBasicTableModel(com.github.bordertech.wcomponents.AdapterBasicTableModel) SimpleTableModel(com.github.bordertech.wcomponents.SimpleTableModel) Test(org.junit.Test)

Example 33 with WButton

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

the class WTableRenderer_Test method testDoPaintTableActionsWithConstraints.

@Test
public void testDoPaintTableActionsWithConstraints() throws IOException, SAXException, XpathException {
    final int minSelectedRowCount1 = 1;
    final int maxSelectedRowCount1 = 2;
    final int selectedOnOther1 = 0;
    final String message1 = "message1";
    final int minSelectedRowCount2 = 1;
    final int maxSelectedRowCount2 = 2;
    final int selectedOnOther2 = 0;
    final String message2 = "message2";
    WTable component = new WTable();
    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));
    TableModel tableModel = createTableModel();
    component.setTableModel(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(((new Integer(selectedOnOther1))).toString(), "//ui:table/ui:actions/ui:action[1]/ui:condition/@selectedOnOther", 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(((new Integer(selectedOnOther2))).toString(), "//ui:table/ui:actions/ui:action[1]/ui:condition/@selectedOnOther", 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 : WTable(com.github.bordertech.wcomponents.WTable) WTableColumn(com.github.bordertech.wcomponents.WTableColumn) ActionConstraint(com.github.bordertech.wcomponents.WTable.ActionConstraint) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) ActionConstraint(com.github.bordertech.wcomponents.WTable.ActionConstraint) TableModel(com.github.bordertech.wcomponents.WTable.TableModel) AdapterBasicTableModel(com.github.bordertech.wcomponents.AdapterBasicTableModel) SimpleTableModel(com.github.bordertech.wcomponents.SimpleTableModel) Test(org.junit.Test)

Example 34 with WButton

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

the class WTextFieldRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WTextField textField = new WTextField();
    WButton button = new WButton();
    WSuggestions suggestions = new WSuggestions();
    WContainer root = new WContainer();
    root.add(textField);
    root.add(button);
    root.add(suggestions);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(textField.getId(), "//ui:textfield/@id", textField);
    assertXpathNotExists("//ui:textfield/@disabled", textField);
    assertXpathNotExists("//ui:textfield/@hidden", textField);
    assertXpathNotExists("//ui:textfield/@required", textField);
    assertXpathNotExists("//ui:textfield/@readOnly", textField);
    assertXpathNotExists("//ui:textfield/@minLength", textField);
    assertXpathNotExists("//ui:textfield/@maxLength", textField);
    assertXpathNotExists("//ui:textfield/@toolTip", textField);
    assertXpathNotExists("//ui:textfield/@accessibleText", textField);
    assertXpathNotExists("//ui:textfield/@size", textField);
    assertXpathNotExists("//ui:textfield/@buttonId", textField);
    assertXpathNotExists("//ui:textfield/@pattern", textField);
    assertXpathNotExists("//ui:textfield/@list", textField);
    textField.setDisabled(true);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("true", "//ui:textfield/@disabled", textField);
    setFlag(textField, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("true", "//ui:textfield/@hidden", textField);
    textField.setMandatory(true);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("true", "//ui:textfield/@required", textField);
    textField.setMinLength(45);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("45", "//ui:textfield/@minLength", textField);
    textField.setMaxLength(50);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("50", "//ui:textfield/@maxLength", textField);
    textField.setToolTip("tooltip");
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(textField.getToolTip(), "//ui:textfield/@toolTip", textField);
    textField.setAccessibleText("accessible");
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(textField.getAccessibleText(), "//ui:textfield/@accessibleText", textField);
    textField.setColumns(40);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("40", "//ui:textfield/@size", textField);
    textField.setDefaultSubmitButton(button);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(button.getId(), "//ui:textfield/@buttonId", textField);
    textField.setPattern("");
    assertSchemaMatch(textField);
    assertXpathNotExists("//ui:textfield/@pattern", textField);
    textField.setPattern("test[123]");
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(textField.getPattern(), "//ui:textfield/@pattern", textField);
    textField.setText("Hello");
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(textField.getText(), "normalize-space(//ui:textfield)", textField);
    textField.setSuggestions(suggestions);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(suggestions.getId(), "//ui:textfield/@list", textField);
    textField.setPlaceholder("enter stuff here");
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("enter stuff here", "//ui:textfield/@placeholder", textField);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WSuggestions(com.github.bordertech.wcomponents.WSuggestions) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 35 with WButton

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

the class WApplicationRenderer_Test method testDoPaintWithChildren.

@Test
public void testDoPaintWithChildren() throws IOException, SAXException, XpathException {
    WApplication application = new WApplication();
    WText text = new WText("test text");
    WButton button = new WButton("button");
    application.add(text);
    application.add(button);
    MockWEnvironment environment = new MockWEnvironment();
    UIContext uic = createUIContext();
    uic.setEnvironment(environment);
    setActiveContext(uic);
    application.setUnsavedChanges(true);
    // Check Schema
    assertSchemaMatch(application);
    assertXpathEvaluatesTo(WComponent.DEFAULT_APPLICATION_ID, "//ui:application/@id", application);
    assertXpathEvaluatesTo("true", "//ui:application/@unsavedChanges", application);
    // Check Children
    assertXpathEvaluatesTo("test text", "normalize-space(//ui:application/text()[1])", application);
    assertXpathEvaluatesTo("1", "count(//ui:application/html:button)", application);
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) WApplication(com.github.bordertech.wcomponents.WApplication) WText(com.github.bordertech.wcomponents.WText) UIContext(com.github.bordertech.wcomponents.UIContext) 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