Search in sources :

Example 1 with StyleDescriptor

use of com.enonic.xp.style.StyleDescriptor in project xp by enonic.

the class PortalUrlServiceImpl_processHtmlTest method process_image_with_styles.

@Test
public void process_image_with_styles() {
    // Creates a content
    final Media media = ContentFixtures.newMedia();
    Mockito.when(this.contentService.getById(media.getId())).thenReturn(media);
    Mockito.when(this.contentService.getBinaryKey(media.getId(), media.getMediaAttachment().getBinaryReference())).thenReturn("binaryHash");
    final ImageStyle imageStyle = ImageStyle.create().name("mystyle").aspectRatio("2:1").filter("myfilter").build();
    final StyleDescriptor styleDescriptor = StyleDescriptor.create().application(ApplicationKey.from("myapp")).addStyleElement(imageStyle).build();
    Mockito.when(styleDescriptorService.getByApplications(Mockito.any())).thenReturn(StyleDescriptors.from(styleDescriptor));
    // Process an html text containing a style
    final String link1 = "<a href=\"image://" + media.getId() + "?style=mystyle\">Image</a>";
    final String link2 = "<a href=\"image://" + media.getId() + "?style=missingstyle\">Image</a>";
    final ProcessHtmlParams params1 = new ProcessHtmlParams().portalRequest(this.portalRequest).value(link1);
    final ProcessHtmlParams params2 = new ProcessHtmlParams().portalRequest(this.portalRequest).value(link2);
    final String processedLink1 = this.service.processHtml(params1);
    final String processedLink2 = this.service.processHtml(params2);
    // Checks that the page URL of the content is returned
    final String expectedResult1 = "<a href=\"/site/default/draft/context/path/_/image/" + media.getId() + ":8cf45815bba82c9711c673c9bb7304039a790026/" + "block-768-384" + "/" + media.getName() + "?filter=myfilter\">Image</a>";
    final String expectedResult2 = "<a href=\"/site/default/draft/context/path/_/image/" + media.getId() + ":8cf45815bba82c9711c673c9bb7304039a790026/" + "width-768" + "/" + media.getName() + "\">Image</a>";
    assertEquals(expectedResult1, processedLink1);
    assertEquals(expectedResult2, processedLink2);
}
Also used : StyleDescriptor(com.enonic.xp.style.StyleDescriptor) Media(com.enonic.xp.content.Media) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) ImageStyle(com.enonic.xp.style.ImageStyle) Test(org.junit.jupiter.api.Test)

Example 2 with StyleDescriptor

use of com.enonic.xp.style.StyleDescriptor in project xp by enonic.

the class XmlStyleDescriptorParserTest method assertResult.

private void assertResult() throws Exception {
    final StyleDescriptor result = this.builder.build();
    assertEquals("myapplication", result.getApplicationKey().toString());
    assertEquals("assets/styles.css", result.getCssPath());
    assertEquals(4, result.getElements().size());
    final GenericStyle element0 = (GenericStyle) result.getElements().get(0);
    final ImageStyle element1 = (ImageStyle) result.getElements().get(1);
    final ImageStyle element2 = (ImageStyle) result.getElements().get(2);
    final ImageStyle element3 = (ImageStyle) result.getElements().get(3);
    assertEquals("style", element0.getElement());
    assertEquals("warning", element0.getName());
    assertEquals("Warning", element0.getDisplayName());
    assertEquals("warning.displayName", element0.getDisplayNameI18nKey());
    assertEquals("image", element1.getElement());
    assertEquals("editor-align-justify", element1.getName());
    assertEquals("Justify", element1.getDisplayName());
    assertEquals("style.editor.align.justify", element1.getDisplayNameI18nKey());
    assertEquals("image", element2.getElement());
    assertEquals("editor-width-auto", element2.getName());
    assertEquals("Override ${width}", element2.getDisplayName());
    assertEquals("editor-width-auto-text", element2.getDisplayNameI18nKey());
    assertEquals("image", element3.getElement());
    assertEquals("editor-style-cinema", element3.getName());
    assertEquals("Cinema", element3.getDisplayName());
    assertEquals("editor-style-cinema-text", element3.getDisplayNameI18nKey());
    assertEquals("21:9", element3.getAspectRatio());
    assertEquals("pixelate(10)", element3.getFilter());
}
Also used : GenericStyle(com.enonic.xp.style.GenericStyle) StyleDescriptor(com.enonic.xp.style.StyleDescriptor) ImageStyle(com.enonic.xp.style.ImageStyle)

Example 3 with StyleDescriptor

use of com.enonic.xp.style.StyleDescriptor in project xp by enonic.

the class StyleDescriptorServiceImplTest method getByApplication.

@Test
public void getByApplication() {
    final ApplicationKey appKey = ApplicationKey.from("myapp1");
    final StyleDescriptor descriptor = this.service.getByApplication(appKey);
    assertNotNull(descriptor);
    assertEquals(descriptor.getApplicationKey(), appKey);
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) StyleDescriptor(com.enonic.xp.style.StyleDescriptor) Test(org.junit.jupiter.api.Test)

Example 4 with StyleDescriptor

use of com.enonic.xp.style.StyleDescriptor in project xp by enonic.

the class StyleDescriptorServiceImplTest method getByApplicationInvalidStyles.

@Test
public void getByApplicationInvalidStyles() {
    addApplication("myapp3", "/apps/myapp3");
    final ApplicationKey appKey = ApplicationKey.from("myapp3");
    final StyleDescriptor descriptor = this.service.getByApplication(appKey);
    assertNull(descriptor);
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) StyleDescriptor(com.enonic.xp.style.StyleDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

StyleDescriptor (com.enonic.xp.style.StyleDescriptor)4 Test (org.junit.jupiter.api.Test)3 ApplicationKey (com.enonic.xp.app.ApplicationKey)2 ImageStyle (com.enonic.xp.style.ImageStyle)2 Media (com.enonic.xp.content.Media)1 ProcessHtmlParams (com.enonic.xp.portal.url.ProcessHtmlParams)1 GenericStyle (com.enonic.xp.style.GenericStyle)1