DDMFormPagesTemplateContextFactory { public List<Object> create() { _evaluate(); return createPagesTemplateContext( _ddmFormLayout.getDDMFormLayoutPages()); } DDMFormPagesTemplateContextFactory(
		DDMForm ddmForm, DDMFormLayout ddmFormLayout,
		DDMFormRenderingContext ddmFormRenderingContext,
		DDMStructureLayoutLocalService ddmStructureLayoutLocalService,
		DDMStructureLocalService ddmStructureLocalService,
		JSONFactory jsonFactory); List<Object> create(); void setDDMFormEvaluator(DDMFormEvaluator ddmFormEvaluator); void setDDMFormFieldTypeServicesTracker(
		DDMFormFieldTypeServicesTracker ddmFormFieldTypeServicesTracker);  }
@Test public void testCheckboxMultipleFieldTemplateContext() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); String formFieldLabel = String.format(_HTML_WRAPPER, "label"); String formFieldTip = String.format(_HTML_WRAPPER, "tip"); String formFieldOption = String.format(_HTML_WRAPPER, "option"); ddmForm.addDDMFormField( DDMFormTestUtil.createDDMFormField( "Field1", formFieldLabel, "checkbox-multiple", "string", false, false, true, formFieldTip, formFieldOption)); mockDDMFormFieldTypeServicesTracker( "checkbox-multiple", _ddmFormFieldTemplateContextContributorTestHelper. createCheckboxMultipleDDMFormFieldTemplateContextContributor()); DDMFormLayout ddmFormLayout = new DDMFormLayout(); ddmFormLayout = createDDMFormLayoutPage( ddmFormLayout, "Page 1", "Page 1 Description", "Field1"); DDMFormPagesTemplateContextFactory ddmFormPagesTemplateContextFactory = createDDMFormPagesTemplateContextFactory( ddmForm, ddmFormLayout, null, false, true, true); List<Object> pages = ddmFormPagesTemplateContextFactory.create(); Map<String, Object> fieldTemplateContext = getFieldTemplateContext( pages); Assert.assertEquals(formFieldLabel, fieldTemplateContext.get("label")); List<Map<String, String>> options = (List<Map<String, String>>)fieldTemplateContext.get("options"); Map<String, String> optionField = options.get(0); Assert.assertEquals(formFieldOption, optionField.get("label")); Assert.assertEquals(formFieldTip, fieldTemplateContext.get("tip")); }
@Test public void testDateFieldTemplateContext() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); String formFieldLabel = String.format(_HTML_WRAPPER, "label"); String formFieldTip = String.format(_HTML_WRAPPER, "tip"); ddmForm.addDDMFormField( DDMFormTestUtil.createDDMFormField( "Field1", formFieldLabel, "date", "string", false, false, true, formFieldTip)); mockDDMFormFieldTypeServicesTracker( "date", _ddmFormFieldTemplateContextContributorTestHelper. createDateDDMFormFieldTemplateContextContributor()); DDMFormLayout ddmFormLayout = new DDMFormLayout(); ddmFormLayout = createDDMFormLayoutPage( ddmFormLayout, "Page 1", "Page 1 Description", "Field1"); DDMFormPagesTemplateContextFactory ddmFormPagesTemplateContextFactory = createDDMFormPagesTemplateContextFactory( ddmForm, ddmFormLayout, null, false, true, true); List<Object> pages = ddmFormPagesTemplateContextFactory.create(); Map<String, Object> fieldTemplateContext = getFieldTemplateContext( pages); Assert.assertEquals(formFieldLabel, fieldTemplateContext.get("label")); Assert.assertEquals(formFieldTip, fieldTemplateContext.get("tip")); }
@Test public void testDisablePages() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); ddmForm.addDDMFormRule( new DDMFormRule(Arrays.asList("jumpPage(0, 2)"), "TRUE")); ddmForm.addDDMFormField( DDMFormTestUtil.createDDMFormField( "Field1", "Field1", "text", "string", false, false, true)); ddmForm.addDDMFormField( DDMFormTestUtil.createDDMFormField( "Field2", "Field2", "text", "string", false, false, false)); ddmForm.addDDMFormField( DDMFormTestUtil.createDDMFormField( "Field3", "Field3", "text", "string", false, false, false)); DDMFormLayout ddmFormLayout = new DDMFormLayout(); ddmFormLayout = createDDMFormLayoutPage( ddmFormLayout, "Page 1", "Page 1 Description", "Field1"); ddmFormLayout = createDDMFormLayoutPage( ddmFormLayout, "Page 2", "Page 2 Description", "Field2"); ddmFormLayout = createDDMFormLayoutPage( ddmFormLayout, "Page 3", "Page 3 Description", "Field3"); DDMFormValues ddmFormValues = DDMFormValuesTestUtil.createDDMFormValues( ddmForm); ddmFormValues.addDDMFormFieldValue( DDMFormValuesTestUtil.createUnlocalizedDDMFormFieldValue( "Field1", "A")); ddmFormValues.addDDMFormFieldValue( DDMFormValuesTestUtil.createUnlocalizedDDMFormFieldValue( "Field2", "")); ddmFormValues.addDDMFormFieldValue( DDMFormValuesTestUtil.createUnlocalizedDDMFormFieldValue( "Field3", "")); DDMFormPagesTemplateContextFactory ddmFormPagesTemplateContextFactory = createDDMFormPagesTemplateContextFactory( ddmForm, ddmFormLayout, ddmFormValues, false, false, false); mockDDMFormFieldTypeServicesTracker( "text", _ddmFormFieldTemplateContextContributorTestHelper. createTextDDMFormFieldTemplateContextContributor()); List<Object> pagesTemplateContext = ddmFormPagesTemplateContextFactory.create(); Assert.assertEquals( pagesTemplateContext.toString(), 3, pagesTemplateContext.size()); Map<String, Object> page1TemplateContext = (Map<String, Object>)pagesTemplateContext.get(0); Assert.assertTrue(MapUtil.getBoolean(page1TemplateContext, "enabled")); Map<String, Object> page2TemplateContext = (Map<String, Object>)pagesTemplateContext.get(1); Assert.assertFalse(MapUtil.getBoolean(page2TemplateContext, "enabled")); Map<String, Object> page3TemplateContext = (Map<String, Object>)pagesTemplateContext.get(2); Assert.assertTrue(MapUtil.getBoolean(page3TemplateContext, "enabled")); }
@Test public void testGridFieldTemplateContext() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); String formFieldLabel = String.format(_HTML_WRAPPER, "label"); String formFieldTip = String.format(_HTML_WRAPPER, "tip"); String formFieldOption = String.format(_HTML_WRAPPER, "option"); ddmForm.addDDMFormField( DDMFormTestUtil.createGridDDMFormField( "Field1", formFieldLabel, "grid", "string", false, false, true, formFieldTip, formFieldOption)); mockDDMFormFieldTypeServicesTracker( "grid", _ddmFormFieldTemplateContextContributorTestHelper. createGridDDMFormFieldTemplateContextContributor()); DDMFormLayout ddmFormLayout = new DDMFormLayout(); ddmFormLayout = createDDMFormLayoutPage( ddmFormLayout, "Page 1", "Page 1 Description", "Field1"); DDMFormValues ddmFormValues = DDMFormValuesTestUtil.createDDMFormValues( ddmForm); ddmFormValues.addDDMFormFieldValue( DDMFormValuesTestUtil.createDDMFormFieldValue( "Field1", new UnlocalizedValue("{}"))); DDMFormPagesTemplateContextFactory ddmFormPagesTemplateContextFactory = createDDMFormPagesTemplateContextFactory( ddmForm, ddmFormLayout, ddmFormValues, false, true, true); List<Object> pages = ddmFormPagesTemplateContextFactory.create(); Map<String, Object> fieldTemplateContext = getFieldTemplateContext( pages); Assert.assertEquals(formFieldLabel, fieldTemplateContext.get("label")); List<Map<String, String>> columns = (List<Map<String, String>>)fieldTemplateContext.get("columns"); Map<String, String> columnField = columns.get(0); Assert.assertEquals(formFieldOption, columnField.get("label")); List<Map<String, String>> rows = (List<Map<String, String>>)fieldTemplateContext.get("rows"); Map<String, String> rowField = rows.get(0); Assert.assertEquals(formFieldOption, rowField.get("label")); Assert.assertEquals(formFieldTip, fieldTemplateContext.get("tip")); }
@Test public void testNumericFieldTemplateContext() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); String formFieldLabel = String.format(_HTML_WRAPPER, "label"); String formFieldTip = String.format(_HTML_WRAPPER, "tip"); String formFieldPlaceholder = String.format( _HTML_WRAPPER, "placeHolder"); String formFieldTooltip = String.format(_HTML_WRAPPER, "toolTip"); ddmForm.addDDMFormField( DDMFormTestUtil.createNumericDDMFormField( "Field1", formFieldLabel, "integer", false, false, true, formFieldTip, formFieldPlaceholder, formFieldTooltip)); mockDDMFormFieldTypeServicesTracker( "numeric", _ddmFormFieldTemplateContextContributorTestHelper. createNumericDDMFormFieldTemplateContextContributor()); DDMFormLayout ddmFormLayout = new DDMFormLayout(); ddmFormLayout = createDDMFormLayoutPage( ddmFormLayout, "Page 1", "Page 1 Description", "Field1"); DDMFormPagesTemplateContextFactory ddmFormPagesTemplateContextFactory = createDDMFormPagesTemplateContextFactory( ddmForm, ddmFormLayout, null, false, true, true); List<Object> pages = ddmFormPagesTemplateContextFactory.create(); Map<String, Object> fieldTemplateContext = getFieldTemplateContext( pages); Assert.assertEquals(formFieldLabel, fieldTemplateContext.get("label")); Assert.assertEquals( formFieldPlaceholder, fieldTemplateContext.get("placeholder")); Assert.assertEquals(formFieldTip, fieldTemplateContext.get("tip")); Assert.assertEquals( formFieldTooltip, fieldTemplateContext.get("tooltip")); }
@Test public void testOnePageThreeRows() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm( "Field1", "Field2", "Field3", "Field4", "Field5"); DDMFormLayout ddmFormLayout = new DDMFormLayout(); DDMFormLayoutPage ddmFormLayoutPage = createDDMFormLayoutPage( "Page 1", "Page 1 Description"); DDMFormLayoutRow ddmFormLayoutRow1 = new DDMFormLayoutRow(); ddmFormLayoutRow1.setDDMFormLayoutColumns( createDDMFormLayoutColumns("Field1", "Field2")); ddmFormLayoutPage.addDDMFormLayoutRow(ddmFormLayoutRow1); DDMFormLayoutRow ddmFormLayoutRow2 = new DDMFormLayoutRow(); ddmFormLayoutRow2.setDDMFormLayoutColumns( createDDMFormLayoutColumns("Field3")); ddmFormLayoutPage.addDDMFormLayoutRow(ddmFormLayoutRow2); DDMFormLayoutRow ddmFormLayoutRow3 = new DDMFormLayoutRow(); ddmFormLayoutRow3.addDDMFormLayoutColumn( new DDMFormLayoutColumn(12, "Field4", "Field5")); ddmFormLayoutPage.addDDMFormLayoutRow(ddmFormLayoutRow3); ddmFormLayout.addDDMFormLayoutPage(ddmFormLayoutPage); DDMFormPagesTemplateContextFactory ddmFormPagesTemplateContextFactory = createDDMFormPagesTemplateContextFactory( ddmForm, ddmFormLayout, null, false, true, false); List<Object> pages = ddmFormPagesTemplateContextFactory.create(); Assert.assertEquals(pages.toString(), 1, pages.size()); Map<String, Object> page1 = (Map<String, Object>)pages.get(0); Assert.assertEquals("Page 1", page1.get("title")); Assert.assertEquals("Page 1 Description", page1.get("description")); List<Object> rows = (List<Object>)page1.get("rows"); Assert.assertEquals(rows.toString(), 3, rows.size()); Map<String, Object> row1 = (Map<String, Object>)rows.get(0); List<Object> columnsRow1 = (List<Object>)row1.get("columns"); Assert.assertEquals(columnsRow1.toString(), 2, columnsRow1.size()); assertColumnSize(6, (Map<String, Object>)columnsRow1.get(0)); assertColumnSize(6, (Map<String, Object>)columnsRow1.get(1)); Map<String, Object> row2 = (Map<String, Object>)rows.get(1); List<Object> columnsRow2 = (List<Object>)row2.get("columns"); Assert.assertEquals(columnsRow2.toString(), 1, columnsRow2.size()); assertColumnSize(12, (Map<String, Object>)columnsRow2.get(0)); Map<String, Object> row3 = (Map<String, Object>)rows.get(2); List<Object> columnsRow3 = (List<Object>)row3.get("columns"); Assert.assertEquals(columnsRow3.toString(), 1, columnsRow3.size()); assertColumnSize(12, (Map<String, Object>)columnsRow3.get(0)); }
@Test public void testPageDescription() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DDMFormLayout ddmFormLayout = new DDMFormLayout(); String descriptionPage = String.format( _HTML_WRAPPER, "descriptionPage"); DDMFormLayoutPage ddmFormLayoutPage1 = createDDMFormLayoutPage( "titlePage", descriptionPage); ddmFormLayout.addDDMFormLayoutPage(ddmFormLayoutPage1); DDMFormPagesTemplateContextFactory ddmFormPagesTemplateContextFactory = createDDMFormPagesTemplateContextFactory( ddmForm, ddmFormLayout, null, false, true, true); List<Object> pages = ddmFormPagesTemplateContextFactory.create(); Map<String, Object> pageTemplateContext = (Map<String, Object>)pages.get(0); Assert.assertEquals( descriptionPage, pageTemplateContext.get("description")); }
@Test public void testPageTitle() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DDMFormLayout ddmFormLayout = new DDMFormLayout(); String pageTitle = String.format(_HTML_WRAPPER, "titlePage"); DDMFormLayoutPage ddmFormLayoutPage1 = createDDMFormLayoutPage( pageTitle, "descriptionPage"); ddmFormLayout.addDDMFormLayoutPage(ddmFormLayoutPage1); DDMFormPagesTemplateContextFactory ddmFormPagesTemplateContextFactory = createDDMFormPagesTemplateContextFactory( ddmForm, ddmFormLayout, null, false, true, true); List<Object> pages = ddmFormPagesTemplateContextFactory.create(); Map<String, Object> pageTemplateContext = (Map<String, Object>)pages.get(0); Assert.assertEquals(pageTitle, pageTemplateContext.get("title")); }
@Test public void testRadioFieldTemplateContext() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); String formFieldLabel = String.format(_HTML_WRAPPER, "label"); String formFieldOption = String.format(_HTML_WRAPPER, "option"); String formFieldPredefinedValue = StringBundler.concat( StringPool.OPEN_BRACKET, String.format(_HTML_WRAPPER, "predefinedValue"), StringPool.CLOSE_BRACKET); String formFieldTip = String.format(_HTML_WRAPPER, "tip"); ddmForm.addDDMFormField( DDMFormTestUtil.createDDMFormField( "Field1", formFieldLabel, "radio", "string", false, false, true, formFieldTip, formFieldPredefinedValue, formFieldOption)); mockDDMFormFieldTypeServicesTracker( "radio", _ddmFormFieldTemplateContextContributorTestHelper. createRadioDDMFormFieldTemplateContextContributor()); DDMFormLayout ddmFormLayout = new DDMFormLayout(); ddmFormLayout = createDDMFormLayoutPage( ddmFormLayout, "Page 1", "Page 1 Description", "Field1"); DDMFormPagesTemplateContextFactory ddmFormPagesTemplateContextFactory = createDDMFormPagesTemplateContextFactory( ddmForm, ddmFormLayout, null, false, true, true); List<Object> pages = ddmFormPagesTemplateContextFactory.create(); Map<String, Object> fieldTemplateContext = getFieldTemplateContext( pages); List<Map<String, String>> options = (List<Map<String, String>>)fieldTemplateContext.get("options"); Map<String, String> optionField = options.get(0); Assert.assertEquals(formFieldLabel, fieldTemplateContext.get("label")); Assert.assertEquals(formFieldOption, optionField.get("label")); Object predefinedValue = fieldTemplateContext.get("predefinedValue"); Assert.assertEquals( formFieldPredefinedValue, predefinedValue.toString()); Assert.assertEquals(formFieldTip, fieldTemplateContext.get("tip")); }
@Test public void testRequiredFieldsWithoutRequiredFieldsWarning() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); ddmForm.addDDMFormField( DDMFormTestUtil.createDDMFormField( "Field1", "Field1", "text", "string", false, false, true)); ddmForm.addDDMFormField( DDMFormTestUtil.createDDMFormField( "Field2", "Field2", "text", "string", false, false, false)); ddmForm.addDDMFormField( DDMFormTestUtil.createDDMFormField( "Field3", "Field3", "text", "string", false, false, false)); DDMFormLayout ddmFormLayout = new DDMFormLayout(); ddmFormLayout = createDDMFormLayoutPage( ddmFormLayout, "Page 1", "Page 1 Description", "Field1", "Field2"); ddmFormLayout = createDDMFormLayoutPage( ddmFormLayout, "Page 2", "Page 2 Description", "Field3"); DDMFormPagesTemplateContextFactory ddmFormPagesTemplateContextFactory = createDDMFormPagesTemplateContextFactory( ddmForm, ddmFormLayout, null, false, false, false); List<Object> pagesTemplateContext = ddmFormPagesTemplateContextFactory.create(); Assert.assertEquals( pagesTemplateContext.toString(), 2, pagesTemplateContext.size()); Map<String, Object> page1TemplateContext = (Map<String, Object>)pagesTemplateContext.get(0); Assert.assertFalse( MapUtil.getBoolean( page1TemplateContext, "showRequiredFieldsWarning")); Map<String, Object> page2TemplateContext = (Map<String, Object>)pagesTemplateContext.get(1); Assert.assertFalse( MapUtil.getBoolean( page2TemplateContext, "showRequiredFieldsWarning")); }
@Test public void testRequiredFieldsWithRequiredFieldsWarning() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); ddmForm.addDDMFormField( DDMFormTestUtil.createDDMFormField( "Field1", "Field1", "text", "string", false, false, true)); ddmForm.addDDMFormField( DDMFormTestUtil.createDDMFormField( "Field2", "Field2", "text", "string", false, false, false)); ddmForm.addDDMFormField( DDMFormTestUtil.createDDMFormField( "Field3", "Field3", "text", "string", false, false, false)); DDMFormLayout ddmFormLayout = new DDMFormLayout(); ddmFormLayout = createDDMFormLayoutPage( ddmFormLayout, "Page 1", "Page 1 Description", "Field1", "Field2"); ddmFormLayout = createDDMFormLayoutPage( ddmFormLayout, "Page 2", "Page 2 Description", "Field3"); DDMFormPagesTemplateContextFactory ddmFormPagesTemplateContextFactory = createDDMFormPagesTemplateContextFactory( ddmForm, ddmFormLayout, null, false, true, false); List<Object> pagesTemplateContext = ddmFormPagesTemplateContextFactory.create(); Assert.assertEquals( pagesTemplateContext.toString(), 2, pagesTemplateContext.size()); Map<String, Object> page1TemplateContext = (Map<String, Object>)pagesTemplateContext.get(0); Assert.assertTrue( MapUtil.getBoolean( page1TemplateContext, "showRequiredFieldsWarning")); Map<String, Object> page2TemplateContext = (Map<String, Object>)pagesTemplateContext.get(1); Assert.assertFalse( MapUtil.getBoolean( page2TemplateContext, "showRequiredFieldsWarning")); }
@Test public void testSelectFieldTemplateContext() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); String formFieldLabel = String.format(_HTML_WRAPPER, "label"); String formFieldOption = String.format(_HTML_WRAPPER, "option"); String formFieldTip = String.format(_HTML_WRAPPER, "tip"); ddmForm.addDDMFormField( DDMFormTestUtil.createDDMFormField( "Field1", formFieldLabel, "select", "string", false, false, true, formFieldTip, formFieldOption)); mockDDMFormFieldTypeServicesTracker( "select", _ddmFormFieldTemplateContextContributorTestHelper. createSelectDDMFormFieldTemplateContextContributor()); DDMFormLayout ddmFormLayout = new DDMFormLayout(); ddmFormLayout = createDDMFormLayoutPage( ddmFormLayout, "Page 1", "Page 1 Description", "Field1"); DDMFormPagesTemplateContextFactory ddmFormPagesTemplateContextFactory = createDDMFormPagesTemplateContextFactory( ddmForm, ddmFormLayout, null, false, true, true); List<Object> pages = ddmFormPagesTemplateContextFactory.create(); Map<String, Object> fieldTemplateContext = getFieldTemplateContext( pages); Assert.assertEquals(formFieldLabel, fieldTemplateContext.get("label")); List<Map<String, String>> options = (List<Map<String, String>>)fieldTemplateContext.get("options"); Map<String, String> optionField = options.get(0); Assert.assertEquals(formFieldOption, optionField.get("label")); Assert.assertEquals(formFieldTip, fieldTemplateContext.get("tip")); }
@Test public void testTextFieldTemplateContext() throws Exception { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); String formFieldLabel = String.format(_HTML_WRAPPER, "label"); String formFieldOption = String.format(_HTML_WRAPPER, "option"); String formFieldPredefinedValue = String.format( _HTML_WRAPPER, "predefinedValue"); String formFieldPlaceholder = String.format( _HTML_WRAPPER, "placeHolder"); String formFieldTip = String.format(_HTML_WRAPPER, "tip"); String formFieldTooltip = String.format(_HTML_WRAPPER, "toolTip"); ddmForm.addDDMFormField( DDMFormTestUtil.createDDMFormField( "Field1", formFieldLabel, "text", "string", false, false, true, formFieldTip, formFieldPredefinedValue, formFieldPlaceholder, formFieldTooltip, formFieldOption)); mockDDMFormFieldTypeServicesTracker( "text", _ddmFormFieldTemplateContextContributorTestHelper. createTextDDMFormFieldTemplateContextContributor()); DDMFormLayout ddmFormLayout = new DDMFormLayout(); ddmFormLayout = createDDMFormLayoutPage( ddmFormLayout, "Page 1", "Page 1 Description", "Field1"); DDMFormPagesTemplateContextFactory ddmFormPagesTemplateContextFactory = createDDMFormPagesTemplateContextFactory( ddmForm, ddmFormLayout, null, false, true, true); List<Object> pages = ddmFormPagesTemplateContextFactory.create(); Map<String, Object> fieldTemplateContext = getFieldTemplateContext( pages); Assert.assertEquals(formFieldLabel, fieldTemplateContext.get("label")); List<Map<String, String>> options = (List<Map<String, String>>)fieldTemplateContext.get("options"); Map<String, String> optionField = options.get(0); Assert.assertEquals(formFieldOption, optionField.get("label")); Assert.assertEquals( formFieldPlaceholder, fieldTemplateContext.get("placeholder")); Assert.assertEquals( formFieldPredefinedValue, fieldTemplateContext.get("predefinedValue")); Assert.assertEquals(formFieldTip, fieldTemplateContext.get("tip")); Assert.assertEquals( formFieldTooltip, fieldTemplateContext.get("tooltip")); }