Ejemplo n.º 1
0
        public void TestFilter()
        {
            initialXmlDoc  = new XmlDocument();
            expectedXmlDoc = new XmlDocument();

            initialHTML = "<html><head><title>TITLE</title></head>"
                          + "<body>"
                          + "<p class=\"xoffice0\">Text0</p>"
                          + "<p><span id=\"id1\">Text1</span></p>"
                          + "</body>"
                          + "</html>";


            expectedHTML = "<html><head><title>TITLE</title></head>"
                           + "<body>"

                           //the CSS should be inlined, the classes for inlined CSS should be removed
                           + "<p style=\"" + XWikiClientTestUtil.CSS_PROPERTIES_XOFFICE0 + "\">Text0</p>"
                           + "<p><span id=\"id1\" style=\"" + XWikiClientTestUtil.CSS_PROPERTIES_ID1 + "\">Text1</span></p>"

                           + "</body>"
                           + "</html>";

            initialXmlDoc.LoadXml(initialHTML);
            expectedXmlDoc.LoadXml(expectedHTML);

            WebToLocalStyleFilter filter = new WebToLocalStyleFilter(manager);

            filter.Filter(ref initialXmlDoc);

            Assert.IsTrue(XmlDocComparator.AreIdentical(initialXmlDoc, expectedXmlDoc));
        }
        public void TestFilter()
        {
            WebListsAdaptorFilter webListsAdaptorFilter = new WebListsAdaptorFilter(manager);

            webListsAdaptorFilter.Filter(ref initialXmlDoc);
            Assert.IsTrue(XmlDocComparator.AreIdentical(initialXmlDoc, expectedXmlDoc));
        }
Ejemplo n.º 3
0
        public void TestInlineCSSNoStyleNodes()
        {
            initialXmlDoc  = new XmlDocument();
            expectedXmlDoc = new XmlDocument();

            initialHTML = "<html><head><title>TITLE</title>"
                          + "<style type=\"text/css\">"
                          + Environment.NewLine
                          + ".oneClass {font-family:sans-serif;font-size:90%;}"
                          + "#oneId {color:red;}"
                          + Environment.NewLine
                          + "</style></head><body><h1>HEADER 1</h1>"
                          + "<p class=\"oneClass\">Text 1</p>"
                          + "<p><span id=\"oneId\">Text 2</span></p>"
                          + "<p>Text 3 <span class=\"oneClass\" id=\"oneId\">Text 4</span> Text 5</p>"
                          + "</body></html>";

            expectedHTML = "<html><head><title>TITLE</title>"
                           + "</head><body><h1>HEADER 1</h1>"
                           + "<p style=\"font-family:sans-serif;font-size:90%;\">Text 1</p>"
                           + "<p><span id=\"oneId\" style=\"color:red;\">Text 2</span></p>"
                           + "<p>Text 3 <span id=\"oneId\" style=\"font-family:sans-serif;font-size:90%;color:red;\">Text 4</span> Text 5</p>"
                           + "</body></html>";

            initialXmlDoc.LoadXml(initialHTML);
            expectedXmlDoc.LoadXml(expectedHTML);

            CSSUtil.InlineCSS(ref initialXmlDoc);
            Assert.IsTrue(XmlDocComparator.AreIdentical(initialXmlDoc, expectedXmlDoc));
        }
        public void TestFilter()
        {
            StyleRemoverFilter styleRemoverFilter = new StyleRemoverFilter(manager);

            styleRemoverFilter.Filter(ref initialXmlDoc);
            Assert.IsTrue(XmlDocComparator.AreIdentical(initialXmlDoc, expectedXmlDoc));
        }
