Skip to content

Commit

Permalink
Reintroduce language files tests (#12367)
Browse files Browse the repository at this point in the history
* Reintroducing language files tests

* Fix casing

* Update tests/Umbraco.Tests.UnitTests/Umbraco.Core/EmbeddedResources/LanguageXmlTests.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
  • Loading branch information
elit0451 and nikolajlauridsen committed May 16, 2022
1 parent af4e3ca commit 2ed71a6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
@@ -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);
}
}
}
Expand Up @@ -8,10 +8,12 @@
using AutoFixture.NUnit3;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Options;
using Moq;
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.Services;
Expand Down Expand Up @@ -94,6 +96,22 @@ private IEnumerable<string> GetUiFiles(IEnumerable<string> pathFromNetCore)

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.");
}
}
}
}

0 comments on commit 2ed71a6

Please sign in to comment.