Reintroduce language files tests (#12367)
* Reintroducing language files tests
* Fix casing
* Update tests/Umbraco.Tests.UnitTests/Umbraco.Core/EmbeddedResources/LanguageXmlTests.cs
Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
(cherry picked from commit 2ed71a64ec)
This commit is contained in:
committed by
Bjarke Berg
parent
af4e3ca1a6
commit
fd0637c96d
@@ -0,0 +1,36 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
|
using Microsoft.Extensions.FileProviders;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using Umbraco.Cms.Core.Composing;
|
||||||
|
|
||||||
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.EmbeddedResources
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class LanguageXmlTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void Can_Load_Language_Xml_Files()
|
||||||
|
{
|
||||||
|
var readFilesCount = 0;
|
||||||
|
var xmlDocument = new XmlDocument();
|
||||||
|
|
||||||
|
var languageProvider = new EmbeddedFileProvider(typeof(IAssemblyProvider).Assembly, "Umbraco.Cms.Core.EmbeddedResources.Lang");
|
||||||
|
var files = languageProvider.GetDirectoryContents(string.Empty)
|
||||||
|
.Where(x => !x.IsDirectory && x.Name.EndsWith(".xml"));
|
||||||
|
|
||||||
|
foreach (var languageFile in files)
|
||||||
|
{
|
||||||
|
using var stream = new StreamReader(languageFile.CreateReadStream());
|
||||||
|
|
||||||
|
// Load will throw an exception if the XML isn't valid.
|
||||||
|
xmlDocument.Load(stream);
|
||||||
|
readFilesCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure that at least one file was read.
|
||||||
|
Assert.AreNotEqual(0, readFilesCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,10 +8,12 @@ using System.Threading.Tasks;
|
|||||||
using AutoFixture.NUnit3;
|
using AutoFixture.NUnit3;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||||
|
using Microsoft.Extensions.FileProviders;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Umbraco.Cms.Core;
|
using Umbraco.Cms.Core;
|
||||||
|
using Umbraco.Cms.Core.Composing;
|
||||||
using Umbraco.Cms.Core.Configuration.Models;
|
using Umbraco.Cms.Core.Configuration.Models;
|
||||||
using Umbraco.Cms.Core.Hosting;
|
using Umbraco.Cms.Core.Hosting;
|
||||||
using Umbraco.Cms.Core.Services;
|
using Umbraco.Cms.Core.Services;
|
||||||
@@ -95,5 +97,21 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common
|
|||||||
Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't");
|
Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void LanguageFilesAreLowerCase()
|
||||||
|
{
|
||||||
|
var languageProvider = new EmbeddedFileProvider(typeof(IAssemblyProvider).Assembly, "Umbraco.Cms.Core.EmbeddedResources.Lang");
|
||||||
|
var files = languageProvider.GetDirectoryContents(string.Empty)
|
||||||
|
.Where(x => !x.IsDirectory && x.Name.EndsWith(".xml"))
|
||||||
|
.Select(x => x.Name);
|
||||||
|
|
||||||
|
foreach (var fileName in files)
|
||||||
|
{
|
||||||
|
Assert.AreEqual(
|
||||||
|
fileName.ToLower(),
|
||||||
|
fileName,
|
||||||
|
$"Language files must be all lowercase but {fileName} is not lowercase.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user