U4-9326 Removing a master template from a Template does not update the Template's path correctly

This commit is contained in:
Shannon
2016-12-30 11:42:02 +11:00
parent 2d94ac7a19
commit 98430fd573
2 changed files with 35 additions and 1 deletions

View File

@@ -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

View File

@@ -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<int>(() => 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()