Adds unit tests for LookupByNiceUrlAndTemplate and fixes issues for when paths contain .aspx

This commit is contained in:
Shannon Deminick
2012-08-15 01:01:21 +06:00
parent ce53f400a8
commit f52ae8c46b
5 changed files with 46 additions and 6 deletions

View File

@@ -0,0 +1,33 @@
using NUnit.Framework;
using Umbraco.Web.Routing;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.template;
namespace Umbraco.Tests.DocumentLookups
{
[TestFixture]
public class LookupByNiceUrlAndTemplateTests : BaseRoutingTest
{
[TestCase("/blah")]
[TestCase("/default.aspx/blah")] //this one is actually rather important since this is the path that comes through when we are running in pre-IIS 7 for the root document '/' !
[TestCase("/home/Sub1/blah")]
[TestCase("/Home/Sub1/Blah")] //different cases
[TestCase("/home/Sub1.aspx/blah")]
public void Match_Document_By_Url_With_Template(string urlAsString)
{
var template = Template.MakeNew("test", new User(0));
var altTemplate = Template.MakeNew("blah", new User(0));
var routingContext = GetRoutingContext(urlAsString, template);
var url = routingContext.UmbracoContext.UmbracoUrl; //very important to use the cleaned up umbraco url
var docRequest = new DocumentRequest(url, routingContext);
var lookup = new LookupByNiceUrlAndTemplate();
var result = lookup.TrySetDocument(docRequest);
Assert.IsTrue(result);
Assert.IsNotNull(docRequest.Node);
Assert.IsNotNull(docRequest.Template);
Assert.AreEqual("blah".ToUpperInvariant(), docRequest.Template.Alias.ToUpperInvariant());
}
}
}

View File

@@ -16,7 +16,7 @@ namespace Umbraco.Tests.DocumentLookups
[TestCase("/Sub1")]
[TestCase("/sub1")]
[TestCase("/sub1.aspx")]
public void Match_Document_By_Directory_Url_Hide_Top_Level(string urlAsString)
public void Match_Document_By_Url_Hide_Top_Level(string urlAsString)
{
var template = Template.MakeNew("test", new User(0));
var routingContext = GetRoutingContext(urlAsString, template);
@@ -36,7 +36,7 @@ namespace Umbraco.Tests.DocumentLookups
[TestCase("/home/Sub1")]
[TestCase("/Home/Sub1")] //different cases
[TestCase("/home/Sub1.aspx")]
public void Match_Document_By_Directory_Url(string urlAsString)
public void Match_Document_By_Url(string urlAsString)
{
var template = Template.MakeNew("test", new User(0));
var routingContext = GetRoutingContext(urlAsString, template);

View File

@@ -63,6 +63,7 @@
<Compile Include="DocumentLookups\BaseRoutingTest.cs" />
<Compile Include="DocumentLookups\LookupByAliasTests.cs" />
<Compile Include="DocumentLookups\LookupByIdTests.cs" />
<Compile Include="DocumentLookups\LookupByNiceUrlAndTemplateTests.cs" />
<Compile Include="DocumentLookups\LookupByNiceUrlTests.cs" />
<Compile Include="DocumentLookups\RenderRouteHandlerTests.cs" />
<Compile Include="DocumentLookups\RouteTestExtensions.cs" />

View File

@@ -14,6 +14,8 @@ namespace Umbraco.Tests
[TestCase("http://localhost/home/Sub1", "http://localhost/home/sub1")]
[TestCase("http://localhost/home/Sub1.aspx", "http://localhost/home/sub1")]
[TestCase("http://localhost/home/Sub1.aspx?test=blah", "http://localhost/home/sub1?test=blah")]
[TestCase("http://Localhost/home/sub1.aspx/blah", "http://localhost/home/sub1/blah")]
[TestCase("http://Localhost/home/sub1.aspx/blah?test=asdf", "http://localhost/home/sub1/blah?test=asdf")]
public void Uri_To_Umbraco(string url, string expected)
{
var uri = new Uri(url);

View File

@@ -76,14 +76,18 @@ namespace Umbraco.Web
//we need to check if the path is /default.aspx because this will occur when using a
//web server pre IIS 7 when requesting the root document
//if this is the case we need to change it to '/'
if (path.EndsWith("default.aspx", StringComparison.InvariantCultureIgnoreCase))
if (path.StartsWith("/default.aspx", StringComparison.InvariantCultureIgnoreCase))
{
path = path.Substring(0, path.Length - "default.aspx".Length);
path = "/" + path.Substring("/default.aspx".Length, path.Length - "/default.aspx".Length);
}
if (path != "/")
path = path.TrimEnd('/');
if (path.EndsWith(".aspx"))
path = path.Substring(0, path.Length - ".aspx".Length);
//if any part of the path contains .aspx, replace it with nothing.
//sometimes .aspx is not at the end since we might have /home/sub1.aspx/customtemplate
path = path.Replace(".aspx", "");
//if (path.EndsWith(".aspx"))
// path = path.Substring(0, path.Length - ".aspx".Length);
return uri.Rewrite(path);
}