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")));
}
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();
}
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");
}
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");
}
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));
}
Aggregations