diff --git a/src/Umbraco.Tests/Routing/LookupByNiceUrlTests.cs b/src/Umbraco.Tests/Routing/LookupByNiceUrlTests.cs index de76880efc..25150c3599 100644 --- a/src/Umbraco.Tests/Routing/LookupByNiceUrlTests.cs +++ b/src/Umbraco.Tests/Routing/LookupByNiceUrlTests.cs @@ -19,39 +19,56 @@ namespace Umbraco.Tests.Routing get { return false; } } - [TestCase("/")] - [TestCase("/default.aspx")] //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("/Sub1")] - [TestCase("/sub1")] - [TestCase("/sub1.aspx")] - public void Match_Document_By_Url_Hide_Top_Level(string urlAsString) + [TestCase("/", 1046)] + [TestCase("/default.aspx", 1046)] //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("/Sub1", 1173)] + [TestCase("/sub1", 1173)] + [TestCase("/sub1.aspx", 1173)] + [TestCase("/home/sub1", -1)] // should fail + + // these two are special. getNiceUrl(1046) returns "/" but getNiceUrl(1172) cannot also return "/" so + // we've made it return "/test-page" => we have to support that url back in the lookup... + [TestCase("/home", 1046)] + [TestCase("/test-page", 1172)] + + public void Match_Document_By_Url_Hide_Top_Level(string urlString, int expectedId) { - var routingContext = GetRoutingContext(urlAsString); + var routingContext = GetRoutingContext(urlString); var url = routingContext.UmbracoContext.UmbracoUrl; //very important to use the cleaned up umbraco url - var docRequest = new DocumentRequest(url, routingContext); + var docreq = new DocumentRequest(url, routingContext); var lookup = new LookupByNiceUrl(); ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "true"); - var result = lookup.TrySetDocument(docRequest); + var result = lookup.TrySetDocument(docreq); - Assert.IsTrue(result); + if (expectedId > 0) + { + Assert.IsTrue(result); + Assert.AreEqual(expectedId, docreq.DocumentId); + } + else + { + Assert.IsFalse(result); + } } - [TestCase("/")] - [TestCase("/default.aspx")] //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")] - [TestCase("/Home/Sub1")] //different cases - [TestCase("/home/Sub1.aspx")] - public void Match_Document_By_Url(string urlAsString) + [TestCase("/", 1046)] + [TestCase("/default.aspx", 1046)] //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", 1046)] + [TestCase("/home/Sub1", 1173)] + [TestCase("/Home/Sub1", 1173)] //different cases + [TestCase("/home/Sub1.aspx", 1173)] + public void Match_Document_By_Url(string urlString, int expectedId) { - var routingContext = GetRoutingContext(urlAsString); + var routingContext = GetRoutingContext(urlString); var url = routingContext.UmbracoContext.UmbracoUrl; //very important to use the cleaned up umbraco url - var docRequest = new DocumentRequest(url, routingContext); + var docreq = new DocumentRequest(url, routingContext); var lookup = new LookupByNiceUrl(); - var result = lookup.TrySetDocument(docRequest); + var result = lookup.TrySetDocument(docreq); Assert.IsTrue(result); + Assert.AreEqual(expectedId, docreq.DocumentId); } } diff --git a/src/Umbraco.Tests/UriUtilityTests.cs b/src/Umbraco.Tests/UriUtilityTests.cs index 46edb5e356..6328c9ba12 100644 --- a/src/Umbraco.Tests/UriUtilityTests.cs +++ b/src/Umbraco.Tests/UriUtilityTests.cs @@ -43,6 +43,8 @@ namespace Umbraco.Tests public void Uri_To_Umbraco(string sourceUrl, string expectedUrl) { + UriUtility.SetAppDomainAppVirtualPath("/"); + var expectedUri = new Uri(expectedUrl); var sourceUri = new Uri(sourceUrl); var resultUri = UriUtility.UriToUmbraco(sourceUri); @@ -74,6 +76,7 @@ namespace Umbraco.Tests { ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", directoryUrls ? "true" : "false"); Umbraco.Core.Configuration.UmbracoSettings.AddTrailingSlash = trailingSlash; + UriUtility.SetAppDomainAppVirtualPath("/"); var expectedUri = NewUri(expectedUrl); var sourceUri = NewUri(sourceUrl); diff --git a/src/Umbraco.Web/UriUtility.cs b/src/Umbraco.Web/UriUtility.cs index e411ba3cb5..921c860a53 100644 --- a/src/Umbraco.Web/UriUtility.cs +++ b/src/Umbraco.Web/UriUtility.cs @@ -54,6 +54,8 @@ namespace Umbraco.Web { if (virtualPath.StartsWith(_appPathPrefix)) virtualPath = virtualPath.Substring(_appPathPrefix.Length); + if (virtualPath.Length == 0) + virtualPath = "/"; return virtualPath; }