use of com.github.bordertech.wcomponents.DefaultWComponent in project wcomponents by BorderTech.
the class WSuggestionsRenderer_Test method testDoPaintAjaxOptions.
@Test
public void testDoPaintAjaxOptions() throws IOException, SAXException, XpathException {
List<String> options = Arrays.asList("A", "B", "C");
WSuggestions field = new WSuggestions(options);
// Set action for AJAX refresh
field.setRefreshAction(new Action() {
@Override
public void execute(final ActionEvent event) {
// Do nothing
}
});
assertSchemaMatch(field);
assertXpathEvaluatesTo(field.getId(), "//ui:suggestions/@id", field);
assertXpathNotExists("//ui:suggestions/@min", field);
assertXpathNotExists("//ui:suggestions/@data", field);
// AJAX flag should be true
assertXpathEvaluatesTo("true", "//ui:suggestions/@ajax", field);
// Suggestions should only be rendered when refreshed via AJAX
assertXpathNotExists("//ui:suggestions/ui:suggestion", field);
// Setup suggestions as the current AJAX trigger
UIContext uic = createUIContext();
uic.setUI(new DefaultWComponent());
setActiveContext(uic);
try {
AjaxOperation operation = new AjaxOperation(field.getId(), field.getId());
AjaxHelper.setCurrentOperationDetails(operation, null);
assertSchemaMatch(field);
assertXpathExists("//ui:suggestions/ui:suggestion", field);
assertXpathEvaluatesTo(options.get(0), "//ui:suggestions/ui:suggestion[1]/@value", field);
assertXpathEvaluatesTo(options.get(1), "//ui:suggestions/ui:suggestion[2]/@value", field);
assertXpathEvaluatesTo(options.get(2), "//ui:suggestions/ui:suggestion[3]/@value", field);
} finally {
AjaxHelper.clearCurrentOperationDetails();
}
}
use of com.github.bordertech.wcomponents.DefaultWComponent in project wcomponents by BorderTech.
the class WSectionRenderer_Test method testRenderedEagerMode.
@Test
public void testRenderedEagerMode() throws IOException, SAXException, XpathException {
WSection section = new WSection(SECTION_HEADING);
section.setMode(SectionMode.EAGER);
section.getContent().add(new WText(SECTION_CONTENT));
UIContext uic = createUIContext();
uic.setUI(new DefaultWComponent());
setActiveContext(uic);
// The section's content should NOT be rendered
assertSchemaMatch(section);
assertXpathEvaluatesTo("", "//ui:section/@type", section);
assertXpathEvaluatesTo("", "//ui:section/@hidden", section);
assertXpathEvaluatesTo("eager", "//ui:section/@mode", section);
assertXpathEvaluatesTo("", "normalize-space(//ui:section/ui:panel)", section);
try {
// Section is the AJAX Trigger, content should be rendered
AjaxOperation operation = new AjaxOperation(section.getId(), section.getId());
AjaxHelper.setCurrentOperationDetails(operation, null);
assertSchemaMatch(section);
assertXpathEvaluatesTo("", "//ui:section/@type", section);
assertXpathEvaluatesTo("", "//ui:section/@hidden", section);
assertXpathEvaluatesTo("eager", "//ui:section/@mode", section);
assertXpathEvaluatesTo(SECTION_CONTENT, "normalize-space(//ui:section/ui:panel)", section);
} finally {
AjaxHelper.clearCurrentOperationDetails();
}
}
use of com.github.bordertech.wcomponents.DefaultWComponent in project wcomponents by BorderTech.
the class WValidationErrorsRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
WValidationErrors errors = new WValidationErrors();
String content = getMaliciousContent();
List<Diagnostic> diags = new ArrayList<>();
diags.add(new DiagnosticImpl(Diagnostic.ERROR, new DefaultWComponent(), content));
errors.setErrors(diags);
assertSafeContent(errors);
}
use of com.github.bordertech.wcomponents.DefaultWComponent in project wcomponents by BorderTech.
the class WFigureRenderer_Test method testRenderedEagerMode.
@Test
public void testRenderedEagerMode() throws IOException, SAXException, XpathException {
WFigure figure = new WFigure(new WText(FIGURE_CONTENT), FIGURE_HEADING);
figure.setMode(FigureMode.EAGER);
UIContext uic = createUIContext();
uic.setUI(new DefaultWComponent());
setActiveContext(uic);
// The figure's content should NOT be rendered
assertSchemaMatch(figure);
assertXpathEvaluatesTo("", "//ui:figure/@type", figure);
assertXpathEvaluatesTo("", "//ui:figure/@hidden", figure);
assertXpathEvaluatesTo("eager", "//ui:figure/@mode", figure);
assertXpathEvaluatesTo("", "//ui:figure/ui:content", figure);
try {
// Figure is the AJAX Trigger, content should be rendered
AjaxOperation operation = new AjaxOperation(figure.getId(), figure.getId());
AjaxHelper.setCurrentOperationDetails(operation, null);
assertSchemaMatch(figure);
assertXpathEvaluatesTo("", "//ui:figure/@type", figure);
assertXpathEvaluatesTo("", "//ui:figure/@hidden", figure);
assertXpathEvaluatesTo("eager", "//ui:figure/@mode", figure);
assertXpathEvaluatesTo(FIGURE_CONTENT, "//ui:figure/ui:content", figure);
} finally {
AjaxHelper.clearCurrentOperationDetails();
}
}
use of com.github.bordertech.wcomponents.DefaultWComponent in project wcomponents by BorderTech.
the class WInternalLinkRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
WInternalLink link = new WInternalLink(getMaliciousContent(), new DefaultWComponent());
assertSafeContent(link);
link.setToolTip(getMaliciousAttribute("ui:link"));
assertSafeContent(link);
link.setAccessibleText(getMaliciousAttribute("ui:link"));
assertSafeContent(link);
}
Aggregations