Search in sources :

Example 1 with ExtendedRenderingConfiguration

use of org.xwiki.rendering.configuration.ExtendedRenderingConfiguration in project xwiki-platform by xwiki.

the class XWikiWikiModelTest method getImageURLWhenBothWidthAndHeightAreUnspecifiedAndImageSizeIsLimited.

/**
 * Tests that the proper image URL is generated when both the width and the height are unspecified and image size is
 * limited in the configuration.
 *
 * @throws Exception if an exception occurs while running the test
 */
@Test
public void getImageURLWhenBothWidthAndHeightAreUnspecifiedAndImageSizeIsLimited() throws Exception {
    ExtendedRenderingConfiguration configuration = this.mocker.getInstance(ExtendedRenderingConfiguration.class);
    when(configuration.getImageWidthLimit()).thenReturn(200);
    when(configuration.getImageHeightLimit()).thenReturn(170);
    Map<String, String> parameters = Collections.emptyMap();
    testImageURL(new AttachmentResourceReference("attachmentReference"), parameters, true, "width=200&height=170&keepAspectRatio=true");
}
Also used : ExtendedRenderingConfiguration(org.xwiki.rendering.configuration.ExtendedRenderingConfiguration) AttachmentResourceReference(org.xwiki.rendering.listener.reference.AttachmentResourceReference) Test(org.junit.Test)

Example 2 with ExtendedRenderingConfiguration

use of org.xwiki.rendering.configuration.ExtendedRenderingConfiguration in project xwiki-platform by xwiki.

the class XWikiWikiModelTest method getImageURLWhenBothWidthAndHeightAreUnspecifiedAndImageSizeIsNotLimited.

/**
 * Tests that the proper image URL is generated when both the width and the height are unspecified and the image
 * size is not limited in the configuration.
 *
 * @throws Exception if an exception occurs while running the test
 */
@Test
public void getImageURLWhenBothWidthAndHeightAreUnspecifiedAndImageSizeIsNotLimited() throws Exception {
    final ExtendedRenderingConfiguration configuration = this.mocker.getInstance(ExtendedRenderingConfiguration.class);
    when(configuration.getImageWidthLimit()).thenReturn(-1);
    when(configuration.getImageHeightLimit()).thenReturn(-1);
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("style", "bad CSS declaration");
    testImageURL(new AttachmentResourceReference("attachmentReference"), parameters, true, null);
}
Also used : ExtendedRenderingConfiguration(org.xwiki.rendering.configuration.ExtendedRenderingConfiguration) HashMap(java.util.HashMap) AttachmentResourceReference(org.xwiki.rendering.listener.reference.AttachmentResourceReference) Test(org.junit.Test)

Example 3 with ExtendedRenderingConfiguration

use of org.xwiki.rendering.configuration.ExtendedRenderingConfiguration in project xwiki-platform by xwiki.

the class XWikiWikiModelTest method testImageURL.

private void testImageURL(final ResourceReference imageReference, Map<String, String> parameters, final boolean expectedIsImageDimensionsIncludedInImageURL, final String expectedQueryString) throws Exception {
    AttachmentReference attachmentReference = new AttachmentReference("image", new DocumentReference("wiki", "space", "page"));
    ExtendedRenderingConfiguration configuration = this.mocker.getInstance(ExtendedRenderingConfiguration.class);
    when(configuration.isImageDimensionsIncludedInImageURL()).thenReturn(expectedIsImageDimensionsIncludedInImageURL);
    when(this.referenceResolver.resolve(imageReference, EntityType.ATTACHMENT)).thenReturn(attachmentReference);
    when(this.documentAccessBridge.getAttachmentURL(attachmentReference, expectedQueryString, false)).thenReturn("?" + expectedQueryString);
    assertEquals("?" + expectedQueryString, this.mocker.getComponentUnderTest().getImageURL(imageReference, parameters));
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) ExtendedRenderingConfiguration(org.xwiki.rendering.configuration.ExtendedRenderingConfiguration) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 4 with ExtendedRenderingConfiguration

use of org.xwiki.rendering.configuration.ExtendedRenderingConfiguration in project xwiki-platform by xwiki.

the class XWikiWikiModelTest method getImageURLWhenBothWidthAndHeightAreUnspecifiedAndOnlyImageWidthIsLimited.

/**
 * Tests that the proper image URL is generated when both the width and the height are unspecified and only the
 * image width is limited in the configuration.
 *
 * @throws Exception if an exception occurs while running the test
 */
@Test
public void getImageURLWhenBothWidthAndHeightAreUnspecifiedAndOnlyImageWidthIsLimited() throws Exception {
    final ExtendedRenderingConfiguration configuration = this.mocker.getInstance(ExtendedRenderingConfiguration.class);
    when(configuration.getImageWidthLimit()).thenReturn(25);
    when(configuration.getImageHeightLimit()).thenReturn(-1);
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("width", "45%");
    parameters.put("style", "height:10em");
    testImageURL(new AttachmentResourceReference("attachmentReference"), parameters, true, "width=25");
}
Also used : ExtendedRenderingConfiguration(org.xwiki.rendering.configuration.ExtendedRenderingConfiguration) HashMap(java.util.HashMap) AttachmentResourceReference(org.xwiki.rendering.listener.reference.AttachmentResourceReference) Test(org.junit.Test)

Aggregations

ExtendedRenderingConfiguration (org.xwiki.rendering.configuration.ExtendedRenderingConfiguration)4 Test (org.junit.Test)3 AttachmentResourceReference (org.xwiki.rendering.listener.reference.AttachmentResourceReference)3 HashMap (java.util.HashMap)2 AttachmentReference (org.xwiki.model.reference.AttachmentReference)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1