RemoveHtmlTests.cs :  » Bloggers » SubText » UnitTests » Subtext » Framework » Text » 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 » Text » RemoveHtmlTests.cs
using MbUnit.Framework;
using Subtext.Framework.Text;

namespace UnitTests.Subtext.Framework.Text{
    /// <summary>
    /// Unit tests of the <see cref="HtmlHelper.RemoveHtml"/> method and 
    /// just that method.
    /// </summary>
    [TestFixture]
    public class RemoveHtmlTests
    {
        [Test]
        public void NullHtml_ReturnsEmptyString()
        {
            Assert.AreEqual(string.Empty, HtmlHelper.RemoveHtml(null));
        }

        [Test]
        public void Html_WithEmptyString_ReturnsEmpty()
        {
            Assert.AreEqual(string.Empty, HtmlHelper.RemoveHtml(string.Empty));
        }

        [Test]
        public void Html_WithNoTags_ReturnsTextOnly()
        {
            string html = "This has no tags!";
            Assert.AreEqual(html, HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithOnlyATag_ReturnsEmptyString()
        {
            string html = "<foo>";
            Assert.AreEqual(string.Empty, HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithOnlyConsecutiveTags_ReturnsEmptyString()
        {
            string html = "<foo><bar><baz />";
            Assert.AreEqual(string.Empty, HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithTextBeforeTag_ReturnsText()
        {
            string html = "Hello<foo>";
            Assert.AreEqual("Hello", HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithTextAfterTag_ReturnsText()
        {
            string html = "<foo>World";
            Assert.AreEqual("World", HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithTextBetweenTags_ReturnsText()
        {
            string html = "<p><foo>World</foo></p>";
            Assert.AreEqual("World", HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithClosingTagInAttrValue_StripsEntireTag()
        {
            string html = "<foo title=\"/>\" />";
            Assert.AreEqual(string.Empty, HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithSingleQuotedAttrContainingDoubleQuotesAndEndTagChar_StripsEntireTag()
        {
            string html = @"<foo ='test""/>title' />";
            Assert.AreEqual(string.Empty, HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithDoubleQuotedAttributeContainingSingleQuotesAndEndTagChar_StripsEntireTag()
        {
            string html = @"<foo =""test'/>title"" />";
            Assert.AreEqual(string.Empty, HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithNonQuotedAttribute_StripsEntireTagWithoutStrippingText()
        {
            string html = @"<foo title=test>title />";
            Assert.AreEqual("title />", HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithNonQuotedAttributeContainingDoubleQuotes_StripsEntireTagWithoutStrippingText()
        {
            string html = @"<p title = test-test""-test>title />Test</p>";
            Assert.AreEqual("title />Test", HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithNonQuotedAttributeContainingQuotedSection_StripsEntireTagWithoutStrippingText()
        {
            string html = @"<p title = test-test""- >""test> ""title />Test</p>";
            Assert.AreEqual(@"""test> ""title />Test", HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithTagClosingCharInAttributeValueWithNoNameFollowedByText_ReturnsText()
        {
            string html = @"<foo = "" />title"" />Test";
            Assert.AreEqual("Test", HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithTextThatLooksLikeTag_ReturnsText()
        {
            string html = @"<oo = "" />title"" />Test";
            Assert.AreEqual(html, HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithCommentOnly_ReturnsEmptyString()
        {
            string s = "<!-- this go bye bye>";
            Assert.AreEqual(string.Empty, HtmlHelper.RemoveHtml(s));
        }

        [Test]
        public void Html_WithNonDashDashComment_ReturnsEmptyString()
        {
            string s = "<! this go bye bye>";
            Assert.AreEqual(string.Empty, HtmlHelper.RemoveHtml(s));
        }

        [Test]
        public void Html_WithTwoConsecutiveComments_ReturnsEmptyString()
        {
            string s = "<!-- this go bye bye><!-- another comment>";
            Assert.AreEqual(string.Empty, HtmlHelper.RemoveHtml(s));
        }

        [Test]
        public void Html_WithTextBeforeComment_ReturnsText()
        {
            string s = "Hello<!-- this go bye bye -->";
            Assert.AreEqual("Hello", HtmlHelper.RemoveHtml(s));
        }

        [Test]
        public void Html_WithTextAfterComment_ReturnsText()
        {
            string s = "<!-- this go bye bye -->World";
            Assert.AreEqual("World", HtmlHelper.RemoveHtml(s));
        }

        [Test]
        public void Html_WithAngleBracketsButNotHtml_ReturnsText()
        {
            string s = "<$)*(@&$(@*>";
            Assert.AreEqual(s, HtmlHelper.RemoveHtml(s));
        }

        [Test]
        public void Html_WithCommentInterleavedWithText_ReturnsText()
        {
            string s = "Hello <!-- this go bye bye --> World <!--> This is fun";
            Assert.AreEqual("Hello  World  This is fun", HtmlHelper.RemoveHtml(s));
        }

        [Test]
        public void Html_WithCommentBetweenNonTagButLooksLikeTag_DoesStripComment()
        {
            string s = @"<123 title=""<!bc def>"">";
            Assert.AreEqual(@"<123 title="""">", HtmlHelper.RemoveHtml(s));
        }

        [Test]
        public void Html_WithTagClosedByStartTag_StripsFirstTag()
        {
            string html = "<foo<>Test";
            Assert.AreEqual("<>Test", HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithTagClosedByStartComment_StripsFirstTag()
        {
            //Note in Firefox, this renders: <!--foo>Test
            string html = "<foo<!--foo>Test";
            Assert.AreEqual("Test", HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithTagClosedByProperComment_StripsFirstTag()
        {
            string html = "<FOO<!-- FOO -->Test";
            Assert.AreEqual("Test", HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_WithTagClosedByEmptyComment_StripsFirstTag()
        {
            string html = "<foo<!>Test";
            Assert.AreEqual("Test", HtmlHelper.RemoveHtml(html));
        }

        [Test]
        public void Html_ThatBrokeSubtextBefore_NowDoesntPegCPU()
        {
            string html =
                @"Hi Friends,<br /><br />I have some different problem to validate the HTML<br /><br />html code is something like <br /><br /><html><br />.<br />.<br />.<br /><body ...><br /><br /><table ..><br /><tr ..><td><br />  <img src=""test.asp?t=123"" border=0 alt=test /><br />  ...<br /><br />  <script type='text/javascript'><br />  <!--<br />     function test(xvar){<br />        var text = xvar;<br />        .................<br />     }<br />   --><br /></td><br /></tr><br /></body><br /></html<br /><br /><br />Now i need to validate all tag attributes value should be with ""<br /><br />e.g <br />img tag alt and border attribute values are without "" <br />there are various tags like table and div has same problem <br /><br /><br />can anyone help me find attributes value without quotation mark and replace with quotation mark (please note that some javascript or URL's with query para should not should not effect)<br /><br /><br />Sincerely thanks in advance<br /><br />";
            string expected =
                @"Hi Friends,I have some different problem to validate the HTMLhtml code is something like ...    ...         function test(xvar){        var text = xvar;        .................     }   -->Now i need to validate all tag attributes value should be with ""e.g img tag alt and border attribute values are without "" there are various tags like table and div has same problem can anyone help me find attributes value without quotation mark and replace with quotation mark (please note that some javascript or URL's with query para should not should not effect)Sincerely thanks in advance";
            Assert.AreEqual(expected, HtmlHelper.RemoveHtml(html));
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.