Search in sources :

Example 11 with TagTester

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

the class EscapeAttributesInChoicesTest method escapeAttributes.

@Test
public void escapeAttributes() {
    tester.startPage(EscapeAttributesInChoicesPage.class);
    String lastResponseAsString = tester.getLastResponseAsString();
    TagTester radioTagTester = tester.getTagById("radiofield1-apple\" onmouseover=\"alert('hi');\" \"");
    assertNotNull(radioTagTester);
    assertNull(radioTagTester.getAttribute("onmouseover"));
    TagTester dropDownChoiceOptionTagTester = createTagByAttribute(lastResponseAsString, "value", "apple\" onmouseover=\"alert('hi');\" \"");
    assertNotNull(dropDownChoiceOptionTagTester);
    assertNull(dropDownChoiceOptionTagTester.getAttribute("onmouseover"));
    TagTester checkBoxMultipleChoiceTagTester = createTagByAttribute(lastResponseAsString, "name", "checkboxfield");
    assertNotNull(checkBoxMultipleChoiceTagTester);
    assertEquals("apple\" onmouseover=\"alert('hi');\" \"", checkBoxMultipleChoiceTagTester.getAttribute("value"));
    assertNull(checkBoxMultipleChoiceTagTester.getAttribute("onmouseover"));
    TagTester labelForCheckBoxMultipleChoiceTagTester = createTagByAttribute(lastResponseAsString, "for", "checkboxfield2-checkboxfield_apple\" onmouseover=\"alert('hi');\" \"");
    assertNotNull(labelForCheckBoxMultipleChoiceTagTester);
    assertNull(labelForCheckBoxMultipleChoiceTagTester.getAttribute("onmouseover"));
}
Also used : TagTester(org.apache.wicket.util.tester.TagTester) Test(org.junit.Test)

Example 12 with TagTester

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

the class AjaxUpdatedImageTest method wicket1382.

/**
 * Tests that Image re-rendered in Ajax request have 'wicket:antiCache' parameter in its 'src'
 * attribute value
 */
@Test
public void wicket1382() {
    AjaxyImagesPage page = tester.startPage(AjaxyImagesPage.class);
    TagTester tagTester = tester.getTagById(page.image.getMarkupId());
    final String srcAttr = tagTester.getAttribute("src");
    assertFalse("Image has not be rendered in Ajax request so it has no wicket:antiCache' parameter", srcAttr.contains("antiCache"));
    // make an ajax call
    tester.clickLink("link", true);
    page = (AjaxyImagesPage) tester.getLastRenderedPage();
    tagTester = tester.getTagById(page.image.getMarkupId());
    final String srcAttr1 = tagTester.getAttribute("src");
    assertTrue("Image has not be rendered in Ajax request so it has no wicket:antiCache' parameter", srcAttr1.contains("antiCache"));
}
Also used : TagTester(org.apache.wicket.util.tester.TagTester) Test(org.junit.Test)

Example 13 with TagTester

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

the class ExternalImageTest method testExternalImageModel.

@Test
public void testExternalImageModel() {
    tester.startPage(ExternalImageTestPage.class);
    tester.getLastResponse().getDocument();
    Component externalImage2Component = tester.getComponentFromLastRenderedPage("externalImage2");
    ExternalImage externalImage2 = (ExternalImage) externalImage2Component;
    TagTester tagById = tester.getTagById("externalImage2");
    IModel<List<Serializable>> srcSet = externalImage2.getSrcSetModel();
    for (Serializable model : srcSet.getObject()) {
        String attribute = tagById.getAttribute("srcset");
        Assert.assertTrue(attribute.contains(model.toString()));
    }
    String attribute = tagById.getAttribute("src");
    Assert.assertEquals(externalImage2.getDefaultModelObject(), attribute);
}
Also used : Serializable(java.io.Serializable) List(java.util.List) Component(org.apache.wicket.Component) TagTester(org.apache.wicket.util.tester.TagTester) Test(org.junit.Test)

Example 14 with TagTester

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

the class ResponsiveImageTest method testPictureTagIsRenderedRight.

@Test
public void testPictureTagIsRenderedRight() {
    tester.startPage(ImagePictureTestPage.class);
    String lastResponseAsString = tester.getLastResponse().getDocument();
    TagTester pictureTagTester = TagTester.createTagByAttribute(lastResponseAsString, "picture");
    Assert.assertTrue(pictureTagTester.hasChildTag("img"));
    Assert.assertTrue(pictureTagTester.hasChildTag("source"));
    TagTester sourceTagTester = TagTester.createTagByAttribute(lastResponseAsString, "source");
    Assert.assertTrue(sourceTagTester.hasAttribute("media"));
    Assert.assertEquals("(min-width: 650px)", sourceTagTester.getAttribute("media"));
    Assert.assertEquals("(min-width: 50em) 33vw", sourceTagTester.getAttribute("sizes"));
}
Also used : TagTester(org.apache.wicket.util.tester.TagTester) Test(org.junit.Test)

Example 15 with TagTester

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

the class ResponsiveImageTest method testSrcSetIsNotAvailableOnDefaultUsage.

@Test
public void testSrcSetIsNotAvailableOnDefaultUsage() {
    tester.startPage(ImageResourceReferenceTestPage.class);
    String lastResponseAsString = tester.getLastResponse().getDocument();
    TagTester createTagByAttribute = TagTester.createTagByAttribute(lastResponseAsString, "img");
    Assert.assertFalse(createTagByAttribute.hasAttribute("srcset"));
    Assert.assertEquals(Image.Cors.ANONYMOUS.getRealName(), createTagByAttribute.getAttribute("crossorigin"));
}
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