Search in sources :

Example 6 with Form

use of com.enonic.xp.form.Form 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")));
}
Also used : PageDescriptor(com.enonic.xp.page.PageDescriptor) Form(com.enonic.xp.form.Form) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) DescriptorKey(com.enonic.xp.page.DescriptorKey) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test)

Example 7 with Form

use of com.enonic.xp.form.Form in project xp by enonic.

the class XmlXDataParser method doParse.

@Override
protected void doParse(final DomElement root) throws Exception {
    assertTagName(root, "x-data");
    this.builder.displayName(root.getChildValueTrimmed("display-name"));
    this.builder.displayNameI18nKey(root.getChild("display-name") != null ? root.getChild("display-name").getAttribute("i18n") : null);
    this.builder.description(root.getChildValue("description"));
    this.builder.descriptionI18nKey(root.getChild("description") != null ? root.getChild("description").getAttribute("i18n") : null);
    final XmlFormMapper mapper = new XmlFormMapper(this.currentApplication);
    final Form form = mapper.buildForm(root.getChild("form"));
    this.builder.form(form);
}
Also used : Form(com.enonic.xp.form.Form)

Example 8 with Form

use of com.enonic.xp.form.Form in project xp by enonic.

the class MacroDescriptorTest method testCreate.

@Test
public void testCreate() {
    FieldSet body = FieldSet.create().label("Body").name("body").addFormItem(Input.create().name("param1").label("Parameter 1").inputType(InputTypeName.TEXT_LINE).build()).build();
    final Form config = Form.create().addFormItem(body).build();
    final MacroDescriptor macroDescriptor1 = MacroDescriptor.create().key(MacroKey.from("my-app:macro1")).description("my description").displayName("my display name").form(config).icon(Icon.from(new byte[] { 123 }, "image/png", Instant.now())).build();
    assertEquals("my-app:macro1", macroDescriptor1.getKey().toString());
    assertEquals("macro1", macroDescriptor1.getName());
    assertEquals("my display name", macroDescriptor1.getDisplayName());
    assertEquals("my description", macroDescriptor1.getDescription());
    assertEquals(config, macroDescriptor1.getForm());
}
Also used : FieldSet(com.enonic.xp.form.FieldSet) Form(com.enonic.xp.form.Form) Test(org.junit.jupiter.api.Test)

Example 9 with Form

use of com.enonic.xp.form.Form in project xp by enonic.

the class SiteDescriptorTest method create_site_descriptor.

@Test
public void create_site_descriptor() {
    // Builds a Form
    final FormItem formItem = Input.create().name("input").label("Input").inputType(InputTypeName.DOUBLE).build();
    final Form form = Form.create().addFormItem(formItem).build();
    // Builds MixinNames
    List<XDataMapping> xDataMappingList = new ArrayList<>();
    xDataMappingList.add(XDataMapping.create().xDataName(XDataName.from("myapplication:my")).build());
    XDataMappings xDataMappings = XDataMappings.from(xDataMappingList);
    // Builds a SiteDescriptor
    SiteDescriptor siteDescriptor = SiteDescriptor.create().form(form).xDataMappings(xDataMappings).build();
    assertEquals(form, siteDescriptor.getForm());
    assertEquals(xDataMappings, siteDescriptor.getXDataMappings());
}
Also used : Form(com.enonic.xp.form.Form) FormItem(com.enonic.xp.form.FormItem) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 10 with Form

use of com.enonic.xp.form.Form in project xp by enonic.

the class TaskDescriptorTest method testDescriptor.

@Test
public void testDescriptor() {
    final DescriptorKey key = DescriptorKey.from(ApplicationKey.SYSTEM, "test");
    final Form form = Form.create().build();
    final TaskDescriptor descriptor = TaskDescriptor.create().key(key).description("test").config(form).build();
    assertSame(key, descriptor.getKey());
    assertEquals("test", descriptor.getDescription());
    assertSame(form, descriptor.getConfig());
}
Also used : Form(com.enonic.xp.form.Form) DescriptorKey(com.enonic.xp.page.DescriptorKey) Test(org.junit.jupiter.api.Test)

Aggregations

Form (com.enonic.xp.form.Form)79 Test (org.junit.jupiter.api.Test)59 PropertyTree (com.enonic.xp.data.PropertyTree)36 FormDefaultValuesProcessor (com.enonic.xp.form.FormDefaultValuesProcessor)17 Input (com.enonic.xp.form.Input)17 FormItemSet (com.enonic.xp.form.FormItemSet)13 FormOptionSet (com.enonic.xp.form.FormOptionSet)11 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)10 ContentType (com.enonic.xp.schema.content.ContentType)8 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)7 AbstractSchemaTest (com.enonic.xp.core.impl.schema.AbstractSchemaTest)5 PropertySet (com.enonic.xp.data.PropertySet)5 Content (com.enonic.xp.content.Content)4 CreateContentParams (com.enonic.xp.content.CreateContentParams)4 EditableContent (com.enonic.xp.content.EditableContent)4 MacroKey (com.enonic.xp.macro.MacroKey)4 XData (com.enonic.xp.schema.xdata.XData)4 SiteConfigs (com.enonic.xp.site.SiteConfigs)4 ContentPath (com.enonic.xp.content.ContentPath)3 Page (com.enonic.xp.page.Page)3