Search in sources :

Example 46 with Page

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

the class ComponentHandlerTest method createFragmentContent.

private Content createFragmentContent() {
    PropertyTree rootDataSet = new PropertyTree();
    final Content.Builder content = Content.create().id(ContentId.from("fragmentId")).path(ContentPath.from("site/somepath/fragment")).owner(PrincipalKey.from("user:myStore:me")).displayName("My Content").modifier(PrincipalKey.from("user:system:admin")).type(ContentTypeName.fragment());
    Page page = Page.create().template(PageTemplateKey.from("my-page")).fragment(PartComponent.create().descriptor("myapp:mypart").build()).config(rootDataSet).build();
    content.page(page);
    return content.build();
}
Also used : Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Page(com.enonic.xp.page.Page)

Example 47 with Page

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

the class ComponentHandlerTest method createPageWithFragment.

private Content createPageWithFragment(final String id, final String path, final String contentTypeName, final boolean withPage) {
    PropertyTree rootDataSet = new PropertyTree();
    rootDataSet.addString("property1", "value1");
    final Content.Builder content = Content.create().id(ContentId.from(id)).path(ContentPath.from(path)).owner(PrincipalKey.from("user:myStore:me")).displayName("My Content").modifier(PrincipalKey.from("user:system:admin")).type(ContentTypeName.from(contentTypeName));
    if (withPage) {
        PageRegions pageRegions = PageRegions.create().add(Region.create().name("main-region").add(FragmentComponent.create().fragment(ContentId.from("fragmentId")).build()).build()).build();
        Page page = Page.create().template(PageTemplateKey.from("my-page")).regions(pageRegions).config(rootDataSet).build();
        content.page(page);
    }
    return content.build();
}
Also used : PageRegions(com.enonic.xp.page.PageRegions) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Page(com.enonic.xp.page.Page)

Example 48 with Page

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

the class PageResolverTest method given_Content_with_Page_without_regions_then_effective_Page_gets_regions_from_Template.

@Test
public void given_Content_with_Page_without_regions_then_effective_Page_gets_regions_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").type(ContentTypeName.templateFolder()).page(Page.create().template(template.getKey()).config(configB).build()).build();
    when(pageTemplateService.getByKey(template.getKey())).thenReturn(template);
    // exercise
    PageResolverResult result = pageResolver.resolve(RenderMode.LIVE, content, site);
    final Page effectivePage = result.getEffectivePage();
    // verify
    assertEquals(regionsA, effectivePage.getRegions());
    assertEquals(configB, effectivePage.getConfig());
    assertEquals(template.getKey(), effectivePage.getTemplate());
    assertNull(effectivePage.getDescriptor());
    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 49 with Page

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

the class PageResolverTest method content_with_Page_but_template_was_deleted_fallback_to_default_not_found.

@Test
public void content_with_Page_but_template_was_deleted_fallback_to_default_not_found() {
    Site site = Site.create().id(ContentId.from("site-id")).path(ContentPath.from("/site")).displayName("My Site").type(ContentTypeName.from("portal:site")).build();
    Content content = Content.create().parentPath(site.getPath()).id(ContentId.from("content-id")).name("my-content").page(Page.create().template(PageTemplateKey.from("t-not-exists")).build()).type(ContentTypeName.templateFolder()).build();
    final WebException webExceptionInLive = assertThrows(WebException.class, () -> pageResolver.resolve(RenderMode.LIVE, content, site));
    assertEquals(HttpStatus.NOT_FOUND, webExceptionInLive.getStatus());
    assertEquals(webExceptionInLive.getMessage(), "Template [t-not-exists] is missing and no default template found for content");
    final WebException webExceptionInInline = assertThrows(WebException.class, () -> pageResolver.resolve(RenderMode.INLINE, content, site));
    assertEquals(HttpStatus.IM_A_TEAPOT, webExceptionInInline.getStatus());
    final WebException webExceptionInPreview = assertThrows(WebException.class, () -> pageResolver.resolve(RenderMode.PREVIEW, content, site));
    assertEquals(HttpStatus.NOT_FOUND, webExceptionInPreview.getStatus());
    final PageResolverResult result = pageResolver.resolve(RenderMode.EDIT, content, site);
    final Page effectivePage = result.getEffectivePage();
    assertSame(content.getPage(), effectivePage);
    assertNull(result.getController());
}
Also used : Site(com.enonic.xp.site.Site) WebException(com.enonic.xp.web.WebException) Content(com.enonic.xp.content.Content) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test)

Example 50 with Page

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

the class PageResolverTest method content_is_PageTemplate.

@Test
public void content_is_PageTemplate() {
    Site site = Site.create().id(ContentId.from("site-id")).path(ContentPath.from("/site")).displayName("My Site").type(ContentTypeName.from("portal:site")).build();
    final Page page = Page.create().descriptor(DescriptorKey.from("myapp:my-descriptor")).config(configA).regions(regionsA).build();
    PageTemplate template = PageTemplate.newPageTemplate().key(PageTemplateKey.from("t-1")).parentPath(site.getPath()).name("my-template").page(page).canRender(ContentTypeNames.from(ContentTypeName.folder())).build();
    PageResolverResult result = pageResolver.resolve(RenderMode.LIVE, template, site);
    final Page effectivePage = result.getEffectivePage();
    assertSame(page, effectivePage);
    assertEquals(DescriptorKey.from("myapp:my-descriptor"), result.getController());
    verifyNoInteractions(pageTemplateService);
}
Also used : Site(com.enonic.xp.site.Site) PageTemplate(com.enonic.xp.page.PageTemplate) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test)

Aggregations

Page (com.enonic.xp.page.Page)58 PropertyTree (com.enonic.xp.data.PropertyTree)30 Test (org.junit.jupiter.api.Test)28 Content (com.enonic.xp.content.Content)25 Site (com.enonic.xp.site.Site)12 DescriptorKey (com.enonic.xp.page.DescriptorKey)9 PageRegions (com.enonic.xp.page.PageRegions)9 AbstractDataSerializerTest (com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest)7 PageDescriptor (com.enonic.xp.page.PageDescriptor)7 PageTemplate (com.enonic.xp.page.PageTemplate)7 PropertySet (com.enonic.xp.data.PropertySet)6 Form (com.enonic.xp.form.Form)5 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)5 LayoutComponent (com.enonic.xp.region.LayoutComponent)5 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)4 EditableContent (com.enonic.xp.content.EditableContent)4 Component (com.enonic.xp.region.Component)4 PartComponent (com.enonic.xp.region.PartComponent)4 ContentId (com.enonic.xp.content.ContentId)3 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)3