From 1553f02b18585c3946f9b146156042f5e1ab80a4 Mon Sep 17 00:00:00 2001 From: Claus Date: Mon, 1 Nov 2021 15:50:54 +0100 Subject: [PATCH] adding unit test for validating language xml files. (#7174) * adding unit test for validating language xml files. * locating the language files by traversing instead of hardcoded path. * debugging null refs. * debugging * Updated method of detecting language folder for XML tests, that should work correctly on the build server. * Path amends to support running test on build server. * Path amends to support running test on build server (2). Co-authored-by: Andy Butland --- .../Configurations/LanguageXmlTests.cs | 51 +++++++++++++++++++ src/Umbraco.Tests/Umbraco.Tests.csproj | 1 + 2 files changed, 52 insertions(+) create mode 100644 src/Umbraco.Tests/Configurations/LanguageXmlTests.cs diff --git a/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs b/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs new file mode 100644 index 000000000000..19f8c96f2593 --- /dev/null +++ b/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Xml; +using NUnit.Framework; +using Umbraco.Tests.TestHelpers; + +namespace Umbraco.Tests.Configurations +{ + [TestFixture] + public class LanguageXmlTests + { + [Test] + public void Can_Load_Language_Xml_Files() + { + var languageDirectory = GetLanguageDirectory(); + var readFilesCount = 0; + var xmlDocument = new XmlDocument(); + foreach (var languageFile in languageDirectory.EnumerateFiles("*.xml")) + { + // Load will throw an exception if the XML isn't valid. + xmlDocument.Load(languageFile.FullName); + readFilesCount++; + } + + // Ensure that at least one file was read. + Assert.AreNotEqual(0, readFilesCount); + } + + private static DirectoryInfo GetLanguageDirectory() + { + var testDirectoryPathParts = Path.GetDirectoryName(TestContext.CurrentContext.TestDirectory) + .Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); + var solutionDirectoryPathParts = testDirectoryPathParts + .Take(Array.IndexOf(testDirectoryPathParts, "src") + 1); + var languageFolderPathParts = new List(solutionDirectoryPathParts); + var additionalPathParts = new[] { "Umbraco.Web.UI", "Umbraco", "config", "lang" }; + languageFolderPathParts.AddRange(additionalPathParts); + + // Hack for build-server - when this path is generated in that envrionment it's missing the "src" folder. + // Not sure why, but if it's missing we'll add it in the right place. + if (!languageFolderPathParts.Contains("src")) + { + languageFolderPathParts.Insert(languageFolderPathParts.Count - additionalPathParts.Length, "src"); + } + + return new DirectoryInfo(string.Join(Path.DirectorySeparatorChar.ToString(), languageFolderPathParts)); + } + } +} diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index c00c67ca1ce7..c77ba6d188c4 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -120,6 +120,7 @@ +