Ejemplo n.º 5
0
        public void TestInlineCSSMoreRules()
        {
            initialXmlDoc  = new XmlDocument();
            expectedXmlDoc = new XmlDocument();

            initialHTML = "<html><head><title>TITLE</title>"
                          + "<style>"
                          + ".aClass {font-family:sans-serif;}"
                          + "p {font-size:100%;}"
                          + ".aClass {color:#2020FF;}"
                          + "p, .aClass {padding:3px;}"
                          + "</style>"
                          + "</head>"
                          + "<body>"
                          + "<p class=\"aClass\">Some text</p>"
                          + "</body></html>";

            expectedHTML = "<html><head><title>TITLE</title>"
                           + "<style>"
                           + "p {font-size:100%;}"
                           + "p, .aClass {padding:3px;}"
                           + "</style>"
                           + "</head>"
                           + "<body>"
                           + "<p style=\"font-family:sans-serif;color:#2020FF;padding:3px;\">Some text</p>"
                           + "</body></html>";

            initialXmlDoc.LoadXml(initialHTML);
            expectedXmlDoc.LoadXml(expectedHTML);

            CSSUtil.InlineCSS(ref initialXmlDoc);
            Assert.IsTrue(XmlDocComparator.AreIdentical(initialXmlDoc, expectedXmlDoc));
        }
Ejemplo n.º 6
0
        public void TestLocalToWebStyleFilter()
        {
            bool foundInlineStyles      = false;
            bool foundNonXOfficeClasses = false;

            new LocalToWebStyleFilter(manager).Filter(ref initialXmlDoc);

            initialXmlDoc.Normalize();
            expectedXmlDoc.Normalize();

            XmlNodeList allNodes = initialXmlDoc.GetElementsByTagName("*");

            foreach (XmlNode node in allNodes)
            {
                //searching for inline styles
                if (node.Attributes["style"] != null)
                {
                    if (("" + node.Attributes["style"].Value).Length > 0)
                    {
                        foundInlineStyles = true;
                        break; //no need to continue searching other problems
                    }
                }

                //searching for non-XOffice CSS classes in nodes
                if (node.Attributes["class"] != null)
                {
                    if (("" + node.Attributes["class"].Value).Length > 0)
                    {
                        if (node.Attributes["class"].Value.ToLower().IndexOf("xoffice") < 0)
                        {
                            foundNonXOfficeClasses = true;
                            break;
                        }
                    }
                }
            }

            Assert.IsFalse(foundInlineStyles);
            Assert.IsFalse(foundNonXOfficeClasses);

            XmlNodeList totalStyleNodes = initialXmlDoc.GetElementsByTagName("style");

            Assert.IsNotNull(totalStyleNodes);
            Assert.IsTrue(totalStyleNodes.Count == 1);

            XmlNode styleNode = initialXmlDoc.GetElementsByTagName("style")[0];

            Assert.IsNotNull(styleNode);

            string cssContent = ExtractStyleContent(styleNode);

            int cssClassesCount = CountCSSClasses(cssContent);

            Assert.IsTrue(cssClassesCount == 5);
            //Assert.IsTrue(OptimizedCSSClasses(cssContent));
            Assert.IsTrue(XmlDocComparator.AreIdentical(initialXmlDoc, expectedXmlDoc));
        }
