Search in sources :

Example 1 with TagTester

use of org.apache.wicket.util.tester.TagTester in project wicket by apache.

the class NonCachingImageTest method test.

/**
 * {@link NonCachingImage} always adds anticache.
 */
@Test
public void test() {
    NonCachingImagePage page = tester.startPage(NonCachingImagePage.class);
    TagTester tag = tester.getTagById(page.image.getMarkupId());
    assertTrue(tag.getAttribute("src").contains("antiCache"));
}
Also used : TagTester(org.apache.wicket.util.tester.TagTester) Test(org.junit.Test)

Example 2 with TagTester

use of org.apache.wicket.util.tester.TagTester in project wicket by apache.

the class TextAreaTest method requiredAttribute.

/**
 * https://issues.apache.org/jira/browse/WICKET-5289
 */
@Test
public void requiredAttribute() {
    TestPage testPage = new TestPage();
    testPage.textArea.setOutputMarkupId(true);
    testPage.textArea.setType(String.class);
    testPage.textArea.setRequired(true);
    testPage.textArea.add(new HTML5Attributes());
    tester.startPage(testPage);
    TagTester tagTester = tester.getTagById(testPage.textArea.getMarkupId());
    String required = tagTester.getAttribute("required");
    assertEquals("required", required);
}
Also used : HTML5Attributes(org.apache.wicket.markup.html.HTML5Attributes) TagTester(org.apache.wicket.util.tester.TagTester) Test(org.junit.Test)

Example 3 with TagTester

use of org.apache.wicket.util.tester.TagTester in project wicket by apache.

the class MediaTagsTest method audioTagIsRenderedRight.

@Test
public void audioTagIsRenderedRight() {
    tester.startPage(MediaTagsTestPage.class);
    String lastResponseAsString = tester.getLastResponse().getDocument();
    TagTester createTagByAttribute = TagTester.createTagByAttribute(lastResponseAsString, "audio");
    assertTrue(createTagByAttribute.hasAttribute("autoplay"));
    assertTrue(createTagByAttribute.hasAttribute("controls"));
    assertTrue(createTagByAttribute.hasAttribute("loop"));
    assertTrue(createTagByAttribute.hasAttribute("muted"));
    assertEquals("user-credentials", createTagByAttribute.getAttribute("crossorigin"));
    String attribute = createTagByAttribute.getAttribute("src");
    assertTrue("The time period is set right in the src attribute", attribute.contains("#t=5,10"));
    assertTrue("page parameter is in the url of the src attribute", attribute.contains("test=test"));
}
Also used : TagTester(org.apache.wicket.util.tester.TagTester) Test(org.junit.Test)

Example 4 with TagTester

use of org.apache.wicket.util.tester.TagTester in project wicket by apache.

the class MediaTagsTest method extendedVideoTagIsRenderedRight.

@Test
public void extendedVideoTagIsRenderedRight() {
    tester.startPage(MediaTagsExtendedTestPage.class);
    String lastResponseAsString = tester.getLastResponse().getDocument();
    TagTester createTagByAttribute = TagTester.createTagByAttribute(lastResponseAsString, "video");
    assertTrue(createTagByAttribute.hasChildTag("source"));
    assertTrue(createTagByAttribute.hasChildTag("track"));
    TagTester sourceTag = TagTester.createTagByAttribute(lastResponseAsString, "source");
    assertEquals("video/mp4", sourceTag.getAttribute("type"));
    assertEquals("screen and (device-width:500px)", sourceTag.getAttribute("media"));
    assertEquals("http://www.mytestpage.xc/video.m4a", sourceTag.getAttribute("src"));
    TagTester trackTag = TagTester.createTagByAttribute(lastResponseAsString, "track");
    assertTrue(trackTag.getAttribute("src").contains("dummySubtitles"));
    assertEquals("subtitles", trackTag.getAttribute("kind"));
    assertEquals("Subtitles of video", trackTag.getAttribute("label"));
    assertEquals("default", trackTag.getAttribute("default"));
    assertEquals("de", trackTag.getAttribute("srclang"));
}
Also used : TagTester(org.apache.wicket.util.tester.TagTester) Test(org.junit.Test)

Example 5 with TagTester

use of org.apache.wicket.util.tester.TagTester in project wicket by apache.

the class ButtonTest method whenButtonElement_thenModelObjectIsUsedAsTextContent.

/**
 * https://issues.apache.org/jira/browse/WICKET-6225
 */
@Test
public void whenButtonElement_thenModelObjectIsUsedAsTextContent() {
    tester.getApplication().getMarkupSettings().setStripWicketTags(false);
    String text = "some text & another text";
    TestPage testPage = new TestPage(Model.of(text)) {

        @Override
        public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass) {
            return new StringResourceStream("<html><body>" + "<form wicket:id=\"form\"><button wicket:id=\"button\"></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(text)));
}
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)

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