Ejemplo n.º 1
0
        public void ApplyContentFilters_MultipleWordRegexReplaceWithUrlEncode()
        {
            string content         = "This is a $g(compound query)";
            string expectedContent = "This is a search?q=compound+query";

            SiteConfig siteConfig      = createSiteConfigWithFilter(@"\$g\((?<expr>[\w\s\d]+)\)", "search?q=$url(${expr})", true);
            string     modifiedContent = SiteUtilities.ApplyContentFilters(siteConfig, content);

            Assert.AreEqual(expectedContent, modifiedContent, "Should have replaced $g with a URL encoded search URL.");
        }
Ejemplo n.º 2
0
        public void ApplyContentFilters_MultipleReplaceWithUrlEncode()
        {
            string content         = "This is a $g(compound query) and $g(another one)";
            string expectedContent = "This is a search?q=compound+query and search?q=another+one";

            SiteConfig siteConfig      = createSiteConfigWithFilter(@"\$g\((?<expr>[\w\s\d]+)\)", "search?q=$url(${expr})", true);
            string     modifiedContent = SiteUtilities.ApplyContentFilters(siteConfig, content);

            Assert.AreEqual(expectedContent, modifiedContent, "Should have replaced both expressions");
        }
Ejemplo n.º 3
0
        public void ApplyContentFilters_SingleWordRegexReplace()
        {
            string content         = "This is a $g(query)";
            string expectedContent = "This is a search?q=query";

            SiteConfig siteConfig      = createSiteConfigWithFilter(@"\$g\((?<expr>[\w\s\d]+)\)", "search?q=${expr}", true);
            string     modifiedContent = SiteUtilities.ApplyContentFilters(siteConfig, content);

            Assert.AreEqual(expectedContent, modifiedContent, "Should have replaced $g with a search URL.");
        }
Ejemplo n.º 4
0
        public void ApplyContentFilters_NonRegexReplace()
        {
            string content         = "Smile :-) if you are happy.";
            string expectedContent = "Smile <img src='happy.gif'> if you are happy.";

            SiteConfig siteConfig      = createSiteConfigWithFilter(@":-)", @"<img src='happy.gif'>", false);
            string     modifiedContent = SiteUtilities.ApplyContentFilters(siteConfig, content);

            Assert.AreEqual(expectedContent, modifiedContent, "Should have replaced emoticon with img tag.");
        }
Ejemplo n.º 5
0
        public void ApplyContentFilters_UrlReplaceOnly()
        {
            string content         = "$url(multiple words)";
            string expectedContent = "multiple+words";

            SiteConfig siteConfig      = createSiteConfigWithFilter(@":-)", @"<img src='happy.gif'>", false);
            string     modifiedContent = SiteUtilities.ApplyContentFilters(siteConfig, content);

            Assert.AreEqual(expectedContent, modifiedContent, "Should have URL encoded the output.");
        }
Ejemplo n.º 6
0
        public void ApplyContentFilters_NonSpaceUrlEncode()
        {
            string content         = "Encode: $url(<tag> & ﷲ)";
            string expectedContent = "Encode: %3ctag%3e+%26+%ef%b7%b2";

            SiteConfig siteConfig      = createSiteConfigWithFilter(@"\$g\((?<expr>[\w\s\d]+)\)", "search?q=${expr}", true);
            string     modifiedContent = SiteUtilities.ApplyContentFilters(siteConfig, content);

            Assert.AreEqual(expectedContent, modifiedContent, "Should have replaced $g with a search URL.");
        }
Ejemplo n.º 7
0
        public void ApplyContentFilters_NoReplacements()
        {
            string content         = "Smile";
            string expectedContent = "Smile";

            SiteConfig siteConfig      = createSiteConfigWithFilter(@":-)", @"<img src='happy.gif'>", false);
            string     modifiedContent = SiteUtilities.ApplyContentFilters(siteConfig, content);

            Assert.AreEqual(expectedContent, modifiedContent, "Should not have changed anything.");
        }
Ejemplo n.º 8
0
        public void ApplyContentFilters_MultipleFilters()
        {
            string content         = "This is a $g(query)";
            string expectedContent = "This was a search?q=query";

            SiteConfig siteConfig = createSiteConfigWithFilter(@"\$g\((?<expr>[\w\s\d]+)\)", "search?q=${expr}", true);

            siteConfig.ContentFilters.Add(createContentFilter(" is ", " was ", false));
            string modifiedContent = SiteUtilities.ApplyContentFilters(siteConfig, content);

            Assert.AreEqual(expectedContent, modifiedContent, "Should performed both filters");
        }
Ejemplo n.º 9
0
 public static string ApplyContentFilters(SiteConfig siteConfig, string content)
 {
     return(SiteUtilities.ApplyContentFilters(siteConfig, content));
 }