|
3 | 3 | using System.Linq;
|
4 | 4 | using System.Text;
|
5 | 5 | using System.Text.RegularExpressions;
|
| 6 | +using System.Web; |
6 | 7 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
7 | 8 | using i18n.Domain.Concrete;
|
| 9 | +using i18n.Helpers; |
| 10 | +using NSubstitute; |
8 | 11 |
|
9 | 12 | namespace i18n.Tests
|
10 | 13 | {
|
11 | 14 | [TestClass]
|
12 | 15 | public class ResponseFilterTests
|
13 | 16 | {
|
14 |
| - void Helper_ResponseFilter_can_patch_html_urls(string suffix, string pre, string expectedPatched, Uri requestUrl = null) |
| 17 | + void Helper_ResponseFilter_can_patch_html_urls(string suffix, string pre, string expectedPatched, string requestUrl = null) |
15 | 18 | {
|
| 19 | + HttpRequestBase fakeRequest = Substitute.For<HttpRequestBase>(); |
| 20 | + HttpResponseBase fakeResponse = Substitute.For<HttpResponseBase>(); |
| 21 | + HttpContextBase fakeContext = Substitute.For<HttpContextBase>(); |
| 22 | + |
| 23 | + fakeRequest.Url.Returns(requestUrl.IsSet() ? new Uri(requestUrl) : null); |
| 24 | + fakeResponse.Headers.Returns(new System.Net.WebHeaderCollection |
| 25 | + { |
| 26 | + //{ "Authorization", "xyz" } |
| 27 | + }); |
| 28 | + |
| 29 | + fakeContext.Request.Returns(fakeRequest); |
| 30 | + fakeContext.Response.Returns(fakeResponse); |
| 31 | + |
16 | 32 | i18n.EarlyUrlLocalizer obj = new i18n.EarlyUrlLocalizer(new UrlLocalizer());
|
17 |
| - string post = obj.ProcessOutgoing(pre, suffix, null); |
| 33 | + string post = obj.ProcessOutgoing(pre, suffix, fakeContext); |
18 | 34 | Assert.AreEqual(expectedPatched, post);
|
19 | 35 | }
|
20 | 36 |
|
21 | 37 | [TestMethod]
|
22 | 38 | public void ResponseFilter_can_patch_html_urls()
|
23 | 39 | {
|
| 40 | + // Non-rooted path as href/src url. This should become rooted based on the path of the current request url. |
| 41 | + // See impl. details in EarlyUrlLocalizer.LocalizeUrl. Reference issue #286. |
| 42 | + Helper_ResponseFilter_can_patch_html_urls("fr", "<img src=\"123\"></img>" , "<img src=\"/fr/123\"></img>" , "http://example.com/Default.aspx"); |
| 43 | + Helper_ResponseFilter_can_patch_html_urls("fr", "<img src=\"123\"></img>" , "<img src=\"/fr/blogs/123\"></img>" , "http://example.com/blogs/Default.aspx"); |
| 44 | + Helper_ResponseFilter_can_patch_html_urls("fr", "<img src=\"123\"></img>" , "<img src=\"/fr/blogs/123\"></img>" , "http://example.com/blogs/"); |
| 45 | + Helper_ResponseFilter_can_patch_html_urls("fr", "<img src=\"123\"></img>" , "<img src=\"/fr/123\"></img>" , "http://example.com/blogs"); |
| 46 | + // NB: for the following we use .txt rather than .jpg because the defaule outgoing URL filter excludes .jpg urls. |
| 47 | + Helper_ResponseFilter_can_patch_html_urls("fr", "<img src=\"content/fred.txt\"></img>" , "<img src=\"/fr/content/fred.txt\"></img>" , "http://example.com/blog"); |
| 48 | + Helper_ResponseFilter_can_patch_html_urls("fr", "<img src=\"content/fred.txt\"></img>" , "<img src=\"/fr/blog/content/fred.txt\"></img>" , "http://example.com/blog/"); |
| 49 | + Helper_ResponseFilter_can_patch_html_urls("fr", "<img src=\"/content/fred.txt\"></img>" , "<img src=\"/fr/content/fred.txt\"></img>" , "http://example.com/blog/"); |
| 50 | + Helper_ResponseFilter_can_patch_html_urls("fr", "<img src=\"http://example.com/content/fred.txt\"></img>", "<img src=\"http://example.com/fr/content/fred.txt\"></img>" , "http://example.com/blog/"); |
| 51 | + Helper_ResponseFilter_can_patch_html_urls("fr", "<img src=\"http://other.com/content/fred.txt\"></img>" , "<img src=\"http://other.com/content/fred.txt\"></img>" , "http://example.com/blog/"); // NB: foreign site so no langtag added |
| 52 | + |
24 | 53 | // One attribute.
|
25 | 54 | Helper_ResponseFilter_can_patch_html_urls(
|
26 | 55 | "fr",
|
|
0 commit comments