Ejemplo n.º 7
0
        public void TestInlineCSSOneStyleNode()
        {
            initialXmlDoc  = new XmlDocument();
            expectedXmlDoc = new XmlDocument();

            initialHTML = "<html><head><title>TITLE</title>"
                          + "<style>"
                          + "p,div, span {font-family:sans-serif;}"
                          + ".normal {font-family:sans-serif;}"
                          + "</style>"
                          + "<style>"
                          + ".code {font-family:monospace;}"
                          + "#errmsg {color:red;}"
                          + "</style>"
                          + "</head>"
                          + "<body>"
                          + "<p class=\"normal\">Normal text</p>"
                          + "<p class=\"code\">return 0;</p>"
                          + "<p><span class=\"code\" id=\"errmsg\">Error message</span></p>"
                          + "</body></html>";

            expectedHTML = "<html><head><title>TITLE</title>"
                           + "<style>"
                           + "p,div, span {font-family:sans-serif;}"
                           + "</style>"
                           + "</head>"
                           + "<body>"
                           + "<p style=\"font-family:sans-serif;\">Normal text</p>"
                           + "<p style=\"font-family:monospace;\">return 0;</p>"
                           + "<p><span id=\"errmsg\" style=\"font-family:monospace;color:red;\">Error message</span></p>"
                           + "</body></html>";

            initialXmlDoc.LoadXml(initialHTML);
            expectedXmlDoc.LoadXml(expectedHTML);

            CSSUtil.InlineCSS(ref initialXmlDoc);

            Assert.IsTrue(XmlDocComparator.AreIdentical(initialXmlDoc, expectedXmlDoc));
        }
 public void TestFilter()
 {
     new OfficeAttributesRemoverFilter(manager).Filter(ref initialXmlDoc);
     Assert.IsTrue(XmlDocComparator.AreIdentical(initialXmlDoc, expectedXmlDoc));
 }
Ejemplo n.º 9
0
        public void TestConvertInlineStylesToCssClasses()
        {
            initialXmlDoc  = new XmlDocument();
            expectedXmlDoc = new XmlDocument();

            initialHTML = "<html><head><title>TITLE</title></head>"
                          + "<body>"
                          + "<div style=\"border:1px red solid;padding:3px;margin:3px;\">"
                          + "<p style=\"font-family:sans-serif;\">Text 1</p>"
                          + "<p style=\"font-family:sans-serif;\">Text 2</p>"
                          + "<p style=\"font-family:sans-serif;\">"
                          + "Text 3"
                          + "<span style=\"color:orange;\">Text 4</span>"
                          + "<span style=\"color:black;\">Text 5</span>"
                          + "</p>"
                          + "</div>"
                          + "</body></html>";

            initialXmlDoc.LoadXml(initialHTML);


            expectedHTML = "<html><head><title>TITLE</title></head>"
                           + "<body>"
                           + "<div class=\"xoffice0\">"
                           + "<p class=\"xoffice1\">Text 1</p>"
                           + "<p class=\"xoffice2\">Text 2</p>"
                           + "<p class=\"xoffice3\">"
                           + "Text 3"
                           + "<span class=\"xoffice4\">Text 4</span>"
                           + "<span class=\"xoffice5\">Text 5</span>"
                           + "</p>"
                           + "</div>"
                           + "</body></html>";

            expectedXmlDoc.LoadXml(expectedHTML);

            int       counter    = 0;
            Hashtable cssClasses = new Hashtable();
            XmlNode   node       = initialXmlDoc.GetElementsByTagName("div")[0];

            CSSUtil.ConvertInlineStylesToCssClasses(node, ref initialXmlDoc, ref counter, ref cssClasses);

            string[] properties =
            {
                "border:1px red solid;padding:3px;margin:3px;",
                "font-family:sans-serif;",
                "color:orange;",
                "color:black;"
            };

            //after conversion we should get the expected document
            Assert.IsTrue(XmlDocComparator.AreIdentical(expectedXmlDoc, initialXmlDoc));

            //6 key/value pairs in cssClasses hashtable
            Assert.IsTrue(cssClasses.Count == 6);

            //6 CSS classes from .xoffice0 to .xoffice5
            for (int i = 0; i < 6; i++)
            {
                Assert.IsTrue(cssClasses.ContainsKey(".xoffice" + i));
            }

            //all the properties extracted from inline styles should be found in the cssClasses hashtable
            foreach (string cssProp in properties)
            {
                Assert.IsTrue(cssClasses.ContainsValue(cssProp));
            }
        }
 public void TestFilter()
 {
     new GrammarAndSpellingErrorsFilter(manager).Filter(ref initialXmlDoc);
     Assert.IsTrue(XmlDocComparator.AreIdentical(initialXmlDoc, cleanedXmlDoc));
 }