Beispiel #1
0
        /// <summary>
        /// Called by the dna framework so that the component can have a chance at processing the request
        /// </summary>
        public override void ProcessRequest()
        {
            // Start by creating the base node for the component
            _typedArticleNode = AddElementTag(RootElement, "TYPEDARTICLE");

            // Check to make sure the user is logged in
            if (!InputContext.ViewingUser.UserLoggedIn)
            {
                // We can only use typed article when the user is logged in
                AddErrorXml("User", "User not logged in", _typedArticleNode);
                return;
            }

            // Check template we need to use for this request
            int templateID = InputContext.GetParamIntOrZero("TemplateID", "Get the template to use for this request");
            if (templateID == 0)
            {
                // We've not been given a template id!
                AddErrorXml("TypedArticle", "No Template ID Given!", _typedArticleNode);
                return;
            }

            // Create the UITemplate to get the XML for the given template id
            _template = new UITemplate(InputContext);
            _template.UITemplateID = templateID;
            _template.LoadTemplate();
            if (_template.HasErrors)
            {
                // Invalid templateid given
                AddInside(_typedArticleNode, _template);
                return;
            }

            // Now check to see if we're creating, editing or updating
            if (InputContext.DoesParamExist("Update", "Are we updating an article"))
            {
                // We're submitting updates to the article
                AddAttribute(_typedArticleNode, "ACTION", "UPDATE");

                // Process the updated article data
                UpdateArticle();
            }
            else if (InputContext.DoesParamExist("Edit", "Are we editing an article"))
            {
                // We're about to edit an article
                AddAttribute(_typedArticleNode, "ACTION", "EDIT");

                // Add the current articles data to the template
                EditArticle();
            }
            else if (InputContext.DoesParamExist("Create", "Are we Creating an article"))
            {
                // We're about to edit an article
                AddAttribute(_typedArticleNode, "ACTION", "CREATE");

                // Add the current articles data to the template
                CreateArticle();
            }
            else
            {
                // Just show the field for the given template
                AddAttribute(_typedArticleNode, "ACTION", "");
            }

            // Put the keyphrase delimiter into the XML so the skins can let the user know
            string delimiter = NamespacePhrases.GetSiteDelimiterToken(InputContext);
            AddTextTag(_typedArticleNode, "KEYPHRASE-DELIMITER", delimiter);

            // Finish by adding the template's xml to this object
            AddInside(_typedArticleNode, _template);
        }
Beispiel #2
0
        public void Test01CreateUITemplate()
        {
            Console.WriteLine("Before Test01CreateUITemplate");

            //Create the mocked inputcontext
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = mock.NewMock<IInputContext>();
            //XmlDocument siteconfig = new XmlDocument();
            //siteconfig.LoadXml("<SITECONFIG />");
            ISite site = mock.NewMock<ISite>();
            //Stub.On(site).GetProperty("SiteConfig").Will(Return.Value(siteconfig.FirstChild));
            Stub.On(site).GetProperty("SiteID").Will(Return.Value(1));

            BBC.Dna.User user = new BBC.Dna.User(mockedInputContext);
            Stub.On(mockedInputContext).GetProperty("ViewingUser").Will(Return.Value(user));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(site));

            // Create the stored procedure reader for the UITemplate object
            IInputContext context = DnaMockery.CreateDatabaseInputContext();
            using (IDnaDataReader reader = context.CreateDnaDataReader("createuitemplate"))
            {
                Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("createuitemplate").Will(Return.Value(reader));

                // Create a new UITemplate object and get the list of fields
                UITemplate testUITemplate = new UITemplate(mockedInputContext);
                testUITemplate.UITemplateID = 0;
                XmlDocument templateDoc = new XmlDocument();
                templateDoc.LoadXml(_testTemplateXML);

                XmlElement test = ((XmlElement)templateDoc.SelectSingleNode("H2G2/UITEMPLATE"));
                test.SetAttribute("UITEMPLATEID", _createdUITemplateID.ToString());

                test = ((XmlElement)templateDoc.SelectSingleNode("H2G2/UITEMPLATE/NAME"));
                test.InnerText = test.InnerText + DateTime.Now.ToString();

                testUITemplate.SaveTemplate((XmlElement)templateDoc.FirstChild.FirstChild);
                _createdUITemplateID = testUITemplate.UITemplateID;

                DnaXmlValidator validator = new DnaXmlValidator(testUITemplate.RootElement.InnerXml, _schemaUri);
                validator.Validate();
            }
            Console.WriteLine("After Test01CreateUITemplate");
        }
Beispiel #3
0
        public void Test06GetIncorrectUITemplate()
        {
            Console.WriteLine("Before Test06GetIncorrectUITemplate");

            //Create the mocked inputcontext
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = mock.NewMock<IInputContext>();
            //XmlDocument siteconfig = new XmlDocument();
            //siteconfig.LoadXml("<SITECONFIG />");
            ISite site = mock.NewMock<ISite>();
            //Stub.On(site).GetProperty("SiteConfig").Will(Return.Value(siteconfig.FirstChild));
            Stub.On(site).GetProperty("SiteID").Will(Return.Value(1));

            BBC.Dna.User user = new BBC.Dna.User(mockedInputContext);
            Stub.On(mockedInputContext).GetProperty("ViewingUser").Will(Return.Value(user));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(site));

            // Create the stored procedure reader for the UITemplate object
            IInputContext context = DnaMockery.CreateDatabaseInputContext();
            using (IDnaDataReader reader = context.CreateDnaDataReader("getuitemplate"))
            {
                Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("getuitemplate").Will(Return.Value(reader));

                // Create a new UITemplate object and get the list of fields
                UITemplate testUITemplate = new UITemplate(mockedInputContext);
                testUITemplate.UITemplateID = 999999999;
                testUITemplate.LoadTemplate();

                Assert.IsTrue(testUITemplate.HasErrors, "The template should return an error.");
            }
            Console.WriteLine("After Test06GetIncorrectUITemplate");
        }
