use of com.enonic.xp.page.PageDescriptor in project xp by enonic.
the class HtmlAreaContentProcessorTest method component_config_data.
@Test
public void component_config_data() throws IOException {
final PropertyTree data = new PropertyTree();
data.addProperty("htmlData", ValueFactory.newString("<img data-src=\"image://image-id\"/>"));
final Form form = Form.create().addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build();
final PartDescriptor partDescriptor = PartDescriptor.create().key(DescriptorKey.from("app:part")).config(form).build();
Mockito.when(partDescriptorService.getByKey(partDescriptor.getKey())).thenReturn(partDescriptor);
final PartComponent partComponent = PartComponent.create().descriptor("myapp:part").descriptor(partDescriptor.getKey()).config(data).build();
final PageDescriptor pageDescriptor = PageDescriptor.create().regions(RegionDescriptors.create().add(RegionDescriptor.create().name("region").build()).build()).key(DescriptorKey.from("app:page")).config(Form.create().build()).build();
Mockito.when(pageDescriptorService.getByKey(pageDescriptor.getKey())).thenReturn(pageDescriptor);
final Page page = Page.create().config(new PropertyTree()).descriptor(pageDescriptor.getKey()).regions(PageRegions.create().add(Region.create().name("region").add(partComponent).build()).build()).build();
final EditableContent editableContent = new EditableContent(Media.create().name("myContentName").type(contentTypeName).page(page).parentPath(ContentPath.ROOT).data(new PropertyTree()).build());
result.getEditor().edit(editableContent);
assertEquals(1, editableContent.processedReferences.build().getSize());
assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id")));
}
use of com.enonic.xp.page.PageDescriptor in project xp by enonic.
the class HtmlAreaContentProcessorTest method text_component_value.
@Test
public void text_component_value() throws IOException {
// final PropertyTree data = new PropertyTree();
// data.addProperty( "htmlData", ValueFactory.newString( "<img data-src=\"image://image-id\"/>" ) );
// final Form form = Form.create().addFormItem(
// Input.create().name( "htmlData" ).label( "htmlData" ).inputType( InputTypeName.HTML_AREA ).build() ).build();
// final PartDescriptor partDescriptor = PartDescriptor.create().key( DescriptorKey.from( "app:part" ) ).config( form ).build();
// Mockito.when( partDescriptorService.getByKey( partDescriptor.getKey() ) ).thenReturn( partDescriptor );
final TextComponent textComponent = TextComponent.create().text("<img data-src=\"image://image-id\"/>").build();
final PageDescriptor pageDescriptor = PageDescriptor.create().regions(RegionDescriptors.create().add(RegionDescriptor.create().name("region").build()).build()).key(DescriptorKey.from("app:page")).config(Form.create().build()).build();
Mockito.when(pageDescriptorService.getByKey(pageDescriptor.getKey())).thenReturn(pageDescriptor);
final Page page = Page.create().config(new PropertyTree()).descriptor(pageDescriptor.getKey()).regions(PageRegions.create().add(Region.create().name("region").add(textComponent).build()).build()).build();
final EditableContent editableContent = new EditableContent(Media.create().name("myContentName").type(contentTypeName).page(page).parentPath(ContentPath.ROOT).data(new PropertyTree()).build());
result.getEditor().edit(editableContent);
assertEquals(1, editableContent.processedReferences.build().getSize());
assertTrue(editableContent.processedReferences.build().contains(ContentId.from("image-id")));
}
use of com.enonic.xp.page.PageDescriptor in project xp by enonic.
the class HtmlAreaContentProcessor method processPageData.
private void processPageData(final Page page, final ContentIds.Builder processedIds) {
if (page == null) {
return;
}
if (page.hasDescriptor()) {
final PageDescriptor pageDescriptor = pageDescriptorService.getByKey(page.getDescriptor());
final Collection<Property> properties = getProperties(page.getConfig(), pageDescriptor.getConfig().getFormItems());
processDataTree(properties, processedIds);
}
if (page.hasRegions()) {
processRegionsData(page.getRegions(), processedIds);
}
}
use of com.enonic.xp.page.PageDescriptor in project xp by enonic.
the class RenderBaseHandlerTest method createDescriptor.
private PageDescriptor createDescriptor() {
final ApplicationKey applicationKey = ApplicationKey.from("mainapplication");
final String name = "mypage";
final DescriptorKey key = DescriptorKey.from(applicationKey, name);
final String xml = "<?xml version=\"1.0\"?>\n" + "<page>\n" + " <display-name>Landing page</display-name>\n" + " <config/>\n" + "</page>";
final PageDescriptor.Builder builder = PageDescriptor.create();
parseXml(applicationKey, builder, xml);
return builder.key(key).displayName("Landing page").build();
}
use of com.enonic.xp.page.PageDescriptor in project xp by enonic.
the class RenderBaseHandlerTest method setupCustomizedTemplateContentAndSite.
protected final void setupCustomizedTemplateContentAndSite() {
Content content = createPage("id", "site/somepath/content", "myapplication:ctype", true);
final PageDescriptor controllerDescriptor = createDescriptor();
Page page = Page.create(content.getPage()).template(null).descriptor(controllerDescriptor.getKey()).build();
content = Content.create(content).page(page).build();
when(this.contentService.getByPath(ContentPath.from("site/somepath/content").asAbsolute())).thenReturn(content);
when(this.contentService.getNearestSite(isA(ContentId.class))).thenReturn(createSite("id", "site"));
when(this.contentService.getById(content.getId())).thenReturn(content);
}
Aggregations