Fixes issue that you could not remove a property group, fixes issue that the inherited flag during mapping wasn't set on a standalone parent property group, updated/created tests to support.

This commit is contained in:
Shannon
2015-07-13 15:29:00 +02:00
parent bfe4f79b7c
commit 8521dfb0d7
3 changed files with 166 additions and 12 deletions

View File

@@ -69,7 +69,7 @@ namespace Umbraco.Tests.Models.Mapping
}
[Test]
public void ContentTypeDisplay_To_PropertyType()
public void PropertyTypeDisplay_To_PropertyType()
{
// setup the mocks to return the data we want to test against...
@@ -207,6 +207,33 @@ namespace Umbraco.Tests.Models.Mapping
}
}
[Test]
public void ContentTypeDisplay_With_Composition_To_IContentType()
{
//Arrange
// setup the mocks to return the data we want to test against...
_dataTypeService.Setup(x => x.GetDataTypeDefinitionById(It.IsAny<int>()))
.Returns(Mock.Of<IDataTypeDefinition>(
definition =>
definition.Id == 555
&& definition.PropertyEditorAlias == "myPropertyType"
&& definition.DatabaseType == DataTypeDatabaseType.Nvarchar));
var display = CreateCompositionContentTypeDisplay();
//Act
var result = Mapper.Map<IContentType>(display);
//Assert
//TODO: Now we need to assert all of the more complicated parts
Assert.AreEqual(display.Groups.Count(x => x.Inherited == false), result.PropertyGroups.Count);
}
[Test]
public void IContentType_To_ContentTypeDisplay()
{
@@ -306,6 +333,15 @@ namespace Umbraco.Tests.Models.Mapping
});
MockedContentTypes.EnsureAllIds(ctMain, 8888);
var ctChild1 = MockedContentTypes.CreateSimpleContentType("child1", "Child 1", ctMain, true);
ctChild1.AddPropertyType(new PropertyType(Constants.PropertyEditors.TextboxAlias, DataTypeDatabaseType.Ntext)
{
Alias = "someProperty",
Name = "Some Property",
Description = "",
Mandatory = false,
SortOrder = 1,
DataTypeDefinitionId = -88
}, "Another tab");
MockedContentTypes.EnsureAllIds(ctChild1, 7777);
var contentType = MockedContentTypes.CreateSimpleContentType("child2", "Child 2", ctChild1, true, "CustomGroup");
//not assigned to tab
@@ -349,7 +385,7 @@ namespace Umbraco.Tests.Models.Mapping
Assert.AreEqual(allPropertyIdsMapped.Count(), allSourcePropertyIds.Count());
Assert.IsTrue(allPropertyIdsMapped.ContainsAll(allSourcePropertyIds));
Assert.AreEqual(1, result.Groups.Count(x => x.ParentTabContentTypes.Any()));
Assert.AreEqual(2, result.Groups.Count(x => x.ParentTabContentTypes.Any()));
Assert.IsTrue(result.Groups.SelectMany(x => x.ParentTabContentTypes).ContainsAll(new[] {ctMain.Id, ctChild1.Id}));
Assert.AreEqual(contentType.AllowedTemplates.Count(), result.AllowedTemplates.Count());
@@ -437,6 +473,113 @@ namespace Umbraco.Tests.Models.Mapping
}
}
}
};
}
private ContentTypeDisplay CreateCompositionContentTypeDisplay()
{
return new ContentTypeDisplay
{
Alias = "test",
AllowAsRoot = true,
AllowedTemplates = new List<EntityBasic>
{
new EntityBasic
{
Id = 555,
Alias = "template1",
Name = "Template1"
},
new EntityBasic
{
Id = 556,
Alias = "template2",
Name = "Template2"
}
},
AllowedContentTypes = new[] { 666, 667 },
AvailableCompositeContentTypes = new List<EntityBasic>(),
DefaultTemplate = new EntityBasic() { Alias = "test" },
Description = "hello world",
Icon = "tree-icon",
Id = 1234,
Key = new Guid("8A60656B-3866-46AB-824A-48AE85083070"),
Name = "My content type",
Path = "-1,1234",
ParentId = -1,
Thumbnail = "tree-thumb",
IsContainer = true,
Groups = new List<PropertyGroupDisplay>()
{
new PropertyGroupDisplay
{
Id = 987,
Name = "Tab 1",
ParentGroupId = -1,
SortOrder = 0,
Inherited = false,
Properties = new List<PropertyTypeDisplay>
{
new PropertyTypeDisplay
{
Alias = "property1",
Description = "this is property 1",
Inherited = false,
Label = "Property 1",
Validation = new PropertyTypeValidation
{
Mandatory = false,
Pattern = ""
},
Editor = "myPropertyType",
Value = "value 1",
//View = ??? - isn't this the same as editor?
Config = new Dictionary<string, object>
{
{"item1", "value1"},
{"item2", "value2"}
},
SortOrder = 0,
DataTypeId = 555,
View = "blah"
}
}
},
new PropertyGroupDisplay
{
Id = 894,
Name = "Tab 2",
ParentGroupId = -1,
SortOrder = 0,
Inherited = true,
Properties = new List<PropertyTypeDisplay>
{
new PropertyTypeDisplay
{
Alias = "parentProperty",
Description = "this is a property from the parent",
Inherited = true,
Label = "Parent property",
Validation = new PropertyTypeValidation
{
Mandatory = false,
Pattern = ""
},
Editor = "myPropertyType",
Value = "parent value",
//View = ??? - isn't this the same as editor?
Config = new Dictionary<string, object>
{
{"item1", "value1"}
},
SortOrder = 0,
DataTypeId = 555,
View = "blah"
}
}
}
}
};
}