From 98430fd5734e718991b04d2d9c02f00a9a9fb156 Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 30 Dec 2016 11:42:02 +1100 Subject: [PATCH] U4-9326 Removing a master template from a Template does not update the Template's path correctly --- .../Repositories/TemplateRepository.cs | 7 ++++- .../Repositories/TemplateRepositoryTest.cs | 29 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs b/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs index fa780e1bd0..de52ce643b 100644 --- a/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/TemplateRepository.cs @@ -241,7 +241,12 @@ namespace Umbraco.Core.Persistence.Repositories { entity.Path = string.Concat(parent.Path, ",", entity.Id); } - + else + { + //this means that the master template has been removed, so we need to reset the template's + //path to be at the root + entity.Path = string.Concat("-1,", entity.Id); + } } //Get TemplateDto from db to get the Primary key of the entity diff --git a/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs index 36ae69c733..1a4a7a2338 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/TemplateRepositoryTest.cs @@ -707,6 +707,35 @@ namespace Umbraco.Tests.Persistence.Repositories } } + [Test] + public void Path_Is_Set_Correctly_On_Update_With_Master_Template_Removal() + { + // Arrange + var provider = new PetaPocoUnitOfWorkProvider(Logger); + var unitOfWork = provider.GetUnitOfWork(); + using (var repository = CreateRepository(unitOfWork)) + { + var parent = new Template("parent", "parent"); + var child1 = new Template("child1", "child1"); + + child1.MasterTemplateAlias = parent.Alias; + child1.MasterTemplateId = new Lazy(() => parent.Id); + + repository.AddOrUpdate(parent); + repository.AddOrUpdate(child1); + unitOfWork.Commit(); + + //Act + child1.SetMasterTemplate(null); + repository.AddOrUpdate(child1); + unitOfWork.Commit(); + + //Assert + Assert.AreEqual(string.Format("-1,{0}", child1.Id), child1.Path); + + } + } + [TearDown] public override void TearDown()