diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs index 03e72d0e91..19ec4970e3 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs @@ -41,11 +41,11 @@ namespace Umbraco.Core.Persistence.Repositories .RightJoin() .On(left => left.Id, right => right.PropertyTypeGroupId) .InnerJoin() - .On(left => left.DataTypeId, right => right.DataTypeId) - .OrderBy(x => x.PropertyTypeGroupId); + .On(left => left.DataTypeId, right => right.DataTypeId); var translator = new SqlTranslator(sqlClause, query); - var sql = translator.Translate(); + var sql = translator.Translate() + .OrderBy(x => x.PropertyTypeGroupId); var dtos = Database.Fetch(new GroupPropertyTypeRelator().Map, sql); diff --git a/src/Umbraco.Core/Services/DataTypeService.cs b/src/Umbraco.Core/Services/DataTypeService.cs index 0b22d74070..12a591318f 100644 --- a/src/Umbraco.Core/Services/DataTypeService.cs +++ b/src/Umbraco.Core/Services/DataTypeService.cs @@ -246,7 +246,7 @@ namespace Umbraco.Core.Services foreach (var group in contentType.PropertyGroups) { - var types = @group.PropertyTypes.Where(x => x.DataTypeDefinitionId == dataTypeDefinition.Id); + var types = @group.PropertyTypes.Where(x => x.DataTypeDefinitionId == dataTypeDefinition.Id).ToList(); foreach (var propertyType in types) { @group.PropertyTypes.Remove(propertyType); diff --git a/src/Umbraco.Tests/Services/ContentServiceTests.cs b/src/Umbraco.Tests/Services/ContentServiceTests.cs index 689743d403..64a0149bb5 100644 --- a/src/Umbraco.Tests/Services/ContentServiceTests.cs +++ b/src/Umbraco.Tests/Services/ContentServiceTests.cs @@ -3,17 +3,12 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using NUnit.Framework; -using Umbraco.Core; using Umbraco.Core.Models; -using Umbraco.Core.Models.Rdbms; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.UnitOfWork; using Umbraco.Core.Services; -using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; -using umbraco.editorControls.tinyMCE3; -using umbraco.interfaces; namespace Umbraco.Tests.Services { diff --git a/src/Umbraco.Tests/Services/DataTypeServiceTests.cs b/src/Umbraco.Tests/Services/DataTypeServiceTests.cs new file mode 100644 index 0000000000..31b0489949 --- /dev/null +++ b/src/Umbraco.Tests/Services/DataTypeServiceTests.cs @@ -0,0 +1,66 @@ +using System; +using System.Linq; +using NUnit.Framework; +using Umbraco.Core.Models; + +namespace Umbraco.Tests.Services +{ + /// + /// Tests covering the DataTypeService + /// + [TestFixture, RequiresSTA] + public class DataTypeServiceTests : BaseServiceTest + { + [SetUp] + public override void Initialize() + { + base.Initialize(); + } + + [TearDown] + public override void TearDown() + { + base.TearDown(); + } + + [Test] + public void DataTypeService_Can_Persist_New_DataTypeDefinition() + { + // Arrange + var dataTypeService = ServiceContext.DataTypeService; + var textfieldId = new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea"); + + // Act + var dataTypeDefinition = new DataTypeDefinition(-1, textfieldId) { Name = "Testing Textfield", DatabaseType = DataTypeDatabaseType.Ntext }; + dataTypeService.Save(dataTypeDefinition); + + // Assert + Assert.That(dataTypeDefinition, Is.Not.Null); + Assert.That(dataTypeDefinition.HasIdentity, Is.True); + } + + [Test] + public void DataTypeService_Can_Delete_Textfield_DataType_And_Clear_Usages() + { + // Arrange + var dataTypeService = ServiceContext.DataTypeService; + var textfieldId = new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea"); + var dataTypeDefinitions = dataTypeService.GetDataTypeDefinitionByControlId(textfieldId); + + // Act + var definition = dataTypeDefinitions.First(); + var definitionId = definition.Id; + dataTypeService.Delete(definition); + + var deletedDefinition = dataTypeService.GetDataTypeDefinitionById(definitionId); + + // Assert + Assert.That(deletedDefinition, Is.Null); + + //Further assertions against the ContentType that contains PropertyTypes based on the TextField + var contentType = ServiceContext.ContentTypeService.GetContentType(1045); + Assert.That(contentType.Alias, Is.EqualTo("umbTextpage")); + Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(1)); + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Tests/TestHelpers/Entities/MockedContentTypes.cs b/src/Umbraco.Tests/TestHelpers/Entities/MockedContentTypes.cs index 92e2ecd90d..131e02dad1 100644 --- a/src/Umbraco.Tests/TestHelpers/Entities/MockedContentTypes.cs +++ b/src/Umbraco.Tests/TestHelpers/Entities/MockedContentTypes.cs @@ -105,9 +105,9 @@ namespace Umbraco.Tests.TestHelpers.Entities contentType.Trashed = false; var contentCollection = new PropertyTypeCollection(); - contentCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "title", Name = "Title", Description = "", HelpText = "", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -88 }); - contentCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "bodyText", Name = "Body Text", Description = "", HelpText = "", Mandatory = false, SortOrder = 2, DataTypeDefinitionId = -87 }); - contentCollection.Add(new PropertyType(new Guid(), DataTypeDatabaseType.Ntext) { Alias = "author", Name = "Author", Description = "Name of the author", HelpText = "", Mandatory = false, SortOrder = 3, DataTypeDefinitionId = -88 }); + contentCollection.Add(new PropertyType(new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea"), DataTypeDatabaseType.Ntext) { Alias = "title", Name = "Title", Description = "", HelpText = "", Mandatory = false, SortOrder = 1, DataTypeDefinitionId = -88 }); + contentCollection.Add(new PropertyType(new Guid("5E9B75AE-FACE-41c8-B47E-5F4B0FD82F83"), DataTypeDatabaseType.Ntext) { Alias = "bodyText", Name = "Body Text", Description = "", HelpText = "", Mandatory = false, SortOrder = 2, DataTypeDefinitionId = -87 }); + contentCollection.Add(new PropertyType(new Guid("ec15c1e5-9d90-422a-aa52-4f7622c63bea"), DataTypeDatabaseType.Ntext) { Alias = "author", Name = "Author", Description = "Name of the author", HelpText = "", Mandatory = false, SortOrder = 3, DataTypeDefinitionId = -88 }); contentType.PropertyGroups.Add(new PropertyGroup(contentCollection) { Name = "Content", SortOrder = 1 }); diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index f0df81e8d7..83abf06eab 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -294,6 +294,7 @@ + True diff --git a/src/umbraco.cms/businesslogic/web/DocumentType.cs b/src/umbraco.cms/businesslogic/web/DocumentType.cs index 2a0de44b2b..5b30ed7845 100644 --- a/src/umbraco.cms/businesslogic/web/DocumentType.cs +++ b/src/umbraco.cms/businesslogic/web/DocumentType.cs @@ -7,7 +7,6 @@ using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Persistence.Caching; using umbraco.BusinessLogic; -using umbraco.cms.businesslogic.propertytype; using umbraco.DataLayer; using System.Collections.Generic; using Umbraco.Core; @@ -551,7 +550,12 @@ namespace umbraco.cms.businesslogic.web protected virtual void FireAfterSave(SaveEventArgs e) { if (AfterSave != null) - AfterSave(this, e); + { + var updated = this._contentType == null + ? new DocumentType(this.Id) + : new DocumentType(this._contentType); + AfterSave(updated, e); + } } ///