Adding Export of DictionaryItems including test
Conflicts: src/Umbraco.Core/Services/PackagingService.cs src/Umbraco.Tests/Services/PackagingServiceTests.cs
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Events;
|
||||
@@ -946,6 +947,40 @@ namespace Umbraco.Core.Services
|
||||
#endregion
|
||||
|
||||
#region Dictionary Items
|
||||
|
||||
public XElement Export(IEnumerable<IDictionaryItem> dictionaryItem, bool includeChildren = true)
|
||||
{
|
||||
var xml = new XElement("DictionaryItems");
|
||||
foreach (var item in dictionaryItem)
|
||||
{
|
||||
xml.Add(Export(item, includeChildren));
|
||||
}
|
||||
return xml;
|
||||
}
|
||||
|
||||
private XElement Export(IDictionaryItem dictionaryItem, bool includeChildren)
|
||||
{
|
||||
var xml = new XElement("DictionaryItem", new XAttribute("Key", dictionaryItem.ItemKey));
|
||||
foreach (var translation in dictionaryItem.Translations)
|
||||
{
|
||||
xml.Add(new XElement("Value",
|
||||
new XAttribute("LanguageId", translation.Language.Id),
|
||||
new XAttribute("LanguageCultureAlias", translation.Language.IsoCode),
|
||||
new XCData(translation.Value)));
|
||||
}
|
||||
|
||||
if (includeChildren)
|
||||
{
|
||||
var children = _localizationService.GetDictionaryItemChildren(dictionaryItem.Key);
|
||||
foreach (var child in children)
|
||||
{
|
||||
xml.Add(Export(child, true));
|
||||
}
|
||||
}
|
||||
|
||||
return xml;
|
||||
}
|
||||
|
||||
public IEnumerable<IDictionaryItem> ImportDictionaryItems(XElement dictionaryItemElementList)
|
||||
{
|
||||
var languages = _localizationService.GetAllLanguages().ToList();
|
||||
@@ -1014,6 +1049,7 @@ namespace Umbraco.Core.Services
|
||||
var translation = new DictionaryTranslation(language, valueElement.Value);
|
||||
translations.Add(translation);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Files
|
||||
|
||||
@@ -1,41 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Services.Importing;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
{
|
||||
//[TestFixture]
|
||||
//public class PackagingServiceTests : BaseServiceTest
|
||||
//{
|
||||
// [Test]
|
||||
// public void Export_Content()
|
||||
// {
|
||||
// var yesNo = DataTypesResolver.Current.GetById(new Guid(Constants.PropertyEditors.TrueFalse));
|
||||
// var txtField = DataTypesResolver.Current.GetById(new Guid(Constants.PropertyEditors.Textbox));
|
||||
[TestFixture]
|
||||
public class PackagingServiceTests : BaseServiceTest
|
||||
{
|
||||
[SetUp]
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
// var contentWithDataType = MockedContentTypes.CreateSimpleContentType(
|
||||
// "test",
|
||||
// "Test",
|
||||
// new PropertyTypeCollection(
|
||||
// new PropertyType[]
|
||||
// {
|
||||
// new PropertyType(new DataTypeDefinition(-1, txtField.Id)
|
||||
// {
|
||||
// Name = "Testing Textfield", DatabaseType = DataTypeDatabaseType.Ntext
|
||||
// }),
|
||||
// new PropertyType(new DataTypeDefinition(-1, yesNo.Id)
|
||||
// {
|
||||
// Name = "Testing intfield", DatabaseType = DataTypeDatabaseType.Integer
|
||||
// })
|
||||
// }));
|
||||
[TearDown]
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
}
|
||||
|
||||
// var content = MockedContent.CreateSimpleContent(contentWithDataType);
|
||||
// content.Name = "Test";
|
||||
[Test]
|
||||
public void PackagingService_Can_Export_DictionaryItems()
|
||||
{
|
||||
// Arrange
|
||||
CreateTestData();
|
||||
var dictionaryItem = ServiceContext.LocalizationService.GetDictionaryItemByKey("Parent");
|
||||
|
||||
// var exported = ServiceContext.PackagingService.Export(content);
|
||||
var newPackageXml = XElement.Parse(ImportResources.Dictionary_Package);
|
||||
var dictionaryItemsElement = newPackageXml.Elements("DictionaryItems").First();
|
||||
|
||||
// }
|
||||
//}
|
||||
// Act
|
||||
var xml = ServiceContext.PackagingService.Export(new []{dictionaryItem});
|
||||
|
||||
// Assert
|
||||
Assert.That(xml.ToString(), Is.EqualTo(dictionaryItemsElement.ToString()));
|
||||
}
|
||||
|
||||
public void CreateTestData()
|
||||
{
|
||||
var languageNbNo = new Language("nb-NO") { CultureName = "nb-NO" };
|
||||
ServiceContext.LocalizationService.Save(languageNbNo);
|
||||
|
||||
var languageEnGb = new Language("en-GB") { CultureName = "en-GB" };
|
||||
ServiceContext.LocalizationService.Save(languageEnGb);
|
||||
|
||||
var parentItem = new DictionaryItem("Parent");
|
||||
var parentTranslations = new List<IDictionaryTranslation>
|
||||
{
|
||||
new DictionaryTranslation(languageNbNo, "ForelderVerdi"),
|
||||
new DictionaryTranslation(languageEnGb, "ParentValue")
|
||||
};
|
||||
parentItem.Translations = parentTranslations;
|
||||
ServiceContext.LocalizationService.Save(parentItem);
|
||||
|
||||
var childItem = new DictionaryItem(parentItem.Key, "Child");
|
||||
var childTranslations = new List<IDictionaryTranslation>
|
||||
{
|
||||
new DictionaryTranslation(languageNbNo, "BarnVerdi"),
|
||||
new DictionaryTranslation(languageEnGb, "ChildValue")
|
||||
};
|
||||
childItem.Translations = childTranslations;
|
||||
ServiceContext.LocalizationService.Save(childItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user