Adds unit test for ensuring reset identities on cloning a content type
This commit is contained in:
@@ -24,6 +24,69 @@ namespace Umbraco.Tests.Models
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone_Content_Type_With_Reset_Identities()
|
||||
{
|
||||
var contentType = MockedContentTypes.CreateTextpageContentType();
|
||||
contentType.Id = 99;
|
||||
|
||||
var i = 200;
|
||||
foreach (var propertyType in contentType.PropertyTypes)
|
||||
{
|
||||
propertyType.Id = ++i;
|
||||
}
|
||||
foreach (var group in contentType.PropertyGroups)
|
||||
{
|
||||
group.Id = ++i;
|
||||
}
|
||||
//add a property type without a property group
|
||||
contentType.PropertyTypeCollection.Add(
|
||||
new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "title2", Name = "Title2", Description = "", HelpText = "", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -88 });
|
||||
|
||||
contentType.AllowedTemplates = new[] { new Template("-1,2", "Name", "name") { Id = 200 }, new Template("-1,3", "Name2", "name2") { Id = 201 } };
|
||||
contentType.AllowedContentTypes = new[] { new ContentTypeSort(new Lazy<int>(() => 888), 8, "sub"), new ContentTypeSort(new Lazy<int>(() => 889), 9, "sub2") };
|
||||
contentType.Id = 10;
|
||||
contentType.CreateDate = DateTime.Now;
|
||||
contentType.CreatorId = 22;
|
||||
contentType.SetDefaultTemplate(new Template("-1,2,3,4", "Test Template", "testTemplate")
|
||||
{
|
||||
Id = 88
|
||||
});
|
||||
contentType.Description = "test";
|
||||
contentType.Icon = "icon";
|
||||
contentType.IsContainer = true;
|
||||
contentType.Thumbnail = "thumb";
|
||||
contentType.Key = Guid.NewGuid();
|
||||
contentType.Level = 3;
|
||||
contentType.Path = "-1,4,10";
|
||||
contentType.SortOrder = 5;
|
||||
contentType.Trashed = false;
|
||||
contentType.UpdateDate = DateTime.Now;
|
||||
|
||||
//ensure that nothing is marked as dirty
|
||||
contentType.ResetDirtyProperties(false);
|
||||
|
||||
var clone = (ContentType)contentType.Clone("newAlias");
|
||||
|
||||
Assert.AreEqual("newAlias", clone.Alias);
|
||||
Assert.AreNotEqual("newAlias", contentType.Alias);
|
||||
Assert.IsFalse(clone.HasIdentity);
|
||||
|
||||
foreach (var propertyGroup in clone.PropertyGroups)
|
||||
{
|
||||
Assert.IsFalse(propertyGroup.HasIdentity);
|
||||
foreach (var propertyType in propertyGroup.PropertyTypes)
|
||||
{
|
||||
Assert.IsFalse(propertyType.HasIdentity);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var propertyType in clone.PropertyTypes.Where(x => x.HasIdentity))
|
||||
{
|
||||
Assert.IsFalse(propertyType.HasIdentity);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone_Content_Type()
|
||||
{
|
||||
@@ -36,6 +99,10 @@ namespace Umbraco.Tests.Models
|
||||
{
|
||||
propertyType.Id = ++i;
|
||||
}
|
||||
foreach (var group in contentType.PropertyGroups)
|
||||
{
|
||||
group.Id = ++i;
|
||||
}
|
||||
contentType.AllowedTemplates = new[] { new Template("-1,2", "Name", "name") { Id = 200 }, new Template("-1,3", "Name2", "name2") { Id = 201 } };
|
||||
contentType.AllowedContentTypes = new[] {new ContentTypeSort(new Lazy<int>(() => 888), 8, "sub"), new ContentTypeSort(new Lazy<int>(() => 889), 9, "sub2")};
|
||||
contentType.Id = 10;
|
||||
|
||||
Reference in New Issue
Block a user