Ensures cultures set on content are correctly cased (#19290)

* Ensures cultures set on content are correctly cased and verifies with integration tests.

* Improved test comments.

* Move culture casing check into an extension method and use from content service.

* Deduplicated test code and added more test cases

* Only run invalid culture codes test on Windows

---------

Co-authored-by: Kenn Jacobsen <kja@umbraco.dk>
This commit is contained in:
Andy Butland
2025-05-14 09:47:21 +02:00
committed by GitHub
parent a84c114f54
commit 6fd6319b12
5 changed files with 194 additions and 9 deletions

View File

@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
@@ -395,4 +396,17 @@ public class StringExtensionsTests
var ids = input.GetIdsFromPathReversed();
Assert.AreEqual(expected, string.Join(",", ids));
}
[TestCase(null, null)]
[TestCase("", "")]
[TestCase("*", "*")]
[TestCase("en", "en")]
[TestCase("EN", "en")]
[TestCase("en-US", "en-US")]
[TestCase("en-gb", "en-GB")]
public void EnsureCultureCode_ReturnsExpectedResult(string? culture, string? expected) => Assert.AreEqual(expected, culture.EnsureCultureCode());
[Test]
[Platform(Include = "Win")]
public void EnsureCultureCode_ThrowsOnUnrecognisedCode() => Assert.Throws<CultureNotFoundException>(() => "xxx-xxx".EnsureCultureCode());
}