[Fat-develop] FAT/test/FAT.Test/Web/HtmlDetails HtmlDetailsEnhancerTest.cs,1.1,1.2
Brought to you by:
exortech
|
From: <dmc...@pr...> - 2004-02-01 12:29:08
|
Update of /cvsroot/fat/FAT/test/FAT.Test/Web/HtmlDetails In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18067/test/FAT.Test/Web/HtmlDetails Modified Files: HtmlDetailsEnhancerTest.cs Log Message: Relative urls in html is now expanded so that <img src="url" >, <a href="url" >, <form action="url" > etc. work in thumbnail creation and in IE pop-up when thumbnail is clicked. Introduced "view source" link so that original, unmodified html source is still accessible. Index: HtmlDetailsEnhancerTest.cs =================================================================== RCS file: /cvsroot/fat/FAT/test/FAT.Test/Web/HtmlDetails/HtmlDetailsEnhancerTest.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** HtmlDetailsEnhancerTest.cs 28 Jan 2004 22:14:50 -0000 1.1 --- HtmlDetailsEnhancerTest.cs 1 Feb 2004 12:27:16 -0000 1.2 *************** *** 11,27 **** public class HtmlDetailsEnhancerTest : Assertion { - private string html = "<html><head><title>foo</title></head><body><b>Some Text</b><br><b>Some More Text</b><br></body></html>"; - private string url = "http://testhost/testpath/test.aspx"; - private HtmlDetailsEnhancer htmlDetailsEnhancer; - - [SetUp] - public void CreateObjectToTest() - { - htmlDetailsEnhancer = new HtmlDetailsEnhancer(url, html); - } - [Test] public void Construction() { AssertEquals(html, htmlDetailsEnhancer.Html); AssertEquals(url, htmlDetailsEnhancer.Url); --- 11,21 ---- public class HtmlDetailsEnhancerTest : Assertion { [Test] public void Construction() { + string html = "<html></html>"; + string url = "http://testhost/testpath/test.aspx"; + HtmlDetailsEnhancer htmlDetailsEnhancer = new HtmlDetailsEnhancer(url, html); + AssertEquals(html, htmlDetailsEnhancer.Html); AssertEquals(url, htmlDetailsEnhancer.Url); *************** *** 31,34 **** --- 25,32 ---- public void Image() { + string html = "<html><head><title>foo</title></head><body><b>Some Text</b><br><b>Some More Text</b><br></body></html>"; + string url = "http://testhost/testpath/test.aspx"; + HtmlDetailsEnhancer htmlDetailsEnhancer = new HtmlDetailsEnhancer(url, html); + AssertNotNull(htmlDetailsEnhancer.Thumbnail); Assert(htmlDetailsEnhancer.Thumbnail.Height >10); *************** *** 36,43 **** } - // TODO: expand urls [Test] ! public void HtmlWithAbsoluteUrls() { } } --- 34,104 ---- } [Test] ! public void UrlRoot() { + HtmlDetailsEnhancer htmlDetailsEnhancer = new HtmlDetailsEnhancer("http://localhost/FAT.Web/PageVisited.aspx", "<html/>"); + AssertEquals("http://localhost/FAT.Web", htmlDetailsEnhancer.UrlRoot); + + htmlDetailsEnhancer = new HtmlDetailsEnhancer("http://www.google.co.uk", "<html/>"); + AssertEquals("http://www.google.co.uk", htmlDetailsEnhancer.UrlRoot); + } + + [Test] + public void UrlHost() + { + HtmlDetailsEnhancer htmlDetailsEnhancer = new HtmlDetailsEnhancer("http://localhost/FAT.Web/PageVisited.aspx", "<html/>"); + AssertEquals("http://localhost", htmlDetailsEnhancer.UrlHost); + + htmlDetailsEnhancer = new HtmlDetailsEnhancer("http://www.google.co.uk", "<html/>"); + AssertEquals("http://www.google.co.uk", htmlDetailsEnhancer.UrlHost); + } + + [Test] + public void ExpandsFolderRelativeUrlsToBeAbsolute() + { + AssertHtmlExpansion("http://localhost/FAT.Web/PageVisited.aspx", + @"<form name=""CreateTest"" method=""post"" action = ""PageToPostTo.aspx"" id=""CreateTest"">", + @"<form name=""CreateTest"" method=""post"" action = ""http://localhost/FAT.Web/PageToPostTo.aspx"" id=""CreateTest"">"); + + AssertHtmlExpansion("http://www.google.co.uk", + @"<form name= ""CreateTest"" method=""post"" action= ""PageToPostTo.aspx"" id=""CreateTest"">", + @"<form name= ""CreateTest"" method=""post"" action= ""http://www.google.co.uk/PageToPostTo.aspx"" id=""CreateTest"">"); + } + + [Test] + public void ExpandsHostRelativeUrlsToBeAbsolute() + { + AssertHtmlExpansion("http://localhost/FAT.Web/PageVisited.aspx", + @"<form name=""CreateTest"" method=""post"" action =""/FAT.Web2/PageToPostTo.aspx"" id=""CreateTest"">", + @"<form name=""CreateTest"" method=""post"" action =""http://localhost/FAT.Web2/PageToPostTo.aspx"" id=""CreateTest"">"); + + AssertHtmlExpansion("http://www.google.co.uk", + @"<img src =""/intl/en_uk/images/logo.gif"" width=276 height=110 alt=""Google"">", + @"<img src =""http://www.google.co.uk/intl/en_uk/images/logo.gif"" width=276 height=110 alt=""Google"">"); + } + + [Test] + public void ExpandsRelativeUrlsToBeAbsoluteWhereThereAreMultipleOccurences() + { + string htmlFragment = @"<form name= ""CreateTest"" method=""post"" \naction= ""PageToPostTo.aspx"" id=""CreateTest"">\n"; + string expectedHtmlFragment = @"<form name= ""CreateTest"" method=""post"" \naction= ""http://www.google.co.uk/PageToPostTo.aspx"" id=""CreateTest"">\n"; + AssertHtmlExpansion("http://www.google.co.uk", htmlFragment + htmlFragment, expectedHtmlFragment + expectedHtmlFragment); + + htmlFragment = @"<img src =""/intl/en_uk/images/logo.gif"" width=276 height=110 alt=""Google"">\n\r"; + expectedHtmlFragment = @"<img src =""http://www.google.co.uk/intl/en_uk/images/logo.gif"" width=276 height=110 alt=""Google"">\n\r"; + AssertHtmlExpansion("http://www.google.co.uk", htmlFragment + htmlFragment, expectedHtmlFragment + expectedHtmlFragment); + } + + [Test] + public void LeavesUntouchedAbsoluteUrls() + { + string html = @"<form name=""CreateTest"" method=""post"" action=""http://localhost2/FAT.Web2/PageToPostTo.aspx"" id=""CreateTest"">"; + AssertHtmlExpansion("http://localhost/FAT.Web/PageVisited.aspx", html, html); + } + + private void AssertHtmlExpansion(string url, string html, string expectedExpandedHtml) + { + HtmlDetailsEnhancer htmlDetailsEnhancer = new HtmlDetailsEnhancer(url, html); + Assertion.AssertEquals(expectedExpandedHtml, htmlDetailsEnhancer.HtmlWithAbsoluteUrls); } } |