Search in sources :

Example 71 with Form

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

the class MixinTest method mixinBuilderTest.

@Test
public void mixinBuilderTest() {
    final Form.Builder formBuilder = Form.create();
    formBuilder.addFormItem(Input.create().name("name").label("Name").inputType(InputTypeName.TEXT_LINE).build());
    Mixin mixin1 = Mixin.create().name(MixinName.from("myapplication:my1")).form(formBuilder.build()).build();
    Mixin mixin2 = Mixin.create(mixin1).build();
    assertEquals(mixin1.getForm(), mixin2.getForm());
}
Also used : Form(com.enonic.xp.form.Form) InlineMixin(com.enonic.xp.form.InlineMixin) Test(org.junit.jupiter.api.Test)

Example 72 with Form

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

the class ExtraDataValidator method validate.

@Override
public void validate(final ContentValidatorParams params, final ValidationErrors.Builder validationErrorsBuilder) {
    for (final ExtraData extraData : params.getExtraDatas()) {
        final XDataName name = extraData.getName();
        final XData xData = this.xDataService.getByName(name);
        if (xData == null) {
            LOG.warn("Mixin not found: '" + name);
            continue;
        }
        final Form mixinForm = xData.getForm();
        if (extraData.getData().getRoot().getPropertySize() > 0) {
            OccurrenceValidator.validate(mixinForm, extraData.getData().getRoot(), validationErrorsBuilder);
        }
    }
}
Also used : Form(com.enonic.xp.form.Form) XData(com.enonic.xp.schema.xdata.XData) ExtraData(com.enonic.xp.content.ExtraData) XDataName(com.enonic.xp.schema.xdata.XDataName)

Example 73 with Form

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

the class CreateContentHandlerTest method mockCreateContent.

private void mockCreateContent() {
    when(this.contentService.create(any(CreateContentParams.class))).thenAnswer(mock -> createContent((CreateContentParams) mock.getArguments()[0]));
    final FormItemSet eSet = FormItemSet.create().name("e").addFormItem(Input.create().label("f").name("f").inputType(InputTypeName.DOUBLE).build()).addFormItem(Input.create().label("g").name("g").inputType(InputTypeName.CHECK_BOX).build()).build();
    final FormItemSet dSet = FormItemSet.create().name("d").addFormItem(eSet).build();
    final ContentType contentType = ContentType.create().name("test:myContentType").superType(ContentTypeName.structured()).addFormItem(Input.create().label("a").name("a").inputType(InputTypeName.LONG).build()).addFormItem(Input.create().label("b").name("b").inputType(InputTypeName.LONG).build()).addFormItem(Input.create().label("c").name("c").occurrences(0, 10).inputType(InputTypeName.TEXT_LINE).build()).addFormItem(dSet).build();
    GetContentTypeParams getContentType = GetContentTypeParams.from(ContentTypeName.from("test:myContentType"));
    when(this.contentTypeService.getByName(Mockito.eq(getContentType))).thenReturn(contentType);
    final PropertyTree extraData = new PropertyTree();
    extraData.addDouble("a", 1.0);
    extraData.addBoolean("b", true);
    final XData xData = XData.create().name(XDataName.from("com.enonic.myapplication:myschema")).addFormItem(Input.create().label("a").name("a").inputType(InputTypeName.DOUBLE).build()).addFormItem(Input.create().label("b").name("b").inputType(InputTypeName.CHECK_BOX).build()).build();
    final SiteDescriptor siteDescriptor1 = SiteDescriptor.create().form(Form.create().addFormItem(Input.create().label("a").name("a").inputType(InputTypeName.TEXT_LINE).build()).addFormItem(Input.create().label("b").name("b").inputType(InputTypeName.CHECK_BOX).build()).build()).build();
    final SiteDescriptor siteDescriptor2 = SiteDescriptor.create().form(Form.create().addFormItem(Input.create().label("c").name("c").inputType(InputTypeName.LONG).build()).build()).build();
    when(this.siteService.getDescriptor(ApplicationKey.from("appKey1"))).thenReturn(siteDescriptor1);
    when(this.siteService.getDescriptor(ApplicationKey.from("appKey2"))).thenReturn(siteDescriptor2);
    when(this.xDataService.getByName(Mockito.eq(XDataName.from("com.enonic.myapplication:myschema")))).thenReturn(xData);
    when(this.mixinService.inlineFormItems(any(Form.class))).then(returnsFirstArg());
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) Form(com.enonic.xp.form.Form) CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) XData(com.enonic.xp.schema.xdata.XData) FormItemSet(com.enonic.xp.form.FormItemSet)

Example 74 with Form

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

the class ContentTypeHandlerTest method testExampleGetType.

@Test
public void testExampleGetType() {
    final Form form = getExampleForm();
    Mockito.when(mixinService.inlineFormItems(Mockito.eq(form))).thenReturn(form);
    final ContentType contentType = exampleContentType();
    final GetContentTypeParams params = new GetContentTypeParams().contentTypeName(contentType.getName());
    Mockito.when(contentTypeService.getByName(params)).thenReturn(contentType);
    runScript("/lib/xp/examples/content/getType.js");
}
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 75 with Form

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

the class ContentTypeHandlerTest method testList.

@Test
public void testList() throws Exception {
    final Form form = getForm();
    Mockito.when(mixinService.inlineFormItems(Mockito.eq(form))).thenReturn(form);
    final ContentTypes contentTypes = testContentTypes();
    Mockito.when(contentTypeService.getAll()).thenReturn(contentTypes);
    runFunction("/test/ContentTypeHandlerTest.js", "testList");
}
Also used : Form(com.enonic.xp.form.Form) ContentTypes(com.enonic.xp.schema.content.ContentTypes) 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