Search in sources :

Example 6 with MockWEnvironment

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

the class WApplicationRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    MockWEnvironment environment = new MockWEnvironment();
    environment.setPostPath("WApplicationRendererTest.postPath");
    WApplication application = new WApplication();
    UIContext uic = createUIContext();
    uic.setEnvironment(environment);
    uic.setUI(application);
    setActiveContext(uic);
    application.setTitle(getMaliciousAttribute("ui:application"));
    assertSafeContent(application);
    uic.getEnvironment().getHiddenParameters().put(getMaliciousAttribute("ui:param"), "dummy");
    uic.getEnvironment().getHiddenParameters().put("dummy", getMaliciousAttribute("ui:param"));
    assertSafeContent(application);
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) WApplication(com.github.bordertech.wcomponents.WApplication) UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 7 with MockWEnvironment

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

the class WApplicationRenderer_Test method testBasicRenderedFormat.

@Test
public void testBasicRenderedFormat() throws XpathException, IOException, SAXException {
    // Basic component (no optional fields)
    MockWEnvironment environment = new MockWEnvironment();
    WApplication application = new WApplication();
    environment.setPostPath("WApplicationRendererTest.postPath");
    UIContext uic = createUIContext();
    uic.setEnvironment(environment);
    uic.setUI(application);
    setActiveContext(uic);
    assertSchemaMatch(application);
    assertXpathEvaluatesTo(environment.getPostPath(), "//ui:application/@applicationUrl", application);
    assertXpathEvaluatesTo(environment.getWServletPath(), "//ui:application/@ajaxUrl", application);
    assertXpathNotExists("//ui:application/@defaultFocusId", application);
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) WApplication(com.github.bordertech.wcomponents.WApplication) UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 8 with MockWEnvironment

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

the class WApplicationRenderer_Test method testRenderedFormatWithFocussedComponent.

@Test
public void testRenderedFormatWithFocussedComponent() throws XpathException, IOException, SAXException {
    MockWEnvironment environment = new MockWEnvironment();
    WApplication application = new WApplication();
    environment.setPostPath("WApplicationRendererTest.postPath");
    WTextField focussedComponent = new WTextField();
    application.add(focussedComponent);
    UIContext uic = createUIContext();
    uic.setEnvironment(environment);
    uic.setUI(application);
    uic.setFocusRequired(true);
    uic.setFocussed(focussedComponent);
    setActiveContext(uic);
    assertSchemaMatch(application);
    assertXpathEvaluatesTo(environment.getPostPath(), "//ui:application/@applicationUrl", application);
    assertXpathEvaluatesTo(WComponent.DEFAULT_APPLICATION_ID, "//ui:application/@id", application);
    assertXpathEvaluatesTo(environment.getWServletPath(), "//ui:application/@ajaxUrl", application);
    assertXpathEvaluatesTo(focussedComponent.getId(), "//ui:application/@defaultFocusId", application);
    uic.setFocusRequired(false);
    assertXpathNotExists("//ui:application/@defaultFocusId", application);
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) WApplication(com.github.bordertech.wcomponents.WApplication) UIContext(com.github.bordertech.wcomponents.UIContext) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Aggregations

MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)8 UIContext (com.github.bordertech.wcomponents.UIContext)6 WApplication (com.github.bordertech.wcomponents.WApplication)6 Test (org.junit.Test)6 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)2 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)2 Before (org.junit.Before)2 WButton (com.github.bordertech.wcomponents.WButton)1 WLabel (com.github.bordertech.wcomponents.WLabel)1 WText (com.github.bordertech.wcomponents.WText)1 WTextField (com.github.bordertech.wcomponents.WTextField)1 HashMap (java.util.HashMap)1