From 5b1ed8bef511e04b8c5613792b62cd79ee1f7e62 Mon Sep 17 00:00:00 2001 From: Stephan Date: Wed, 16 Sep 2015 11:08:18 +0200 Subject: [PATCH] U4-7108 - fix ContentTypeService.GetMediaType(guid) --- .../Repositories/ContentTypeBaseRepository.cs | 14 +++++++------- .../Repositories/ContentTypeRepositoryTest.cs | 16 ++++++++++++++++ .../Services/ContentTypeServiceTests.cs | 13 +++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs index 2b4c446e6c..631bb7e1fb 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs @@ -1070,6 +1070,11 @@ AND umbracoNode.id <> @id", out IDictionary allPropertyTypeCollection, out IDictionary allPropertyGroupCollection) { + allPropertyGroupCollection = new Dictionary(); + allPropertyTypeCollection = new Dictionary(); + + // query below is not safe + pointless if array is empty + if (contentTypeIds.Length == 0) return; // first part Gets all property groups including property type data even when no property type exists on the group // second part Gets all property types including ones that are not on a group @@ -1105,10 +1110,8 @@ AND umbracoNode.id <> @id", INNER JOIN cmsDataType as DT ON PT.dataTypeId = DT.nodeId LEFT JOIN cmsPropertyTypeGroup as PG - ON PG.id = PT.propertyTypeGroupId"); - - if (contentTypeIds.Any()) - sqlBuilder.AppendLine(" WHERE (PT.contentTypeId in (@contentTypeIds))"); + ON PG.id = PT.propertyTypeGroupId + WHERE (PT.contentTypeId in (@contentTypeIds))"); sqlBuilder.AppendLine(" ORDER BY (pgId)"); @@ -1119,9 +1122,6 @@ AND umbracoNode.id <> @id", var result = db.Fetch(sqlBuilder.ToString(), new { contentTypeIds = contentTypeIds }); - allPropertyGroupCollection = new Dictionary(); - allPropertyTypeCollection = new Dictionary(); - foreach (var contentTypeId in contentTypeIds) { //from this we need to make : diff --git a/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs index d0e8d3af5e..1669b1af5e 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs @@ -248,6 +248,22 @@ namespace Umbraco.Tests.Persistence.Repositories } } + [Test] + public void Can_Perform_Get_By_Missing_Guid_On_ContentTypeRepository() + { + // Arrange + var provider = new PetaPocoUnitOfWorkProvider(Logger); + var unitOfWork = provider.GetUnitOfWork(); + using (var repository = CreateRepository(unitOfWork)) + { + // Act + var result = repository.Get(Guid.NewGuid()); + + // Assert + Assert.That(result, Is.Null); + } + } + [Test] public void Can_Perform_GetAll_On_ContentTypeRepository() { diff --git a/src/Umbraco.Tests/Services/ContentTypeServiceTests.cs b/src/Umbraco.Tests/Services/ContentTypeServiceTests.cs index 7408429fa4..18ec84bf30 100644 --- a/src/Umbraco.Tests/Services/ContentTypeServiceTests.cs +++ b/src/Umbraco.Tests/Services/ContentTypeServiceTests.cs @@ -144,6 +144,19 @@ namespace Umbraco.Tests.Services Assert.AreEqual(11, descendants.Count()); } + [Test] + public void Get_With_Missing_Guid() + { + // Arrange + var contentTypeService = ServiceContext.ContentTypeService; + + //Act + var result = contentTypeService.GetMediaType(Guid.NewGuid()); + + //Assert + Assert.IsNull(result); + } + [Test] public void Can_Bulk_Save_New_Hierarchy_Content_Types() {