Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroduce language files tests #12367

Merged
merged 3 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
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 @@ public async Task BackOfficeDefaultExists(

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