use of com.enonic.xp.page.PageDescriptor in project xp by enonic.
the class HtmlAreaContentProcessorTest method page_config_data.
@Test
public void page_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 PageDescriptor pageDescriptor = PageDescriptor.create().config(form).regions(RegionDescriptors.create().build()).key(DescriptorKey.from("aaa:bbb")).build();
Mockito.when(pageDescriptorService.getByKey(Mockito.isA(DescriptorKey.class))).thenReturn(pageDescriptor);
final Page page = Page.create().config(data).descriptor(pageDescriptor.getKey()).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 XmlPageDescriptorParserTest method assertResult.
private void assertResult() throws Exception {
final PageDescriptor result = this.builder.build();
assertEquals("myapplication:mypage", result.getKey().toString());
assertEquals("mypage", result.getName());
assertEquals("Landing page", result.getDisplayName());
assertEquals("key.display-name", result.getDisplayNameI18nKey());
assertEquals("My Page Description", result.getDescription());
assertEquals("key.description", result.getDescriptionI18nKey());
final Form config = result.getConfig();
assertNotNull(config);
assertEquals(InputTypeName.DOUBLE, config.getFormItem("pause").toInput().getInputType());
assertEquals("Pause parameter", config.getFormItem("pause").toInput().getLabel());
assertEquals("key1.label", config.getFormItem("pause").toInput().getLabelI18nKey());
assertEquals("key1.help-text", config.getFormItem("pause").toInput().getHelpTextI18nKey());
assertNotNull(config.getFormItem("myFormItemSet").toFormItemSet());
assertEquals("My form item set", config.getFormItem("myFormItemSet").toFormItemSet().getLabel());
assertEquals(InputTypeName.TEXT_LINE, config.getFormItem("myFormItemSet.fieldSetItem").toInput().getInputType());
assertEquals("Field set Item", config.getFormItem("myFormItemSet.fieldSetItem").toInput().getLabel());
assertEquals("key2.label", config.getFormItem("myFormItemSet.fieldSetItem").toInput().getLabelI18nKey());
assertEquals("key2.help-text", config.getFormItem("myFormItemSet.fieldSetItem").toInput().getHelpTextI18nKey());
final RegionDescriptors regions = result.getRegions();
assertNotNull(regions);
assertEquals(3, regions.numberOfRegions());
assertNotNull(regions.getRegionDescriptor("header"));
}
use of com.enonic.xp.page.PageDescriptor in project xp by enonic.
the class ApplicationInfoServiceImplTest method mockPageDescriptors.
private void mockPageDescriptors(final ApplicationKey applicationKey) {
final PageDescriptor pageDescriptor1 = PageDescriptor.create().displayName("Landing page").config(Form.create().build()).regions(RegionDescriptors.create().build()).key(DescriptorKey.from("module:landing-page")).build();
final PageDescriptor pageDescriptor2 = PageDescriptor.create().displayName("Log out").config(Form.create().build()).regions(RegionDescriptors.create().build()).key(DescriptorKey.from("module:logout-page")).build();
final PageDescriptors pageDescriptors = PageDescriptors.from(pageDescriptor1, pageDescriptor2);
Mockito.when(pageDescriptorService.getByApplication(applicationKey)).thenReturn(pageDescriptors);
}
use of com.enonic.xp.page.PageDescriptor in project xp by enonic.
the class PageDescriptorServiceImpl method getByKey.
@Override
public PageDescriptor getByKey(final DescriptorKey key) {
final ResourceProcessor<DescriptorKey, PageDescriptor> processor = newProcessor(key);
final PageDescriptor descriptor = this.resourceService.processResource(processor);
if (descriptor == null) {
return createDefaultDescriptor(key);
}
return PageDescriptor.copyOf(descriptor).config(this.mixinService.inlineFormItems(descriptor.getConfig())).build();
}
use of com.enonic.xp.page.PageDescriptor in project xp by enonic.
the class PageDefaultValuesProcessor method applyPageDefaultValues.
private void applyPageDefaultValues(final Page editedPage) {
final PropertyTree pageData = editedPage.getConfig();
if (editedPage.getDescriptor() == null) {
return;
}
final PageDescriptor pageForm = pageDescriptorService.getByKey(editedPage.getDescriptor());
if (pageForm == null || pageForm.getConfig() == null) {
return;
}
formDefaultValuesProcessor.setDefaultValues(pageForm.getConfig(), pageData);
}
Aggregations