From 3dfd8b0cea4d7615586b0d177296722b462d82b6 Mon Sep 17 00:00:00 2001 From: Claus Date: Tue, 19 Nov 2019 09:31:20 +0100 Subject: [PATCH 1/7] adding unit test for validating language xml files. --- .../Configurations/LanguageXmlTests.cs | 29 +++++++++++++++++++ src/Umbraco.Tests/Umbraco.Tests.csproj | 1 + 2 files changed, 30 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..7746bc168730 --- /dev/null +++ b/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs @@ -0,0 +1,29 @@ +using System.IO; +using System.Xml; +using NUnit.Framework; +using Umbraco.Core.IO; +using Umbraco.Tests.TestHelpers; + +namespace Umbraco.Tests.Configurations +{ + + [TestFixture] + public class LanguageXmlTests + { + [Test] + public void Can_Load_Language_Xml_Files() + { + var languageDirectory = new DirectoryInfo(TestHelper.MapPathForTest(SystemDirectories.Umbraco + "/../../../../Umbraco.Web.UI/Umbraco/config/lang/")); + var readFilesCount = 0; + foreach (var languageFile in languageDirectory.EnumerateFiles("*.xml")) + { + var xmlDocument = new XmlDocument(); + // 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); + } + } +} diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 2f816233090e..849acba1aa81 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -120,6 +120,7 @@ + From 28a51e50c24a42e2ec1ecc75c18108cf4948009f Mon Sep 17 00:00:00 2001 From: Claus Date: Tue, 19 Nov 2019 10:51:27 +0100 Subject: [PATCH 2/7] locating the language files by traversing instead of hardcoded path. --- src/Umbraco.Tests/Configurations/LanguageXmlTests.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs b/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs index 7746bc168730..84672d0dc239 100644 --- a/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs +++ b/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs @@ -1,7 +1,6 @@ using System.IO; using System.Xml; using NUnit.Framework; -using Umbraco.Core.IO; using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.Configurations @@ -13,11 +12,16 @@ public class LanguageXmlTests [Test] public void Can_Load_Language_Xml_Files() { - var languageDirectory = new DirectoryInfo(TestHelper.MapPathForTest(SystemDirectories.Umbraco + "/../../../../Umbraco.Web.UI/Umbraco/config/lang/")); + var dir = new DirectoryInfo(TestHelper.MapPathForTest("~/")); + while (dir.Name != "src") + { + dir = dir.Parent; + } + var languageDirectory = new DirectoryInfo(dir.FullName + "/Umbraco.Web.UI/Umbraco/config/lang/"); var readFilesCount = 0; + var xmlDocument = new XmlDocument(); foreach (var languageFile in languageDirectory.EnumerateFiles("*.xml")) { - var xmlDocument = new XmlDocument(); // load will throw an exception if the xml isn't valid. xmlDocument.Load(languageFile.FullName); readFilesCount++; From 8f9e3a03efb2f88f879df8311b9b89f581e405e1 Mon Sep 17 00:00:00 2001 From: Claus Date: Tue, 19 Nov 2019 11:46:33 +0100 Subject: [PATCH 3/7] debugging null refs. --- src/Umbraco.Tests/Configurations/LanguageXmlTests.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs b/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs index 84672d0dc239..6f9ca63b7ec9 100644 --- a/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs +++ b/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using System.Xml; using NUnit.Framework; using Umbraco.Tests.TestHelpers; @@ -13,9 +14,13 @@ public class LanguageXmlTests public void Can_Load_Language_Xml_Files() { var dir = new DirectoryInfo(TestHelper.MapPathForTest("~/")); + if (dir == null) + throw new NullReferenceException("dir is null. | " + dir.FullName); while (dir.Name != "src") { dir = dir.Parent; + if (dir == null) + throw new NullReferenceException("dir is null - 2 | " + dir.FullName); } var languageDirectory = new DirectoryInfo(dir.FullName + "/Umbraco.Web.UI/Umbraco/config/lang/"); var readFilesCount = 0; From 05831f8045cb69096d40c4eee02a3c3b0969250d Mon Sep 17 00:00:00 2001 From: Claus Date: Tue, 19 Nov 2019 12:26:57 +0100 Subject: [PATCH 4/7] debugging --- src/Umbraco.Tests/Configurations/LanguageXmlTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs b/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs index 6f9ca63b7ec9..860c0fda4c22 100644 --- a/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs +++ b/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs @@ -18,9 +18,9 @@ public void Can_Load_Language_Xml_Files() throw new NullReferenceException("dir is null. | " + dir.FullName); while (dir.Name != "src") { - dir = dir.Parent; - if (dir == null) + if (dir.Parent == null) throw new NullReferenceException("dir is null - 2 | " + dir.FullName); + dir = dir.Parent; } var languageDirectory = new DirectoryInfo(dir.FullName + "/Umbraco.Web.UI/Umbraco/config/lang/"); var readFilesCount = 0; From 2a4efa4a180809cc4fd51b619cdb1aa9168ba3ad Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 27 Oct 2021 13:44:58 +0200 Subject: [PATCH 5/7] Updated method of detecting language folder for XML tests, that should work correctly on the build server. --- .../Configurations/LanguageXmlTests.cs | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs b/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs index 860c0fda4c22..587ddfd516c4 100644 --- a/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs +++ b/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs @@ -1,38 +1,41 @@ 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 dir = new DirectoryInfo(TestHelper.MapPathForTest("~/")); - if (dir == null) - throw new NullReferenceException("dir is null. | " + dir.FullName); - while (dir.Name != "src") - { - if (dir.Parent == null) - throw new NullReferenceException("dir is null - 2 | " + dir.FullName); - dir = dir.Parent; - } - var languageDirectory = new DirectoryInfo(dir.FullName + "/Umbraco.Web.UI/Umbraco/config/lang/"); + 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. + // Load will throw an exception if the XML isn't valid. xmlDocument.Load(languageFile.FullName); readFilesCount++; } - // ensure that at least one file was read. + + // Ensure that at least one file was read. Assert.AreNotEqual(0, readFilesCount); } + + private static DirectoryInfo GetLanguageDirectory() + { + var testDirectoryPathParts = Path.GetDirectoryName(Path.GetDirectoryName(TestContext.CurrentContext.TestDirectory)).Split(Path.DirectorySeparatorChar); + var solutionDirectoryPathParts = testDirectoryPathParts + .Take(Array.IndexOf(testDirectoryPathParts, "src") + 1); + var languageFolderPathParts = new List(solutionDirectoryPathParts); + languageFolderPathParts.AddRange(new[] { "Umbraco.Web.UI", "Umbraco", "config", "lang" }); + return new DirectoryInfo(string.Join(Path.DirectorySeparatorChar.ToString(), languageFolderPathParts)); + } } } From 84bdfe4623053e21842511ca3f39f3182dbe19f2 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 27 Oct 2021 14:53:04 +0200 Subject: [PATCH 6/7] Path amends to support running test on build server. --- src/Umbraco.Tests/Configurations/LanguageXmlTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs b/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs index 587ddfd516c4..7fe29a4a4caa 100644 --- a/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs +++ b/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs @@ -30,7 +30,8 @@ public void Can_Load_Language_Xml_Files() private static DirectoryInfo GetLanguageDirectory() { - var testDirectoryPathParts = Path.GetDirectoryName(Path.GetDirectoryName(TestContext.CurrentContext.TestDirectory)).Split(Path.DirectorySeparatorChar); + 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); From a3d092a0b1bb9369875b4b1434d19acc40096acd Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 27 Oct 2021 15:21:05 +0200 Subject: [PATCH 7/7] Path amends to support running test on build server (2). --- src/Umbraco.Tests/Configurations/LanguageXmlTests.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs b/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs index 7fe29a4a4caa..19f8c96f2593 100644 --- a/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs +++ b/src/Umbraco.Tests/Configurations/LanguageXmlTests.cs @@ -35,7 +35,16 @@ private static DirectoryInfo GetLanguageDirectory() var solutionDirectoryPathParts = testDirectoryPathParts .Take(Array.IndexOf(testDirectoryPathParts, "src") + 1); var languageFolderPathParts = new List(solutionDirectoryPathParts); - languageFolderPathParts.AddRange(new[] { "Umbraco.Web.UI", "Umbraco", "config", "lang" }); + 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)); } }