mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
- Re-enabled (and rewrote) some of the RoutableService tests
- RoutableAspect's slug field taken out of tab order w/ JS (when the slugifier is going to do its thing) --HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045777
This commit is contained in:
@@ -1,54 +1,115 @@
|
|||||||
using Autofac;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Autofac;
|
||||||
using Autofac.Builder;
|
using Autofac.Builder;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.Drivers;
|
||||||
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
using Orchard.ContentManagement.Records;
|
||||||
|
using Orchard.Core.Common.Models;
|
||||||
|
using Orchard.Core.Common.Providers;
|
||||||
|
using Orchard.Core.Common.Records;
|
||||||
using Orchard.Core.Common.Services;
|
using Orchard.Core.Common.Services;
|
||||||
|
using Orchard.Data;
|
||||||
|
using Orchard.Security;
|
||||||
|
using Orchard.Tests.Packages;
|
||||||
|
|
||||||
namespace Orchard.Core.Tests.Common.Services {
|
namespace Orchard.Core.Tests.Common.Services {
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class RoutableServiceTests {
|
public class RoutableServiceTests : DatabaseEnabledTestsBase {
|
||||||
#region Setup/Teardown
|
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Init() {
|
public override void Init() {
|
||||||
var builder = new ContainerBuilder();
|
base.Init();
|
||||||
builder.Register<RoutableService>().As<IRoutableService>();
|
_routableService = _container.Resolve<IRoutableService>();
|
||||||
IContainer container = builder.Build();
|
|
||||||
_routableService = container.Resolve<IRoutableService>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
public override void Register(ContainerBuilder builder) {
|
||||||
|
builder.Register<DefaultContentManager>().As<IContentManager>();
|
||||||
|
builder.Register<ThingHandler>().As<IContentHandler>();
|
||||||
|
builder.Register<RoutableService>().As<IRoutableService>();
|
||||||
|
}
|
||||||
|
|
||||||
private IRoutableService _routableService;
|
private IRoutableService _routableService;
|
||||||
|
|
||||||
//[Test]
|
[Test]
|
||||||
//public void BeginningSlashesShouldBeReplacedByADash() {
|
public void InvalidCharactersShouldBeReplacedByADash() {
|
||||||
// Assert.That(_routableService.Slugify("/slug"), Is.EqualTo("-slug"));
|
var contentManager = _container.Resolve<IContentManager>();
|
||||||
// Assert.That(_routableService.Slugify("//slug"), Is.EqualTo("-slug"));
|
|
||||||
// Assert.That(_routableService.Slugify("//////////////slug"), Is.EqualTo("-slug"));
|
|
||||||
//}
|
|
||||||
|
|
||||||
//[Test]
|
var thing = contentManager.Create<Thing>(ThingDriver.ContentType.Name, t => {
|
||||||
//public void MultipleSlashesShouldBecomeOne() {
|
t.As<RoutableAspect>().Record = new RoutableRecord();
|
||||||
// Assert.That(_routableService.Slugify("/slug//with///lots/of////s/lashes"), Is.EqualTo("-slug/with/lots/of/s/lashes"));
|
t.Title = "Please do not use any of the following characters in your slugs: \":\", \"/\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\"";
|
||||||
// Assert.That(_routableService.Slugify("slug/with/a/couple//slashes"), Is.EqualTo("slug/with/a/couple/slashes"));
|
});
|
||||||
//}
|
|
||||||
|
|
||||||
//[Test]
|
_routableService.FillSlug(thing.As<RoutableAspect>());
|
||||||
//public void InvalidCharactersShouldBeReplacedByADash() {
|
|
||||||
// Assert.That(_routableService.Slugify(
|
|
||||||
// "Please do not use any of the following characters in your slugs: \":\", \"/\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\""),
|
|
||||||
// Is.EqualTo(
|
|
||||||
// "Please-do-not-use-any-of-the-following-characters-in-your-slugs-\"-\"-\"/\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\""));
|
|
||||||
//}
|
|
||||||
|
|
||||||
//[Test]
|
Assert.That(thing.Slug, Is.EqualTo("Please-do-not-use-any-of-the-following-characters-in-your-slugs-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\""));
|
||||||
//public void VeryLongStringTruncatedTo1000Chars() {
|
}
|
||||||
// var veryVeryLongSlug = "this is a very long slug...";
|
|
||||||
// for (var i = 0; i < 100; i++)
|
|
||||||
// veryVeryLongSlug += "aaaaaaaaaa";
|
|
||||||
|
|
||||||
// Assert.That(veryVeryLongSlug.Length, Is.AtLeast(1001));
|
[Test]
|
||||||
// Assert.That(_routableService.Slugify(veryVeryLongSlug).Length, Is.EqualTo(1000));
|
public void VeryLongStringTruncatedTo1000Chars() {
|
||||||
//}
|
var contentManager = _container.Resolve<IContentManager>();
|
||||||
|
|
||||||
|
var veryVeryLongTitle = "this is a very long slug...";
|
||||||
|
for (var i = 0; i < 100; i++)
|
||||||
|
veryVeryLongTitle += "aaaaaaaaaa";
|
||||||
|
|
||||||
|
var thing = contentManager.Create<Thing>(ThingDriver.ContentType.Name, t => {
|
||||||
|
t.As<RoutableAspect>().Record = new RoutableRecord();
|
||||||
|
t.Title = veryVeryLongTitle;
|
||||||
|
});
|
||||||
|
|
||||||
|
_routableService.FillSlug(thing.As<RoutableAspect>());
|
||||||
|
|
||||||
|
Assert.That(veryVeryLongTitle.Length, Is.AtLeast(1001));
|
||||||
|
Assert.That(thing.Slug.Length, Is.EqualTo(1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IEnumerable<Type> DatabaseTypes {
|
||||||
|
get {
|
||||||
|
return new[] {
|
||||||
|
typeof(RoutableRecord),
|
||||||
|
typeof(ContentItemRecord),
|
||||||
|
typeof(ContentItemVersionRecord),
|
||||||
|
typeof(ContentTypeRecord),
|
||||||
|
typeof(CommonRecord),
|
||||||
|
typeof(CommonVersionRecord),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[UsedImplicitly]
|
||||||
|
public class ThingHandler : ContentHandler {
|
||||||
|
public ThingHandler()
|
||||||
|
{
|
||||||
|
Filters.Add(new ActivatingFilter<Thing>(ThingDriver.ContentType.Name));
|
||||||
|
Filters.Add(new ActivatingFilter<ContentPart<CommonVersionRecord>>(ThingDriver.ContentType.Name));
|
||||||
|
Filters.Add(new ActivatingFilter<CommonAspect>(ThingDriver.ContentType.Name));
|
||||||
|
Filters.Add(new ActivatingFilter<RoutableAspect>(ThingDriver.ContentType.Name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Thing : ContentPart {
|
||||||
|
public int Id { get { return ContentItem.Id; } }
|
||||||
|
|
||||||
|
public string Title {
|
||||||
|
get { return this.As<RoutableAspect>().Title; }
|
||||||
|
set { this.As<RoutableAspect>().Title = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Slug {
|
||||||
|
get { return this.As<RoutableAspect>().Slug; }
|
||||||
|
set { this.As<RoutableAspect>().Slug = value; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ThingDriver : ContentItemDriver<Thing> {
|
||||||
|
public readonly static ContentType ContentType = new ContentType {
|
||||||
|
Name = "thing",
|
||||||
|
DisplayName = "Thing"
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -16,6 +16,8 @@
|
|||||||
<% using (this.Capture("end-of-page-scripts")) { %>
|
<% using (this.Capture("end-of-page-scripts")) { %>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function(){
|
$(function(){
|
||||||
|
//pull slug input from tab order
|
||||||
|
$("<%=String.Format("input#{0}Slug", !string.IsNullOrEmpty(Model.Prefix) ? Model.Prefix + "_" : "") %>").attr("tabindex",-1);
|
||||||
$("<%=String.Format("input#{0}Title", !string.IsNullOrEmpty(Model.Prefix) ? Model.Prefix + "_" : "") %>").blur(function(){
|
$("<%=String.Format("input#{0}Title", !string.IsNullOrEmpty(Model.Prefix) ? Model.Prefix + "_" : "") %>").blur(function(){
|
||||||
$(this).slugify({
|
$(this).slugify({
|
||||||
target:$("<%=String.Format("input#{0}Slug", !string.IsNullOrEmpty(Model.Prefix) ? Model.Prefix + "_" : "") %>"),
|
target:$("<%=String.Format("input#{0}Slug", !string.IsNullOrEmpty(Model.Prefix) ? Model.Prefix + "_" : "") %>"),
|
||||||
|
Reference in New Issue
Block a user