Cloning of a multi-language item
MarcinOkon opened this issue · 3 comments
MarcinOkon commented
Hi
When trying to clone an item with multiple languages the non-english languages have no SourceUri set.
[Test]
public void TestCloning()
{
//Arrange
using (var db = new Db
{
new DbItem("SourceItem")
{
new DbField("Title")
{
{ "en", "Hello!" },
{ "de", "Servus!" }
}
}
})
{
Item source = db.GetItem("/sitecore/content/SourceItem");
//Act
source.CloneTo(source.Parent, "CloneItem", false);
//Assert
Item sourceEn = db.GetItem("/sitecore/content/SourceItem", "en");
Item sourceDe = db.GetItem("/sitecore/content/SourceItem", "de");
Item cloneEn = db.GetItem("/sitecore/content/CloneItem", "en");
Item cloneDe = db.GetItem("/sitecore/content/CloneItem", "de");
Assert.AreEqual(1, cloneEn.Versions.Count);
Assert.AreEqual(1, cloneDe.Versions.Count);
Assert.AreEqual(sourceEn.Uri, cloneEn.SourceUri);
Assert.AreEqual(sourceDe.Uri, cloneDe.SourceUri); //fails here with null
}
}
I have compared the CloneTo execution with a real sitecore instance and I think there is a difference in how both are handling field changes on items without a version.
Here is a test case that demonstrates it:
[Test]
public void TestEdit()
{
using (var db = new Db
{
new DbItem("home")
{
new DbField("Title")
{
{"en", "Hello!"}
}
}
})
{
Item homeEn = db.GetItem("/sitecore/content/home", "en");
Item homeDe = db.GetItem("/sitecore/content/home", "de");
Assert.AreEqual(1, homeEn.Versions.Count);
Assert.AreEqual(0, homeDe.Versions.Count);
using (new EditContext(homeEn))
{
homeEn.Fields["Title"].SetValue("Bye!", true);
}
using (new EditContext(homeDe))
{
homeDe.Fields["Title"].SetValue("Servus!", true);
}
Assert.AreEqual(1, homeDe.Versions.Count);
Assert.AreEqual(1, homeEn.Versions.Count);
Assert.AreEqual("Bye!", homeEn["Title"]);
Assert.AreEqual("Servus!", homeDe["Title"]); //fails here with string.empty
}
}
sshushliapin commented
@MarcinOkon, good catch, thanks! Fixed.
sshushliapin commented
Available as v0.36.2.
MarcinOkon commented
thank you for the fast fix!