Search in sources :

Example 6 with TagTester

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()));
}
Also used : TagTester(org.apache.wicket.util.tester.TagTester) Test(org.junit.Test)

Example 7 with TagTester

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)));
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) StringResourceStream(org.apache.wicket.util.resource.StringResourceStream) TagTester(org.apache.wicket.util.tester.TagTester) Test(org.junit.Test)

Example 8 with TagTester

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")));
}
Also used : TagTester(org.apache.wicket.util.tester.TagTester) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) MockPageWithOneComponent(org.apache.wicket.MockPageWithOneComponent) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) WicketTestCase(org.apache.wicket.util.tester.WicketTestCase) MockPageWithOneComponent(org.apache.wicket.MockPageWithOneComponent) TagTester(org.apache.wicket.util.tester.TagTester) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) Test(org.junit.Test)

Example 9 with TagTester

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)));
}
Also used : TagTester(org.apache.wicket.util.tester.TagTester) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) MockPageWithOneComponent(org.apache.wicket.MockPageWithOneComponent) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) WicketTestCase(org.apache.wicket.util.tester.WicketTestCase) MockPageWithOneComponent(org.apache.wicket.MockPageWithOneComponent) TagTester(org.apache.wicket.util.tester.TagTester) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) Test(org.junit.Test)

Example 10 with TagTester

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:;"));
}
Also used : TagTester(org.apache.wicket.util.tester.TagTester) Test(org.junit.Test)

Aggregations

TagTester (org.apache.wicket.util.tester.TagTester)21 Test (org.junit.Test)21 MockPageWithLink (org.apache.wicket.MockPageWithLink)3 Component (org.apache.wicket.Component)2 MarkupContainer (org.apache.wicket.MarkupContainer)2 MockPageWithOneComponent (org.apache.wicket.MockPageWithOneComponent)2 HTML5Attributes (org.apache.wicket.markup.html.HTML5Attributes)2 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)2 StringResourceStream (org.apache.wicket.util.resource.StringResourceStream)2 WicketTestCase (org.apache.wicket.util.tester.WicketTestCase)2 Matchers.equalTo (org.hamcrest.Matchers.equalTo)2 Matchers.is (org.hamcrest.Matchers.is)2 Serializable (java.io.Serializable)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1