Search in sources :

Example 1 with Form

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

Example 2 with Form

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

the class ContentTypeHandler method inlineMixins.

private ContentType inlineMixins(final ContentType contentType) {
    final ContentType.Builder ctInlined = ContentType.create(contentType);
    final Form inlinedForm = mixinService.get().inlineFormItems(contentType.getForm());
    if (inlinedForm == null) {
        return contentType;
    }
    return ctInlined.form(inlinedForm).build();
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) Form(com.enonic.xp.form.Form)

Example 3 with Form

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

the class ContentTypeHandlerTest method testExampleGetTypes.

@Test
public void testExampleGetTypes() {
    final Form form = getForm();
    Mockito.when(mixinService.inlineFormItems(Mockito.eq(form))).thenReturn(form);
    final ContentTypes contentTypes = testContentTypes();
    Mockito.when(contentTypeService.getAll()).thenReturn(contentTypes);
    runScript("/lib/xp/examples/content/getTypes.js");
}
Also used : Form(com.enonic.xp.form.Form) ContentTypes(com.enonic.xp.schema.content.ContentTypes) Test(org.junit.jupiter.api.Test)

Example 4 with Form

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

the class ContentTypeHandlerTest method testGet.

@Test
public void testGet() throws Exception {
    final Form form = getForm();
    Mockito.when(mixinService.inlineFormItems(Mockito.eq(form))).thenReturn(form);
    final ContentType contentType = testContentType();
    final GetContentTypeParams params = new GetContentTypeParams().contentTypeName(contentType.getName());
    Mockito.when(contentTypeService.getByName(params)).thenReturn(contentType);
    runFunction("/test/ContentTypeHandlerTest.js", "testGet");
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) Form(com.enonic.xp.form.Form) Test(org.junit.jupiter.api.Test)

Example 5 with Form

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

the class SubmitTaskHandlerTest method initialize.

@Override
public void initialize() throws Exception {
    super.initialize();
    taskService = Mockito.mock(TaskService.class);
    addService(TaskService.class, taskService);
    final TaskDescriptorService taskDescriptorService = Mockito.mock(TaskDescriptorService.class);
    addService(TaskDescriptorService.class, taskDescriptorService);
    final MixinService mixinService = Mockito.mock(MixinService.class);
    addService(MixinService.class, mixinService);
    final Form cfg1 = Form.create().addFormItem(Input.create().name("count").label("Count").inputType(InputTypeName.LONG).required(true).build()).build();
    final Form cfg2 = Form.create().addFormItem(Input.create().name("values").label("Values").inputType(InputTypeName.TEXT_LINE).required(true).multiple(true).build()).build();
    final TaskDescriptor desc1 = TaskDescriptor.create().key(DescriptorKey.from("myapplication:job42")).config(cfg1).build();
    final TaskDescriptor desc2 = TaskDescriptor.create().key(DescriptorKey.from("myapplication:my-task")).config(cfg2).build();
    final TaskDescriptor desc3 = TaskDescriptor.create().key(DescriptorKey.from("other-app:some-task")).build();
    Mockito.when(taskDescriptorService.getTasks()).thenReturn(Descriptors.from(desc1, desc2, desc3));
    Mockito.when(mixinService.inlineFormItems(any(Form.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
    addService(PropertyTreeMarshallerService.class, PropertyTreeMarshallerServiceFactory.newInstance(mixinService));
}
Also used : TaskDescriptorService(com.enonic.xp.task.TaskDescriptorService) TaskDescriptor(com.enonic.xp.task.TaskDescriptor) Form(com.enonic.xp.form.Form) TaskService(com.enonic.xp.task.TaskService) MixinService(com.enonic.xp.schema.mixin.MixinService)

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