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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations