use of org.apache.wicket.util.tester.TagTester in project wicket by apache.
the class ButtonTest method whenInputElement_thenModelObjectIsUsedForValueAttribute.
/**
* WICKET-4734 Asserting that the value attribute on tag input is escaped once by default
*/
@Test
public void whenInputElement_thenModelObjectIsUsedForValueAttribute() {
tester.getApplication().getMarkupSettings().setStripWicketTags(false);
String text = "some text & another text";
TestPage testPage = new TestPage(Model.of(text));
tester.startPage(testPage);
TagTester buttonTagTester = tester.getTagByWicketId("button");
assertThat(buttonTagTester, is(notNullValue()));
assertThat(buttonTagTester.getAttribute("value"), is(equalTo(text)));
assertThat(buttonTagTester.getValue(), is(nullValue()));
}
use of org.apache.wicket.util.tester.TagTester in project wicket by apache.
the class ButtonTest method whenButtonElementWithoutModelObject_thenUseTextContentFromHtml.
/**
* https://issues.apache.org/jira/browse/WICKET-6225
*/
@Test
public void whenButtonElementWithoutModelObject_thenUseTextContentFromHtml() {
tester.getApplication().getMarkupSettings().setStripWicketTags(false);
String text = "some text & another text";
final String textInHtml = "Button label in HTML";
TestPage testPage = new TestPage(Model.of("")) {
@Override
public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass) {
return new StringResourceStream("<html><body>" + "<form wicket:id=\"form\"><button wicket:id=\"button\">" + textInHtml + "</button></form></body></html>");
}
};
tester.startPage(testPage);
TagTester buttonTagTester = tester.getTagByWicketId("button");
assertThat(buttonTagTester, is(notNullValue()));
assertThat(buttonTagTester.getAttribute("value"), is(nullValue()));
assertThat(buttonTagTester.getValue(), is(equalTo(textInHtml)));
}
use of org.apache.wicket.util.tester.TagTester in project wicket by apache.
the class BehaviorTest method onTagTest.
@Test
public void onTagTest() {
WebMarkupContainer component = new WebMarkupContainer(MockPageWithOneComponent.COMPONENT_ID);
MockPageWithOneComponent page = new MockPageWithOneComponent();
page.add(component);
String value = "value";
String key = "key";
component.add(Behavior.onTag((c, tag) -> tag.put(key, value)));
component.add(Behavior.onAttribute("class", oldValue -> "zzz"));
tester.startPage(page);
TagTester tagTester = tester.getTagByWicketId(MockPageWithOneComponent.COMPONENT_ID);
assertThat(tagTester.getAttribute(key), is(equalTo(value)));
assertThat(tagTester.getAttribute("class"), is(equalTo("zzz")));
}
use of org.apache.wicket.util.tester.TagTester in project wicket by apache.
the class BehaviorTest method onAttributeTest.
@Test
public void onAttributeTest() {
WebMarkupContainer component = new WebMarkupContainer(MockPageWithOneComponent.COMPONENT_ID);
MockPageWithOneComponent page = new MockPageWithOneComponent();
page.add(component);
String value = "value";
String key = "key";
component.add(Behavior.onAttribute(key, oldValue -> value));
tester.startPage(page);
TagTester tagTester = tester.getTagByWicketId(MockPageWithOneComponent.COMPONENT_ID);
assertThat(tagTester.getAttribute(key), is(equalTo(value)));
}
use of org.apache.wicket.util.tester.TagTester in project wicket by apache.
the class AjaxLinkTest method anchorGetsHrefReplaced.
/**
* If the AjaxLink is attached to an "a" tag the href value should be replaced with "#" because
* we use the onclick to execute the javascript.
*/
@Test
public void anchorGetsHrefReplaced() {
tester.startPage(AjaxLinkPage.class);
TagTester ajaxLink = tester.getTagByWicketId("ajaxLink");
// It was a link to google in the markup, but should be replaced to "#"
assertTrue(ajaxLink.getAttributeIs("href", "javascript:;"));
}
Aggregations