Search in sources :

Example 1 with PageTemplate

use of com.enonic.xp.page.PageTemplate in project xp by enonic.

the class PageResolverTest method given_Content_without_Page_then_effective_Page_is_same_as_in_Template.

@Test
public void given_Content_without_Page_then_effective_Page_is_same_as_in_Template() {
    // setup
    Site site = Site.create().id(ContentId.from("site-id")).path(ContentPath.from("/site")).displayName("My Site").type(ContentTypeName.from("portal:site")).build();
    PageTemplate template = PageTemplate.newPageTemplate().key(PageTemplateKey.from("t-1")).parentPath(site.getPath()).name("my-template").page(Page.create().descriptor(DescriptorKey.from("myapp:my-descriptor")).config(configA).regions(regionsA).build()).build();
    Content content = Content.create().parentPath(site.getPath()).name("my-content").build();
    when(pageTemplateService.getDefault(notNull())).thenReturn(template);
    // exercise
    PageResolverResult result = pageResolver.resolve(RenderMode.LIVE, content, site);
    final Page effectivePage = result.getEffectivePage();
    // verify
    assertEquals(configA, effectivePage.getConfig());
    assertEquals(regionsA, effectivePage.getRegions());
    assertNull(effectivePage.getDescriptor());
    assertEquals(template.getKey(), effectivePage.getTemplate());
    assertEquals(DescriptorKey.from("myapp:my-descriptor"), result.getController());
}
Also used : Site(com.enonic.xp.site.Site) PageTemplate(com.enonic.xp.page.PageTemplate) Content(com.enonic.xp.content.Content) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test)

Example 2 with PageTemplate

use of com.enonic.xp.page.PageTemplate in project xp by enonic.

the class PageResolverTest method given_Content_with_Page_without_config_then_effective_Page_gets_config_from_Template.

@Test
public void given_Content_with_Page_without_config_then_effective_Page_gets_config_from_Template() {
    // setup
    Site site = Site.create().id(ContentId.from("site-id")).path(ContentPath.from("/site")).displayName("My Site").type(ContentTypeName.from("portal:site")).build();
    PageTemplate template = PageTemplate.newPageTemplate().key(PageTemplateKey.from("t-1")).parentPath(site.getPath()).name("my-template").page(Page.create().descriptor(DescriptorKey.from("myapp:my-descriptor")).config(configA).regions(regionsA).build()).canRender(ContentTypeNames.from(ContentTypeName.templateFolder())).build();
    Content content = Content.create().parentPath(site.getPath()).name("my-content").page(Page.create().template(template.getKey()).regions(regionsB).build()).type(ContentTypeName.templateFolder()).build();
    when(pageTemplateService.getByKey(template.getKey())).thenReturn(template);
    // exercise
    PageResolverResult result = pageResolver.resolve(RenderMode.LIVE, content, site);
    final Page effectivePage = result.getEffectivePage();
    // verify
    assertEquals(configA, effectivePage.getConfig());
    assertEquals(regionsB, effectivePage.getRegions());
    assertEquals(template.getKey(), effectivePage.getTemplate());
    assertNull(effectivePage.getDescriptor());
}
Also used : Site(com.enonic.xp.site.Site) PageTemplate(com.enonic.xp.page.PageTemplate) Content(com.enonic.xp.content.Content) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test)

Example 3 with PageTemplate

use of com.enonic.xp.page.PageTemplate in project xp by enonic.

the class ComponentInstructionTest method testInstructionRenderByName.

@Test
public void testInstructionRenderByName() throws Exception {
    RendererDelegate rendererFactory = newRendererFactory("<b>part content</b>");
    ComponentService componentService = Mockito.mock(ComponentService.class);
    Component component = createPartComponent();
    doReturn(component).when(componentService).getByKey(isA(DescriptorKey.class));
    ComponentInstruction instruction = new ComponentInstruction();
    instruction.setRendererDelegate(rendererFactory);
    instruction.setComponentService(componentService);
    PortalRequest portalRequest = new PortalRequest();
    Content content = createPage("content-id", "content-name", "myapplication:content-type");
    portalRequest.setContent(content);
    Site site = createSite("site-id", "site-name", "myapplication:content-type");
    portalRequest.setSite(site);
    PageTemplate pageTemplate = createPageTemplate();
    portalRequest.setPageTemplate(pageTemplate);
    String outputHtml = instruction.evaluate(portalRequest, "COMPONENT module:myPartComponent").getAsString();
    assertEquals("<b>part content</b>", outputHtml);
}
Also used : Site(com.enonic.xp.site.Site) PageTemplate(com.enonic.xp.page.PageTemplate) Content(com.enonic.xp.content.Content) DescriptorKey(com.enonic.xp.page.DescriptorKey) ComponentService(com.enonic.xp.region.ComponentService) Component(com.enonic.xp.region.Component) PartComponent(com.enonic.xp.region.PartComponent) RendererDelegate(com.enonic.xp.portal.impl.rendering.RendererDelegate) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 4 with PageTemplate

