Index: xword/ContentFiltering/ContentFiltering.csproj =================================================================== --- xword/ContentFiltering/ContentFiltering.csproj (revision 21043) +++ xword/ContentFiltering/ContentFiltering.csproj (working copy) @@ -31,6 +31,10 @@ 4 + + False + ..\dependencies\nunit.framework.dll + 3.5 @@ -58,6 +62,7 @@ + Index: xword/ContentFiltering/Office/Word/LocalToWebHTML.cs =================================================================== --- xword/ContentFiltering/Office/Word/LocalToWebHTML.cs (revision 21043) +++ xword/ContentFiltering/Office/Word/LocalToWebHTML.cs (working copy) @@ -113,7 +113,7 @@ /// Deletes the style attributes from the Word generated content /// /// A refrence to the xml document. - private void ClearStyles(ref XmlDocument xmlDoc) + public void ClearStyles(ref XmlDocument xmlDoc) { XPathNavigator navigator = xmlDoc.CreateNavigator(); XPathExpression expression = navigator.Compile("//@style"); Index: xword/ContentFiltering/Test/LocalToWebHTMLTest.cs =================================================================== --- xword/ContentFiltering/Test/LocalToWebHTMLTest.cs (revision 0) +++ xword/ContentFiltering/Test/LocalToWebHTMLTest.cs (revision 0) @@ -0,0 +1,149 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; +using System.Xml; +using XWiki.Office.Word; +using System.Collections; + +namespace ContentFiltering.Test +{ + /// + /// Test class for LocalToWebHTML. + /// + [TestFixture] + public class LocalToWebHTMLTest + { + private XmlDocument xmlDoc; + private XmlDocument expectedXmlDoc; + private String initialHTML; + private String expectedHTML; + + /// + /// Default constructor. + /// + public LocalToWebHTMLTest() + { + + } + + /// + /// Initialise the test. + /// + [TestFixtureSetUp] + public void GlobalSetUp() + { + xmlDoc = new XmlDocument(); + expectedXmlDoc = new XmlDocument(); + initialHTML = "Test1" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "
Title
LeftRight
TextText
" + + "" + + "" + + "" + + "" + + "
1
23
45
" + +""; + + expectedHTML = "Test1" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "
Title
LeftRight
TextText
" + + "" + + "" + + "" + + "" + + "
1
23
45
" + + ""; + } + + /// + /// Test method for ClearStyles(), checks if colspan and rowspan attributes + /// are kept after cleaning. + /// + [Test] + public void TestClearStyles() + { + xmlDoc.LoadXml(initialHTML); + expectedXmlDoc.LoadXml(expectedHTML); + + XWiki.Clients.IXWikiClient client = null; + ConversionManager manager = new ConversionManager("http://serverURL", "localFolder", "docFullName", "localFileName", client); + LocalToWebHTML localToWeb = new LocalToWebHTML(manager); + + localToWeb.ClearStyles(ref xmlDoc); + + XmlNodeList xmlDocChildren = xmlDoc.ChildNodes; + XmlNodeList expectedChildren = expectedXmlDoc.ChildNodes; + + Assert.AreEqual(xmlDocChildren.Count, expectedChildren.Count); + IEnumerator xmlDocChildrenEnumerator=xmlDocChildren.GetEnumerator(); + IEnumerator expectedChildrenEnumerator = expectedChildren.GetEnumerator(); + bool canEnumarate = (xmlDocChildrenEnumerator.MoveNext() && expectedChildrenEnumerator.MoveNext()); + + XmlNode node1, node2; + XmlAttribute attribute; + string node1AttributeName, node1AttributeValue, node2AttributeName, node2AttributeValue; + + while (canEnumarate) + { + node1 = (XmlNode) xmlDocChildrenEnumerator.Current; + node2 = (XmlNode) expectedChildrenEnumerator.Current; + + // all properties should be equal + Assert.AreEqual(node1.Attributes.Count, node2.Attributes.Count); + Assert.AreEqual(node1.ChildNodes.Count, node2.ChildNodes.Count); + Assert.AreEqual(node1.InnerText, node2.InnerText); + Assert.AreEqual(node1.Name, node2.Name); + Assert.AreEqual(node1.NodeType, node2.NodeType); + Assert.AreEqual(node1.Value, node2.Value); + + //all attributes from the current node in xmlDoc should exist + //in current node from expectedXmlDoc, with the same values + foreach (XmlAttribute attr in node1.Attributes) + { + node1AttributeName=attr.Name; + node1AttributeValue = attr.Value; + attribute = node2.Attributes[node1AttributeName]; + node2AttributeName = attribute.Name; + node2AttributeValue = attribute.Value; + + Assert.AreEqual(node1AttributeName, node2AttributeName); + Assert.AreEqual(node1AttributeValue, node2AttributeValue); + } + + //all attributes from the current node in expectedXmlDoc should exist + //in current node from xmlDoc, with the same values + foreach (XmlAttribute attr in node2.Attributes) + { + node2AttributeName = attr.Name; + node2AttributeValue = attr.Value; + attribute = node1.Attributes[node2AttributeName]; + node1AttributeName = attribute.Name; + node1AttributeValue = attribute.Value; + + Assert.AreEqual(node2AttributeName, node1AttributeName); + Assert.AreEqual(node2AttributeValue, node1AttributeValue); + } + + canEnumarate = (xmlDocChildrenEnumerator.MoveNext() && expectedChildrenEnumerator.MoveNext()); + } + + //The node-by-node comparison should be enough, but just in case... + Assert.AreEqual(xmlDoc.InnerXml, expectedXmlDoc.InnerXml); + } + + } +}