Example #1
0
        public void CheckboxesFieldTests_SubmitIncorrectValue_ServerValidationFails()
        {
            var controller = new CheckboxesFieldController();

            controller.Model.ValidatorDefinition.Required = true;

            var control = new MvcWidgetProxy();

            control.ControllerName = typeof(CheckboxesFieldController).FullName;
            control.Settings       = new ControllerSettings(controller);

            var formId = ServerOperationsFeather.Forms().CreateFormWithWidget(control);

            var formManager = FormsManager.GetManager();
            var form        = formManager.GetForms().FirstOrDefault(f => f.Id == formId);

            var pageManager = PageManager.GetManager();

            try
            {
                var template = pageManager.GetTemplates().FirstOrDefault(t => t.Name == "SemanticUI.default" && t.Title == "default");
                Assert.IsNotNull(template, "Template was not found");

                var pageId = FeatherServerOperations.Pages().CreatePageWithTemplate(template, "CheckboxesFieldValidationTest", "checkboxes-field-validation-test");
                ServerOperationsFeather.Forms().AddFormControlToPage(pageId, formId);

                var checkboxesFieldName = ServerOperationsFeather.Forms().GetFirstFieldName(formManager, form);
                var result        = ServerOperationsFeather.Forms().SubmitField(checkboxesFieldName, string.Empty, pageManager, pageId);
                var contentResult = result as ViewResult;
                Assert.IsNotNull(contentResult, "Submit should return content result.");
                Assert.AreEqual(Res.Get <FormResources>().UnsuccessfullySubmittedMessage, contentResult.ViewBag.SubmitMessage, "The Submit didn't result in error as expected!");
                Assert.AreEqual("Form.SubmitResultView", contentResult.ViewName);

                var formEntry = formManager.GetFormEntries(form).LastOrDefault();
                Assert.IsNull(formEntry, "Form entry has been submitted even when the form is not valid.");
            }
            finally
            {
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Pages().DeleteAllPages();
                FormsModuleCodeSnippets.DeleteForm(formId);
            }
        }
        public void CheckboxesFieldTests_SubmitValue_ResponseIsCorrect()
        {
            var submitedCheckboxesValue = Res.Get <FieldResources>().OptionSecondChoice;

            var controller = new CheckboxesFieldController();

            var control = new MvcWidgetProxy();

            control.Settings       = new ControllerSettings(controller);
            control.ControllerName = typeof(CheckboxesFieldController).FullName;

            var formId = ServerOperationsFeather.Forms().CreateFormWithWidget(control);

            var formManager = FormsManager.GetManager();
            var form        = formManager.GetForms().FirstOrDefault(f => f.Id == formId);

            var pageManager = PageManager.GetManager();

            try
            {
                var template = pageManager.GetTemplates().FirstOrDefault(t => t.Name == "SemanticUI.default" && t.Title == "default");
                Assert.IsNotNull(template, "Template was not found");

                var pageId = FeatherServerOperations.Pages().CreatePageWithTemplate(template, "CheckboxesListFieldValueTest", "checkboxes-field-submit-value-test");
                ServerOperationsFeather.Forms().AddFormControlToPage(pageId, formId);

                var checkboxesFieldName = ServerOperationsFeather.Forms().GetFirstFieldName(formManager, form);
                ServerOperationsFeather.Forms().SubmitField(checkboxesFieldName, submitedCheckboxesValue, pageManager, pageId);

                var formEntry = formManager.GetFormEntries(form).LastOrDefault();
                Assert.IsNotNull(formEntry, "Form entry has not been submitted.");

                var submittedValue = formEntry.GetValue(checkboxesFieldName) as string;
                Assert.AreEqual(submitedCheckboxesValue, submittedValue, "Form did not persisted the submitted checkboxes value correctly.");
            }
            finally
            {
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Pages().DeleteAllPages();
                FormsModuleCodeSnippets.DeleteForm(formId);
            }
        }
        public void CheckboxesFieldTests_EditDefaultChoices_MarkupIsCorrect()
        {
            var choice1 = "Choice1";
            var choice2 = "Choice2";
            var choice3 = "Choice3";

            var controller = new CheckboxesFieldController();

            controller.Model.SerializedChoices = "[\"{0}\",\"{1}\",\"{2}\"]".Arrange(choice1, choice2, choice3);
            controller.Model.HasOtherChoice    = true;

            var control = new MvcWidgetProxy();

            control.Settings       = new ControllerSettings(controller);
            control.ControllerName = typeof(CheckboxesFieldController).FullName;

            var formId = ServerOperationsFeather.Forms().CreateFormWithWidget(control);

            var pageManager = PageManager.GetManager();

            try
            {
                var template = pageManager.GetTemplates().FirstOrDefault(t => t.Name == "SemanticUI.default" && t.Title == "default");
                Assert.IsNotNull(template, "Template was not found");

                var pageId = FeatherServerOperations.Pages().CreatePageWithTemplate(template, "CheckboxesFieldDefaultValueTest", "checkboxes-field-value-test");
                ServerOperationsFeather.Forms().AddFormControlToPage(pageId, formId);

                var pageContent = ServerOperationsFeather.Pages().GetPageContent(pageId);
                Assert.IsTrue(pageContent.Contains(choice1), "Form did not render the first choice in the checkboxes field.");
                Assert.IsTrue(pageContent.Contains(choice2), "Form did not render the second choice in the checkboxes field.");
                Assert.IsTrue(pageContent.Contains(choice3), "Form did not render the third choice in the checkboxes field.");
                Assert.IsTrue(pageContent.Contains(Res.Get <FieldResources>().Other), "Form did not render the 'Other' choice in the checkboxes field.");
            }
            finally
            {
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Pages().DeleteAllPages();
                FormsModuleCodeSnippets.DeleteForm(formId);
            }
        }
        public void CheckboxesFieldTests_SubmitIncorrectValue_ServerValidationFails()
        {
            var controller = new CheckboxesFieldController();
            controller.Model.ValidatorDefinition.Required = true;

            var control = new MvcWidgetProxy();
            control.ControllerName = typeof(CheckboxesFieldController).FullName;
            control.Settings = new ControllerSettings(controller);

            var formId = ServerOperationsFeather.Forms().CreateFormWithWidget(control);

            var formManager = FormsManager.GetManager();
            var form = formManager.GetForms().FirstOrDefault(f => f.Id == formId);

            var pageManager = PageManager.GetManager();

            try
            {
                var template = pageManager.GetTemplates().FirstOrDefault(t => t.Name == "SemanticUI.default" && t.Title == "default");
                Assert.IsNotNull(template, "Template was not found");

                var pageId = FeatherServerOperations.Pages().CreatePageWithTemplate(template, "CheckboxesFieldValidationTest", "checkboxes-field-validation-test");
                ServerOperationsFeather.Forms().AddFormControlToPage(pageId, formId);

                var checkboxesFieldName = ServerOperationsFeather.Forms().GetFirstFieldName(formManager, form);
                var result = ServerOperationsFeather.Forms().SubmitField(checkboxesFieldName, string.Empty, pageManager, pageId);
                var contentResult = result as ContentResult;
                Assert.IsNotNull(contentResult, "Submit should return content result.");
                Assert.AreEqual(Res.Get<FormResources>().UnsuccessfullySubmittedMessage, contentResult.Content, "The Submit didn't result in error as expected!");

                var formEntry = formManager.GetFormEntries(form).LastOrDefault();
                Assert.IsNull(formEntry, "Form entry has been submitted even when the form is not valid.");
            }
            finally
            {
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Pages().DeleteAllPages();
                FormsModuleCodeSnippets.DeleteForm(formId);
            }
        }
        public void CheckboxesConfigure_WithoutOtherChoice_RenderCheckboxes()
        {
            var fieldTitle  = "Checkboxes2";
            var formControl = new MvcControllerProxy();

            formControl.ControllerName = typeof(CheckboxesFieldController).FullName;
            var controller = new CheckboxesFieldController();

            controller.Model.HasOtherChoice  = false;
            controller.Model.MetaField       = new MetaField();
            controller.Model.MetaField.Title = fieldTitle;
            formControl.Settings             = new ControllerSettings(controller);
            ((CheckboxesFieldController)formControl.Controller).Model.HasOtherChoice  = false;
            ((CheckboxesFieldController)formControl.Controller).Model.MetaField       = new MetaField();
            ((CheckboxesFieldController)formControl.Controller).Model.MetaField.Title = fieldTitle;

            var configurator   = new BackendFieldFallbackConfigurator();
            var backendControl = configurator.ConfigureFormControl(formControl, Guid.NewGuid());

            Assert.AreEqual(typeof(FormCheckboxes), backendControl.GetType(), "Backend control is not with correct type!");
            Assert.AreEqual(fieldTitle, ((FormCheckboxes)backendControl).Title, "The title of the field is not correctly set!");
        }
        public void CheckboxesFieldTests_EditDefaultChoices_MarkupIsCorrect()
        {
            var choice1 = "Choice1";
            var choice2 = "Choice2";
            var choice3 = "Choice3";

            var controller = new CheckboxesFieldController();
            controller.Model.SerializedChoices = "[\"{0}\",\"{1}\",\"{2}\"]".Arrange(choice1, choice2, choice3);
            controller.Model.HasOtherChoice = true;

            var control = new MvcWidgetProxy();
            control.Settings = new ControllerSettings(controller);
            control.ControllerName = typeof(CheckboxesFieldController).FullName;

            var formId = ServerOperationsFeather.Forms().CreateFormWithWidget(control);

            var pageManager = PageManager.GetManager();

            try
            {
                var template = pageManager.GetTemplates().FirstOrDefault(t => t.Name == "SemanticUI.default" && t.Title == "default");
                Assert.IsNotNull(template, "Template was not found");

                var pageId = FeatherServerOperations.Pages().CreatePageWithTemplate(template, "CheckboxesFieldDefaultValueTest", "checkboxes-field-value-test");
                ServerOperationsFeather.Forms().AddFormControlToPage(pageId, formId);

                var pageContent = FeatherServerOperations.Pages().GetPageContent(pageId);
                Assert.IsTrue(pageContent.Contains(choice1), "Form did not render the first choice in the checkboxes field.");
                Assert.IsTrue(pageContent.Contains(choice2), "Form did not render the second choice in the checkboxes field.");
                Assert.IsTrue(pageContent.Contains(choice3), "Form did not render the third choice in the checkboxes field.");
                Assert.IsTrue(pageContent.Contains(Res.Get<FieldResources>().Other), "Form did not render the 'Other' choice in the checkboxes field.");
            }
            finally
            {
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Pages().DeleteAllPages();
                FormsModuleCodeSnippets.DeleteForm(formId);
            }
        }
        public void CheckboxesFieldTests_SubmitValue_ResponseIsCorrect()
        {
            var submitedCheckboxesValue = Res.Get<FieldResources>().OptionSecondChoice;

            var controller = new CheckboxesFieldController();

            var control = new MvcWidgetProxy();
            control.Settings = new ControllerSettings(controller);
            control.ControllerName = typeof(CheckboxesFieldController).FullName;

            var formId = ServerOperationsFeather.Forms().CreateFormWithWidget(control);

            var formManager = FormsManager.GetManager();
            var form = formManager.GetForms().FirstOrDefault(f => f.Id == formId);

            var pageManager = PageManager.GetManager();

            try
            {
                var template = pageManager.GetTemplates().FirstOrDefault(t => t.Name == "SemanticUI.default" && t.Title == "default");
                Assert.IsNotNull(template, "Template was not found");

                var pageId = FeatherServerOperations.Pages().CreatePageWithTemplate(template, "CheckboxesListFieldValueTest", "checkboxes-field-submit-value-test");
                ServerOperationsFeather.Forms().AddFormControlToPage(pageId, formId);

                var checkboxesFieldName = ServerOperationsFeather.Forms().GetFirstFieldName(formManager, form);
                ServerOperationsFeather.Forms().SubmitField(checkboxesFieldName, submitedCheckboxesValue, pageManager, pageId);

                var formEntry = formManager.GetFormEntries(form).LastOrDefault();
                Assert.IsNotNull(formEntry, "Form entry has not been submitted.");

                var submittedValue = formEntry.GetValue(checkboxesFieldName) as string;
                Assert.AreEqual(submitedCheckboxesValue, submittedValue, "Form did not persisted the submitted checkboxes value correctly.");
            }
            finally
            {
                Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Pages().DeleteAllPages();
                FormsModuleCodeSnippets.DeleteForm(formId);
            }
        }