Changing generated slugs to be lower-cased

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4046006
This commit is contained in:
skewed 2010-01-27 07:12:27 +00:00
parent 5d797fed00
commit 1157fac6b1
2 changed files with 18 additions and 4 deletions

View File

@ -40,14 +40,14 @@ namespace Orchard.Core.Tests.Common.Services {
_routableService.FillSlug(thing.As<RoutableAspect>());
Assert.That(thing.Slug, Is.EqualTo("Please-do-not-use-any-of-the-following-characters-in-your-slugs-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\""));
Assert.That(thing.Slug, Is.EqualTo("please-do-not-use-any-of-the-following-characters-in-your-slugs-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\"-\""));
}
[Test]
public void VeryLongStringTruncatedTo1000Chars() {
var contentManager = _container.Resolve<IContentManager>();
var veryVeryLongTitle = "this is a very long slug...";
var veryVeryLongTitle = "this is a very long title...";
for (var i = 0; i < 100; i++)
veryVeryLongTitle += "aaaaaaaaaa";
@ -98,6 +98,20 @@ namespace Orchard.Core.Tests.Common.Services {
Assert.That(slug, Is.EqualTo("woohoo-2-2"));
}
[Test]
public void GeneratedSlugIsLowerCased() {
var contentManager = _container.Resolve<IContentManager>();
var thing = contentManager.Create<Thing>(ThingDriver.ContentType.Name, t => {
t.As<RoutableAspect>().Record = new RoutableRecord();
t.Title = "This Is Some Interesting Title";
});
_routableService.FillSlug(thing.As<RoutableAspect>());
Assert.That(thing.Slug, Is.EqualTo("this-is-some-interesting-title"));
}
protected override IEnumerable<Type> DatabaseTypes {
get {
return new[] {

View File

@ -19,14 +19,14 @@ namespace Orchard.Core.Common.Services {
if (slug.Length > 1000)
slug = slug.Substring(0, 1000);
model.Slug = slug;
model.Slug = slug.ToLowerInvariant();
}
public void FillSlug<TModel>(TModel model, Func<string, string> generateSlug) where TModel : RoutableAspect {
if (!string.IsNullOrEmpty(model.Slug) || string.IsNullOrEmpty(model.Title))
return;
model.Slug = generateSlug(model.Title);
model.Slug = generateSlug(model.Title).ToLowerInvariant();
}