From 36868644dc38bf688c8d1788205cfc60136b20eb Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Tue, 23 Jun 2020 17:51:25 +0200 Subject: [PATCH] Check and fix broken anchor links. In addition to #1682. --- BTCPayServer.Tests/UnitTest1.cs | 23 ++++++++++++++++--- .../Views/Apps/UpdateCrowdfund.cshtml | 2 +- .../Views/Apps/UpdatePointOfSale.cshtml | 2 +- .../PaymentRequest/EditPaymentRequest.cshtml | 2 +- BTCPayServer/Views/Server/Theme.cshtml | 4 ++-- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index f8dc9f3d3..87b39fe3e 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -85,7 +85,7 @@ namespace BTCPayServer.Tests var views = Path.Combine(TestUtils.TryGetSolutionDirectoryInfo().FullName, "BTCPayServer", "Views"); var viewFiles = Directory.EnumerateFiles(views, "*.cshtml", SearchOption.AllDirectories).ToArray(); Assert.NotEmpty(viewFiles); - Regex regex = new Regex("href=\"(http.*?)[\"#]"); + Regex regex = new Regex("href=\"(http.*?)\""); var httpClient = new HttpClient(); List checkLinks = new List(); foreach (var file in viewFiles) @@ -155,16 +155,33 @@ namespace BTCPayServer.Tests private static async Task AssertLinkNotDead(HttpClient httpClient, string url, string file) { + var uri = new Uri(url); + try { - using var request = new HttpRequestMessage(HttpMethod.Get, new Uri(url)); + using var request = new HttpRequestMessage(HttpMethod.Get, uri); request.Headers.TryAddWithoutValidation("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); request.Headers.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0"); - Assert.Equal(HttpStatusCode.OK, (await httpClient.SendAsync(request)).StatusCode); + var response = await httpClient.SendAsync(request); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + if (uri.Fragment.Length != 0) + { + var fragment = uri.Fragment.Substring(1); + var contents = await response.Content.ReadAsStringAsync(); + Assert.Matches($"id=\"{fragment}\"", contents); + } + Logs.Tester.LogInformation($"OK: {url} ({file})"); } + catch (Exception ex) when (ex is MatchesException) + { + var details = ex.Message; + Logs.Tester.LogInformation($"FAILED: {url} ({file}) – anchor not found: {uri.Fragment}"); + + throw; + } catch (Exception ex) { var details = ex is EqualException ? (ex as EqualException).Actual : ex.Message; diff --git a/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml b/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml index 6fc103d84..13925fba3 100644 --- a/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml +++ b/BTCPayServer/Views/Apps/UpdateCrowdfund.cshtml @@ -100,7 +100,7 @@
- +
diff --git a/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml b/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml index 2b3dfa8da..11cd876c9 100644 --- a/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml +++ b/BTCPayServer/Views/Apps/UpdatePointOfSale.cshtml @@ -79,7 +79,7 @@
- +
diff --git a/BTCPayServer/Views/PaymentRequest/EditPaymentRequest.cshtml b/BTCPayServer/Views/PaymentRequest/EditPaymentRequest.cshtml index fc3888ad0..389c7c4d0 100644 --- a/BTCPayServer/Views/PaymentRequest/EditPaymentRequest.cshtml +++ b/BTCPayServer/Views/PaymentRequest/EditPaymentRequest.cshtml @@ -85,7 +85,7 @@
- + diff --git a/BTCPayServer/Views/Server/Theme.cshtml b/BTCPayServer/Views/Server/Theme.cshtml index 89a273112..ef70f136e 100644 --- a/BTCPayServer/Views/Server/Theme.cshtml +++ b/BTCPayServer/Views/Server/Theme.cshtml @@ -27,14 +27,14 @@
- +

Bootstrap theme

- +