Beispiel #4
0
        public void Test08GetUITemplateForValidationParamsWithProfanity()
        {
            Console.WriteLine("Before Test08GetUITemplateForValidationParamsWithProfanity");

            //Create the mocked inputcontext
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = DnaMockery.CreateDatabaseInputContext();
            //XmlDocument siteconfig = new XmlDocument();
            //siteconfig.LoadXml("<SITECONFIG />");
            ISite site = mock.NewMock<ISite>();
            //Stub.On(site).GetProperty("SiteConfig").Will(Return.Value(siteconfig.FirstChild));
            Stub.On(site).GetProperty("SiteID").Will(Return.Value(1));

            Stub.On(site).GetProperty("ModClassID").Will(Return.Value(1));

            BBC.Dna.User user = new BBC.Dna.User(mockedInputContext);
            Stub.On(mockedInputContext).GetProperty("ViewingUser").Will(Return.Value(user));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(site));

            // Create the site options for the new mocked site
            SiteOptionList siteOptionList = new SiteOptionList();
            siteOptionList.CreateFromDatabase(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default);
            siteOptionList.SetValueBool(1, "Forum", "EmailAddressFilter", true, DnaMockery.CreateDatabaseReaderCreator(), null);
            siteOptionList.SetValueBool(1, "General", "IsURLFiltered", true, DnaMockery.CreateDatabaseReaderCreator(), null);

            // Stub the call to the siteoption
            Stub.On(mockedInputContext).Method("GetSiteOptionValueBool").With("Forum", "EmailAddressFilter").Will(Return.Value(true));
            // Stub the call to the siteoption
            Stub.On(mockedInputContext).Method("GetSiteOptionValueBool").With("General", "IsURLFiltered").Will(Return.Value(true));

            // Initialise the profanities object
            var p = new ProfanityFilter(DnaMockery.CreateDatabaseReaderCreator(), DnaDiagnostics.Default, CacheFactory.GetCacheManager(), null, null);

            using (IDnaDataReader reader = mockedInputContext.CreateDnaDataReader("getuitemplate"))
            {
                Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("getuitemplate").Will(Return.Value(reader));

                // Create a new UITemplate object and get the list of fields
                UITemplate testUITemplate = new UITemplate(mockedInputContext);
                testUITemplate.UITemplateID = _createdUITemplateID;
                testUITemplate.LoadTemplate();
                List<KeyValuePair<string, string>> parameters = new List<KeyValuePair<string, string>>();

                KeyValuePair<string, string> subject = new KeyValuePair<string, string>("SUBJECT", "TestSubject");
                parameters.Add(subject);
                KeyValuePair<string, string> description = new KeyValuePair<string, string>("Description", "TestDescription with f**k");
                parameters.Add(description);

                testUITemplate.ProcessParameters(parameters);

                testUITemplate.Validate();

                DnaXmlValidator validator = new DnaXmlValidator(testUITemplate.RootElement.InnerXml, _schemaUri);
                validator.Validate();
            }
            Console.WriteLine("After Test08GetUITemplateForValidationParamsWithProfanity");
        }
Beispiel #5
0
        public void Test02GetUITemplate()
        {
            Console.WriteLine("Before Test02GetUITemplate");

            //Create the mocked inputcontext
            Mockery mock = new Mockery();
            IInputContext mockedInputContext = mock.NewMock<IInputContext>();
            //XmlDocument siteconfig = new XmlDocument();
            //siteconfig.LoadXml("<SITECONFIG />");
            ISite site = mock.NewMock<ISite>();
            //Stub.On(site).GetProperty("SiteConfig").Will(Return.Value(siteconfig.FirstChild));
            Stub.On(site).GetProperty("SiteID").Will(Return.Value(1));

            BBC.Dna.User user = new BBC.Dna.User(mockedInputContext);
            Stub.On(mockedInputContext).GetProperty("ViewingUser").Will(Return.Value(user));
            Stub.On(mockedInputContext).GetProperty("CurrentSite").Will(Return.Value(site));

            // Create the stored procedure reader for the UITemplate object
            IInputContext context = DnaMockery.CreateDatabaseInputContext();
            using (IDnaDataReader reader = context.CreateDnaDataReader("getuitemplate"))
            {
                Stub.On(mockedInputContext).Method("CreateDnaDataReader").With("getuitemplate").Will(Return.Value(reader));

                // Create a new UITemplate object and get the list of fields
                UITemplate testUITemplate = new UITemplate(mockedInputContext);
                testUITemplate.UITemplateID = _createdUITemplateID;
                testUITemplate.LoadTemplate();

                DnaXmlValidator validator = new DnaXmlValidator(testUITemplate.RootElement.InnerXml, _schemaUri);
                validator.Validate();
            }
            Console.WriteLine("After Test02GetUITemplate");
        }