Search in sources :

Example 26 with WMenuItem

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

the class WMenuItemRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WMenu menu = new WMenu();
    WMenuItem item = new WMenuItem(getMaliciousAttribute());
    menu.add(item);
    assertSafeContent(menu);
    item.setToolTip(getMaliciousAttribute());
    assertSafeContent(menu);
    item.setAccessibleText(getMaliciousAttribute());
    assertSafeContent(menu);
    item.setUrl(getMaliciousAttribute());
    assertSafeContent(menu);
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WMenu(com.github.bordertech.wcomponents.WMenu) Test(org.junit.Test)

Example 27 with WMenuItem

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

the class WMenuItemRenderer_Test method testSelectability.

@Test
public void testSelectability() throws IOException, SAXException, XpathException {
    // Selectability - output as @role
    WMenuItem item = new WMenuItem(itemText);
    WMenu wrapped = wrapMenuItem(item);
    wrapped.setSelectionMode(MenuSelectContainer.SelectionMode.SINGLE);
    // default selectability is selectable
    assertXpathEvaluatesTo("menuitemradio", "//ui:menuitem/@role", item);
    item = new WMenuItem(itemText);
    wrapped.add(item);
    item.setSelectability(Boolean.FALSE);
    assertSchemaMatch(wrapped);
    assertXpathNotExists("//ui:menuitem/@role", item);
    item = new WMenuItem(itemText);
    wrapped.add(item);
    item.setSelectability(Boolean.TRUE);
    assertSchemaMatch(wrapped);
    assertXpathEvaluatesTo("menuitemradio", "//ui:menuitem/@role", item);
    item = new WMenuItem(itemText);
    wrapped = wrapMenuItem(item);
    wrapped.setSelectionMode(MenuSelectContainer.SelectionMode.MULTIPLE);
    // default selectability is selectable and so role is menuitemcheckbox
    assertXpathEvaluatesTo("menuitemcheckbox", "//ui:menuitem/@role", item);
    item = new WMenuItem(itemText);
    wrapped.add(item);
    item.setSelectability(Boolean.FALSE);
    assertXpathNotExists("//ui:menuitem/@role", item);
    item = new WMenuItem(itemText);
    wrapped.add(item);
    item.setSelectability(Boolean.TRUE);
    assertXpathEvaluatesTo("menuitemcheckbox", "//ui:menuitem/@role", item);
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WMenu(com.github.bordertech.wcomponents.WMenu) Test(org.junit.Test)

Example 28 with WMenuItem

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

the class WMenuItemRenderer_Test method testAccessKey.

@Test
public void testAccessKey() throws IOException, SAXException, XpathException {
    // AccessKey
    WMenuItem item = new WMenuItem(itemText, url);
    WMenu wrapped = wrapMenuItem(item);
    item.setAccessKey('A');
    assertSchemaMatch(wrapped);
    assertXpathEvaluatesTo("A", "//ui:menuitem/@accessKey", item);
    // no access key if nested
    WSubMenu sub = new WSubMenu("sub");
    wrapped.add(sub);
    item = new WMenuItem(itemText, url);
    sub.add(item);
    item.setAccessKey('A');
    assertSchemaMatch(wrapped);
    assertXpathNotExists("//ui:menuitem/@accessKey", item);
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WSubMenu(com.github.bordertech.wcomponents.WSubMenu) WMenu(com.github.bordertech.wcomponents.WMenu) Test(org.junit.Test)

Example 29 with WMenuItem

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

the class WMenuItemRenderer_Test method testHidden.

@Test
public void testHidden() throws IOException, SAXException, XpathException {
    WMenuItem item = new WMenuItem(itemText, url);
    WMenu wrapped = wrapMenuItem(item);
    setFlag(item, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(wrapped);
    assertXpathEvaluatesTo("true", "//ui:menuitem/@hidden", item);
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WMenu(com.github.bordertech.wcomponents.WMenu) Test(org.junit.Test)

Example 30 with WMenuItem

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

the class WMenuItemRenderer_Test method testAction.

@Test
public void testAction() throws IOException, SAXException, XpathException {
    // Test with action
    WMenuItem item = new WMenuItem(itemText, new TestAction());
    WMenu wrapped = wrapMenuItem(item);
    assertSchemaMatch(wrapped);
    assertXpathEvaluatesTo(itemText, "normalize-space(//ui:menuitem/ui:decoratedlabel)", item);
    assertXpathNotExists("//ui:menuitem/@url", item);
    assertXpathEvaluatesTo("true", "//ui:menuitem/@submit", item);
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WMenu(com.github.bordertech.wcomponents.WMenu) TestAction(com.github.bordertech.wcomponents.TestAction) Test(org.junit.Test)

Aggregations

WMenuItem (com.github.bordertech.wcomponents.WMenuItem)31 WMenu (com.github.bordertech.wcomponents.WMenu)23 Test (org.junit.Test)16 WSubMenu (com.github.bordertech.wcomponents.WSubMenu)11 WDecoratedLabel (com.github.bordertech.wcomponents.WDecoratedLabel)5 WText (com.github.bordertech.wcomponents.WText)5 Action (com.github.bordertech.wcomponents.Action)4 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)4 WImage (com.github.bordertech.wcomponents.WImage)4 WMenuItemGroup (com.github.bordertech.wcomponents.WMenuItemGroup)4 TreeNode (com.github.bordertech.wcomponents.util.TreeNode)2 Margin (com.github.bordertech.wcomponents.Margin)1 Request (com.github.bordertech.wcomponents.Request)1 TestAction (com.github.bordertech.wcomponents.TestAction)1 WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)1 WButton (com.github.bordertech.wcomponents.WButton)1 WContainer (com.github.bordertech.wcomponents.WContainer)1 WContent (com.github.bordertech.wcomponents.WContent)1 WContentLink (com.github.bordertech.wcomponents.WContentLink)1 WPanel (com.github.bordertech.wcomponents.WPanel)1