Files
Umbraco-CMS/src/Umbraco.Tests/Routing/uQueryGetNodeIdByUrlTests.cs
Shannon Deminick c0102f1c71 Refactored the traversal, ishelper, etc... methods to be extension methods on IPublishedContent so now all of these methods are available on the Typed object not just the dynamic object which makes a whole lot more sense... and you can have intellisense.
Updated DynamicPublishedContent's methods to just proxy calls to the new extension methods so that all of the logic is contained in one place.
Added new GetRootDocuments to the IPublishedContentStore since we need this in order to get the root list of documents for many of these methods.
Fixed an issue with the DynamicNode to IPublishedContent converter.
Fixed many of the failing unit tests.
2012-10-04 01:31:08 +05:00

100 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Umbraco.Tests.Stubs;
using Umbraco.Tests.TestHelpers;
using System.Configuration;
using Umbraco.Web;
using Umbraco.Web.Routing;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.template;
namespace Umbraco.Tests.Routing
{
[TestFixture]
public class uQueryGetNodeIdByUrlTests : BaseRoutingTest
{
public override void TearDown()
{
base.TearDown();
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "");
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "");
}
internal override IRoutesCache GetRoutesCache()
{
return new DefaultRoutesCache(false);
}
public override void Initialize()
{
base.Initialize();
var url = "/test";
var lookup = new Umbraco.Web.Routing.LookupByNiceUrl();
var lookups = new Umbraco.Web.Routing.IPublishedContentLookup[] { lookup };
var t = Template.MakeNew("test", new User(0));
var umbracoContext = GetUmbracoContext(url, t.Id);
var contentStore = new DefaultPublishedContentStore();
var niceUrls = new NiceUrlProvider(contentStore, umbracoContext);
var routingContext = new RoutingContext(
umbracoContext,
lookups,
new FakeLastChanceLookup(),
contentStore,
niceUrls);
//assign the routing context back to the umbraco context
umbracoContext.RoutingContext = routingContext;
////assign the routing context back to the umbraco context
//umbracoContext.RoutingContext = routingContext;
Umbraco.Web.UmbracoContext.Current = routingContext.UmbracoContext;
}
[TestCase(1046, "/home")]
[TestCase(1173, "/home/sub1")]
[TestCase(1174, "/home/sub1/sub2")]
[TestCase(1176, "/home/sub1/sub-3")]
[TestCase(1177, "/home/sub1/custom-sub-1")]
[TestCase(1178, "/home/sub1/custom-sub-2")]
[TestCase(1175, "/home/sub-2")]
[TestCase(1172, "/test-page")]
public void GetNodeIdByUrl_Not_Hiding_Top_Level_Absolute(int nodeId, string url)
{
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
Assert.AreEqual(nodeId, global::umbraco.uQuery.GetNodeIdByUrl("http://example.com" + url));
}
[TestCase(1046, "/home")]
[TestCase(1173, "/home/sub1")]
[TestCase(1174, "/home/sub1/sub2")]
[TestCase(1176, "/home/sub1/sub-3")]
[TestCase(1177, "/home/sub1/custom-sub-1")]
[TestCase(1178, "/home/sub1/custom-sub-2")]
[TestCase(1175, "/home/sub-2")]
[TestCase(1172, "/test-page")]
public void GetNodeIdByUrl_Not_Hiding_Top_Level_Relative(int nodeId, string url)
{
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
Assert.AreEqual(nodeId, global::umbraco.uQuery.GetNodeIdByUrl(url));
}
}
}