Search in sources :

Example 21 with WMenu

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

the class WMenuItemRenderer_Test method testRoleWhenSelectedNotSelectable.

@Test
public void testRoleWhenSelectedNotSelectable() throws IOException, SAXException, XpathException {
    /*
		 * A WMenuItem may be set as selected even if it is not in a selection container. This is a flaw in an
		 * old part of the WComponents API.
		 */
    WMenuItem item = new WMenuItem(itemText);
    WMenu wrapped = wrapMenuItem(item);
    wrapped.setSelectionMode(MenuSelectContainer.SelectionMode.SINGLE);
    assertXpathNotExists("//ui:menuitem/@selected", item);
    wrapped.setSelectedItem(item);
    assertSchemaMatch(wrapped);
    assertXpathEvaluatesTo("true", "//ui:menuitem/@selected", item);
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WMenu(com.github.bordertech.wcomponents.WMenu) Test(org.junit.Test)

Example 22 with WMenu

use of com.github.bordertech.wcomponents.WMenu 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 23 with WMenu

use of com.github.bordertech.wcomponents.WMenu 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 24 with WMenu

use of com.github.bordertech.wcomponents.WMenu 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 25 with WMenu

use of com.github.bordertech.wcomponents.WMenu 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)

Aggregations

WMenu (com.github.bordertech.wcomponents.WMenu)28 WMenuItem (com.github.bordertech.wcomponents.WMenuItem)23 Test (org.junit.Test)16 WSubMenu (com.github.bordertech.wcomponents.WSubMenu)8 Action (com.github.bordertech.wcomponents.Action)4 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)4 WDecoratedLabel (com.github.bordertech.wcomponents.WDecoratedLabel)2 WImage (com.github.bordertech.wcomponents.WImage)2 WMenuItemGroup (com.github.bordertech.wcomponents.WMenuItemGroup)2 WText (com.github.bordertech.wcomponents.WText)2 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 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 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1