use of com.enonic.xp.page.PageTemplate in project xp by enonic.

the class PageResolver method resolve.

public PageResolverResult resolve(final RenderMode mode, final Content content, final Site site) {
    final Page page = content.getPage();
    final PageTemplate pageTemplate;
    final DescriptorKey controller;
    final Page effectivePage;
    if (content instanceof PageTemplate) {
        pageTemplate = (PageTemplate) content;
        controller = getControllerFromTemplate(pageTemplate, mode);
        effectivePage = pageTemplate.getPage();
    } else if (page != null) {
        if (page.getFragment() != null) {
            controller = null;
            effectivePage = page;
        } else if (page.getDescriptor() != null) {
            controller = page.getDescriptor();
            effectivePage = page;
        } else if (page.getTemplate() != null) {
            pageTemplate = getPageTemplateOrFindDefault(page.getTemplate(), content.getType(), site.getPath());
            if (pageTemplate != null) {
                controller = getControllerFromTemplate(pageTemplate, mode);
                effectivePage = mergePageFromPageTemplate(pageTemplate, page);
            } else {
                controller = errorOrNull(null, mode, String.format("Template [%s] is missing and no default template found for content", page.getTemplate()));
                effectivePage = page;
            }
        } else {
            controller = errorOrNull(null, mode, "Content page has neither template nor descriptor");
            effectivePage = page;
        }
    } else {
        pageTemplate = this.pageTemplateService.getDefault(GetDefaultPageTemplateParams.create().sitePath(site.getPath()).contentType(content.getType()).build());
        if (pageTemplate != null) {
            controller = getControllerFromTemplate(pageTemplate, mode);
            effectivePage = mergePageFromPageTemplate(pageTemplate, null);
        } else {
            controller = errorOrNull(null, mode, "No default template found for content");
            effectivePage = null;
        }
    }
    return new PageResolverResult(effectivePage, controller);
}
Also used : PageTemplate(com.enonic.xp.page.PageTemplate) DescriptorKey(com.enonic.xp.page.DescriptorKey) Page(com.enonic.xp.page.Page)

Example 5 with PageTemplate

use of com.enonic.xp.page.PageTemplate in project xp by enonic.

the class PageResolverTest method content_without_Page_and_Template_withoutPage.

@Test
public void content_without_Page_and_Template_withoutPage() {
    Site site = Site.create().id(ContentId.from("site-id")).path(ContentPath.from("/site")).displayName("My Site").type(ContentTypeName.from("portal:site")).build();
    PageTemplate template = PageTemplate.newPageTemplate().key(PageTemplateKey.from("t-1")).parentPath(site.getPath()).name("my-template").build();
    Content content = Content.create().parentPath(site.getPath()).name("my-content").build();
    when(pageTemplateService.getDefault(notNull())).thenReturn(template);
    PageResolverResult result = pageResolver.resolve(RenderMode.EDIT, content, site);
    final Page effectivePage = result.getEffectivePage();
    assertNull(effectivePage.getDescriptor());
    assertEquals(template.getKey(), effectivePage.getTemplate());
}
Also used : Site(com.enonic.xp.site.Site) PageTemplate(com.enonic.xp.page.PageTemplate) Content(com.enonic.xp.content.Content) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test)

Aggregations

PageTemplate (com.enonic.xp.page.PageTemplate)12 Content (com.enonic.xp.content.Content)9 Site (com.enonic.xp.site.Site)8 Test (org.junit.jupiter.api.Test)8 Page (com.enonic.xp.page.Page)7 DescriptorKey (com.enonic.xp.page.DescriptorKey)3 PropertyTree (com.enonic.xp.data.PropertyTree)2 PortalRequest (com.enonic.xp.portal.PortalRequest)2 RendererDelegate (com.enonic.xp.portal.impl.rendering.RendererDelegate)2 Component (com.enonic.xp.region.Component)2 ComponentService (com.enonic.xp.region.ComponentService)2 PartComponent (com.enonic.xp.region.PartComponent)2 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)1 ContentPath (com.enonic.xp.content.ContentPath)1 FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)1 FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)1 CreatePageParams (com.enonic.xp.page.CreatePageParams)1 PageRegions (com.enonic.xp.page.PageRegions)1 PageTemplates (com.enonic.xp.page.PageTemplates)1 ValueFilter (com.enonic.xp.query.filter.ValueFilter)1