# Conflicts: # src/Umbraco.Cms.Imaging.ImageSharp/ConfigureImageSharpMiddlewareOptions.cs # src/Umbraco.Core/Models/AuditItem.cs # src/Umbraco.Core/Routing/UmbracoRequestPaths.cs # src/Umbraco.Core/Services/ContentService.cs # src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs # src/Umbraco.Infrastructure/Persistence/Repositories/Implement/MediaRepository.cs # src/Umbraco.Web.BackOffice/Controllers/ContentController.cs # src/Umbraco.Web.UI.Client/package-lock.json # src/Umbraco.Web.UI.Client/package.json # src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js # src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbtabbedcontent.directive.js # src/Umbraco.Web.UI.Client/src/common/directives/components/media/umbmedianodeinfo.directive.js # src/Umbraco.Web.UI.Client/src/common/directives/components/upload/umbfiledropzone.directive.js # src/Umbraco.Web.UI.Client/src/common/services/mediahelper.service.js # src/Umbraco.Web.UI.Client/src/common/services/rte-blockeditor-clipboard.service.js # src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js # src/Umbraco.Web.UI.Client/src/common/services/user.service.js # src/Umbraco.Web.UI.Client/src/less/components/umb-media-grid.less # src/Umbraco.Web.UI.Client/src/views/components/media/umbimagepreview/umb-image-preview.html # src/Umbraco.Web.UI.Client/src/views/components/media/umbimagepreview/umbimagepreview.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js # src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/rte.component.js # src/Umbraco.Web.UI.Client/src/views/templates/edit.html # src/Umbraco.Web.UI.Client~HEAD # src/Umbraco.Web.UI.Login/package-lock.json # src/Umbraco.Web.UI.Login/package.json # src/Umbraco.Web.UI.Login/src/auth.element.ts # src/Umbraco.Web.UI.Login/src/components/pages/login.page.element.ts # src/Umbraco.Web.UI.Login/src/index.ts # tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Login/login.spec.ts # tests/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/UmbracoRequestPathsTests.cs
115 lines
4.1 KiB
C#
115 lines
4.1 KiB
C#
// Copyright (c) Umbraco.
|
|
// See LICENSE for more details.
|
|
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
using Umbraco.Cms.Core.Hosting;
|
|
using Umbraco.Cms.Core.Routing;
|
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Routing;
|
|
|
|
// TODO: not testing virtual directory!
|
|
[TestFixture]
|
|
public class UriUtilityTests
|
|
{
|
|
// test normal urls
|
|
[TestCase("http://LocalHost/", "http://localhost/")]
|
|
[TestCase("http://LocalHost/?x=y", "http://localhost/?x=y")]
|
|
[TestCase("http://LocalHost/Home", "http://localhost/home")]
|
|
[TestCase("http://LocalHost/Home?x=y", "http://localhost/home?x=y")]
|
|
[TestCase("http://LocalHost/Home/Sub1", "http://localhost/home/sub1")]
|
|
[TestCase("http://LocalHost/Home/Sub1?x=y", "http://localhost/home/sub1?x=y")]
|
|
|
|
// test that the trailing slash goes but not on hostname
|
|
[TestCase("http://LocalHost/", "http://localhost/")]
|
|
[TestCase("http://LocalHost/////", "http://localhost/")]
|
|
[TestCase("http://LocalHost/Home/", "http://localhost/home")]
|
|
[TestCase("http://LocalHost/Home/////", "http://localhost/home")]
|
|
[TestCase("http://LocalHost/Home/?x=y", "http://localhost/home?x=y")]
|
|
[TestCase("http://LocalHost/Home/Sub1/", "http://localhost/home/sub1")]
|
|
[TestCase("http://LocalHost/Home/Sub1/?x=y", "http://localhost/home/sub1?x=y")]
|
|
public void Uri_To_Umbraco(string sourceUrl, string expectedUrl)
|
|
{
|
|
// Arrange
|
|
var sourceUri = new Uri(sourceUrl);
|
|
var uriUtility = BuildUriUtility("/");
|
|
|
|
// Act
|
|
var resultUri = uriUtility.UriToUmbraco(sourceUri);
|
|
|
|
// Assert
|
|
var expectedUri = new Uri(expectedUrl);
|
|
Assert.AreEqual(expectedUri.ToString(), resultUri.ToString());
|
|
}
|
|
|
|
// test directoryUrl true, trailingSlash false
|
|
[TestCase("/", "/", false)]
|
|
[TestCase("/home", "/home", false)]
|
|
[TestCase("/home/sub1", "/home/sub1", false)]
|
|
|
|
// test directoryUrl true, trailingSlash true
|
|
[TestCase("/", "/", true)]
|
|
[TestCase("/home", "/home/", true)]
|
|
[TestCase("/home/sub1", "/home/sub1/", true)]
|
|
public void Uri_From_Umbraco(string sourceUrl, string expectedUrl, bool trailingSlash)
|
|
{
|
|
// Arrange
|
|
var sourceUri = new Uri(sourceUrl, UriKind.Relative);
|
|
var requestHandlerSettings = new RequestHandlerSettings { AddTrailingSlash = trailingSlash };
|
|
var uriUtility = BuildUriUtility("/");
|
|
|
|
// Act
|
|
var resultUri = uriUtility.UriFromUmbraco(sourceUri, requestHandlerSettings);
|
|
|
|
// Assert
|
|
var expectedUri = new Uri(expectedUrl, UriKind.Relative);
|
|
Assert.AreEqual(expectedUri.ToString(), resultUri.ToString());
|
|
}
|
|
|
|
[TestCase("/", "/", "/")]
|
|
[TestCase("/", "/foo", "/foo")]
|
|
[TestCase("/", "~/foo", "/foo")]
|
|
[TestCase("/vdir", "/", "/vdir/")]
|
|
[TestCase("/vdir", "/foo", "/vdir/foo")]
|
|
[TestCase("/vdir", "/foo/", "/vdir/foo/")]
|
|
[TestCase("/vdir", "~/foo", "/vdir/foo")]
|
|
public void Uri_To_Absolute(string virtualPath, string sourceUrl, string expectedUrl)
|
|
{
|
|
// Arrange
|
|
var uriUtility = BuildUriUtility(virtualPath);
|
|
|
|
// Act
|
|
var resultUrl = uriUtility.ToAbsolute(sourceUrl);
|
|
|
|
// Assert
|
|
Assert.AreEqual(expectedUrl, resultUrl);
|
|
}
|
|
|
|
[TestCase("/", "/", "/")]
|
|
[TestCase("/", "/foo", "/foo")]
|
|
[TestCase("/", "/foo/", "/foo/")]
|
|
[TestCase("/vdir", "/vdir", "/")]
|
|
[TestCase("/vdir", "/vdir/", "/")]
|
|
[TestCase("/vdir", "/vdir/foo", "/foo")]
|
|
[TestCase("/vdir", "/vdir/foo/", "/foo/")]
|
|
public void Url_To_App_Relative(string virtualPath, string sourceUrl, string expectedUrl)
|
|
{
|
|
// Arrange
|
|
var uriUtility = BuildUriUtility(virtualPath);
|
|
|
|
// Act
|
|
var resultUrl = uriUtility.ToAppRelative(sourceUrl);
|
|
|
|
// Assert
|
|
Assert.AreEqual(expectedUrl, resultUrl);
|
|
}
|
|
|
|
private UriUtility BuildUriUtility(string virtualPath)
|
|
{
|
|
var mockHostingEnvironment = new Mock<IHostingEnvironment>();
|
|
mockHostingEnvironment.Setup(x => x.ApplicationVirtualPath).Returns(virtualPath);
|
|
return new UriUtility(mockHostingEnvironment.Object);
|
|
}
|
|
}
|