-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added MakeLinksAbsolute and MakeLinksRootRelative settings
- Loading branch information
1 parent
3e2aa31
commit 3830e2f
Showing
5 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
tests/Statiq.Web.Tests/Modules/RenderPostProcessTemplatesFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
using Statiq.Common; | ||
using Statiq.Testing; | ||
using Statiq.Web.Modules; | ||
|
||
namespace Statiq.Web.Tests.Modules | ||
{ | ||
[TestFixture] | ||
public class RenderPostProcessTemplatesFixture : BaseFixture | ||
{ | ||
public class ExecuteTests : RenderPostProcessTemplatesFixture | ||
{ | ||
[Test] | ||
public async Task MakesRelativeLinksAbsolute() | ||
{ | ||
// Given | ||
TestExecutionContext context = new TestExecutionContext(); | ||
context.Services.AddSingleton<IReadOnlyFileSystem>(context.FileSystem); | ||
context.Settings[WebKeys.MakeLinksAbsolute] = true; | ||
context.Settings[Keys.Host] = "site.com"; | ||
context.Settings[Keys.LinksUseHttps] = true; | ||
TestDocument document = new TestDocument( | ||
new NormalizedPath("/a/b/c.html"), | ||
new NormalizedPath("a/b/c.html"), | ||
@"<html> | ||
<body> | ||
Foo <a href=""../d"">FizzBuzz</a> | ||
</body> | ||
</html>"); | ||
Templates templates = new Templates(); | ||
RenderPostProcessTemplates module = new RenderPostProcessTemplates(templates); | ||
|
||
// When | ||
TestDocument result = await ExecuteAsync(document, context, module).SingleAsync(); | ||
|
||
// Then | ||
result.Content.ShouldBe( | ||
@"<html><head></head><body> | ||
Foo <a href=""https://site.com/a/d"">FizzBuzz</a> | ||
</body></html>", | ||
StringCompareShould.IgnoreLineEndings); | ||
} | ||
|
||
[Test] | ||
public async Task MakesRelativeLinksRootRelative() | ||
{ | ||
// Given | ||
TestExecutionContext context = new TestExecutionContext(); | ||
context.Services.AddSingleton<IReadOnlyFileSystem>(context.FileSystem); | ||
context.Settings[WebKeys.MakeLinksRootRelative] = true; | ||
context.Settings[Keys.Host] = "site.com"; | ||
context.Settings[Keys.LinksUseHttps] = true; | ||
TestDocument document = new TestDocument( | ||
new NormalizedPath("/a/b/c.html"), | ||
new NormalizedPath("a/b/c.html"), | ||
@"<html> | ||
<body> | ||
Foo <a href=""../d"">FizzBuzz</a> | ||
</body> | ||
</html>"); | ||
Templates templates = new Templates(); | ||
RenderPostProcessTemplates module = new RenderPostProcessTemplates(templates); | ||
|
||
// When | ||
TestDocument result = await ExecuteAsync(document, context, module).SingleAsync(); | ||
|
||
// Then | ||
result.Content.ShouldBe( | ||
@"<html><head></head><body> | ||
Foo <a href=""/a/d"">FizzBuzz</a> | ||
</body></html>", | ||
StringCompareShould.IgnoreLineEndings); | ||
} | ||
} | ||
} | ||
} |