mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fixing a bug with "~/something/*" url's in the UrlRuleProvider
--HG-- branch : dev
This commit is contained in:
@@ -135,6 +135,7 @@
|
|||||||
<Compile Include="Values.cs" />
|
<Compile Include="Values.cs" />
|
||||||
<Compile Include="Users\Controllers\AdminControllerTests.cs" />
|
<Compile Include="Users\Controllers\AdminControllerTests.cs" />
|
||||||
<Compile Include="Users\Services\MembershipServiceTests.cs" />
|
<Compile Include="Users\Services\MembershipServiceTests.cs" />
|
||||||
|
<Compile Include="Widgets\RuleEngine\UrlRuleProviderTest.cs" />
|
||||||
<Compile Include="Widgets\Services\WidgetsServiceTest.cs" />
|
<Compile Include="Widgets\Services\WidgetsServiceTest.cs" />
|
||||||
<Compile Include="Widgets\WidgetsTests.cs" />
|
<Compile Include="Widgets\WidgetsTests.cs" />
|
||||||
<Compile Include="XmlRpc\Controllers\HomeControllerTests.cs" />
|
<Compile Include="XmlRpc\Controllers\HomeControllerTests.cs" />
|
||||||
|
@@ -0,0 +1,65 @@
|
|||||||
|
using Autofac;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Orchard.Mvc;
|
||||||
|
using Orchard.Tests.Stubs;
|
||||||
|
using Orchard.UI.Widgets;
|
||||||
|
using Orchard.Widgets.RuleEngine;
|
||||||
|
|
||||||
|
namespace Orchard.Tests.Modules.Widgets.RuleEngine {
|
||||||
|
[TestFixture]
|
||||||
|
public class UrlRuleProviderTest {
|
||||||
|
private IContainer _container;
|
||||||
|
private IRuleProvider _urlRuleProvider;
|
||||||
|
private StubHttpContextAccessor _stubContextAccessor;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Init() {
|
||||||
|
var builder = new ContainerBuilder();
|
||||||
|
builder.RegisterType<UrlRuleProvider>().As<IRuleProvider>();
|
||||||
|
_stubContextAccessor = new StubHttpContextAccessor();
|
||||||
|
builder.RegisterInstance(_stubContextAccessor).As<IHttpContextAccessor>();
|
||||||
|
_container = builder.Build();
|
||||||
|
_urlRuleProvider = _container.Resolve<IRuleProvider>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void UrlForHomePageMatchesHomePagePath() {
|
||||||
|
_stubContextAccessor.StubContext = new StubHttpContext("~/");
|
||||||
|
var context = new RuleContext {FunctionName = "url", Arguments = new[] {"~/"}};
|
||||||
|
_urlRuleProvider.Process(context);
|
||||||
|
Assert.That(context.Result, Is.True);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void UrlForAboutPageMatchesAboutPagePath() {
|
||||||
|
_stubContextAccessor.StubContext = new StubHttpContext("~/about");
|
||||||
|
var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/about" } };
|
||||||
|
_urlRuleProvider.Process(context);
|
||||||
|
Assert.That(context.Result, Is.True);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void UrlForBlogWithEndingWildcardMatchesBlogPostPageInSaidBlog() {
|
||||||
|
_stubContextAccessor.StubContext = new StubHttpContext("~/my-blog/my-blog-post");
|
||||||
|
var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/my-blog/*" } };
|
||||||
|
_urlRuleProvider.Process(context);
|
||||||
|
Assert.That(context.Result, Is.True);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void UrlForHomePageDoesNotMatchAboutPagePath() {
|
||||||
|
_stubContextAccessor.StubContext = new StubHttpContext("~/about");
|
||||||
|
var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/" } };
|
||||||
|
_urlRuleProvider.Process(context);
|
||||||
|
Assert.That(context.Result, Is.False);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void UrlForAboutPageMatchesDifferentCasedAboutPagePath() {
|
||||||
|
_stubContextAccessor.StubContext = new StubHttpContext("~/About");
|
||||||
|
var context = new RuleContext { FunctionName = "url", Arguments = new[] { "~/about" } };
|
||||||
|
_urlRuleProvider.Process(context);
|
||||||
|
Assert.That(context.Result, Is.True);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -245,6 +245,7 @@
|
|||||||
<Compile Include="Mvc\Routes\UrlPrefixTests.cs" />
|
<Compile Include="Mvc\Routes\UrlPrefixTests.cs" />
|
||||||
<Compile Include="Records\BigRecord.cs" />
|
<Compile Include="Records\BigRecord.cs" />
|
||||||
<Compile Include="Scripting\ScriptingTests.cs" />
|
<Compile Include="Scripting\ScriptingTests.cs" />
|
||||||
|
<Compile Include="Stubs\StubHttpContextAccessor.cs" />
|
||||||
<Compile Include="Stubs\StubWorkContextAccessor.cs" />
|
<Compile Include="Stubs\StubWorkContextAccessor.cs" />
|
||||||
<Compile Include="Stubs\StubExtensionManager.cs" />
|
<Compile Include="Stubs\StubExtensionManager.cs" />
|
||||||
<Compile Include="Stubs\StubReportsCoordinator.cs" />
|
<Compile Include="Stubs\StubReportsCoordinator.cs" />
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
@@ -28,19 +27,21 @@ namespace Orchard.Tests.Stubs {
|
|||||||
public override HttpRequestBase Request {
|
public override HttpRequestBase Request {
|
||||||
get { return new StubHttpRequest(this); }
|
get { return new StubHttpRequest(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override HttpResponseBase Response {
|
public override HttpResponseBase Response {
|
||||||
get { return new StubHttpResponse(this); }
|
get { return new StubHttpResponse(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override IDictionary Items {
|
public override IDictionary Items {
|
||||||
get { return _items; }
|
get { return _items; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class StubHttpRequest : HttpRequestBase {
|
#region Nested type: StubHttpRequest
|
||||||
|
|
||||||
|
private class StubHttpRequest : HttpRequestBase {
|
||||||
private readonly StubHttpContext _httpContext;
|
private readonly StubHttpContext _httpContext;
|
||||||
private NameValueCollection _serverVariables;
|
|
||||||
private NameValueCollection _headers;
|
private NameValueCollection _headers;
|
||||||
|
private NameValueCollection _serverVariables;
|
||||||
|
|
||||||
public StubHttpRequest(StubHttpContext httpContext) {
|
public StubHttpRequest(StubHttpContext httpContext) {
|
||||||
_httpContext = httpContext;
|
_httpContext = httpContext;
|
||||||
@@ -54,33 +55,45 @@ namespace Orchard.Tests.Stubs {
|
|||||||
get { return "/"; }
|
get { return "/"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string Path {
|
||||||
|
get { return _httpContext._appRelativeCurrentExecutionFilePath.TrimStart('~'); }
|
||||||
|
}
|
||||||
|
|
||||||
public override string PathInfo {
|
public override string PathInfo {
|
||||||
get { return ""; }
|
get { return ""; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override NameValueCollection Headers {
|
public override NameValueCollection Headers {
|
||||||
get {
|
get {
|
||||||
return _headers = _headers
|
return _headers = _headers
|
||||||
?? new NameValueCollection { { "Host", _httpContext._hostHeader } };
|
?? new NameValueCollection {{"Host", _httpContext._hostHeader}};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override NameValueCollection ServerVariables {
|
public override NameValueCollection ServerVariables {
|
||||||
get {
|
get {
|
||||||
return _serverVariables = _serverVariables
|
return _serverVariables = _serverVariables
|
||||||
?? new NameValueCollection { { "HTTP_HOST", _httpContext._hostHeader } };
|
?? new NameValueCollection {{"HTTP_HOST", _httpContext._hostHeader}};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class StubHttpResponse : HttpResponseBase {
|
#endregion
|
||||||
|
|
||||||
|
#region Nested type: StubHttpResponse
|
||||||
|
|
||||||
|
private class StubHttpResponse : HttpResponseBase {
|
||||||
private readonly StubHttpContext _httpContext;
|
private readonly StubHttpContext _httpContext;
|
||||||
|
|
||||||
public StubHttpResponse(StubHttpContext httpContext) {
|
public StubHttpResponse(StubHttpContext httpContext) {
|
||||||
_httpContext = httpContext;
|
_httpContext = httpContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ApplyAppPathModifier(string virtualPath) {
|
public override string ApplyAppPathModifier(string virtualPath) {
|
||||||
return "~/" + virtualPath.TrimStart('/');
|
return "~/" + virtualPath.TrimStart('/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
16
src/Orchard.Tests/Stubs/StubHttpContextAccessor.cs
Normal file
16
src/Orchard.Tests/Stubs/StubHttpContextAccessor.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System.Web;
|
||||||
|
using Orchard.Mvc;
|
||||||
|
|
||||||
|
namespace Orchard.Tests.Stubs {
|
||||||
|
public class StubHttpContextAccessor : IHttpContextAccessor {
|
||||||
|
private HttpContextBase _httpContext;
|
||||||
|
|
||||||
|
public HttpContextBase StubContext {
|
||||||
|
set { _httpContext = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpContextBase Current() {
|
||||||
|
return _httpContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -26,7 +26,7 @@ namespace Orchard.Widgets.RuleEngine {
|
|||||||
if (url != "/" && !url.Contains("?") && url.EndsWith("/"))
|
if (url != "/" && !url.Contains("?") && url.EndsWith("/"))
|
||||||
url = url.TrimEnd('/');
|
url = url.TrimEnd('/');
|
||||||
ruleContext.Result = url.EndsWith("*")
|
ruleContext.Result = url.EndsWith("*")
|
||||||
? context.Request.Path.ToUpperInvariant().StartsWith(url.ToUpperInvariant())
|
? context.Request.Path.ToUpperInvariant().StartsWith(url.TrimEnd('*').ToUpperInvariant())
|
||||||
: context.Request.Path.ToUpperInvariant() == url.ToUpperInvariant();
|
: context.Request.Path.ToUpperInvariant() == url.ToUpperInvariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user