XhtmlConverterTests.cs :  » Bloggers » SubText » UnitTests » Subtext » Framework » Services » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » SubText 
SubText » UnitTests » Subtext » Framework » Services » XhtmlConverterTests.cs
using System.Globalization;
using MbUnit.Framework;
using Subtext.Framework.Services;

namespace UnitTests.Subtext.Framework.Services{
    [TestFixture]
    public class XhtmlConverterTests
    {
        [RowTest]
        [Row("", "")]
        [Row("This is some text", "This is some text")]
        [Row("<span>This is some text</span>", "<span>This is some text</span>")]
        [Row("<img src=\"blah\" />", "<img src=\"blah\" />")]
        [Row("<style type=\"text/css\"><![CDATA[\r\n.blah\r\n{\r\n  font-size: small;\r\n}\r\n]]></style>",
            "<style type=\"text/css\"><![CDATA[\r\n.blah\r\n{\r\n  font-size: small;\r\n}\r\n]]></style>")]
        public void Transform_WithValidMarkup_DoesNotChangeIt(string markup, string expected)
        {
            //arrange
            var converter = new XhtmlConverter();

            //act
            string result = converter.Transform(markup);

            //assert
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Transform_WithAngleBracketInAttributeValue_EncodesAttribute()
        {
            const string html = @"<a title="">"">b</a>";
            const string expected = @"<a title=""&gt;"">b</a>";

            //arrange
            var converter = new XhtmlConverter();

            //act
            string result = converter.Transform(html);

            //assert
            Assert.AreEqual(expected, result);
        }

        [Test]
        [Ignore("Need to follow up with the SgmlReader on this")]
        public void Transform_WithStyleTag_DoesNotWrapStyleInCdata()
        {
            const string html = "<style>.test {color: blue;}</style>";
            const string expected = html;

            //arrange
            var converter = new XhtmlConverter();

            //act
            string result = converter.Transform(html);

            //assert
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Transform_WithConverter_AppliesConverterWhileConvertingHtml()
        {
            const string html = "<p title=\"blah blah\"> blah blah </p>";
            const string expected = "<p title=\"blah blah\"> yadda yadda </p>";

            //arrange
            var converter = new XhtmlConverter(input => input.Replace("blah", "yadda"));

            //act
            string result = converter.Transform(html);

            //assert
            Assert.AreEqual(expected, result);
        }

        [Test]
        public void ConvertHtmlToXHtmlLeavesNestedMarkupAlone()
        {
            //arrange
            const string expected = "<p><span>This is some text</span> <span>this is more text</span></p>";
            var converter = new XhtmlConverter();

            //act
            string result = converter.Transform(expected);

            //assert
            Assert.AreEqual(expected, result);
        }

        /// <summary>
        /// Makes sure that IsValidXHTML recognizes invalid markup.
        /// </summary>
        [RowTest]
        [Row("<a href=\"xyz\">test<b>Test</b>", "<a href=\"xyz\">test<b>Test</b></a>")]
        [Row("This <br /><br />is bad <p> XHTML.", "This <br /><br />is bad <p> XHTML.</p>")]
        [Row("This <br /><br style=\"blah\" />is bad <p> XHTML.",
            "This <br /><br style=\"blah\" />is bad <p> XHTML.</p>")]
        [Row("This <P>is bad </P> XHTML.", "This <p>is bad </p> XHTML.")]
        [Row("<style type=\"text/css\">\r\n<![CDATA[\r\n.blah\r\n{\r\n  font-size: small;\r\n}\r\n]]></style>",
            "<style type=\"text/css\"><![CDATA[\r\n.blah\r\n{\r\n  font-size: small;\r\n}\r\n]]></style>")]
        [Row("<style type=\"text/css\">\r\n\r\n<![CDATA[\r\n.blah\r\n{\r\n  font-size: small;\r\n}\r\n]]></style>",
            "<style type=\"text/css\"><![CDATA[\r\n.blah\r\n{\r\n  font-size: small;\r\n}\r\n]]></style>")]
        public void ConvertHtmlToXHtmlCorrectsInvalidMarkup(string badMarkup, string corrected)
        {
            //arrange
            var converter = new XhtmlConverter();

            //act
            string result = converter.Transform(badMarkup);

            //assert
            Assert.AreEqual(corrected, result);
        }

        [RowTest]
        [Row("<a name=\"test\"></a>", "<a name=\"test\"></a>", "Anchor tags should not be self-closed.")]
        [Row("<a name=\"test\" />", "<a name=\"test\"></a>", "Anchor tags should not be self-closed.")]
        [Row("<script src=\"test\" />", "<script src=\"test\"></script>", "Script tags should not be self-closed.")]
        [Row("<script src=\"test\"></script>", "<script src=\"test\"></script>",
            "Script tags should not be self-closed.")]
        public void ConvertHtmlToXhtmlEnsuresSomeTagsMustNotBeSelfClosed(string html, string expected, string message)
        {
            //arrange
            var converter = new XhtmlConverter();

            //act
            string result = converter.Transform(html);

            //assert
            Assert.AreEqual(expected, result);
        }

        [RowTest]
        [Row("br")]
        [Row("hr")]
        [Row("meta")]
        [Row("link")]
        [Row("input")]
        [Row("img")]
        public void ConvertHtmlToXhtmlEnsuresSomeTagsMustBeSelfClosed(string tag)
        {
            //arrange
            string html = string.Format(CultureInfo.InvariantCulture, "<{0} src=\"blah-blah\"></{0}>", tag);
            string expected = string.Format(CultureInfo.InvariantCulture, "<{0} src=\"blah-blah\" />", tag);
            var converter = new XhtmlConverter();

            //act
            string result = converter.Transform(html);

            //assert
            Assert.AreEqual(expected, result);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.