using System.Text.RegularExpressions; using System.Xml.Linq; using Febe.Tests.Desktop.Support; using Febe.Tests.Web.Support; using Febe.Web.Hosting; namespace Febe.Tests.Web; /// /// Font and icons are Febe's own (decision of 18 November 2026): the system's font, icons drawn in house, no font /// file, no third-party icon set and no reference to the ones used before. /// [TestClass] public sealed partial class InHouseAssetsTests { private const string IconNamespace = "http://www.w3.org/2000/svg"; private static readonly HashSet Shapes = ["path", "line", "polyline", "polygon", "circle", "ellipse", "rect"]; private static readonly HashSet Geometry = ["d", "points", "x", "y", "width", "height", "rx", "ry", "cx", "cy", "r", "x1", "y1", "x2", "y2", "stroke-dasharray", "stroke-dashoffset"]; private static readonly HashSet TextExtensions = [".cs", ".js", ".mjs", ".css", ".html", ".htm", ".json", ".hjson", ".md", ".txt", ".svg", ".xml", ".csproj", ".props", ".targets", ".slnx", ".sh", ".ps1", ".yml", ".yaml", ".nsi", ".config", ".manifest"]; private static readonly HashSet FontExtensions = [".woff", ".woff2", ".ttf", ".otf", ".eot"]; [TestMethod] public void TheInterfaceShipsNoFontFileNoLicenceOfThirdPartyAssetsAndUsesTheSystemFont() { var files = new EmbeddedWwwroot(); foreach (var path in files.Files) { Assert.IsFalse(FontExtensions.Contains(Path.GetExtension(path).ToLowerInvariant()), $"file di caratteri nel programma: {path}"); Assert.IsFalse(Path.GetFileName(path).StartsWith("LICENZA", StringComparison.OrdinalIgnoreCase), $"licenza di terzi nel programma: {path}"); Assert.IsFalse(path.StartsWith("caratteri/", StringComparison.Ordinal), path); } var css = files.ReadText("css/febe.css")!; Assert.DoesNotContain("@font-face", css); Assert.DoesNotContain("url(../caratteri", css); StringAssert.Contains(css, "font-family:var(--carattere)"); var stack = CharacterToken().Match(css); Assert.IsTrue(stack.Success, "il token --carattere c'è"); var families = stack.Groups[1].Value.Split(',', StringSplitOptions.TrimEntries); Assert.AreEqual("system-ui", families[0], "prima il carattere del sistema"); Assert.AreEqual("sans-serif", families[^1], "e in fondo il generico"); CollectionAssert.Contains(families, "\"Segoe UI\""); CollectionAssert.Contains(families, "Roboto"); CollectionAssert.Contains(families, "Cantarell"); CollectionAssert.Contains(families, "\"Noto Sans\""); foreach (var page in new[] { "index.html", "accesso.html" }) { var html = files.ReadText(page)!; Assert.DoesNotContain("as=\"font\"", html, page); Assert.DoesNotContain("/caratteri/", html, page); } } [TestMethod] public async Task ThePagesForbidDownloadedFonts() { await using var server = await WebTestServer.StartAsync(); using var response = await server.Client.GetAsync("/"); var policy = string.Join(' ', response.Headers.GetValues("Content-Security-Policy")); StringAssert.Contains(policy, "font-src 'none'"); } [TestMethod] public void EveryIconIsAPlainStrokeDrawingOnTheGridOfTwentyFour() { var files = new EmbeddedWwwroot(); var icons = files.Files.Where(f => f.StartsWith("icone/", StringComparison.Ordinal)).Order(StringComparer.Ordinal).ToList(); Assert.IsGreaterThanOrEqualTo(60, icons.Count, "le icone ci sono"); foreach (var path in icons) { Assert.AreEqual(".svg", Path.GetExtension(path), $"in icone/ solo disegni: {path}"); var document = XDocument.Parse(files.ReadText(path)!, LoadOptions.None); Assert.IsFalse(document.DescendantNodes().OfType().Any(), $"nessun commento (né avvisi di licenza): {path}"); var root = document.Root!; Assert.AreEqual(XName.Get("svg", IconNamespace), root.Name, path); Assert.AreEqual("0 0 24 24", (string?)root.Attribute("viewBox"), path); Assert.IsNull(root.Attribute("class"), path); Assert.AreEqual("none", (string?)root.Attribute("fill"), path); Assert.AreEqual("currentColor", (string?)root.Attribute("stroke"), path); Assert.IsTrue(root.Elements().Any(), $"vuota: {path}"); foreach (var shape in root.Descendants()) { Assert.AreEqual(IconNamespace, shape.Name.NamespaceName, path); Assert.IsTrue(Shapes.Contains(shape.Name.LocalName), $"{path}: elemento «{shape.Name.LocalName}» non ammesso"); Assert.IsFalse(shape.HasElements, $"{path}: forme annidate"); foreach (var attribute in shape.Attributes()) { Assert.IsTrue(Geometry.Contains(attribute.Name.LocalName), $"{path}: attributo «{attribute.Name.LocalName}» (spessore, colore e riempimento vengono dal foglio di stile)"); if (attribute.Name.LocalName is not ("d" or "points" or "stroke-dasharray" or "stroke-dashoffset")) { var value = double.Parse(attribute.Value, System.Globalization.CultureInfo.InvariantCulture); Assert.IsTrue(value is >= 0 and <= 24, $"{path}: {attribute.Name.LocalName}={attribute.Value} fuori dalla griglia"); } } } } } [TestMethod] public void EveryIconThePagesAskForIsDrawn() { var files = new EmbeddedWwwroot(); var drawn = files.Files.Where(f => f.StartsWith("icone/", StringComparison.Ordinal)) .Select(f => f["icone/".Length..^".svg".Length]).ToHashSet(StringComparer.Ordinal); var asked = 0; foreach (var path in files.Files.Where(f => f.EndsWith(".js", StringComparison.Ordinal))) { foreach (Match match in IconCall().Matches(files.ReadText(path)!)) { asked++; Assert.Contains(match.Groups[1].Value, drawn, $"{path} chiede l'icona «{match.Groups[1].Value}»"); } } Assert.IsGreaterThan(20, asked, "le pagine usano le icone"); } [TestMethod] public void NoFileOfTheProgramStillNamesTheFontOrTheIconSetUsedBefore() { var root = Repository.Root(); if (root is null) { Assert.Inconclusive("Il repository non è accanto alle prove."); } var looked = 0; foreach (var folder in new[] { "src", "tools", "installer", "docker", ".gitea", Path.Combine("docs", "guida") }) { var start = Path.Combine(root, folder); if (!Directory.Exists(start)) { continue; } foreach (var file in Directory.EnumerateFiles(start, "*", SearchOption.AllDirectories)) { var relative = Path.GetRelativePath(root, file); var parts = relative.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); if (parts.Contains("bin") || parts.Contains("obj") || parts.Contains("node_modules")) { continue; } Assert.IsFalse(FontExtensions.Contains(Path.GetExtension(file).ToLowerInvariant()), $"file di caratteri: {relative}"); if (!TextExtensions.Contains(Path.GetExtension(file).ToLowerInvariant())) { continue; } looked++; var match = FormerAssets().Match(File.ReadAllText(file)); Assert.IsFalse(match.Success, $"{relative} nomina ancora «{match.Value}»"); } } Assert.IsGreaterThan(100, looked, "i file del programma sono stati letti"); } [GeneratedRegex(@"--carattere:([^;]+);")] private static partial Regex CharacterToken(); [GeneratedRegex(@"\bicon\('([a-z0-9-]+)'")] private static partial Regex IconCall(); // The font and the icon set Febe carried until 18 November 2026. [GeneratedRegex(@"\b(archivo|lucide)\b", RegexOptions.IgnoreCase)] private static partial Regex FormerAssets(); }