Ensures each property type has a real sort order when adding to the property type collection
This commit is contained in:
@@ -83,6 +83,14 @@ namespace Umbraco.Core.Models
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//check if the item's sort order is already in use
|
||||
if (this.Select(x => x.SortOrder).Contains(item.SortOrder))
|
||||
{
|
||||
//make it the next iteration
|
||||
item.SortOrder = this.Max(x => x.SortOrder) + 1;
|
||||
}
|
||||
|
||||
base.Add(item);
|
||||
OnAdd.IfNotNull(x => x.Invoke());//Could this not be replaced by a Mandate/Contract for ensuring item is not null
|
||||
|
||||
|
||||
@@ -199,6 +199,36 @@ namespace Umbraco.Tests.Services
|
||||
Assert.That(homeDoc.ContentTypeId, Is.EqualTo(ctHomePage.Id));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Create_Content_Type_Ensures_Sort_Orders()
|
||||
{
|
||||
var service = ServiceContext.ContentTypeService;
|
||||
|
||||
var contentType = new ContentType(-1)
|
||||
{
|
||||
Alias = "test",
|
||||
Name = "Test",
|
||||
Description = "ContentType used for simple text pages",
|
||||
Icon = ".sprTreeDoc3",
|
||||
Thumbnail = "doc2.png",
|
||||
SortOrder = 1,
|
||||
CreatorId = 0,
|
||||
Trashed = false
|
||||
};
|
||||
|
||||
contentType.AddPropertyType(new PropertyType(Constants.PropertyEditors.TextboxAlias, DataTypeDatabaseType.Ntext) { Alias = "title", Name = "Title", Description = "", Mandatory = false, DataTypeDefinitionId = -88 });
|
||||
contentType.AddPropertyType(new PropertyType(Constants.PropertyEditors.TinyMCEAlias, DataTypeDatabaseType.Ntext) { Alias = "bodyText", Name = "Body Text", Description = "", Mandatory = false, DataTypeDefinitionId = -87 });
|
||||
contentType.AddPropertyType(new PropertyType(Constants.PropertyEditors.TextboxAlias, DataTypeDatabaseType.Ntext) { Alias = "author", Name = "Author", Description = "Name of the author", Mandatory = false, DataTypeDefinitionId = -88 });
|
||||
|
||||
service.Save(contentType);
|
||||
|
||||
var sortOrders = contentType.PropertyTypes.Select(x => x.SortOrder).ToArray();
|
||||
|
||||
Assert.AreEqual(1, sortOrders.Count(x => x == 0));
|
||||
Assert.AreEqual(1, sortOrders.Count(x => x == 1));
|
||||
Assert.AreEqual(1, sortOrders.Count(x => x == 2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Create_And_Save_ContentType_Composition()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user