Merge pull request #7664 from umbraco/netcore/feature/move-files-after-umbraco-context-abstractions
Netcore: Removed `UrlProvider` from `UmbracoContext`
This commit is contained in:
+9
-3
@@ -25,16 +25,22 @@ dotnet_naming_rule.private_members_with_underscore.severity = suggestion
|
||||
|
||||
dotnet_naming_symbols.private_fields.applicable_kinds = field
|
||||
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
|
||||
# dotnet_naming_symbols.private_fields.required_modifiers = abstract,async,readonly,static # all except const
|
||||
|
||||
dotnet_naming_style.prefix_underscore.capitalization = camel_case
|
||||
dotnet_naming_style.prefix_underscore.required_prefix = _
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# https://github.com/MicrosoftDocs/visualstudio-docs/blob/master/docs/ide/editorconfig-code-style-settings-reference.md
|
||||
[*.cs]
|
||||
csharp_style_var_for_built_in_types = true:suggestion
|
||||
csharp_style_var_when_type_is_apparent = true:suggestion
|
||||
csharp_style_var_elsewhere = true:suggestion
|
||||
csharp_prefer_braces = false : none
|
||||
csharp_prefer_braces = false : none
|
||||
|
||||
[*.{js,less}]
|
||||
trim_trailing_whitespace = false
|
||||
[*.{js,less}]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -101,5 +102,9 @@ namespace Umbraco.Core.Cache
|
||||
var compiled = new Regex(regex, RegexOptions.Compiled);
|
||||
_items.RemoveAll(kvp => compiled.IsMatch(kvp.Key));
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<string, object>> GetEnumerator() => _items.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,5 +171,20 @@ namespace Umbraco.Core.Cache
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
|
||||
{
|
||||
if (!TryGetContextItems(out var items))
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
foreach (DictionaryEntry item in items)
|
||||
{
|
||||
yield return new KeyValuePair<string, object>(item.Key.ToString(), item.Value);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Umbraco.Core.Cache
|
||||
{
|
||||
public interface IRequestCache : IAppCache
|
||||
public interface IRequestCache : IAppCache, IEnumerable<KeyValuePair<string, object>>
|
||||
{
|
||||
bool Set(string key, object value);
|
||||
bool Remove(string key);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -84,5 +85,9 @@ namespace Umbraco.Core.Cache
|
||||
/// <inheritdoc />
|
||||
public virtual void ClearByRegex(string regex)
|
||||
{ }
|
||||
|
||||
public IEnumerator<KeyValuePair<string, object>> GetEnumerator() => new Dictionary<string, object>().GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Web.Dashboards;
|
||||
|
||||
namespace Umbraco.Core
|
||||
@@ -22,6 +23,15 @@ namespace Umbraco.Core
|
||||
public static DashboardCollectionBuilder Dashboards(this Composition composition)
|
||||
=> composition.WithCollectionBuilder<DashboardCollectionBuilder>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content finders collection builder.
|
||||
/// </summary>
|
||||
/// <param name="composition">The composition.</param>
|
||||
/// <returns></returns>
|
||||
public static MediaUrlGeneratorCollectionBuilder MediaUrlGenerators(this Composition composition)
|
||||
=> composition.WithCollectionBuilder<MediaUrlGeneratorCollectionBuilder>();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,21 @@
|
||||
public const string PreviewCookieName = "UMB_PREVIEW";
|
||||
|
||||
public const string InstallerCookieName = "umb_installId";
|
||||
|
||||
/// <summary>
|
||||
/// The cookie name that is used to store the validation value
|
||||
/// </summary>
|
||||
public const string CsrfValidationCookieName = "UMB-XSRF-V";
|
||||
|
||||
/// <summary>
|
||||
/// The cookie name that is set for angular to use to pass in to the header value for "X-UMB-XSRF-TOKEN"
|
||||
/// </summary>
|
||||
public const string AngularCookieName = "UMB-XSRF-TOKEN";
|
||||
|
||||
/// <summary>
|
||||
/// The header name that angular uses to pass in the token to validate the cookie
|
||||
/// </summary>
|
||||
public const string AngularHeadername = "X-UMB-XSRF-TOKEN";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Models.ContentEditing;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
|
||||
namespace Umbraco.Web.ContentApps
|
||||
@@ -12,18 +11,18 @@ namespace Umbraco.Web.ContentApps
|
||||
public class ContentAppFactoryCollection : BuilderCollectionBase<IContentAppFactory>
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ICurrentUserAccessor _currentUserAccessor;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
|
||||
public ContentAppFactoryCollection(IEnumerable<IContentAppFactory> items, ILogger logger, ICurrentUserAccessor currentUserAccessor)
|
||||
public ContentAppFactoryCollection(IEnumerable<IContentAppFactory> items, ILogger logger, IUmbracoContextAccessor umbracoContextAccessor)
|
||||
: base(items)
|
||||
{
|
||||
_logger = logger;
|
||||
_currentUserAccessor = currentUserAccessor;
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
}
|
||||
|
||||
private IEnumerable<IReadOnlyUserGroup> GetCurrentUserGroups()
|
||||
{
|
||||
var currentUser = _currentUserAccessor.TryGetCurrentUser();
|
||||
var currentUser = _umbracoContextAccessor.UmbracoContext?.Security?.CurrentUser;
|
||||
return currentUser == null
|
||||
? Enumerable.Empty<IReadOnlyUserGroup>()
|
||||
: currentUser.Groups;
|
||||
|
||||
@@ -19,8 +19,8 @@ namespace Umbraco.Web.ContentApps
|
||||
{
|
||||
// get the logger just-in-time - see note below for manifest parser
|
||||
var logger = factory.GetInstance<ILogger>();
|
||||
var currentUserAccessor = factory.GetInstance<ICurrentUserAccessor>();
|
||||
return new ContentAppFactoryCollection(CreateItems(factory), logger, currentUserAccessor);
|
||||
var umbracoContextAccessor = factory.GetInstance<IUmbracoContextAccessor>();
|
||||
return new ContentAppFactoryCollection(CreateItems(factory), logger, umbracoContextAccessor);
|
||||
}
|
||||
|
||||
protected override IEnumerable<IContentAppFactory> CreateItems(IFactory factory)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Core.Cookie
|
||||
{
|
||||
public interface ICookieManager
|
||||
{
|
||||
void ExpireCookie(string angularCookieName);
|
||||
}
|
||||
}
|
||||
+20
-18
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Scoping;
|
||||
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
@@ -16,13 +17,13 @@ namespace Umbraco.Web
|
||||
public abstract class HybridAccessorBase<T>
|
||||
where T : class
|
||||
{
|
||||
private readonly IRequestCache _requestCache;
|
||||
|
||||
// ReSharper disable StaticMemberInGenericType
|
||||
private static readonly object Locker = new object();
|
||||
private static bool _registered;
|
||||
// ReSharper restore StaticMemberInGenericType
|
||||
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
protected abstract string ItemKey { get; }
|
||||
|
||||
// read
|
||||
@@ -42,17 +43,16 @@ namespace Umbraco.Web
|
||||
// yes! flows with async!
|
||||
private T NonContextValue
|
||||
{
|
||||
get => (T) CallContext.LogicalGetData(ItemKey);
|
||||
get => CallContext<T>.GetData(ItemKey);
|
||||
set
|
||||
{
|
||||
if (value == null) CallContext.FreeNamedDataSlot(ItemKey);
|
||||
else CallContext.LogicalSetData(ItemKey, value);
|
||||
CallContext<T>.SetData(ItemKey, value);
|
||||
}
|
||||
}
|
||||
|
||||
protected HybridAccessorBase(IHttpContextAccessor httpContextAccessor)
|
||||
protected HybridAccessorBase(IRequestCache requestCache)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
|
||||
_requestCache = requestCache ?? throw new ArgumentNullException(nameof(requestCache));
|
||||
|
||||
lock (Locker)
|
||||
{
|
||||
@@ -65,15 +65,14 @@ namespace Umbraco.Web
|
||||
var itemKey = ItemKey; // virtual
|
||||
SafeCallContext.Register(() =>
|
||||
{
|
||||
var value = CallContext.LogicalGetData(itemKey);
|
||||
CallContext.FreeNamedDataSlot(itemKey);
|
||||
var value = CallContext<T>.GetData(itemKey);
|
||||
return value;
|
||||
}, o =>
|
||||
{
|
||||
if (o == null) return;
|
||||
var value = o as T;
|
||||
if (value == null) throw new ArgumentException($"Expected type {typeof(T).FullName}, got {o.GetType().FullName}", nameof(o));
|
||||
CallContext.LogicalSetData(itemKey, value);
|
||||
CallContext<T>.SetData(itemKey, value);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -81,20 +80,23 @@ namespace Umbraco.Web
|
||||
{
|
||||
get
|
||||
{
|
||||
var httpContext = _httpContextAccessor.HttpContext;
|
||||
if (httpContext == null) return NonContextValue;
|
||||
return (T) httpContext.Items[ItemKey];
|
||||
if (!_requestCache.IsAvailable)
|
||||
{
|
||||
return NonContextValue;
|
||||
}
|
||||
return (T) _requestCache.Get(ItemKey);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
var httpContext = _httpContextAccessor.HttpContext;
|
||||
if (httpContext == null)
|
||||
if (!_requestCache.IsAvailable)
|
||||
{
|
||||
NonContextValue = value;
|
||||
}
|
||||
else if (value == null)
|
||||
httpContext.Items.Remove(ItemKey);
|
||||
_requestCache.Remove(ItemKey);
|
||||
else
|
||||
httpContext.Items[ItemKey] = value;
|
||||
_requestCache.Set(ItemKey, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -1,4 +1,5 @@
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Events;
|
||||
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
@@ -6,8 +7,8 @@ namespace Umbraco.Web
|
||||
{
|
||||
protected override string ItemKey => "Umbraco.Core.Events.HybridEventMessagesAccessor";
|
||||
|
||||
public HybridEventMessagesAccessor(IHttpContextAccessor httpContextAccessor)
|
||||
: base(httpContextAccessor)
|
||||
public HybridEventMessagesAccessor(IRequestCache requestCache)
|
||||
: base(requestCache)
|
||||
{ }
|
||||
|
||||
public EventMessages EventMessages
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
@@ -16,11 +15,6 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
DateTime ObjectCreated { get; }
|
||||
|
||||
/// <summary>
|
||||
/// This is used internally for debugging and also used to define anything required to distinguish this request from another.
|
||||
/// </summary>
|
||||
Guid UmbracoRequestId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the WebSecurity class
|
||||
/// </summary>
|
||||
@@ -62,11 +56,6 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
bool IsFrontEndUmbracoRequest { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url provider.
|
||||
/// </summary>
|
||||
IPublishedUrlProvider UrlProvider { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the PublishedRequest object
|
||||
/// </summary>
|
||||
@@ -88,40 +77,6 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
bool InPreviewMode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url of a content identified by its identifier.
|
||||
/// </summary>
|
||||
/// <param name="contentId">The content identifier.</param>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns>The url for the content.</returns>
|
||||
string Url(int contentId, string culture = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url of a content identified by its identifier.
|
||||
/// </summary>
|
||||
/// <param name="contentId">The content identifier.</param>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns>The url for the content.</returns>
|
||||
string Url(Guid contentId, string culture = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url of a content identified by its identifier, in a specified mode.
|
||||
/// </summary>
|
||||
/// <param name="contentId">The content identifier.</param>
|
||||
/// <param name="mode">The mode.</param>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns>The url for the content.</returns>
|
||||
string Url(int contentId, UrlMode mode, string culture = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url of a content identified by its identifier, in a specified mode.
|
||||
/// </summary>
|
||||
/// <param name="contentId">The content identifier.</param>
|
||||
/// <param name="mode">The mode.</param>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns>The url for the content.</returns>
|
||||
string Url(Guid contentId, UrlMode mode, string culture = null);
|
||||
|
||||
IDisposable ForcedPreview(bool preview);
|
||||
void Dispose();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using Umbraco.Core;
|
||||
namespace Umbraco.Web.Models.ContentEditing
|
||||
{
|
||||
[DataContract(Name = "link", Namespace = "")]
|
||||
internal class LinkDisplay
|
||||
public class LinkDisplay
|
||||
{
|
||||
[DataMember(Name = "icon")]
|
||||
public string Icon { get; set; }
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
namespace Umbraco.Core.PropertyEditors
|
||||
{
|
||||
/// <summary>
|
||||
/// Must be implemented by property editors that store media and return media paths
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Currently there are only 2x core editors that do this: upload and image cropper.
|
||||
/// It would be possible for developers to know implement their own media property editors whereas previously this was not possible.
|
||||
/// </remarks>
|
||||
public interface IDataEditorWithMediaPath
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the media path for the value stored for a property
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
string GetMediaPath(object value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace Umbraco.Core.PropertyEditors
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to generate paths to media items for a specified property editor alias
|
||||
/// </summary>
|
||||
public interface IMediaUrlGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Tries to get a media path for a given property editor alias
|
||||
/// </summary>
|
||||
/// <param name="alias">The property editor alias</param>
|
||||
/// <param name="value">The value of the property</param>
|
||||
/// <returns>
|
||||
/// True if a media path was returned
|
||||
/// </returns>
|
||||
bool TryGetMediaPath(string alias, object value, out string mediaPath);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using Umbraco.Core.Models.Membership;
|
||||
|
||||
namespace Umbraco.Core.Models.Identity
|
||||
{
|
||||
public interface ICurrentUserAccessor
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the current user or null if no user is currently authenticated.
|
||||
/// </summary>
|
||||
/// <returns>The current user or null</returns>
|
||||
IUser TryGetCurrentUser();
|
||||
}
|
||||
}
|
||||
+8
-7
@@ -1,4 +1,5 @@
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
|
||||
namespace Umbraco.Web.Models.PublishedContent
|
||||
{
|
||||
@@ -7,22 +8,22 @@ namespace Umbraco.Web.Models.PublishedContent
|
||||
/// </summary>
|
||||
public class HttpContextVariationContextAccessor : IVariationContextAccessor
|
||||
{
|
||||
public const string ContextKey = "Umbraco.Web.Models.PublishedContent.DefaultVariationContextAccessor";
|
||||
public readonly IHttpContextAccessor HttpContextAccessor;
|
||||
private readonly IRequestCache _requestCache;
|
||||
private const string ContextKey = "Umbraco.Web.Models.PublishedContent.DefaultVariationContextAccessor";
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HttpContextVariationContextAccessor"/> class.
|
||||
/// </summary>
|
||||
public HttpContextVariationContextAccessor(IHttpContextAccessor httpContextAccessor)
|
||||
public HttpContextVariationContextAccessor(IRequestCache requestCache)
|
||||
{
|
||||
HttpContextAccessor = httpContextAccessor;
|
||||
_requestCache = requestCache;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public VariationContext VariationContext
|
||||
{
|
||||
get => (VariationContext) HttpContextAccessor.HttpContext?.Items[ContextKey];
|
||||
set => HttpContextAccessor.HttpContext.Items[ContextKey] = value;
|
||||
get => (VariationContext) _requestCache.Get(ContextKey);
|
||||
set => _requestCache.Set(ContextKey, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -1,14 +1,15 @@
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
|
||||
namespace Umbraco.Web.Models.PublishedContent
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements a hybrid <see cref="IVariationContextAccessor"/>.
|
||||
/// </summary>
|
||||
internal class HybridVariationContextAccessor : HybridAccessorBase<VariationContext>, IVariationContextAccessor
|
||||
public class HybridVariationContextAccessor : HybridAccessorBase<VariationContext>, IVariationContextAccessor
|
||||
{
|
||||
public HybridVariationContextAccessor(IHttpContextAccessor httpContextAccessor)
|
||||
: base(httpContextAccessor)
|
||||
public HybridVariationContextAccessor(IRequestCache requestCache)
|
||||
: base(requestCache)
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -23,4 +24,4 @@ namespace Umbraco.Web.Models.PublishedContent
|
||||
set => Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -182,7 +182,7 @@ namespace Umbraco.Web.Models.PublishedContent
|
||||
// if we found a content with the property having a value, return that property value
|
||||
if (property != null && property.HasValue(culture, segment))
|
||||
{
|
||||
value = property.Value<T>(culture, segment);
|
||||
value = property.Value<T>(this, culture, segment);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ namespace Umbraco.Web.Models.PublishedContent
|
||||
|
||||
if (property.HasValue(culture2, segment))
|
||||
{
|
||||
value = property.Value<T>(culture2, segment);
|
||||
value = property.Value<T>(this, culture2, segment);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ namespace Umbraco.Web.Models.PublishedContent
|
||||
|
||||
if (content.HasValue(alias, culture2, segment))
|
||||
{
|
||||
value = content.Value<T>(alias, culture2, segment);
|
||||
value = content.Value<T>(this, alias, culture2, segment);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ namespace Umbraco.Web.Models.PublishedContent
|
||||
|
||||
if (content.HasValue(alias, culture2, segment))
|
||||
{
|
||||
value = content.Value<T>(alias, culture2, segment);
|
||||
value = content.Value<T>(this, alias, culture2, segment);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Models.Trees
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.Composing;
|
||||
|
||||
namespace Umbraco.Core.PropertyEditors
|
||||
{
|
||||
public class MediaUrlGeneratorCollection : BuilderCollectionBase<IMediaUrlGenerator>
|
||||
{
|
||||
public MediaUrlGeneratorCollection(IEnumerable<IMediaUrlGenerator> items) : base(items)
|
||||
{
|
||||
}
|
||||
|
||||
public bool TryGetMediaPath(string alias, object value, out string mediaPath)
|
||||
{
|
||||
foreach(var generator in this)
|
||||
{
|
||||
if (generator.TryGetMediaPath(alias, value, out var mp))
|
||||
{
|
||||
mediaPath = mp;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
mediaPath = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Umbraco.Core.Composing;
|
||||
|
||||
namespace Umbraco.Core.PropertyEditors
|
||||
{
|
||||
public class MediaUrlGeneratorCollectionBuilder : LazyCollectionBuilderBase<MediaUrlGeneratorCollectionBuilder, MediaUrlGeneratorCollection, IMediaUrlGenerator>
|
||||
{
|
||||
protected override MediaUrlGeneratorCollectionBuilder This => this;
|
||||
}
|
||||
}
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache
|
||||
{
|
||||
public class UmbracoContextPublishedSnapshotAccessor : IPublishedSnapshotAccessor
|
||||
@@ -5,6 +5,7 @@ using Umbraco.Composing;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
@@ -1087,6 +1088,8 @@ namespace Umbraco.Core
|
||||
|
||||
#endregion
|
||||
|
||||
#region Url
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url of the content item.
|
||||
/// </summary>
|
||||
@@ -1117,5 +1120,6 @@ namespace Umbraco.Core
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,16 +16,18 @@ namespace Umbraco.Web.Routing
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IRequestHandlerSection _requestConfig;
|
||||
private readonly ISiteDomainHelper _siteDomainHelper;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly UriUtility _uriUtility;
|
||||
private readonly IPublishedValueFallback _publishedValueFallback;
|
||||
|
||||
public AliasUrlProvider(IGlobalSettings globalSettings, IRequestHandlerSection requestConfig, ISiteDomainHelper siteDomainHelper, UriUtility uriUtility, IPublishedValueFallback publishedValueFallback)
|
||||
public AliasUrlProvider(IGlobalSettings globalSettings, IRequestHandlerSection requestConfig, ISiteDomainHelper siteDomainHelper, UriUtility uriUtility, IPublishedValueFallback publishedValueFallback, IUmbracoContextAccessor umbracoContextAccessor)
|
||||
{
|
||||
_globalSettings = globalSettings;
|
||||
_requestConfig = requestConfig;
|
||||
_siteDomainHelper = siteDomainHelper;
|
||||
_uriUtility = uriUtility;
|
||||
_publishedValueFallback = publishedValueFallback;
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
}
|
||||
|
||||
// note - at the moment we seem to accept pretty much anything as an alias
|
||||
@@ -35,7 +37,7 @@ namespace Umbraco.Web.Routing
|
||||
#region GetUrl
|
||||
|
||||
/// <inheritdoc />
|
||||
public UrlInfo GetUrl(IUmbracoContext umbracoContext, IPublishedContent content, UrlMode mode, string culture, Uri current)
|
||||
public UrlInfo GetUrl(IPublishedContent content, UrlMode mode, string culture, Uri current)
|
||||
{
|
||||
return null; // we have nothing to say
|
||||
}
|
||||
@@ -55,8 +57,9 @@ namespace Umbraco.Web.Routing
|
||||
/// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid
|
||||
/// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para>
|
||||
/// </remarks>
|
||||
public IEnumerable<UrlInfo> GetOtherUrls(IUmbracoContext umbracoContext, int id, Uri current)
|
||||
public IEnumerable<UrlInfo> GetOtherUrls(int id, Uri current)
|
||||
{
|
||||
var umbracoContext = _umbracoContextAccessor.UmbracoContext;
|
||||
var node = umbracoContext.Content.GetById(id);
|
||||
if (node == null)
|
||||
yield break;
|
||||
|
||||
@@ -17,13 +17,13 @@ namespace Umbraco.Web.Routing
|
||||
{
|
||||
private readonly IRedirectUrlService _redirectUrlService;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly IPublishedUrlProvider _publishedUrlProvider;
|
||||
|
||||
public ContentFinderByRedirectUrl(IRedirectUrlService redirectUrlService, ILogger logger, IUmbracoContextAccessor umbracoContextAccessor)
|
||||
public ContentFinderByRedirectUrl(IRedirectUrlService redirectUrlService, ILogger logger, IPublishedUrlProvider publishedUrlProvider)
|
||||
{
|
||||
_redirectUrlService = redirectUrlService;
|
||||
_logger = logger;
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_publishedUrlProvider = publishedUrlProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -47,7 +47,7 @@ namespace Umbraco.Web.Routing
|
||||
}
|
||||
|
||||
var content = frequest.UmbracoContext.Content.GetById(redirectUrl.ContentId);
|
||||
var url = content == null ? "#" : content.Url(_umbracoContextAccessor.UmbracoContext.UrlProvider, redirectUrl.Culture);
|
||||
var url = content == null ? "#" : content.Url(_publishedUrlProvider, redirectUrl.Culture);
|
||||
if (url.StartsWith("#"))
|
||||
{
|
||||
_logger.Debug<ContentFinderByRedirectUrl>("Route {Route} matches content {ContentId} which has no url.", route, redirectUrl.ContentId);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
@@ -10,17 +9,17 @@ namespace Umbraco.Web.Routing
|
||||
/// </summary>
|
||||
public class DefaultMediaUrlProvider : IMediaUrlProvider
|
||||
{
|
||||
private readonly PropertyEditorCollection _propertyEditors;
|
||||
private readonly UriUtility _uriUtility;
|
||||
private readonly MediaUrlGeneratorCollection _mediaPathGenerators;
|
||||
|
||||
public DefaultMediaUrlProvider(PropertyEditorCollection propertyEditors, UriUtility uriUtility)
|
||||
public DefaultMediaUrlProvider(MediaUrlGeneratorCollection mediaPathGenerators, UriUtility uriUtility)
|
||||
{
|
||||
_propertyEditors = propertyEditors ?? throw new ArgumentNullException(nameof(propertyEditors));
|
||||
_mediaPathGenerators = mediaPathGenerators ?? throw new ArgumentNullException(nameof(mediaPathGenerators));
|
||||
_uriUtility = uriUtility;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual UrlInfo GetMediaUrl(IUmbracoContext umbracoContext, IPublishedContent content,
|
||||
public virtual UrlInfo GetMediaUrl(IPublishedContent content,
|
||||
string propertyAlias, UrlMode mode, string culture, Uri current)
|
||||
{
|
||||
var prop = content.GetProperty(propertyAlias);
|
||||
@@ -33,25 +32,23 @@ namespace Umbraco.Web.Routing
|
||||
}
|
||||
|
||||
var propType = prop.PropertyType;
|
||||
string path = null;
|
||||
|
||||
if (_propertyEditors.TryGet(propType.EditorAlias, out var editor)
|
||||
&& editor is IDataEditorWithMediaPath dataEditor)
|
||||
if (_mediaPathGenerators.TryGetMediaPath(propType.EditorAlias, value, out var path))
|
||||
{
|
||||
path = dataEditor.GetMediaPath(value);
|
||||
var url = AssembleUrl(path, current, mode);
|
||||
return UrlInfo.Url(url.ToString(), culture);
|
||||
}
|
||||
|
||||
var url = AssembleUrl(path, current, mode);
|
||||
return url == null ? null : UrlInfo.Url(url.ToString(), culture);
|
||||
return null;
|
||||
}
|
||||
|
||||
private Uri AssembleUrl(string path, Uri current, UrlMode mode)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return null;
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
throw new ArgumentException($"{nameof(path)} cannot be null or whitespace", nameof(path));
|
||||
|
||||
// the stored path is absolute so we just return it as is
|
||||
if(Uri.IsWellFormedUriString(path, UriKind.Absolute))
|
||||
if (Uri.IsWellFormedUriString(path, UriKind.Absolute))
|
||||
return new Uri(path);
|
||||
|
||||
Uri uri;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Logging;
|
||||
@@ -17,24 +16,27 @@ namespace Umbraco.Web.Routing
|
||||
private readonly ILogger _logger;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly ISiteDomainHelper _siteDomainHelper;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly UriUtility _uriUtility;
|
||||
|
||||
public DefaultUrlProvider(IRequestHandlerSection requestSettings, ILogger logger, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper, UriUtility uriUtility)
|
||||
public DefaultUrlProvider(IRequestHandlerSection requestSettings, ILogger logger, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper, IUmbracoContextAccessor umbracoContextAccessor, UriUtility uriUtility)
|
||||
{
|
||||
_requestSettings = requestSettings;
|
||||
_logger = logger;
|
||||
_globalSettings = globalSettings;
|
||||
_siteDomainHelper = siteDomainHelper;
|
||||
_uriUtility = uriUtility;
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
}
|
||||
|
||||
#region GetUrl
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual UrlInfo GetUrl(IUmbracoContext umbracoContext, IPublishedContent content, UrlMode mode, string culture, Uri current)
|
||||
public virtual UrlInfo GetUrl(IPublishedContent content, UrlMode mode, string culture, Uri current)
|
||||
{
|
||||
if (!current.IsAbsoluteUri) throw new ArgumentException("Current url must be absolute.", nameof(current));
|
||||
|
||||
var umbracoContext = _umbracoContextAccessor.UmbracoContext;
|
||||
// will not use cache if previewing
|
||||
var route = umbracoContext.Content.GetRouteById(content.Id, culture);
|
||||
|
||||
@@ -70,7 +72,7 @@ namespace Umbraco.Web.Routing
|
||||
/// <summary>
|
||||
/// Gets the other urls of a published content.
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext">The Umbraco context.</param>
|
||||
/// <param name="umbracoContextAccessor">The Umbraco context.</param>
|
||||
/// <param name="id">The published content id.</param>
|
||||
/// <param name="current">The current absolute url.</param>
|
||||
/// <returns>The other urls for the published content.</returns>
|
||||
@@ -78,8 +80,9 @@ namespace Umbraco.Web.Routing
|
||||
/// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid
|
||||
/// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para>
|
||||
/// </remarks>
|
||||
public virtual IEnumerable<UrlInfo> GetOtherUrls(IUmbracoContext umbracoContext, int id, Uri current)
|
||||
public virtual IEnumerable<UrlInfo> GetOtherUrls(int id, Uri current)
|
||||
{
|
||||
var umbracoContext = _umbracoContextAccessor.UmbracoContext;
|
||||
var node = umbracoContext.Content.GetById(id);
|
||||
if (node == null)
|
||||
yield break;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
|
||||
|
||||
namespace Umbraco.Web.Routing
|
||||
{
|
||||
/// <summary>
|
||||
@@ -11,7 +12,6 @@ namespace Umbraco.Web.Routing
|
||||
/// <summary>
|
||||
/// Gets the url of a media item.
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext">The Umbraco context.</param>
|
||||
/// <param name="content">The published content.</param>
|
||||
/// <param name="propertyAlias">The property alias to resolve the url from.</param>
|
||||
/// <param name="mode">The url mode.</param>
|
||||
@@ -26,6 +26,6 @@ namespace Umbraco.Web.Routing
|
||||
/// e.g. a cdn url provider will most likely always return an absolute url.</para>
|
||||
/// <para>If the provider is unable to provide a url, it returns <c>null</c>.</para>
|
||||
/// </remarks>
|
||||
UrlInfo GetMediaUrl(IUmbracoContext umbracoContext, IPublishedContent content, string propertyAlias, UrlMode mode, string culture, Uri current);
|
||||
UrlInfo GetMediaUrl(IPublishedContent content, string propertyAlias, UrlMode mode, string culture, Uri current);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ namespace Umbraco.Web.Routing
|
||||
/// <summary>
|
||||
/// Gets the url of a published content.
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext">The Umbraco context.</param>
|
||||
/// <param name="content">The published content.</param>
|
||||
/// <param name="mode">The url mode.</param>
|
||||
/// <param name="culture">A culture.</param>
|
||||
@@ -24,12 +23,11 @@ namespace Umbraco.Web.Routing
|
||||
/// when no culture is specified, the current culture.</para>
|
||||
/// <para>If the provider is unable to provide a url, it should return <c>null</c>.</para>
|
||||
/// </remarks>
|
||||
UrlInfo GetUrl(IUmbracoContext umbracoContext, IPublishedContent content, UrlMode mode, string culture, Uri current);
|
||||
UrlInfo GetUrl(IPublishedContent content, UrlMode mode, string culture, Uri current);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the other urls of a published content.
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext">The Umbraco context.</param>
|
||||
/// <param name="id">The published content id.</param>
|
||||
/// <param name="current">The current absolute url.</param>
|
||||
/// <returns>The other urls for the published content.</returns>
|
||||
@@ -37,6 +35,6 @@ namespace Umbraco.Web.Routing
|
||||
/// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid
|
||||
/// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para>
|
||||
/// </remarks>
|
||||
IEnumerable<UrlInfo> GetOtherUrls(IUmbracoContext umbracoContext, int id, Uri current);
|
||||
IEnumerable<UrlInfo> GetOtherUrls(int id, Uri current);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,18 +16,19 @@ namespace Umbraco.Web.Routing
|
||||
#region Ctor and configuration
|
||||
|
||||
/// <summary>
|
||||
/// InitialiIUrlProviderzes a new instance of the <see cref="UrlProvider"/> class with an Umbraco context and a list of url providers.
|
||||
/// Initializes a new instance of the <see cref="UrlProvider"/> class with an Umbraco context and a list of url providers.
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext">The Umbraco context.</param>
|
||||
/// <param name="umbracoContextAccessor">The Umbraco context accessor.</param>
|
||||
/// <param name="routingSettings">Routing settings.</param>
|
||||
/// <param name="urlProviders">The list of url providers.</param>
|
||||
/// <param name="mediaUrlProviders">The list of media url providers.</param>
|
||||
/// <param name="variationContextAccessor">The current variation accessor.</param>
|
||||
public UrlProvider(IUmbracoContext umbracoContext, IWebRoutingSection routingSettings, IEnumerable<IUrlProvider> urlProviders, IEnumerable<IMediaUrlProvider> mediaUrlProviders, IVariationContextAccessor variationContextAccessor)
|
||||
/// <param name="propertyEditorCollection"></param>
|
||||
public UrlProvider(IUmbracoContextAccessor umbracoContextAccessor, IWebRoutingSection routingSettings, UrlProviderCollection urlProviders, MediaUrlProviderCollection mediaUrlProviders, IVariationContextAccessor variationContextAccessor)
|
||||
{
|
||||
if (routingSettings == null) throw new ArgumentNullException(nameof(routingSettings));
|
||||
|
||||
_umbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext));
|
||||
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
|
||||
_urlProviders = urlProviders;
|
||||
_mediaUrlProviders = mediaUrlProviders;
|
||||
_variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor));
|
||||
@@ -40,25 +41,8 @@ namespace Umbraco.Web.Routing
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UrlProvider"/> class with an Umbraco context and a list of url providers.
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext">The Umbraco context.</param>
|
||||
/// <param name="urlProviders">The list of url providers.</param>
|
||||
/// <param name="mediaUrlProviders">The list of media url providers</param>
|
||||
/// <param name="variationContextAccessor">The current variation accessor.</param>
|
||||
/// <param name="mode">An optional provider mode.</param>
|
||||
public UrlProvider(IUmbracoContext umbracoContext, IEnumerable<IUrlProvider> urlProviders, IEnumerable<IMediaUrlProvider> mediaUrlProviders, IVariationContextAccessor variationContextAccessor, UrlMode mode = UrlMode.Auto)
|
||||
{
|
||||
_umbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext));
|
||||
_urlProviders = urlProviders;
|
||||
_mediaUrlProviders = mediaUrlProviders;
|
||||
_variationContextAccessor = variationContextAccessor;
|
||||
|
||||
Mode = mode;
|
||||
}
|
||||
|
||||
private readonly IUmbracoContext _umbracoContext;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly IEnumerable<IUrlProvider> _urlProviders;
|
||||
private readonly IEnumerable<IMediaUrlProvider> _mediaUrlProviders;
|
||||
private readonly IVariationContextAccessor _variationContextAccessor;
|
||||
@@ -72,9 +56,9 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
#region GetUrl
|
||||
|
||||
private IPublishedContent GetDocument(int id) => _umbracoContext.Content.GetById(id);
|
||||
private IPublishedContent GetDocument(Guid id) => _umbracoContext.Content.GetById(id);
|
||||
private IPublishedContent GetMedia(Guid id) => _umbracoContext.Media.GetById(id);
|
||||
private IPublishedContent GetDocument(int id) => _umbracoContextAccessor.UmbracoContext.Content.GetById(id);
|
||||
private IPublishedContent GetDocument(Guid id) => _umbracoContextAccessor.UmbracoContext.Content.GetById(id);
|
||||
private IPublishedContent GetMedia(Guid id) => _umbracoContextAccessor.UmbracoContext.Media.GetById(id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url of a published content.
|
||||
@@ -130,9 +114,9 @@ namespace Umbraco.Web.Routing
|
||||
}
|
||||
|
||||
if (current == null)
|
||||
current = _umbracoContext.CleanedUmbracoUrl;
|
||||
current = _umbracoContextAccessor.UmbracoContext.CleanedUmbracoUrl;
|
||||
|
||||
var url = _urlProviders.Select(provider => provider.GetUrl(_umbracoContext, content, mode, culture, current))
|
||||
var url = _urlProviders.Select(provider => provider.GetUrl(content, mode, culture, current))
|
||||
.FirstOrDefault(u => u != null);
|
||||
return url?.Text ?? "#"; // legacy wants this
|
||||
}
|
||||
@@ -142,7 +126,7 @@ namespace Umbraco.Web.Routing
|
||||
var provider = _urlProviders.OfType<DefaultUrlProvider>().FirstOrDefault();
|
||||
var url = provider == null
|
||||
? route // what else?
|
||||
: provider.GetUrlFromRoute(route, _umbracoContext, id, _umbracoContext.CleanedUmbracoUrl, Mode, culture)?.Text;
|
||||
: provider.GetUrlFromRoute(route, _umbracoContextAccessor.UmbracoContext, id, _umbracoContextAccessor.UmbracoContext.CleanedUmbracoUrl, Mode, culture)?.Text;
|
||||
return url ?? "#";
|
||||
}
|
||||
|
||||
@@ -162,7 +146,7 @@ namespace Umbraco.Web.Routing
|
||||
/// </remarks>
|
||||
public IEnumerable<UrlInfo> GetOtherUrls(int id)
|
||||
{
|
||||
return GetOtherUrls(id, _umbracoContext.CleanedUmbracoUrl);
|
||||
return GetOtherUrls(id, _umbracoContextAccessor.UmbracoContext.CleanedUmbracoUrl);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -177,7 +161,7 @@ namespace Umbraco.Web.Routing
|
||||
/// </remarks>
|
||||
public IEnumerable<UrlInfo> GetOtherUrls(int id, Uri current)
|
||||
{
|
||||
return _urlProviders.SelectMany(provider => provider.GetOtherUrls(_umbracoContext, id, current) ?? Enumerable.Empty<UrlInfo>());
|
||||
return _urlProviders.SelectMany(provider => provider.GetOtherUrls(id, current) ?? Enumerable.Empty<UrlInfo>());
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -231,10 +215,10 @@ namespace Umbraco.Web.Routing
|
||||
}
|
||||
|
||||
if (current == null)
|
||||
current = _umbracoContext.CleanedUmbracoUrl;
|
||||
current = _umbracoContextAccessor.UmbracoContext.CleanedUmbracoUrl;
|
||||
|
||||
var url = _mediaUrlProviders.Select(provider =>
|
||||
provider.GetMediaUrl(_umbracoContext, content, propertyAlias, mode, culture, current))
|
||||
provider.GetMediaUrl(content, propertyAlias, mode, culture, current))
|
||||
.FirstOrDefault(u => u != null);
|
||||
|
||||
return url?.Text ?? "";
|
||||
|
||||
@@ -26,7 +26,8 @@ namespace Umbraco.Web.Routing
|
||||
IContentService contentService,
|
||||
IVariationContextAccessor variationContextAccessor,
|
||||
ILogger logger,
|
||||
UriUtility uriUtility)
|
||||
UriUtility uriUtility,
|
||||
IPublishedUrlProvider publishedUrlProvider)
|
||||
{
|
||||
if (content == null) throw new ArgumentNullException(nameof(content));
|
||||
if (publishedRouter == null) throw new ArgumentNullException(nameof(publishedRouter));
|
||||
@@ -35,6 +36,7 @@ namespace Umbraco.Web.Routing
|
||||
if (textService == null) throw new ArgumentNullException(nameof(textService));
|
||||
if (contentService == null) throw new ArgumentNullException(nameof(contentService));
|
||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
||||
if (publishedUrlProvider == null) throw new ArgumentNullException(nameof(publishedUrlProvider));
|
||||
if (uriUtility == null) throw new ArgumentNullException(nameof(uriUtility));
|
||||
if (variationContextAccessor == null) throw new ArgumentNullException(nameof(variationContextAccessor));
|
||||
|
||||
@@ -61,7 +63,7 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
//get all URLs for all cultures
|
||||
//in a HashSet, so de-duplicates too
|
||||
foreach (var cultureUrl in GetContentUrlsByCulture(content, cultures, publishedRouter, umbracoContext, contentService, textService, variationContextAccessor, logger, uriUtility))
|
||||
foreach (var cultureUrl in GetContentUrlsByCulture(content, cultures, publishedRouter, umbracoContext, contentService, textService, variationContextAccessor, logger, uriUtility, publishedUrlProvider))
|
||||
{
|
||||
urls.Add(cultureUrl);
|
||||
}
|
||||
@@ -79,7 +81,7 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
// get the 'other' urls - ie not what you'd get with GetUrl() but urls that would route to the document, nevertheless.
|
||||
// for these 'other' urls, we don't check whether they are routable, collide, anything - we just report them.
|
||||
foreach (var otherUrl in umbracoContext.UrlProvider.GetOtherUrls(content.Id).OrderBy(x => x.Text).ThenBy(x => x.Culture))
|
||||
foreach (var otherUrl in publishedUrlProvider.GetOtherUrls(content.Id).OrderBy(x => x.Text).ThenBy(x => x.Culture))
|
||||
if (urls.Add(otherUrl)) //avoid duplicates
|
||||
yield return otherUrl;
|
||||
}
|
||||
@@ -103,7 +105,8 @@ namespace Umbraco.Web.Routing
|
||||
ILocalizedTextService textService,
|
||||
IVariationContextAccessor variationContextAccessor,
|
||||
ILogger logger,
|
||||
UriUtility uriUtility)
|
||||
UriUtility uriUtility,
|
||||
IPublishedUrlProvider publishedUrlProvider)
|
||||
{
|
||||
foreach (var culture in cultures)
|
||||
{
|
||||
@@ -116,7 +119,7 @@ namespace Umbraco.Web.Routing
|
||||
string url;
|
||||
try
|
||||
{
|
||||
url = umbracoContext.UrlProvider.GetUrl(content.Id, culture: culture);
|
||||
url = publishedUrlProvider.GetUrl(content.Id, culture: culture);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
+6
-4
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Web.Templates
|
||||
{
|
||||
@@ -13,10 +14,11 @@ namespace Umbraco.Web.Templates
|
||||
this._getMediaUrl = getMediaUrl;
|
||||
}
|
||||
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
public HtmlImageSourceParser(IUmbracoContextAccessor umbracoContextAccessor)
|
||||
private readonly IPublishedUrlProvider _publishedUrlProvider;
|
||||
|
||||
public HtmlImageSourceParser(IPublishedUrlProvider publishedUrlProvider)
|
||||
{
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_publishedUrlProvider = publishedUrlProvider;
|
||||
}
|
||||
|
||||
private static readonly Regex ResolveImgPattern = new Regex(@"(<img[^>]*src="")([^""\?]*)((?:\?[^""]*)?""[^>]*data-udi="")([^""]*)(""[^>]*>)",
|
||||
@@ -54,7 +56,7 @@ namespace Umbraco.Web.Templates
|
||||
public string EnsureImageSources(string text)
|
||||
{
|
||||
if(_getMediaUrl == null)
|
||||
_getMediaUrl = (guid) => _umbracoContextAccessor.UmbracoContext.UrlProvider.GetMediaUrl(guid);
|
||||
_getMediaUrl = (guid) => _publishedUrlProvider.GetMediaUrl(guid);
|
||||
|
||||
return ResolveImgPattern.Replace(text, match =>
|
||||
{
|
||||
+6
-7
@@ -2,8 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Web.Templates
|
||||
@@ -18,10 +16,12 @@ namespace Umbraco.Web.Templates
|
||||
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
|
||||
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly IPublishedUrlProvider _publishedUrlProvider;
|
||||
|
||||
public HtmlLocalLinkParser(IUmbracoContextAccessor umbracoContextAccessor)
|
||||
public HtmlLocalLinkParser(IUmbracoContextAccessor umbracoContextAccessor, IPublishedUrlProvider publishedUrlProvider)
|
||||
{
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_publishedUrlProvider = publishedUrlProvider;
|
||||
}
|
||||
|
||||
internal IEnumerable<Udi> FindUdisFromLocalLinks(string text)
|
||||
@@ -64,7 +64,6 @@ namespace Umbraco.Web.Templates
|
||||
if (_umbracoContextAccessor.UmbracoContext == null)
|
||||
throw new InvalidOperationException("Could not parse internal links, there is no current UmbracoContext");
|
||||
|
||||
var urlProvider = _umbracoContextAccessor.UmbracoContext.UrlProvider;
|
||||
|
||||
foreach((int? intId, GuidUdi udi, string tagValue) in FindLocalLinkIds(text))
|
||||
{
|
||||
@@ -72,9 +71,9 @@ namespace Umbraco.Web.Templates
|
||||
{
|
||||
var newLink = "#";
|
||||
if (udi.EntityType == Constants.UdiEntityType.Document)
|
||||
newLink = urlProvider.GetUrl(udi.Guid);
|
||||
newLink = _publishedUrlProvider.GetUrl(udi.Guid);
|
||||
else if (udi.EntityType == Constants.UdiEntityType.Media)
|
||||
newLink = urlProvider.GetMediaUrl(udi.Guid);
|
||||
newLink = _publishedUrlProvider.GetMediaUrl(udi.Guid);
|
||||
|
||||
if (newLink == null)
|
||||
newLink = "#";
|
||||
@@ -83,7 +82,7 @@ namespace Umbraco.Web.Templates
|
||||
}
|
||||
else if (intId.HasValue)
|
||||
{
|
||||
var newLink = urlProvider.GetUrl(intId.Value);
|
||||
var newLink = _publishedUrlProvider.GetUrl(intId.Value);
|
||||
text = text.Replace(tagValue, "href=\"" + newLink);
|
||||
}
|
||||
}
|
||||
@@ -24,9 +24,4 @@
|
||||
<_Parameter1>Umbraco.Tests.Benchmarks</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Logging\Viewer" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
+1
-1
@@ -22,9 +22,9 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
internal UmbracoContextReference(IUmbracoContext umbracoContext, bool isRoot, IUmbracoContextAccessor umbracoContextAccessor)
|
||||
{
|
||||
UmbracoContext = umbracoContext;
|
||||
IsRoot = isRoot;
|
||||
|
||||
UmbracoContext = umbracoContext;
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Examine
|
||||
@@ -17,19 +18,19 @@ namespace Umbraco.Examine
|
||||
{
|
||||
private readonly IExamineManager _examineManager;
|
||||
private readonly ILocalizationService _languageService;
|
||||
private readonly ICurrentUserAccessor _currentUserAccessor;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly IEntityService _entityService;
|
||||
private readonly IUmbracoTreeSearcherFields _treeSearcherFields;
|
||||
|
||||
public BackOfficeExamineSearcher(IExamineManager examineManager,
|
||||
ILocalizationService languageService,
|
||||
ICurrentUserAccessor currentUserAccessor,
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
IEntityService entityService,
|
||||
IUmbracoTreeSearcherFields treeSearcherFields)
|
||||
{
|
||||
_examineManager = examineManager;
|
||||
_languageService = languageService;
|
||||
_currentUserAccessor = currentUserAccessor;
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_entityService = entityService;
|
||||
_treeSearcherFields = treeSearcherFields;
|
||||
}
|
||||
@@ -48,7 +49,7 @@ namespace Umbraco.Examine
|
||||
query = "\"" + g.ToString() + "\"";
|
||||
}
|
||||
|
||||
var currentUser = _currentUserAccessor.TryGetCurrentUser();
|
||||
var currentUser = _umbracoContextAccessor.UmbracoContext?.Security?.CurrentUser;
|
||||
|
||||
switch (entityType)
|
||||
{
|
||||
|
||||
+1
-4
@@ -1,8 +1,5 @@
|
||||
using System.Linq;
|
||||
using NPoco.Expressions;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Serialization;
|
||||
using Umbraco.Core.Services.Changes;
|
||||
|
||||
namespace Umbraco.Web.Cache
|
||||
@@ -10,7 +7,7 @@ namespace Umbraco.Web.Cache
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="DistributedCache"/>.
|
||||
/// </summary>
|
||||
internal static class DistributedCacheExtensions
|
||||
public static class DistributedCacheExtensions
|
||||
{
|
||||
#region PublicAccessCache
|
||||
|
||||
@@ -148,13 +148,12 @@ namespace Umbraco.Web.Compose
|
||||
/// </summary>
|
||||
public sealed class Notifier
|
||||
{
|
||||
private readonly ICurrentUserAccessor _currentUserAccessor;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly IRuntimeState _runtimeState;
|
||||
private readonly INotificationService _notificationService;
|
||||
private readonly IUserService _userService;
|
||||
private readonly ILocalizedTextService _textService;
|
||||
private readonly IGlobalSettings _globalSettings;
|
||||
private readonly IContentSection _contentConfig;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
@@ -167,21 +166,20 @@ namespace Umbraco.Web.Compose
|
||||
/// <param name="globalSettings"></param>
|
||||
/// <param name="contentConfig"></param>
|
||||
/// <param name="logger"></param>
|
||||
public Notifier(ICurrentUserAccessor currentUserAccessor, IRuntimeState runtimeState, INotificationService notificationService, IUserService userService, ILocalizedTextService textService, IGlobalSettings globalSettings, IContentSection contentConfig, ILogger logger)
|
||||
public Notifier(IUmbracoContextAccessor umbracoContextAccessor, IRuntimeState runtimeState, INotificationService notificationService, IUserService userService, ILocalizedTextService textService, IGlobalSettings globalSettings, ILogger logger)
|
||||
{
|
||||
_currentUserAccessor = currentUserAccessor;
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_runtimeState = runtimeState;
|
||||
_notificationService = notificationService;
|
||||
_userService = userService;
|
||||
_textService = textService;
|
||||
_globalSettings = globalSettings;
|
||||
_contentConfig = contentConfig;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Notify(IAction action, params IContent[] entities)
|
||||
{
|
||||
var user = _currentUserAccessor.TryGetCurrentUser();
|
||||
var user = _umbracoContextAccessor.UmbracoContext?.Security?.CurrentUser;
|
||||
|
||||
//if there is no current user, then use the admin
|
||||
if (user == null)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cookie;
|
||||
using Umbraco.Core.Migrations;
|
||||
|
||||
|
||||
namespace Umbraco.Web.Migrations.PostMigrations
|
||||
{
|
||||
/// <summary>
|
||||
/// Clears Csrf tokens.
|
||||
/// </summary>
|
||||
public class ClearCsrfCookies : IMigration
|
||||
{
|
||||
private readonly ICookieManager _cookieManager;
|
||||
|
||||
public ClearCsrfCookies(ICookieManager cookieManager)
|
||||
{
|
||||
_cookieManager = cookieManager;
|
||||
}
|
||||
|
||||
public void Migrate()
|
||||
{
|
||||
_cookieManager.ExpireCookie(Constants.Web.AngularCookieName);
|
||||
_cookieManager.ExpireCookie(Constants.Web.CsrfValidationCookieName);
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
namespace Umbraco.Core.Migrations.PostMigrations
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements <see cref="IPublishedSnapshotRebuilder"/> in Umbraco.Core (doing nothing).
|
||||
/// </summary>
|
||||
public class NoopPublishedSnapshotRebuilder : IPublishedSnapshotRebuilder
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void Rebuild()
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,31 @@
|
||||
namespace Umbraco.Core.Migrations.PostMigrations
|
||||
using Umbraco.Core.Migrations.PostMigrations;
|
||||
using Umbraco.Web.Cache;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
|
||||
namespace Umbraco.Web.Migrations.PostMigrations
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements <see cref="IPublishedSnapshotRebuilder"/> in Umbraco.Core (doing nothing).
|
||||
/// Implements <see cref="IPublishedSnapshotRebuilder"/> in Umbraco.Web (rebuilding).
|
||||
/// </summary>
|
||||
public class PublishedSnapshotRebuilder : IPublishedSnapshotRebuilder
|
||||
{
|
||||
private readonly IPublishedSnapshotService _publishedSnapshotService;
|
||||
private readonly DistributedCache _distributedCache;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PublishedSnapshotRebuilder"/> class.
|
||||
/// </summary>
|
||||
public PublishedSnapshotRebuilder(IPublishedSnapshotService publishedSnapshotService, DistributedCache distributedCache)
|
||||
{
|
||||
_publishedSnapshotService = publishedSnapshotService;
|
||||
_distributedCache = distributedCache;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Rebuild()
|
||||
{ }
|
||||
{
|
||||
_publishedSnapshotService.Rebuild();
|
||||
_distributedCache.RefreshAllPublishedSnapshot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Web.Models
|
||||
{
|
||||
internal class ImageProcessorImageUrlGenerator : IImageUrlGenerator
|
||||
public class ImageProcessorImageUrlGenerator : IImageUrlGenerator
|
||||
{
|
||||
public string GetImageUrl(ImageUrlGenerationOptions options)
|
||||
{
|
||||
@@ -1,7 +1,5 @@
|
||||
using System.Linq;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Core.Models
|
||||
@@ -11,17 +9,15 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Gets the url of a media item.
|
||||
/// </summary>
|
||||
public static string GetUrl(this IMedia media, string propertyAlias, ILogger logger, PropertyEditorCollection propertyEditors)
|
||||
public static string GetUrl(this IMedia media, string propertyAlias, MediaUrlGeneratorCollection mediaUrlGenerators)
|
||||
{
|
||||
if (!media.Properties.TryGetValue(propertyAlias, out var property))
|
||||
return string.Empty;
|
||||
|
||||
if (propertyEditors.TryGet(property.PropertyType.PropertyEditorAlias, out var editor)
|
||||
&& editor is IDataEditorWithMediaPath dataEditor)
|
||||
{
|
||||
// TODO: would need to be adjusted to variations, when media become variants
|
||||
var value = property.GetValue();
|
||||
return dataEditor.GetMediaPath(value);
|
||||
// TODO: would need to be adjusted to variations, when media become variants
|
||||
if (mediaUrlGenerators.TryGetMediaPath(property.PropertyType.PropertyEditorAlias, property.GetValue(), out var mediaUrl))
|
||||
{
|
||||
return mediaUrl;
|
||||
}
|
||||
|
||||
// Without knowing what it is, just adding a string here might not be very nice
|
||||
@@ -31,10 +27,10 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Gets the urls of a media item.
|
||||
/// </summary>
|
||||
public static string[] GetUrls(this IMedia media, IContentSection contentSection, ILogger logger, PropertyEditorCollection propertyEditors)
|
||||
public static string[] GetUrls(this IMedia media, IContentSection contentSection, MediaUrlGeneratorCollection mediaUrlGenerators)
|
||||
{
|
||||
return contentSection.ImageAutoFillProperties
|
||||
.Select(field => media.GetUrl(field.Alias, logger, propertyEditors))
|
||||
.Select(field => media.GetUrl(field.Alias, mediaUrlGenerators))
|
||||
.Where(link => string.IsNullOrWhiteSpace(link) == false)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
/// <summary>
|
||||
/// Builds a dto from an IMedia item.
|
||||
/// </summary>
|
||||
public static MediaDto BuildDto(PropertyEditorCollection propertyEditors, IMedia entity)
|
||||
public static MediaDto BuildDto(MediaUrlGeneratorCollection mediaUrlGenerators, IMedia entity)
|
||||
{
|
||||
var contentDto = BuildContentDto(entity, Constants.ObjectTypes.Media);
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
NodeId = entity.Id,
|
||||
ContentDto = contentDto,
|
||||
MediaVersionDto = BuildMediaVersionDto(propertyEditors, entity, contentDto)
|
||||
MediaVersionDto = BuildMediaVersionDto(mediaUrlGenerators, entity, contentDto)
|
||||
};
|
||||
|
||||
return dto;
|
||||
@@ -287,7 +287,7 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
return dto;
|
||||
}
|
||||
|
||||
private static MediaVersionDto BuildMediaVersionDto(PropertyEditorCollection propertyEditors, IMedia entity, ContentDto contentDto)
|
||||
private static MediaVersionDto BuildMediaVersionDto(MediaUrlGeneratorCollection mediaUrlGenerators, IMedia entity, ContentDto contentDto)
|
||||
{
|
||||
// try to get a path from the string being stored for media
|
||||
// TODO: only considering umbracoFile
|
||||
@@ -295,11 +295,9 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
string path = null;
|
||||
|
||||
if (entity.Properties.TryGetValue(Constants.Conventions.Media.File, out var property)
|
||||
&& propertyEditors.TryGet(property.PropertyType.PropertyEditorAlias, out var editor)
|
||||
&& editor is IDataEditorWithMediaPath dataEditor)
|
||||
&& mediaUrlGenerators.TryGetMediaPath(property.PropertyType.PropertyEditorAlias, property.GetValue(), out var mediaPath))
|
||||
{
|
||||
var value = property.GetValue();
|
||||
path = dataEditor.GetMediaPath(value);
|
||||
path = mediaPath;
|
||||
}
|
||||
|
||||
var dto = new MediaVersionDto
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
{
|
||||
private readonly IMediaTypeRepository _mediaTypeRepository;
|
||||
private readonly ITagRepository _tagRepository;
|
||||
private readonly MediaUrlGeneratorCollection _mediaUrlGenerators;
|
||||
private readonly MediaByGuidReadRepository _mediaByGuidReadRepository;
|
||||
|
||||
public MediaRepository(
|
||||
@@ -37,12 +38,14 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
IRelationRepository relationRepository,
|
||||
IRelationTypeRepository relationTypeRepository,
|
||||
Lazy<PropertyEditorCollection> propertyEditorCollection,
|
||||
MediaUrlGeneratorCollection mediaUrlGenerators,
|
||||
DataValueReferenceFactoryCollection dataValueReferenceFactories,
|
||||
IDataTypeService dataTypeService)
|
||||
: base(scopeAccessor, cache, logger, languageRepository, relationRepository, relationTypeRepository, propertyEditorCollection, dataValueReferenceFactories, dataTypeService)
|
||||
{
|
||||
_mediaTypeRepository = mediaTypeRepository ?? throw new ArgumentNullException(nameof(mediaTypeRepository));
|
||||
_tagRepository = tagRepository ?? throw new ArgumentNullException(nameof(tagRepository));
|
||||
_mediaUrlGenerators = mediaUrlGenerators;
|
||||
_mediaByGuidReadRepository = new MediaByGuidReadRepository(this, scopeAccessor, cache, logger);
|
||||
}
|
||||
|
||||
@@ -239,7 +242,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
entity.SanitizeEntityPropertiesForXmlStorage();
|
||||
|
||||
// create the dto
|
||||
var dto = ContentBaseFactory.BuildDto(PropertyEditors, entity);
|
||||
var dto = ContentBaseFactory.BuildDto(_mediaUrlGenerators, entity);
|
||||
|
||||
// derive path and level from parent
|
||||
var parent = GetParentNodeDto(entity.ParentId);
|
||||
@@ -330,7 +333,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
}
|
||||
|
||||
// create the dto
|
||||
var dto = ContentBaseFactory.BuildDto(PropertyEditors, entity);
|
||||
var dto = ContentBaseFactory.BuildDto(_mediaUrlGenerators, entity);
|
||||
|
||||
// update the node dto
|
||||
var nodeDto = dto.ContentDto.NodeDto;
|
||||
|
||||
@@ -11,6 +11,9 @@ namespace Umbraco.Core.PropertyEditors
|
||||
: base(items)
|
||||
{ }
|
||||
|
||||
// TODO: We could further reduce circular dependencies with PropertyEditorCollection by not having IDataValueReference implemented
|
||||
// by property editors and instead just use the already built in IDataValueReferenceFactory and/or refactor that into a more normal collection
|
||||
|
||||
public IEnumerable<UmbracoEntityReference> GetAllReferences(IPropertyCollection properties, PropertyEditorCollection propertyEditors)
|
||||
{
|
||||
var trackedRelations = new List<UmbracoEntityReference>();
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
"fileupload",
|
||||
Group = Constants.PropertyEditors.Groups.Media,
|
||||
Icon = "icon-download-alt")]
|
||||
public class FileUploadPropertyEditor : DataEditor, IDataEditorWithMediaPath
|
||||
public class FileUploadPropertyEditor : DataEditor, IMediaUrlGenerator
|
||||
{
|
||||
private readonly IMediaFileSystem _mediaFileSystem;
|
||||
private readonly IContentSection _contentSection;
|
||||
@@ -52,7 +52,16 @@ namespace Umbraco.Web.PropertyEditors
|
||||
return editor;
|
||||
}
|
||||
|
||||
public string GetMediaPath(object value) => value?.ToString();
|
||||
public bool TryGetMediaPath(string alias, object value, out string mediaPath)
|
||||
{
|
||||
if (alias == Alias)
|
||||
{
|
||||
mediaPath = value?.ToString();
|
||||
return true;
|
||||
}
|
||||
mediaPath = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether a property is an upload field.
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
HideLabel = false,
|
||||
Group = Constants.PropertyEditors.Groups.Media,
|
||||
Icon = "icon-crop")]
|
||||
public class ImageCropperPropertyEditor : DataEditor, IDataEditorWithMediaPath
|
||||
public class ImageCropperPropertyEditor : DataEditor, IMediaUrlGenerator
|
||||
{
|
||||
private readonly IMediaFileSystem _mediaFileSystem;
|
||||
private readonly IContentSection _contentSettings;
|
||||
@@ -53,7 +53,16 @@ namespace Umbraco.Web.PropertyEditors
|
||||
_autoFillProperties = new UploadAutoFillProperties(_mediaFileSystem, logger, _contentSettings);
|
||||
}
|
||||
|
||||
public string GetMediaPath(object value) => GetFileSrcFromPropertyValue(value, out _, false);
|
||||
public bool TryGetMediaPath(string alias, object value, out string mediaPath)
|
||||
{
|
||||
if (alias == Alias)
|
||||
{
|
||||
mediaPath = GetFileSrcFromPropertyValue(value, out _, false);
|
||||
return true;
|
||||
}
|
||||
mediaPath = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the corresponding property value editor.
|
||||
|
||||
+7
-3
@@ -1,12 +1,12 @@
|
||||
using System;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
@@ -23,17 +23,21 @@ namespace Umbraco.Web.PropertyEditors
|
||||
private readonly Lazy<IEntityService> _entityService;
|
||||
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly IPublishedUrlProvider _publishedUrlProvider;
|
||||
|
||||
public MultiUrlPickerPropertyEditor(ILogger logger, Lazy<IEntityService> entityService, IPublishedSnapshotAccessor publishedSnapshotAccessor, IDataTypeService dataTypeService, ILocalizationService localizationService, ILocalizedTextService localizedTextService, IIOHelper ioHelper, IShortStringHelper shortStringHelper)
|
||||
public MultiUrlPickerPropertyEditor(ILogger logger, Lazy<IEntityService> entityService, IPublishedSnapshotAccessor publishedSnapshotAccessor, IDataTypeService dataTypeService, ILocalizationService localizationService, ILocalizedTextService localizedTextService, IIOHelper ioHelper, IShortStringHelper shortStringHelper, IUmbracoContextAccessor umbracoContextAccessor, IPublishedUrlProvider publishedUrlProvider)
|
||||
: base(logger, dataTypeService, localizationService, localizedTextService, shortStringHelper, EditorType.PropertyValue)
|
||||
{
|
||||
_entityService = entityService ?? throw new ArgumentNullException(nameof(entityService));
|
||||
_publishedSnapshotAccessor = publishedSnapshotAccessor ?? throw new ArgumentNullException(nameof(publishedSnapshotAccessor));
|
||||
_ioHelper = ioHelper;
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_publishedUrlProvider = publishedUrlProvider;
|
||||
}
|
||||
|
||||
protected override IConfigurationEditor CreateConfigurationEditor() => new MultiUrlPickerConfigurationEditor(_ioHelper);
|
||||
|
||||
protected override IDataValueEditor CreateValueEditor() => new MultiUrlPickerValueEditor(_entityService.Value, _publishedSnapshotAccessor, Logger, DataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper, Attribute);
|
||||
protected override IDataValueEditor CreateValueEditor() => new MultiUrlPickerValueEditor(_entityService.Value, _publishedSnapshotAccessor, Logger, DataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper, Attribute, _umbracoContextAccessor, _publishedUrlProvider);
|
||||
}
|
||||
}
|
||||
+10
-5
@@ -11,9 +11,10 @@ using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
@@ -21,14 +22,18 @@ namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
private readonly IEntityService _entityService;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly IPublishedUrlProvider _publishedUrlProvider;
|
||||
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
|
||||
|
||||
public MultiUrlPickerValueEditor(IEntityService entityService, IPublishedSnapshotAccessor publishedSnapshotAccessor, ILogger logger, IDataTypeService dataTypeService, ILocalizationService localizationService, ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, DataEditorAttribute attribute)
|
||||
public MultiUrlPickerValueEditor(IEntityService entityService, IPublishedSnapshotAccessor publishedSnapshotAccessor, ILogger logger, IDataTypeService dataTypeService, ILocalizationService localizationService, ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, DataEditorAttribute attribute, IUmbracoContextAccessor umbracoContextAccessor, IPublishedUrlProvider publishedUrlProvider)
|
||||
: base(dataTypeService, localizationService, localizedTextService, shortStringHelper, attribute)
|
||||
{
|
||||
_entityService = entityService ?? throw new ArgumentNullException(nameof(entityService));
|
||||
_publishedSnapshotAccessor = publishedSnapshotAccessor ?? throw new ArgumentNullException(nameof(publishedSnapshotAccessor));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
|
||||
_publishedUrlProvider = publishedUrlProvider;
|
||||
}
|
||||
|
||||
public override object ToEditor(IProperty property, string culture = null, string segment = null)
|
||||
@@ -84,7 +89,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
icon = documentEntity.ContentTypeIcon;
|
||||
published = culture == null ? documentEntity.Published : documentEntity.PublishedCultures.Contains(culture);
|
||||
udi = new GuidUdi(Constants.UdiEntityType.Document, documentEntity.Key);
|
||||
url = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(entity.Key)?.Url() ?? "#";
|
||||
url = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(entity.Key)?.Url(_publishedUrlProvider) ?? "#";
|
||||
trashed = documentEntity.Trashed;
|
||||
}
|
||||
else if(entity is IContentEntitySlim contentEntity)
|
||||
@@ -92,7 +97,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
icon = contentEntity.ContentTypeIcon;
|
||||
published = !contentEntity.Trashed;
|
||||
udi = new GuidUdi(Constants.UdiEntityType.Media, contentEntity.Key);
|
||||
url = _publishedSnapshotAccessor.PublishedSnapshot.Media.GetById(entity.Key)?.Url() ?? "#";
|
||||
url = _publishedSnapshotAccessor.PublishedSnapshot.Media.GetById(entity.Key)?.Url(_publishedUrlProvider) ?? "#";
|
||||
trashed = contentEntity.Trashed;
|
||||
}
|
||||
else
|
||||
@@ -160,7 +165,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
internal class LinkDto
|
||||
public class LinkDto
|
||||
{
|
||||
[DataMember(Name = "name")]
|
||||
public string Name { get; set; }
|
||||
+2
-3
@@ -6,7 +6,6 @@ using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
@@ -316,14 +315,14 @@ namespace Umbraco.Web.PropertyEditors
|
||||
? $"'{row.PropType.Name}' cannot be null"
|
||||
: row.PropType.MandatoryMessage;
|
||||
validationResults.Add(new ValidationResult($"Item {(row.RowIndex + 1)}: {message}", new[] { row.PropKey }));
|
||||
}
|
||||
}
|
||||
else if (row.JsonRowValue[row.PropKey].ToString().IsNullOrWhiteSpace() || (row.JsonRowValue[row.PropKey].Type == JTokenType.Array && !row.JsonRowValue[row.PropKey].HasValues))
|
||||
{
|
||||
var message = string.IsNullOrWhiteSpace(row.PropType.MandatoryMessage)
|
||||
? $"'{row.PropType.Name}' cannot be empty"
|
||||
: row.PropType.MandatoryMessage;
|
||||
validationResults.Add(new ValidationResult($"Item {(row.RowIndex + 1)}: {message}", new[] { row.PropKey }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check regex
|
||||
+4
-4
@@ -2,9 +2,7 @@
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
{
|
||||
@@ -12,10 +10,12 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
public class MemberPickerValueConverter : PropertyValueConverterBase
|
||||
{
|
||||
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
|
||||
public MemberPickerValueConverter(IPublishedSnapshotAccessor publishedSnapshotAccessor)
|
||||
public MemberPickerValueConverter(IPublishedSnapshotAccessor publishedSnapshotAccessor, IUmbracoContextAccessor umbracoContextAccessor)
|
||||
{
|
||||
_publishedSnapshotAccessor = publishedSnapshotAccessor ?? throw new ArgumentNullException(nameof(publishedSnapshotAccessor));
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
}
|
||||
|
||||
public override bool IsConverter(IPublishedPropertyType propertyType)
|
||||
@@ -45,7 +45,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
if (source == null)
|
||||
return null;
|
||||
|
||||
if (Current.UmbracoContext != null)
|
||||
if (_umbracoContextAccessor.UmbracoContext != null)
|
||||
{
|
||||
IPublishedContent member;
|
||||
if (source is int id)
|
||||
+4
-5
@@ -3,13 +3,10 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.PropertyEditors.ValueConverters;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
|
||||
namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
@@ -22,6 +19,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
public class MultiNodeTreePickerValueConverter : PropertyValueConverterBase
|
||||
{
|
||||
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
|
||||
private static readonly List<string> PropertiesToExclude = new List<string>
|
||||
{
|
||||
@@ -29,9 +27,10 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
Constants.Conventions.Content.Redirect.ToLower(CultureInfo.InvariantCulture)
|
||||
};
|
||||
|
||||
public MultiNodeTreePickerValueConverter(IPublishedSnapshotAccessor publishedSnapshotAccessor)
|
||||
public MultiNodeTreePickerValueConverter(IPublishedSnapshotAccessor publishedSnapshotAccessor, IUmbracoContextAccessor umbracoContextAccessor)
|
||||
{
|
||||
_publishedSnapshotAccessor = publishedSnapshotAccessor ?? throw new ArgumentNullException(nameof(publishedSnapshotAccessor));
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
}
|
||||
|
||||
public override bool IsConverter(IPublishedPropertyType propertyType)
|
||||
@@ -70,7 +69,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
}
|
||||
|
||||
// TODO: Inject an UmbracoHelper and create a GetUmbracoHelper method based on either injected or singleton
|
||||
if (Current.UmbracoContext != null)
|
||||
if (_umbracoContextAccessor.UmbracoContext != null)
|
||||
{
|
||||
if (propertyType.EditorAlias.Equals(Constants.PropertyEditors.Aliases.MultiNodeTreePicker))
|
||||
{
|
||||
+11
-5
@@ -1,5 +1,3 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -7,8 +5,10 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Serialization;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
{
|
||||
@@ -16,11 +16,17 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
{
|
||||
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
|
||||
private readonly IProfilingLogger _proflog;
|
||||
private readonly IJsonSerializer _jsonSerializer;
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
private readonly IPublishedUrlProvider _publishedUrlProvider;
|
||||
|
||||
public MultiUrlPickerValueConverter(IPublishedSnapshotAccessor publishedSnapshotAccessor, IProfilingLogger proflog)
|
||||
public MultiUrlPickerValueConverter(IPublishedSnapshotAccessor publishedSnapshotAccessor, IProfilingLogger proflog, IJsonSerializer jsonSerializer, IUmbracoContextAccessor umbracoContextAccessor, IPublishedUrlProvider publishedUrlProvider)
|
||||
{
|
||||
_publishedSnapshotAccessor = publishedSnapshotAccessor ?? throw new ArgumentNullException(nameof(publishedSnapshotAccessor));
|
||||
_proflog = proflog ?? throw new ArgumentNullException(nameof(proflog));
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_umbracoContextAccessor = umbracoContextAccessor;
|
||||
_publishedUrlProvider = publishedUrlProvider;
|
||||
}
|
||||
|
||||
public override bool IsConverter(IPublishedPropertyType propertyType) => Constants.PropertyEditors.Aliases.MultiUrlPicker.Equals(propertyType.EditorAlias);
|
||||
@@ -48,7 +54,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
}
|
||||
|
||||
var links = new List<Link>();
|
||||
var dtos = JsonConvert.DeserializeObject<IEnumerable<MultiUrlPickerValueEditor.LinkDto>>(inter.ToString());
|
||||
var dtos = _jsonSerializer.Deserialize<IEnumerable<MultiUrlPickerValueEditor.LinkDto>>(inter.ToString());
|
||||
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
@@ -69,7 +75,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
{
|
||||
continue;
|
||||
}
|
||||
url = content.Url();
|
||||
url = content.Url(_publishedUrlProvider);
|
||||
}
|
||||
|
||||
links.Add(
|
||||
-1
@@ -3,7 +3,6 @@ using System.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Templates;
|
||||
|
||||
namespace Umbraco.Web.PropertyEditors.ValueConverters
|
||||
@@ -21,7 +21,10 @@ using Umbraco.Core.Serialization;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Core.Sync;
|
||||
using Umbraco.Web.Models.PublishedContent;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
using Umbraco.Web.Services;
|
||||
using IntegerValidator = Umbraco.Core.PropertyEditors.Validators.IntegerValidator;
|
||||
|
||||
@@ -77,6 +80,11 @@ namespace Umbraco.Core.Runtime
|
||||
// properties and parameters derive from data editors
|
||||
composition.DataEditors()
|
||||
.Add(() => composition.TypeLoader.GetDataEditors());
|
||||
|
||||
composition.MediaUrlGenerators()
|
||||
.Add<FileUploadPropertyEditor>()
|
||||
.Add<ImageCropperPropertyEditor>();
|
||||
|
||||
composition.RegisterUnique<PropertyEditorCollection>();
|
||||
composition.RegisterUnique<ParameterEditorCollection>();
|
||||
|
||||
@@ -136,12 +144,17 @@ namespace Umbraco.Core.Runtime
|
||||
composition.RegisterUnique<IPublishedModelFactory, NoopPublishedModelFactory>();
|
||||
|
||||
// by default, register a noop rebuilder
|
||||
composition.RegisterUnique<IPublishedSnapshotRebuilder, PublishedSnapshotRebuilder>();
|
||||
composition.RegisterUnique<IPublishedSnapshotRebuilder, NoopPublishedSnapshotRebuilder>();
|
||||
|
||||
composition.SetCultureDictionaryFactory<DefaultCultureDictionaryFactory>();
|
||||
composition.Register(f => f.GetInstance<ICultureDictionaryFactory>().CreateDictionary(), Lifetime.Singleton);
|
||||
composition.RegisterUnique<UriUtility>();
|
||||
|
||||
// register the published snapshot accessor - the "current" published snapshot is in the umbraco context
|
||||
composition.RegisterUnique<IPublishedSnapshotAccessor, UmbracoContextPublishedSnapshotAccessor>();
|
||||
|
||||
composition.RegisterUnique<IVariationContextAccessor, HybridVariationContextAccessor>();
|
||||
|
||||
composition.RegisterUnique<IDashboardService, DashboardService>();
|
||||
|
||||
// register core CMS dashboards and 3rd party types - will be ordered by weight attribute & merged with package.manifest dashboards
|
||||
|
||||
@@ -10,6 +10,7 @@ using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Serialization;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Web;
|
||||
@@ -153,18 +154,18 @@ namespace Umbraco.Tests.Cache
|
||||
|
||||
};
|
||||
|
||||
var httpContextAccessor = TestHelper.GetHttpContextAccessor();
|
||||
|
||||
var umbracoContextFactory = new UmbracoContextFactory(
|
||||
new TestUmbracoContextAccessor(),
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new TestVariationContextAccessor(),
|
||||
new TestDefaultCultureAccessor(),
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
TestObjects.GetGlobalSettings(),
|
||||
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
|
||||
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
|
||||
Mock.Of<IUserService>(),
|
||||
IOHelper,
|
||||
UriUtility);
|
||||
UriUtility,
|
||||
httpContextAccessor);
|
||||
|
||||
// just assert it does not throw
|
||||
var refreshers = new DistributedCacheBinder(null, umbracoContextFactory, null);
|
||||
|
||||
@@ -74,13 +74,12 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
var publishedSnapshotService = new Mock<IPublishedSnapshotService>();
|
||||
publishedSnapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny<string>())).Returns(publishedShapshot);
|
||||
|
||||
var httpContext = _httpContextFactory.HttpContext;
|
||||
var httpContextAccessor = TestHelper.GetHttpContextAccessor(httpContext);
|
||||
_umbracoContext = new UmbracoContext(
|
||||
_httpContextFactory.HttpContext,
|
||||
httpContextAccessor,
|
||||
publishedSnapshotService.Object,
|
||||
new WebSecurity(_httpContextFactory.HttpContext, Mock.Of<IUserService>(), globalSettings, IOHelper),
|
||||
umbracoSettings,
|
||||
Enumerable.Empty<IUrlProvider>(),
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
new WebSecurity(httpContextAccessor, Mock.Of<IUserService>(), globalSettings, IOHelper),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper,
|
||||
|
||||
@@ -439,11 +439,6 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
return (IPublishedContent) appCache.Get(key, () => (new XmlPublishedContent(node, isPreviewing, appCache, contentTypeCache, variationContextAccessor)).CreateModel(Current.PublishedModelFactory));
|
||||
}
|
||||
|
||||
public static void ClearRequest()
|
||||
{
|
||||
Current.AppCaches.RequestCache.ClearByKey(CacheKeyPrefix);
|
||||
}
|
||||
|
||||
private const string CacheKeyPrefix = "CONTENTCACHE_XMLPUBLISHEDCONTENT_";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,8 +44,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
var entityRepository = new EntityRepository(scopeAccessor);
|
||||
var relationRepository = new RelationRepository(scopeAccessor, Logger, relationTypeRepository, entityRepository);
|
||||
var propertyEditors = new Lazy<PropertyEditorCollection>(() => new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<IDataEditor>())));
|
||||
var mediaUrlGenerators = new MediaUrlGeneratorCollection(Enumerable.Empty<IMediaUrlGenerator>());
|
||||
var dataValueReferences = new DataValueReferenceFactoryCollection(Enumerable.Empty<IDataValueReferenceFactory>());
|
||||
var repository = new MediaRepository(scopeAccessor, appCaches, Logger, mediaTypeRepository, tagRepository, Mock.Of<ILanguageRepository>(), relationRepository, relationTypeRepository, propertyEditors, dataValueReferences, DataTypeService);
|
||||
var repository = new MediaRepository(scopeAccessor, appCaches, Logger, mediaTypeRepository, tagRepository, Mock.Of<ILanguageRepository>(), relationRepository, relationTypeRepository, propertyEditors, mediaUrlGenerators, dataValueReferences, DataTypeService);
|
||||
return repository;
|
||||
}
|
||||
|
||||
|
||||
@@ -981,8 +981,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
var entityRepository = new EntityRepository(accessor);
|
||||
var relationRepository = new RelationRepository(accessor, Logger, relationTypeRepository, entityRepository);
|
||||
var propertyEditors = new Lazy<PropertyEditorCollection>(() => new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<IDataEditor>())));
|
||||
var mediaUrlGenerators = new MediaUrlGeneratorCollection(Enumerable.Empty<IMediaUrlGenerator>());
|
||||
var dataValueReferences = new DataValueReferenceFactoryCollection(Enumerable.Empty<IDataValueReferenceFactory>());
|
||||
var repository = new MediaRepository(accessor, AppCaches.Disabled, Logger, mediaTypeRepository, tagRepository, Mock.Of<ILanguageRepository>(), relationRepository, relationTypeRepository, propertyEditors, dataValueReferences, DataTypeService);
|
||||
var repository = new MediaRepository(accessor, AppCaches.Disabled, Logger, mediaTypeRepository, tagRepository, Mock.Of<ILanguageRepository>(), relationRepository, relationTypeRepository, propertyEditors, mediaUrlGenerators, dataValueReferences, DataTypeService);
|
||||
return repository;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
var entityRepository = new EntityRepository(accessor);
|
||||
var relationRepository = new RelationRepository(accessor, Logger, relationTypeRepository, entityRepository);
|
||||
var propertyEditors = new Lazy<PropertyEditorCollection>(() => new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<IDataEditor>())));
|
||||
var mediaUrlGenerators = new MediaUrlGeneratorCollection(Enumerable.Empty<IMediaUrlGenerator>());
|
||||
var dataValueReferences = new DataValueReferenceFactoryCollection(Enumerable.Empty<IDataValueReferenceFactory>());
|
||||
var repository = new MediaRepository(accessor, AppCaches, Mock.Of<ILogger>(), mediaTypeRepository, tagRepository, Mock.Of<ILanguageRepository>(), relationRepository, relationTypeRepository, propertyEditors, dataValueReferences, DataTypeService);
|
||||
var repository = new MediaRepository(accessor, AppCaches, Mock.Of<ILogger>(), mediaTypeRepository, tagRepository, Mock.Of<ILanguageRepository>(), relationRepository, relationTypeRepository, propertyEditors, mediaUrlGenerators, dataValueReferences, DataTypeService);
|
||||
return repository;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,13 +68,12 @@ namespace Umbraco.Tests.PublishedContent
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
|
||||
var httpContext = GetHttpContextFactory("http://umbraco.local/", routeData).HttpContext;
|
||||
|
||||
var httpContextAccessor = TestHelper.GetHttpContextAccessor(httpContext);
|
||||
var umbracoContext = new UmbracoContext(
|
||||
httpContext,
|
||||
httpContextAccessor,
|
||||
publishedSnapshotService.Object,
|
||||
new WebSecurity(httpContext, Current.Services.UserService, globalSettings, IOHelper),
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
Enumerable.Empty<IUrlProvider>(),
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
new WebSecurity(httpContextAccessor, Current.Services.UserService, globalSettings, IOHelper),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper,
|
||||
|
||||
@@ -15,6 +15,7 @@ using Umbraco.Core.Strings;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Templates;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
@@ -43,11 +44,12 @@ namespace Umbraco.Tests.PublishedContent
|
||||
|
||||
var converters = Factory.GetInstance<PropertyValueConverterCollection>();
|
||||
var umbracoContextAccessor = Mock.Of<IUmbracoContextAccessor>();
|
||||
var publishedUrlProvider = Mock.Of<IPublishedUrlProvider>();
|
||||
var logger = Mock.Of<ILogger>();
|
||||
|
||||
var imageSourceParser = new HtmlImageSourceParser(umbracoContextAccessor);
|
||||
var imageSourceParser = new HtmlImageSourceParser(publishedUrlProvider);
|
||||
var pastedImages = new RichTextEditorPastedImages(umbracoContextAccessor, logger, IOHelper, Mock.Of<IMediaService>(), Mock.Of<IContentTypeBaseServiceProvider>(), Mock.Of<IMediaFileSystem>(), ShortStringHelper);
|
||||
var localLinkParser = new HtmlLocalLinkParser(umbracoContextAccessor);
|
||||
var localLinkParser = new HtmlLocalLinkParser(umbracoContextAccessor, publishedUrlProvider);
|
||||
var dataTypeService = new TestObjects.TestDataTypeService(
|
||||
new DataType(new RichTextPropertyEditor(
|
||||
Mock.Of<ILogger>(),
|
||||
|
||||
@@ -23,6 +23,7 @@ using Umbraco.Web.Models.PublishedContent;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
using Umbraco.Web.Templates;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Routing;
|
||||
using Current = Umbraco.Web.Composing.Current;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
@@ -49,9 +50,10 @@ namespace Umbraco.Tests.PublishedContent
|
||||
var mediaFileService = Mock.Of<IMediaFileSystem>();
|
||||
var contentTypeBaseServiceProvider = Mock.Of<IContentTypeBaseServiceProvider>();
|
||||
var umbracoContextAccessor = Mock.Of<IUmbracoContextAccessor>();
|
||||
var imageSourceParser = new HtmlImageSourceParser(umbracoContextAccessor);
|
||||
var publishedUrlProvider = Mock.Of<IPublishedUrlProvider>();
|
||||
var imageSourceParser = new HtmlImageSourceParser(publishedUrlProvider);
|
||||
var pastedImages = new RichTextEditorPastedImages(umbracoContextAccessor, logger, IOHelper, mediaService, contentTypeBaseServiceProvider, mediaFileService, ShortStringHelper);
|
||||
var linkParser = new HtmlLocalLinkParser(umbracoContextAccessor);
|
||||
var linkParser = new HtmlLocalLinkParser(umbracoContextAccessor, publishedUrlProvider);
|
||||
var localizationService = Mock.Of<ILocalizationService>();
|
||||
|
||||
var dataTypeService = new TestObjects.TestDataTypeService(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
@@ -6,8 +7,12 @@ using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Tests.Routing
|
||||
@@ -55,7 +60,8 @@ namespace Umbraco.Tests.Routing
|
||||
GetLangService("en-US", "fr-FR"), GetTextService(), ServiceContext.ContentService,
|
||||
VariationContextAccessor,
|
||||
Logger,
|
||||
UriUtility).ToList();
|
||||
UriUtility,
|
||||
PublishedUrlProvider).ToList();
|
||||
|
||||
Assert.AreEqual(1, urls.Count);
|
||||
Assert.AreEqual("content/itemNotPublished", urls[0].Text);
|
||||
@@ -73,8 +79,18 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoSettings = Current.Configs.Settings();
|
||||
|
||||
var umbContext = GetUmbracoContext("http://localhost:8000",
|
||||
urlProviders: new []{ new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper(), UriUtility) });
|
||||
var umbContext = GetUmbracoContext("http://localhost:8000");
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbContext);
|
||||
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper(),
|
||||
umbracoContextAccessor, UriUtility);
|
||||
var publishedUrlProvider = new UrlProvider(
|
||||
umbracoContextAccessor,
|
||||
TestHelper.WebRoutingSection,
|
||||
new UrlProviderCollection(new []{urlProvider}),
|
||||
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
|
||||
Mock.Of<IVariationContextAccessor>()
|
||||
);
|
||||
|
||||
var publishedRouter = CreatePublishedRouter(Factory,
|
||||
contentFinders:new ContentFinderCollection(new[]{new ContentFinderByUrl(Logger) }));
|
||||
var urls = content.GetContentUrls(publishedRouter,
|
||||
@@ -82,7 +98,8 @@ namespace Umbraco.Tests.Routing
|
||||
GetLangService("en-US", "fr-FR"), GetTextService(), ServiceContext.ContentService,
|
||||
VariationContextAccessor,
|
||||
Logger,
|
||||
UriUtility).ToList();
|
||||
UriUtility,
|
||||
publishedUrlProvider).ToList();
|
||||
|
||||
Assert.AreEqual(1, urls.Count);
|
||||
Assert.AreEqual("/home/", urls[0].Text);
|
||||
@@ -107,8 +124,18 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoSettings = Current.Configs.Settings();
|
||||
|
||||
var umbContext = GetUmbracoContext("http://localhost:8000",
|
||||
urlProviders: new[] { new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper(), UriUtility) });
|
||||
|
||||
var umbContext = GetUmbracoContext("http://localhost:8000");
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbContext);
|
||||
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, TestObjects.GetGlobalSettings(), new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
|
||||
var publishedUrlProvider = new UrlProvider(
|
||||
umbracoContextAccessor,
|
||||
TestHelper.WebRoutingSection,
|
||||
new UrlProviderCollection(new []{urlProvider}),
|
||||
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
|
||||
Mock.Of<IVariationContextAccessor>()
|
||||
);
|
||||
|
||||
var publishedRouter = CreatePublishedRouter(Factory,
|
||||
contentFinders: new ContentFinderCollection(new[] { new ContentFinderByUrl(Logger) }));
|
||||
var urls = child.GetContentUrls(publishedRouter,
|
||||
@@ -116,7 +143,9 @@ namespace Umbraco.Tests.Routing
|
||||
GetLangService("en-US", "fr-FR"), GetTextService(), ServiceContext.ContentService,
|
||||
VariationContextAccessor,
|
||||
Logger,
|
||||
UriUtility).ToList();
|
||||
UriUtility,
|
||||
publishedUrlProvider
|
||||
).ToList();
|
||||
|
||||
Assert.AreEqual(1, urls.Count);
|
||||
Assert.AreEqual("/home/sub1/", urls[0].Text);
|
||||
|
||||
@@ -15,6 +15,8 @@ using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.PublishedContent;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
@@ -36,11 +38,11 @@ namespace Umbraco.Tests.Routing
|
||||
var dataTypeService = Mock.Of<IDataTypeService>();
|
||||
var umbracoSettingsSection = TestObjects.GetUmbracoSettings();
|
||||
|
||||
var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(new IDataEditor[]
|
||||
var propertyEditors = new MediaUrlGeneratorCollection(new IMediaUrlGenerator[]
|
||||
{
|
||||
new FileUploadPropertyEditor(logger, mediaFileSystemMock, contentSection, dataTypeService, LocalizationService, LocalizedTextService, ShortStringHelper, umbracoSettingsSection),
|
||||
new ImageCropperPropertyEditor(logger, mediaFileSystemMock, contentSection, dataTypeService, LocalizationService, IOHelper, ShortStringHelper, LocalizedTextService, umbracoSettingsSection),
|
||||
}));
|
||||
});
|
||||
_mediaUrlProvider = new DefaultMediaUrlProvider(propertyEditors, UriUtility);
|
||||
}
|
||||
|
||||
@@ -56,10 +58,10 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
const string expected = "/media/rfeiw584/test.jpg";
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/", mediaUrlProviders: new[] { _mediaUrlProvider });
|
||||
var umbracoContext = GetUmbracoContext("/");
|
||||
var publishedContent = CreatePublishedContent(Constants.PropertyEditors.Aliases.UploadField, expected, null);
|
||||
|
||||
var resolvedUrl = umbracoContext.UrlProvider.GetMediaUrl(publishedContent, UrlMode.Auto);
|
||||
var resolvedUrl = GetPublishedUrlProvider(umbracoContext).GetMediaUrl(publishedContent, UrlMode.Auto);
|
||||
|
||||
Assert.AreEqual(expected, resolvedUrl);
|
||||
}
|
||||
@@ -75,10 +77,10 @@ namespace Umbraco.Tests.Routing
|
||||
Src = expected
|
||||
});
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/", mediaUrlProviders: new[] { _mediaUrlProvider });
|
||||
var umbracoContext = GetUmbracoContext("/");
|
||||
var publishedContent = CreatePublishedContent(Constants.PropertyEditors.Aliases.ImageCropper, imageCropperValue, configuration);
|
||||
|
||||
var resolvedUrl = umbracoContext.UrlProvider.GetMediaUrl(publishedContent, UrlMode.Auto);
|
||||
var resolvedUrl = GetPublishedUrlProvider(umbracoContext).GetMediaUrl(publishedContent, UrlMode.Auto);
|
||||
|
||||
Assert.AreEqual(expected, resolvedUrl);
|
||||
}
|
||||
@@ -89,10 +91,10 @@ namespace Umbraco.Tests.Routing
|
||||
const string mediaUrl = "/media/rfeiw584/test.jpg";
|
||||
var expected = $"http://localhost{mediaUrl}";
|
||||
|
||||
var umbracoContext = GetUmbracoContext("http://localhost", mediaUrlProviders: new[] { _mediaUrlProvider });
|
||||
var umbracoContext = GetUmbracoContext("http://localhost");
|
||||
var publishedContent = CreatePublishedContent(Constants.PropertyEditors.Aliases.UploadField, mediaUrl, null);
|
||||
|
||||
var resolvedUrl = umbracoContext.UrlProvider.GetMediaUrl(publishedContent, UrlMode.Absolute);
|
||||
var resolvedUrl = GetPublishedUrlProvider(umbracoContext).GetMediaUrl(publishedContent, UrlMode.Absolute);
|
||||
|
||||
Assert.AreEqual(expected, resolvedUrl);
|
||||
}
|
||||
@@ -102,10 +104,10 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
const string expected = "http://localhost/media/rfeiw584/test.jpg";
|
||||
|
||||
var umbracoContext = GetUmbracoContext("http://localhost", mediaUrlProviders: new[] { _mediaUrlProvider });
|
||||
var umbracoContext = GetUmbracoContext("http://localhost");
|
||||
var publishedContent = CreatePublishedContent(Constants.PropertyEditors.Aliases.UploadField, expected, null);
|
||||
|
||||
var resolvedUrl = umbracoContext.UrlProvider.GetMediaUrl(publishedContent, UrlMode.Relative);
|
||||
var resolvedUrl = GetPublishedUrlProvider(umbracoContext).GetMediaUrl(publishedContent, UrlMode.Relative);
|
||||
|
||||
Assert.AreEqual(expected, resolvedUrl);
|
||||
}
|
||||
@@ -113,10 +115,10 @@ namespace Umbraco.Tests.Routing
|
||||
[Test]
|
||||
public void Get_Media_Url_Returns_Empty_String_When_PropertyType_Is_Not_Supported()
|
||||
{
|
||||
var umbracoContext = GetUmbracoContext("/", mediaUrlProviders: new[] { _mediaUrlProvider });
|
||||
var umbracoContext = GetUmbracoContext("/");
|
||||
var publishedContent = CreatePublishedContent(Constants.PropertyEditors.Aliases.Boolean, "0", null);
|
||||
|
||||
var resolvedUrl = umbracoContext.UrlProvider.GetMediaUrl(publishedContent, UrlMode.Absolute, propertyAlias: "test");
|
||||
var resolvedUrl = GetPublishedUrlProvider(umbracoContext).GetMediaUrl(publishedContent, UrlMode.Absolute, propertyAlias: "test");
|
||||
|
||||
Assert.AreEqual(string.Empty, resolvedUrl);
|
||||
}
|
||||
@@ -124,7 +126,7 @@ namespace Umbraco.Tests.Routing
|
||||
[Test]
|
||||
public void Get_Media_Url_Can_Resolve_Variant_Property_Url()
|
||||
{
|
||||
var umbracoContext = GetUmbracoContext("http://localhost", mediaUrlProviders: new[] { _mediaUrlProvider });
|
||||
var umbracoContext = GetUmbracoContext("http://localhost");
|
||||
|
||||
var umbracoFilePropertyType = CreatePropertyType(Constants.PropertyEditors.Aliases.UploadField, null, ContentVariation.Culture);
|
||||
|
||||
@@ -143,10 +145,21 @@ namespace Umbraco.Tests.Routing
|
||||
var contentType = new PublishedContentType(666, "alias", PublishedItemType.Content, Enumerable.Empty<string>(), new [] { umbracoFilePropertyType }, ContentVariation.Culture);
|
||||
var publishedContent = new SolidPublishedContent(contentType) {Properties = new[] {property}};
|
||||
|
||||
var resolvedUrl = umbracoContext.UrlProvider.GetMediaUrl(publishedContent, UrlMode.Auto, "da");
|
||||
var resolvedUrl = GetPublishedUrlProvider(umbracoContext).GetMediaUrl(publishedContent, UrlMode.Auto, "da");
|
||||
Assert.AreEqual(daMediaUrl, resolvedUrl);
|
||||
}
|
||||
|
||||
private IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext)
|
||||
{
|
||||
return new UrlProvider(
|
||||
new TestUmbracoContextAccessor(umbracoContext),
|
||||
TestHelper.WebRoutingSection,
|
||||
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
|
||||
new MediaUrlProviderCollection(new []{_mediaUrlProvider}),
|
||||
Mock.Of<IVariationContextAccessor>()
|
||||
);
|
||||
}
|
||||
|
||||
private static IPublishedContent CreatePublishedContent(string propertyEditorAlias, string propertyValue, object dataTypeConfiguration)
|
||||
{
|
||||
var umbracoFilePropertyType = CreatePropertyType(propertyEditorAlias, dataTypeConfiguration, ContentVariation.Nothing);
|
||||
|
||||
@@ -144,6 +144,7 @@ namespace Umbraco.Tests.Routing
|
||||
var routeData = new RouteData() {Route = route};
|
||||
var umbracoContext = GetUmbracoContext("~/dummy-page", template.Id, routeData, true);
|
||||
var httpContext = GetHttpContextFactory(url, routeData).HttpContext;
|
||||
var httpContextAccessor = TestHelper.GetHttpContextAccessor(httpContext);
|
||||
var publishedRouter = CreatePublishedRouter();
|
||||
var frequest = publishedRouter.CreateRequest(umbracoContext);
|
||||
frequest.PublishedContent = umbracoContext.Content.GetById(1172);
|
||||
@@ -156,7 +157,7 @@ namespace Umbraco.Tests.Routing
|
||||
var handler = new RenderRouteHandler(umbracoContext, new TestControllerFactory(umbracoContextAccessor, Mock.Of<ILogger>(), context =>
|
||||
{
|
||||
var membershipHelper = new MembershipHelper(
|
||||
httpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembersMembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>(), ShortStringHelper, Mock.Of<IEntityService>());
|
||||
httpContextAccessor, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembersMembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>(), ShortStringHelper, Mock.Of<IEntityService>());
|
||||
return new CustomDocumentController(Factory.GetInstance<IGlobalSettings>(),
|
||||
umbracoContextAccessor,
|
||||
Factory.GetInstance<ServiceContext>(),
|
||||
|
||||
@@ -43,7 +43,8 @@ namespace Umbraco.Tests.Routing
|
||||
null, // FIXME: PublishedRouter complexities...
|
||||
Mock.Of<IUmbracoContextFactory>(),
|
||||
new RoutableDocumentFilter(globalSettings, IOHelper),
|
||||
UriUtility
|
||||
UriUtility,
|
||||
AppCaches.RequestCache
|
||||
);
|
||||
|
||||
runtime.Level = RuntimeLevel.Run;
|
||||
|
||||
@@ -13,6 +13,8 @@ using Umbraco.Tests.LegacyXmlPublishedCache;
|
||||
using Umbraco.Tests.PublishedContent;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
@@ -22,6 +24,8 @@ namespace Umbraco.Tests.Routing
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)]
|
||||
public class UrlProviderTests : BaseWebTest
|
||||
{
|
||||
private IUmbracoContextAccessor UmbracoContextAccessor { get; } = new TestUmbracoContextAccessor();
|
||||
|
||||
protected override void Compose()
|
||||
{
|
||||
base.Compose();
|
||||
@@ -46,11 +50,12 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoSettings = Current.Configs.Settings();
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings: globalSettings.Object);
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: globalSettings.Object);
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
|
||||
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object,
|
||||
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
|
||||
|
||||
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
|
||||
var requestHandlerMock = Mock.Get(umbracoSettings.RequestHandler);
|
||||
requestHandlerMock.Setup(x => x.AddTrailingSlash).Returns(false);// (cached routes have none)
|
||||
|
||||
@@ -67,14 +72,14 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
foreach (var sample in samples)
|
||||
{
|
||||
var result = umbracoContext.UrlProvider.GetUrl(sample.Key);
|
||||
var result = publishedUrlProvider.GetUrl(sample.Key);
|
||||
Assert.AreEqual(sample.Value, result);
|
||||
}
|
||||
|
||||
var randomSample = new KeyValuePair<int, string>(1177, "/home/sub1/custom-sub-1");
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var result = umbracoContext.UrlProvider.GetUrl(randomSample.Key);
|
||||
var result = publishedUrlProvider.GetUrl(randomSample.Key);
|
||||
Assert.AreEqual(randomSample.Value, result);
|
||||
}
|
||||
|
||||
@@ -93,6 +98,17 @@ namespace Umbraco.Tests.Routing
|
||||
Assert.AreEqual(0, cachedIds.Count);
|
||||
}
|
||||
|
||||
private IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext, DefaultUrlProvider urlProvider)
|
||||
{
|
||||
return new UrlProvider(
|
||||
new TestUmbracoContextAccessor(umbracoContext),
|
||||
TestHelper.WebRoutingSection,
|
||||
new UrlProviderCollection(new []{urlProvider}),
|
||||
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
|
||||
Mock.Of<IVariationContextAccessor>()
|
||||
);
|
||||
}
|
||||
|
||||
// test hideTopLevelNodeFromPath false
|
||||
[TestCase(1046, "/home/")]
|
||||
[TestCase(1173, "/home/sub1/")]
|
||||
@@ -109,13 +125,14 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoSettings = Current.Configs.Settings();
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings: globalSettings.Object);
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: globalSettings.Object);
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
|
||||
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object,
|
||||
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
|
||||
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
|
||||
|
||||
var result = umbracoContext.UrlProvider.GetUrl(nodeId);
|
||||
var result = publishedUrlProvider.GetUrl(nodeId);
|
||||
Assert.AreEqual(niceUrlMatch, result);
|
||||
}
|
||||
|
||||
@@ -137,13 +154,14 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoSettings = Current.Configs.Settings();
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings: globalSettings.Object);
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings: globalSettings.Object);
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
|
||||
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object,
|
||||
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
|
||||
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
|
||||
|
||||
var result = umbracoContext.UrlProvider.GetUrl(nodeId);
|
||||
var result = publishedUrlProvider.GetUrl(nodeId);
|
||||
Assert.AreEqual(niceUrlMatch, result);
|
||||
}
|
||||
|
||||
@@ -177,15 +195,17 @@ namespace Umbraco.Tests.Routing
|
||||
snapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny<string>()))
|
||||
.Returns(snapshot);
|
||||
|
||||
var umbracoContext = GetUmbracoContext(currentUri, umbracoSettings: umbracoSettings,
|
||||
urlProviders: new[] {
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
},
|
||||
|
||||
var umbracoContext = GetUmbracoContext(currentUri,
|
||||
globalSettings: globalSettings.Object,
|
||||
snapshotService: snapshotService.Object);
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
|
||||
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object,
|
||||
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
|
||||
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
|
||||
|
||||
//even though we are asking for a specific culture URL, there are no domains assigned so all that can be returned is a normal relative url.
|
||||
var url = umbracoContext.UrlProvider.GetUrl(1234, culture: "fr-FR");
|
||||
var url = publishedUrlProvider.GetUrl(1234, culture: "fr-FR");
|
||||
|
||||
Assert.AreEqual("/home/test-fr/", url);
|
||||
}
|
||||
@@ -231,15 +251,17 @@ namespace Umbraco.Tests.Routing
|
||||
snapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny<string>()))
|
||||
.Returns(snapshot);
|
||||
|
||||
var umbracoContext = GetUmbracoContext(currentUri, umbracoSettings: umbracoSettings,
|
||||
urlProviders: new[] {
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
},
|
||||
|
||||
var umbracoContext = GetUmbracoContext(currentUri,
|
||||
globalSettings: globalSettings.Object,
|
||||
snapshotService: snapshotService.Object);
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
|
||||
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object,
|
||||
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
|
||||
|
||||
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
|
||||
|
||||
var url = umbracoContext.UrlProvider.GetUrl(1234, culture: "fr-FR");
|
||||
var url = publishedUrlProvider.GetUrl(1234, culture: "fr-FR");
|
||||
|
||||
Assert.AreEqual("/home/test-fr/", url);
|
||||
}
|
||||
@@ -285,15 +307,16 @@ namespace Umbraco.Tests.Routing
|
||||
snapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny<string>()))
|
||||
.Returns(snapshot);
|
||||
|
||||
var umbracoContext = GetUmbracoContext(currentUri, umbracoSettings: umbracoSettings,
|
||||
urlProviders: new[] {
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
},
|
||||
var umbracoContext = GetUmbracoContext(currentUri,
|
||||
globalSettings: globalSettings.Object,
|
||||
snapshotService: snapshotService.Object);
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
|
||||
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object,
|
||||
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
|
||||
|
||||
|
||||
var url = umbracoContext.UrlProvider.GetUrl(1234, culture: "fr-FR");
|
||||
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
|
||||
var url = publishedUrlProvider.GetUrl(1234, culture: "fr-FR");
|
||||
|
||||
//the current uri is not the culture specific domain we want, so the result is an absolute path to the culture specific domain
|
||||
Assert.AreEqual("http://example.fr/home/test-fr/", url);
|
||||
@@ -307,15 +330,17 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoSettings = Current.Configs.Settings();
|
||||
|
||||
var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, umbracoSettings: umbracoSettings, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings: globalSettings.Object);
|
||||
|
||||
Assert.AreEqual("/home/sub1/custom-sub-1/", umbracoContext.UrlProvider.GetUrl(1177));
|
||||
var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: globalSettings.Object);
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
|
||||
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object,
|
||||
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
|
||||
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
|
||||
|
||||
umbracoContext.UrlProvider.Mode = UrlMode.Absolute;
|
||||
Assert.AreEqual("http://example.com/home/sub1/custom-sub-1/", umbracoContext.UrlProvider.GetUrl(1177));
|
||||
Assert.AreEqual("/home/sub1/custom-sub-1/", publishedUrlProvider.GetUrl(1177));
|
||||
|
||||
publishedUrlProvider.Mode = UrlMode.Absolute;
|
||||
Assert.AreEqual("http://example.com/home/sub1/custom-sub-1/", publishedUrlProvider.GetUrl(1177));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -326,18 +351,18 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
var umbracoSettings = Current.Configs.Settings();
|
||||
|
||||
var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings: globalSettings.Object);
|
||||
var urlProvider = new DefaultUrlProvider(umbracoSettings.RequestHandler, Logger, globalSettings.Object,
|
||||
new SiteDomainHelper(), UmbracoContextAccessor, UriUtility);
|
||||
var umbracoContext = GetUmbracoContext("http://example.com/test", 1111, globalSettings: globalSettings.Object);
|
||||
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
|
||||
|
||||
//mock the Umbraco settings that we need
|
||||
|
||||
Assert.AreEqual("#", umbracoContext.UrlProvider.GetUrl(999999));
|
||||
Assert.AreEqual("#", publishedUrlProvider.GetUrl(999999));
|
||||
|
||||
umbracoContext.UrlProvider.Mode = UrlMode.Absolute;
|
||||
publishedUrlProvider.Mode = UrlMode.Absolute;
|
||||
|
||||
Assert.AreEqual("#", umbracoContext.UrlProvider.GetUrl(999999));
|
||||
Assert.AreEqual("#", publishedUrlProvider.GetUrl(999999));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@ using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.LegacyXmlPublishedCache;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Tests.Routing
|
||||
@@ -18,6 +19,7 @@ namespace Umbraco.Tests.Routing
|
||||
[TestFixture]
|
||||
public class UrlsProviderWithDomainsTests : UrlRoutingTestBase
|
||||
{
|
||||
private IUmbracoContextAccessor UmbracoContextAccessor { get; } = new TestUmbracoContextAccessor();
|
||||
protected override void Compose()
|
||||
{
|
||||
base.Compose();
|
||||
@@ -181,16 +183,17 @@ namespace Umbraco.Tests.Routing
|
||||
var globalSettings = Mock.Get(Factory.GetInstance<IGlobalSettings>()); //this will modify the IGlobalSettings instance stored in the container
|
||||
globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, umbracoSettings: settings, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings:globalSettings.Object);
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings:globalSettings.Object);
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
|
||||
var urlProvider = new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object,
|
||||
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
|
||||
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
|
||||
|
||||
SetDomains1();
|
||||
|
||||
var currentUri = new Uri(currentUrl);
|
||||
var mode = absolute ? UrlMode.Absolute : UrlMode.Auto;
|
||||
var result = umbracoContext.UrlProvider.GetUrl(nodeId, mode, current: currentUri);
|
||||
var result = publishedUrlProvider.GetUrl(nodeId, mode, current: currentUri);
|
||||
Assert.AreEqual(expected, result);
|
||||
}
|
||||
|
||||
@@ -214,16 +217,17 @@ namespace Umbraco.Tests.Routing
|
||||
var globalSettings = Mock.Get(Factory.GetInstance<IGlobalSettings>()); //this will modify the IGlobalSettings instance stored in the container
|
||||
globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, umbracoSettings: settings, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings:globalSettings.Object);
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings:globalSettings.Object);
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
|
||||
var urlProvider = new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object,
|
||||
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
|
||||
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
|
||||
|
||||
SetDomains2();
|
||||
|
||||
var currentUri = new Uri(currentUrl);
|
||||
var mode = absolute ? UrlMode.Absolute : UrlMode.Auto;
|
||||
var result = umbracoContext.UrlProvider.GetUrl(nodeId, mode, current : currentUri);
|
||||
var result = publishedUrlProvider.GetUrl(nodeId, mode, current : currentUri);
|
||||
Assert.AreEqual(expected, result);
|
||||
}
|
||||
|
||||
@@ -239,16 +243,17 @@ namespace Umbraco.Tests.Routing
|
||||
var globalSettings = Mock.Get(Factory.GetInstance<IGlobalSettings>()); //this will modify the IGlobalSettings instance stored in the container
|
||||
globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, umbracoSettings: settings, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings:globalSettings.Object);
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings:globalSettings.Object);
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
|
||||
var urlProvider = new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object,
|
||||
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
|
||||
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
|
||||
|
||||
SetDomains3();
|
||||
|
||||
var currentUri = new Uri(currentUrl);
|
||||
var mode = absolute ? UrlMode.Absolute : UrlMode.Auto;
|
||||
var result = umbracoContext.UrlProvider.GetUrl(nodeId, mode, current : currentUri);
|
||||
var result = publishedUrlProvider.GetUrl(nodeId, mode, current : currentUri);
|
||||
Assert.AreEqual(expected, result);
|
||||
}
|
||||
|
||||
@@ -270,16 +275,17 @@ namespace Umbraco.Tests.Routing
|
||||
var globalSettings = Mock.Get(Factory.GetInstance<IGlobalSettings>()); //this will modify the IGlobalSettings instance stored in the container
|
||||
globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, umbracoSettings: settings, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings:globalSettings.Object);
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings:globalSettings.Object);
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
|
||||
var urlProvider = new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object,
|
||||
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
|
||||
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
|
||||
|
||||
SetDomains4();
|
||||
|
||||
var currentUri = new Uri(currentUrl);
|
||||
var mode = absolute ? UrlMode.Absolute : UrlMode.Auto;
|
||||
var result = umbracoContext.UrlProvider.GetUrl(nodeId, mode, current : currentUri);
|
||||
var result = publishedUrlProvider.GetUrl(nodeId, mode, current : currentUri);
|
||||
Assert.AreEqual(expected, result);
|
||||
}
|
||||
|
||||
@@ -291,25 +297,26 @@ namespace Umbraco.Tests.Routing
|
||||
var globalSettings = Mock.Get(Factory.GetInstance<IGlobalSettings>()); //this will modify the IGlobalSettings instance stored in the container
|
||||
globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, umbracoSettings: settings, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings:globalSettings.Object);
|
||||
var umbracoContext = GetUmbracoContext("/test", 1111, globalSettings:globalSettings.Object);
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
|
||||
var urlProvider = new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object,
|
||||
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
|
||||
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
|
||||
|
||||
SetDomains4();
|
||||
|
||||
string ignore;
|
||||
ignore = umbracoContext.UrlProvider.GetUrl(1001, UrlMode.Auto, current: new Uri("http://domain1.com"));
|
||||
ignore = umbracoContext.UrlProvider.GetUrl(10011, UrlMode.Auto, current: new Uri("http://domain1.com"));
|
||||
ignore = umbracoContext.UrlProvider.GetUrl(100111, UrlMode.Auto, current: new Uri("http://domain1.com"));
|
||||
ignore = umbracoContext.UrlProvider.GetUrl(10012, UrlMode.Auto, current: new Uri("http://domain1.com"));
|
||||
ignore = umbracoContext.UrlProvider.GetUrl(100121, UrlMode.Auto, current: new Uri("http://domain1.com"));
|
||||
ignore = umbracoContext.UrlProvider.GetUrl(10013, UrlMode.Auto, current: new Uri("http://domain1.com"));
|
||||
ignore = umbracoContext.UrlProvider.GetUrl(1002, UrlMode.Auto, current: new Uri("http://domain1.com"));
|
||||
ignore = umbracoContext.UrlProvider.GetUrl(1001, UrlMode.Auto, current: new Uri("http://domain2.com"));
|
||||
ignore = umbracoContext.UrlProvider.GetUrl(10011, UrlMode.Auto, current: new Uri("http://domain2.com"));
|
||||
ignore = umbracoContext.UrlProvider.GetUrl(100111, UrlMode.Auto, current: new Uri("http://domain2.com"));
|
||||
ignore = umbracoContext.UrlProvider.GetUrl(1002, UrlMode.Auto, current: new Uri("http://domain2.com"));
|
||||
ignore = publishedUrlProvider.GetUrl(1001, UrlMode.Auto, current: new Uri("http://domain1.com"));
|
||||
ignore = publishedUrlProvider.GetUrl(10011, UrlMode.Auto, current: new Uri("http://domain1.com"));
|
||||
ignore = publishedUrlProvider.GetUrl(100111, UrlMode.Auto, current: new Uri("http://domain1.com"));
|
||||
ignore = publishedUrlProvider.GetUrl(10012, UrlMode.Auto, current: new Uri("http://domain1.com"));
|
||||
ignore = publishedUrlProvider.GetUrl(100121, UrlMode.Auto, current: new Uri("http://domain1.com"));
|
||||
ignore = publishedUrlProvider.GetUrl(10013, UrlMode.Auto, current: new Uri("http://domain1.com"));
|
||||
ignore = publishedUrlProvider.GetUrl(1002, UrlMode.Auto, current: new Uri("http://domain1.com"));
|
||||
ignore = publishedUrlProvider.GetUrl(1001, UrlMode.Auto, current: new Uri("http://domain2.com"));
|
||||
ignore = publishedUrlProvider.GetUrl(10011, UrlMode.Auto, current: new Uri("http://domain2.com"));
|
||||
ignore = publishedUrlProvider.GetUrl(100111, UrlMode.Auto, current: new Uri("http://domain2.com"));
|
||||
ignore = publishedUrlProvider.GetUrl(1002, UrlMode.Auto, current: new Uri("http://domain2.com"));
|
||||
|
||||
var cache = umbracoContext.Content as PublishedContentCache;
|
||||
if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported.");
|
||||
@@ -328,15 +335,15 @@ namespace Umbraco.Tests.Routing
|
||||
CheckRoute(cachedRoutes, cachedIds, 1002, "/1002");
|
||||
|
||||
// use the cache
|
||||
Assert.AreEqual("/", umbracoContext.UrlProvider.GetUrl(1001, UrlMode.Auto, current: new Uri("http://domain1.com")));
|
||||
Assert.AreEqual("/en/", umbracoContext.UrlProvider.GetUrl(10011, UrlMode.Auto, current: new Uri("http://domain1.com")));
|
||||
Assert.AreEqual("/en/1001-1-1/", umbracoContext.UrlProvider.GetUrl(100111, UrlMode.Auto, current: new Uri("http://domain1.com")));
|
||||
Assert.AreEqual("/fr/", umbracoContext.UrlProvider.GetUrl(10012, UrlMode.Auto, current: new Uri("http://domain1.com")));
|
||||
Assert.AreEqual("/fr/1001-2-1/", umbracoContext.UrlProvider.GetUrl(100121, UrlMode.Auto, current: new Uri("http://domain1.com")));
|
||||
Assert.AreEqual("/1001-3/", umbracoContext.UrlProvider.GetUrl(10013, UrlMode.Auto, current: new Uri("http://domain1.com")));
|
||||
Assert.AreEqual("/1002/", umbracoContext.UrlProvider.GetUrl(1002, UrlMode.Auto, current: new Uri("http://domain1.com")));
|
||||
Assert.AreEqual("/", publishedUrlProvider.GetUrl(1001, UrlMode.Auto, current: new Uri("http://domain1.com")));
|
||||
Assert.AreEqual("/en/", publishedUrlProvider.GetUrl(10011, UrlMode.Auto, current: new Uri("http://domain1.com")));
|
||||
Assert.AreEqual("/en/1001-1-1/", publishedUrlProvider.GetUrl(100111, UrlMode.Auto, current: new Uri("http://domain1.com")));
|
||||
Assert.AreEqual("/fr/", publishedUrlProvider.GetUrl(10012, UrlMode.Auto, current: new Uri("http://domain1.com")));
|
||||
Assert.AreEqual("/fr/1001-2-1/", publishedUrlProvider.GetUrl(100121, UrlMode.Auto, current: new Uri("http://domain1.com")));
|
||||
Assert.AreEqual("/1001-3/", publishedUrlProvider.GetUrl(10013, UrlMode.Auto, current: new Uri("http://domain1.com")));
|
||||
Assert.AreEqual("/1002/", publishedUrlProvider.GetUrl(1002, UrlMode.Auto, current: new Uri("http://domain1.com")));
|
||||
|
||||
Assert.AreEqual("http://domain1.com/fr/1001-2-1/", umbracoContext.UrlProvider.GetUrl(100121, UrlMode.Auto, current: new Uri("http://domain2.com")));
|
||||
Assert.AreEqual("http://domain1.com/fr/1001-2-1/", publishedUrlProvider.GetUrl(100121, UrlMode.Auto, current: new Uri("http://domain2.com")));
|
||||
}
|
||||
|
||||
private static void CheckRoute(IDictionary<int, string> routes, IDictionary<string, int> ids, int id, string route)
|
||||
@@ -354,20 +361,21 @@ namespace Umbraco.Tests.Routing
|
||||
var globalSettings = Mock.Get(Factory.GetInstance<IGlobalSettings>()); //this will modify the IGlobalSettings instance stored in the container
|
||||
globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains
|
||||
|
||||
var umbracoContext = GetUmbracoContext("http://domain1.com/test", 1111, umbracoSettings: settings, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings:globalSettings.Object);
|
||||
var umbracoContext = GetUmbracoContext("http://domain1.com/test", 1111, globalSettings:globalSettings.Object);
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
|
||||
var urlProvider = new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object,
|
||||
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
|
||||
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
|
||||
|
||||
SetDomains4();
|
||||
|
||||
Assert.AreEqual("/en/1001-1-1/", umbracoContext.UrlProvider.GetUrl(100111));
|
||||
Assert.AreEqual("http://domain3.com/en/1003-1-1/", umbracoContext.UrlProvider.GetUrl(100311));
|
||||
Assert.AreEqual("/en/1001-1-1/", publishedUrlProvider.GetUrl(100111));
|
||||
Assert.AreEqual("http://domain3.com/en/1003-1-1/", publishedUrlProvider.GetUrl(100311));
|
||||
|
||||
umbracoContext.UrlProvider.Mode = UrlMode.Absolute;
|
||||
publishedUrlProvider.Mode = UrlMode.Absolute;
|
||||
|
||||
Assert.AreEqual("http://domain1.com/en/1001-1-1/", umbracoContext.UrlProvider.GetUrl(100111));
|
||||
Assert.AreEqual("http://domain3.com/en/1003-1-1/", umbracoContext.UrlProvider.GetUrl(100311));
|
||||
Assert.AreEqual("http://domain1.com/en/1001-1-1/", publishedUrlProvider.GetUrl(100111));
|
||||
Assert.AreEqual("http://domain3.com/en/1003-1-1/", publishedUrlProvider.GetUrl(100311));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -378,17 +386,18 @@ namespace Umbraco.Tests.Routing
|
||||
var globalSettings = Mock.Get(Factory.GetInstance<IGlobalSettings>()); //this will modify the IGlobalSettings instance stored in the container
|
||||
globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false); // ignored w/domains
|
||||
|
||||
var umbracoContext = GetUmbracoContext("http://domain1.com/en/test", 1111, umbracoSettings: settings, urlProviders: new[]
|
||||
{
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings:globalSettings.Object);
|
||||
var umbracoContext = GetUmbracoContext("http://domain1.com/en/test", 1111, globalSettings:globalSettings.Object);
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
|
||||
var urlProvider = new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object,
|
||||
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
|
||||
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
|
||||
|
||||
SetDomains5();
|
||||
|
||||
var url = umbracoContext.UrlProvider.GetUrl(100111, UrlMode.Absolute);
|
||||
var url = publishedUrlProvider.GetUrl(100111, UrlMode.Absolute);
|
||||
Assert.AreEqual("http://domain1.com/en/1001-1-1/", url);
|
||||
|
||||
var result = umbracoContext.UrlProvider.GetOtherUrls(100111).ToArray();
|
||||
var result = publishedUrlProvider.GetOtherUrls(100111).ToArray();
|
||||
|
||||
foreach (var x in result) Console.WriteLine(x);
|
||||
|
||||
@@ -396,5 +405,16 @@ namespace Umbraco.Tests.Routing
|
||||
Assert.AreEqual(result[0].Text, "http://domain1b.com/en/1001-1-1/");
|
||||
Assert.AreEqual(result[1].Text, "http://domain1a.com/en/1001-1-1/");
|
||||
}
|
||||
|
||||
private IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext, DefaultUrlProvider urlProvider)
|
||||
{
|
||||
return new UrlProvider(
|
||||
new TestUmbracoContextAccessor(umbracoContext),
|
||||
TestHelper.WebRoutingSection,
|
||||
new UrlProviderCollection(new []{urlProvider}),
|
||||
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
|
||||
Mock.Of<IVariationContextAccessor>()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
@@ -10,6 +10,8 @@ using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.LegacyXmlPublishedCache;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Web;
|
||||
|
||||
namespace Umbraco.Tests.Routing
|
||||
{
|
||||
@@ -41,11 +43,13 @@ namespace Umbraco.Tests.Routing
|
||||
const string url = "http://domain1.com/1001-1/1001-1-1";
|
||||
|
||||
// get the nice url for 100111
|
||||
var umbracoContext = GetUmbracoContext(url, 9999, umbracoSettings: settings, urlProviders: new []
|
||||
{
|
||||
new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper(), UriUtility)
|
||||
}, globalSettings:globalSettings.Object);
|
||||
Assert.AreEqual("http://domain2.com/1001-1-1/", umbracoContext.UrlProvider.GetUrl(100111, UrlMode.Absolute));
|
||||
var umbracoContext = GetUmbracoContext(url, 9999, globalSettings:globalSettings.Object);
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor(umbracoContext);
|
||||
var urlProvider = new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object,
|
||||
new SiteDomainHelper(), umbracoContextAccessor, UriUtility);
|
||||
var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);
|
||||
|
||||
Assert.AreEqual("http://domain2.com/1001-1-1/", publishedUrlProvider.GetUrl(100111, UrlMode.Absolute));
|
||||
|
||||
// check that the proper route has been cached
|
||||
var cache = umbracoContext.Content as PublishedContentCache;
|
||||
@@ -72,10 +76,15 @@ namespace Umbraco.Tests.Routing
|
||||
//Assert.AreEqual("1001/1001-1/1001-1-1", cachedRoutes[100111]); // yes
|
||||
|
||||
// what's the nice url now?
|
||||
Assert.AreEqual("http://domain2.com/1001-1-1/", umbracoContext.UrlProvider.GetUrl(100111)); // good
|
||||
Assert.AreEqual("http://domain2.com/1001-1-1/", publishedUrlProvider.GetUrl(100111)); // good
|
||||
//Assert.AreEqual("http://domain1.com/1001-1/1001-1-1", routingContext.NiceUrlProvider.GetNiceUrl(100111, true)); // bad
|
||||
}
|
||||
|
||||
private IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext, object urlProvider)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void SetDomains1()
|
||||
{
|
||||
SetupDomainServiceMock(new[]
|
||||
@@ -86,6 +95,17 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
}
|
||||
|
||||
private IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext, DefaultUrlProvider urlProvider)
|
||||
{
|
||||
return new UrlProvider(
|
||||
new TestUmbracoContextAccessor(umbracoContext),
|
||||
TestHelper.WebRoutingSection,
|
||||
new UrlProviderCollection(new []{urlProvider}),
|
||||
new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>()),
|
||||
Mock.Of<IVariationContextAccessor>()
|
||||
);
|
||||
}
|
||||
|
||||
protected override string GetXmlContent(int templateId)
|
||||
{
|
||||
return @"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
|
||||
@@ -193,10 +193,8 @@ namespace Umbraco.Tests.Runtimes
|
||||
Assert.AreEqual("test", content.Name);
|
||||
|
||||
// need an UmbracoCOntext to access the cache
|
||||
// FIXME: not exactly pretty, should not depend on HttpContext
|
||||
var httpContext = Mock.Of<HttpContextBase>();
|
||||
var umbracoContextFactory = factory.GetInstance<IUmbracoContextFactory>();
|
||||
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(httpContext);
|
||||
var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext();
|
||||
var umbracoContext = umbracoContextReference.UmbracoContext;
|
||||
|
||||
// assert that there is no published document
|
||||
|
||||
@@ -117,15 +117,12 @@ namespace Umbraco.Tests.Scoping
|
||||
var service = PublishedSnapshotService as PublishedSnapshotService;
|
||||
|
||||
var httpContext = GetHttpContextFactory(url, routeData).HttpContext;
|
||||
|
||||
var httpContextAccessor = TestHelper.GetHttpContextAccessor(httpContext);
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
var umbracoContext = new UmbracoContext(
|
||||
httpContext,
|
||||
httpContextAccessor,
|
||||
service,
|
||||
new WebSecurity(httpContext, Current.Services.UserService, globalSettings, IOHelper),
|
||||
umbracoSettings ?? SettingsForTests.GetDefaultUmbracoSettings(),
|
||||
urlProviders ?? Enumerable.Empty<IUrlProvider>(),
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
new WebSecurity(httpContextAccessor, Current.Services.UserService, globalSettings, IOHelper),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper,
|
||||
|
||||
@@ -7,8 +7,8 @@ using Microsoft.Owin;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Web;
|
||||
@@ -29,17 +29,19 @@ namespace Umbraco.Tests.Security
|
||||
//should force app ctx to show not-configured
|
||||
ConfigurationManager.AppSettings.Set(Constants.AppSettings.ConfigurationStatus, "");
|
||||
|
||||
var httpContextAccessor = TestHelper.GetHttpContextAccessor();
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
var umbracoContext = new UmbracoContext(
|
||||
Mock.Of<HttpContextBase>(),
|
||||
httpContextAccessor,
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, globalSettings, IOHelper),
|
||||
TestObjects.GetUmbracoSettings(), new List<IUrlProvider>(), Enumerable.Empty<IMediaUrlProvider>(), globalSettings,
|
||||
new TestVariationContextAccessor(), IOHelper, UriUtility);
|
||||
new WebSecurity(httpContextAccessor, Current.Services.UserService, globalSettings, IOHelper), globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper,
|
||||
UriUtility);
|
||||
|
||||
var runtime = Mock.Of<IRuntimeState>(x => x.Level == RuntimeLevel.Install);
|
||||
var mgr = new BackOfficeCookieManager(
|
||||
Mock.Of<IUmbracoContextAccessor>(accessor => accessor.UmbracoContext == umbracoContext), runtime, TestObjects.GetGlobalSettings(), TestHelper.IOHelper);
|
||||
Mock.Of<IUmbracoContextAccessor>(accessor => accessor.UmbracoContext == umbracoContext), runtime, TestObjects.GetGlobalSettings(), IOHelper, AppCaches.RequestCache);
|
||||
|
||||
var result = mgr.ShouldAuthenticateRequest(Mock.Of<IOwinContext>(), new Uri("http://localhost/umbraco"));
|
||||
|
||||
@@ -49,16 +51,19 @@ namespace Umbraco.Tests.Security
|
||||
[Test]
|
||||
public void ShouldAuthenticateRequest_When_Configured()
|
||||
{
|
||||
var httpContextAccessor = TestHelper.GetHttpContextAccessor();
|
||||
var globalSettings = TestObjects.GetGlobalSettings();
|
||||
var umbCtx = new UmbracoContext(
|
||||
Mock.Of<HttpContextBase>(),
|
||||
httpContextAccessor,
|
||||
Mock.Of<IPublishedSnapshotService>(),
|
||||
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, globalSettings, IOHelper),
|
||||
TestObjects.GetUmbracoSettings(), new List<IUrlProvider>(), Enumerable.Empty<IMediaUrlProvider>(), globalSettings,
|
||||
new TestVariationContextAccessor(), IOHelper, UriUtility);
|
||||
new WebSecurity(httpContextAccessor, Current.Services.UserService, globalSettings, IOHelper),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper,
|
||||
UriUtility);
|
||||
|
||||
var runtime = Mock.Of<IRuntimeState>(x => x.Level == RuntimeLevel.Run);
|
||||
var mgr = new BackOfficeCookieManager(Mock.Of<IUmbracoContextAccessor>(accessor => accessor.UmbracoContext == umbCtx), runtime, TestObjects.GetGlobalSettings(), TestHelper.IOHelper);
|
||||
var mgr = new BackOfficeCookieManager(Mock.Of<IUmbracoContextAccessor>(accessor => accessor.UmbracoContext == umbCtx), runtime, TestObjects.GetGlobalSettings(), IOHelper, AppCaches.RequestCache);
|
||||
|
||||
var request = new Mock<OwinRequest>();
|
||||
request.Setup(owinRequest => owinRequest.Uri).Returns(new Uri("http://localhost/umbraco"));
|
||||
|
||||
@@ -20,6 +20,7 @@ using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Core.Sync;
|
||||
using Umbraco.Tests.Strings;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
|
||||
@@ -13,6 +13,7 @@ using System.Linq;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core;
|
||||
using System.Diagnostics;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
|
||||
namespace Umbraco.Tests.Templates
|
||||
{
|
||||
@@ -28,8 +29,7 @@ namespace Umbraco.Tests.Templates
|
||||
</div>
|
||||
</p><p><img src='/media/234234.jpg' data-udi=""umb://media-type/B726D735E4C446D58F703F3FBCFC97A5"" /></p>";
|
||||
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
var imageSourceParser = new HtmlImageSourceParser(umbracoContextAccessor);
|
||||
var imageSourceParser = new HtmlImageSourceParser(Mock.Of<IPublishedUrlProvider>());
|
||||
|
||||
var result = imageSourceParser.FindUdisFromDataAttributes(input).ToList();
|
||||
Assert.AreEqual(2, result.Count);
|
||||
@@ -40,8 +40,7 @@ namespace Umbraco.Tests.Templates
|
||||
[Test]
|
||||
public void Remove_Image_Sources()
|
||||
{
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
var imageSourceParser = new HtmlImageSourceParser(umbracoContextAccessor);
|
||||
var imageSourceParser = new HtmlImageSourceParser(Mock.Of<IPublishedUrlProvider>());
|
||||
|
||||
var result = imageSourceParser.RemoveImageSources(@"<p>
|
||||
<div>
|
||||
@@ -69,21 +68,27 @@ namespace Umbraco.Tests.Templates
|
||||
var media = new Mock<IPublishedContent>();
|
||||
media.Setup(x => x.ContentType).Returns(mediaType);
|
||||
var mediaUrlProvider = new Mock<IMediaUrlProvider>();
|
||||
mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny<IUmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<string>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny<IPublishedContent>(), It.IsAny<string>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
.Returns(UrlInfo.Url("/media/1001/my-image.jpg"));
|
||||
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
|
||||
var umbracoContextFactory = TestUmbracoContextFactory.Create(
|
||||
mediaUrlProvider: mediaUrlProvider.Object,
|
||||
umbracoContextAccessor: umbracoContextAccessor);
|
||||
|
||||
using (var reference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>()))
|
||||
|
||||
var publishedUrlProvider = new UrlProvider(umbracoContextAccessor,
|
||||
TestHelper.WebRoutingSection,
|
||||
new UrlProviderCollection(Enumerable.Empty<IUrlProvider>()),
|
||||
new MediaUrlProviderCollection(new []{mediaUrlProvider.Object}),
|
||||
Mock.Of<IVariationContextAccessor>()
|
||||
);
|
||||
using (var reference = umbracoContextFactory.EnsureUmbracoContext())
|
||||
{
|
||||
var mediaCache = Mock.Get(reference.UmbracoContext.Media);
|
||||
mediaCache.Setup(x => x.GetById(It.IsAny<Guid>())).Returns(media.Object);
|
||||
|
||||
var imageSourceParser = new HtmlImageSourceParser(umbracoContextAccessor);
|
||||
var imageSourceParser = new HtmlImageSourceParser(publishedUrlProvider);
|
||||
|
||||
var result = imageSourceParser.EnsureImageSources(@"<p>
|
||||
<div>
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Web;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing.Objects;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Web;
|
||||
@@ -30,7 +31,7 @@ namespace Umbraco.Tests.Templates
|
||||
</p>";
|
||||
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
var parser = new HtmlLocalLinkParser(umbracoContextAccessor);
|
||||
var parser = new HtmlLocalLinkParser(umbracoContextAccessor, Mock.Of<IPublishedUrlProvider>());
|
||||
|
||||
var result = parser.FindUdisFromLocalLinks(input).ToList();
|
||||
|
||||
@@ -52,7 +53,7 @@ namespace Umbraco.Tests.Templates
|
||||
//setup a mock url provider which we'll use for testing
|
||||
var contentUrlProvider = new Mock<IUrlProvider>();
|
||||
contentUrlProvider
|
||||
.Setup(x => x.GetUrl(It.IsAny<IUmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
.Setup(x => x.GetUrl( It.IsAny<IPublishedContent>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
.Returns(UrlInfo.Url("/my-test-url"));
|
||||
var contentType = new PublishedContentType(666, "alias", PublishedItemType.Content, Enumerable.Empty<string>(), Enumerable.Empty<PublishedPropertyType>(), ContentVariation.Nothing);
|
||||
var publishedContent = new Mock<IPublishedContent>();
|
||||
@@ -63,17 +64,21 @@ namespace Umbraco.Tests.Templates
|
||||
var media = new Mock<IPublishedContent>();
|
||||
media.Setup(x => x.ContentType).Returns(mediaType);
|
||||
var mediaUrlProvider = new Mock<IMediaUrlProvider>();
|
||||
mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny<IUmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<string>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny<IPublishedContent>(), It.IsAny<string>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
.Returns(UrlInfo.Url("/media/1001/my-image.jpg"));
|
||||
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
|
||||
var umbracoContextFactory = TestUmbracoContextFactory.Create(
|
||||
urlProvider: contentUrlProvider.Object,
|
||||
mediaUrlProvider: mediaUrlProvider.Object,
|
||||
umbracoContextAccessor: umbracoContextAccessor);
|
||||
|
||||
using (var reference = umbracoContextFactory.EnsureUmbracoContext(Mock.Of<HttpContextBase>()))
|
||||
var publishedUrlProvider = new UrlProvider(umbracoContextAccessor,
|
||||
TestHelper.WebRoutingSection,
|
||||
new UrlProviderCollection(new []{contentUrlProvider.Object}),
|
||||
new MediaUrlProviderCollection(new []{mediaUrlProvider.Object}),
|
||||
Mock.Of<IVariationContextAccessor>()
|
||||
);
|
||||
using (var reference = umbracoContextFactory.EnsureUmbracoContext())
|
||||
{
|
||||
var contentCache = Mock.Get(reference.UmbracoContext.Content);
|
||||
contentCache.Setup(x => x.GetById(It.IsAny<int>())).Returns(publishedContent.Object);
|
||||
@@ -83,7 +88,7 @@ namespace Umbraco.Tests.Templates
|
||||
mediaCache.Setup(x => x.GetById(It.IsAny<int>())).Returns(media.Object);
|
||||
mediaCache.Setup(x => x.GetById(It.IsAny<Guid>())).Returns(media.Object);
|
||||
|
||||
var linkParser = new HtmlLocalLinkParser(umbracoContextAccessor);
|
||||
var linkParser = new HtmlLocalLinkParser(umbracoContextAccessor, publishedUrlProvider);
|
||||
|
||||
var output = linkParser.EnsureInternalLinks(input);
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
protected override void Compose()
|
||||
{
|
||||
base.Compose();
|
||||
base.Compose();
|
||||
|
||||
Composition.RegisterUnique<IPublishedValueFallback, PublishedValueFallback>();
|
||||
Composition.RegisterUnique<IProfilingLogger, ProfilingLogger>();
|
||||
@@ -99,8 +100,9 @@ namespace Umbraco.Tests.TestHelpers
|
||||
container?.TryGetInstance<ServiceContext>() ?? ServiceContext.CreatePartial(),
|
||||
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()),
|
||||
container?.TryGetInstance<IUmbracoSettingsSection>() ?? Current.Factory.GetInstance<IUmbracoSettingsSection>(),
|
||||
Mock.Of<IUserService>(),
|
||||
Mock.Of<IHttpContextAccessor>());
|
||||
Mock.Of<IHttpContextAccessor>(),
|
||||
Mock.Of<IPublishedUrlProvider>()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,12 +137,10 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting
|
||||
|
||||
var umbracoContextAccessor = Umbraco.Web.Composing.Current.UmbracoContextAccessor;
|
||||
|
||||
var umbCtx = new UmbracoContext(httpContext,
|
||||
var httpContextAccessor = TestHelper.GetHttpContextAccessor(httpContext);
|
||||
var umbCtx = new UmbracoContext(httpContextAccessor,
|
||||
publishedSnapshotService.Object,
|
||||
webSecurity.Object,
|
||||
Mock.Of<IUmbracoSettingsSection>(section => section.WebRouting == Mock.Of<IWebRoutingSection>(routingSection => routingSection.UrlProviderMode == "Auto")),
|
||||
Enumerable.Empty<IUrlProvider>(),
|
||||
Enumerable.Empty<IMediaUrlProvider>(),
|
||||
globalSettings,
|
||||
new TestVariationContextAccessor(),
|
||||
TestHelper.IOHelper,
|
||||
@@ -152,10 +150,10 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting
|
||||
umbracoContextAccessor.UmbracoContext = umbCtx;
|
||||
|
||||
var urlHelper = new Mock<IUrlProvider>();
|
||||
urlHelper.Setup(provider => provider.GetUrl(It.IsAny<IUmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
urlHelper.Setup(provider => provider.GetUrl(It.IsAny<IPublishedContent>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
.Returns(UrlInfo.Url("/hello/world/1234"));
|
||||
|
||||
var membershipHelper = new MembershipHelper(umbCtx.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembersMembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>(), new MockShortStringHelper(), Mock.Of<IEntityService>());
|
||||
var membershipHelper = new MembershipHelper(httpContextAccessor, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembersMembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>(), new MockShortStringHelper(), Mock.Of<IEntityService>());
|
||||
|
||||
var umbHelper = new UmbracoHelper(Mock.Of<IPublishedContent>(),
|
||||
Mock.Of<ITagQuery>(),
|
||||
|
||||
@@ -109,12 +109,13 @@ namespace Umbraco.Tests.TestHelpers
|
||||
|
||||
requestContextMock.Setup(x => x.HttpContext).Returns(httpContextMock.Object);
|
||||
|
||||
if (routeData != null)
|
||||
|
||||
if (routeData is null)
|
||||
{
|
||||
requestContextMock.Setup(x => x.RouteData).Returns(routeData);
|
||||
routeData = new RouteData();
|
||||
}
|
||||
|
||||
|
||||
requestContextMock.Setup(x => x.RouteData).Returns(routeData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
@@ -31,6 +32,7 @@ using Umbraco.Net;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Hosting;
|
||||
using Umbraco.Web.Routing;
|
||||
using File = System.IO.File;
|
||||
|
||||
namespace Umbraco.Tests.TestHelpers
|
||||
@@ -102,6 +104,8 @@ namespace Umbraco.Tests.TestHelpers
|
||||
public static IMainDom MainDom { get; } = new MainDom(Mock.Of<ILogger>(), GetHostingEnvironment(), new MainDomSemaphoreLock(Mock.Of<ILogger>(), GetHostingEnvironment()));
|
||||
public static UriUtility UriUtility { get; } = new UriUtility(GetHostingEnvironment());
|
||||
|
||||
public static IWebRoutingSection WebRoutingSection => SettingsForTests.GetDefaultUmbracoSettings().WebRouting;
|
||||
|
||||
/// <summary>
|
||||
/// Maps the given <paramref name="relativePath"/> making it rooted on <see cref="CurrentAssemblyDirectory"/>. <paramref name="relativePath"/> must start with <code>~/</code>
|
||||
/// </summary>
|
||||
@@ -345,5 +349,31 @@ namespace Umbraco.Tests.TestHelpers
|
||||
{
|
||||
return new DictionaryAppCache();
|
||||
}
|
||||
|
||||
public static IHttpContextAccessor GetHttpContextAccessor(HttpContextBase httpContextBase = null)
|
||||
{
|
||||
if (httpContextBase is null)
|
||||
{
|
||||
var httpContextMock = new Mock<HttpContextBase>();
|
||||
|
||||
httpContextMock.Setup(x => x.DisposeOnPipelineCompleted(It.IsAny<IDisposable>()))
|
||||
.Returns(Mock.Of<ISubscriptionToken>());
|
||||
|
||||
httpContextBase = httpContextMock.Object;
|
||||
}
|
||||
|
||||
var mock = new Mock<IHttpContextAccessor>();
|
||||
|
||||
mock.Setup(x => x.HttpContext).Returns(httpContextBase);
|
||||
|
||||
return mock.Object;
|
||||
}
|
||||
|
||||
public static IPublishedUrlProvider GetPublishedUrlProvider()
|
||||
{
|
||||
var mock = new Mock<IPublishedUrlProvider>();
|
||||
|
||||
return mock.Object;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,6 @@ namespace Umbraco.Tests.TestHelpers
|
||||
/// <remarks>This should be the minimum Umbraco context.</remarks>
|
||||
public IUmbracoContext GetUmbracoContextMock(IUmbracoContextAccessor accessor = null)
|
||||
{
|
||||
var httpContext = Mock.Of<HttpContextBase>();
|
||||
|
||||
var publishedSnapshotMock = new Mock<IPublishedSnapshot>();
|
||||
publishedSnapshotMock.Setup(x => x.Members).Returns(Mock.Of<IPublishedMemberCache>());
|
||||
@@ -120,27 +119,24 @@ namespace Umbraco.Tests.TestHelpers
|
||||
publishedSnapshotServiceMock.Setup(x => x.CreatePublishedSnapshot(It.IsAny<string>())).Returns(publishedSnapshot);
|
||||
var publishedSnapshotService = publishedSnapshotServiceMock.Object;
|
||||
|
||||
var umbracoSettings = GetUmbracoSettings();
|
||||
var globalSettings = GetGlobalSettings();
|
||||
var urlProviders = new UrlProviderCollection(Enumerable.Empty<IUrlProvider>());
|
||||
var mediaUrlProviders = new MediaUrlProviderCollection(Enumerable.Empty<IMediaUrlProvider>());
|
||||
|
||||
if (accessor == null) accessor = new TestUmbracoContextAccessor();
|
||||
|
||||
var httpContextAccessor = TestHelper.GetHttpContextAccessor();
|
||||
|
||||
var umbracoContextFactory = new UmbracoContextFactory(
|
||||
accessor,
|
||||
publishedSnapshotService,
|
||||
new TestVariationContextAccessor(),
|
||||
new TestDefaultCultureAccessor(),
|
||||
umbracoSettings,
|
||||
globalSettings,
|
||||
urlProviders,
|
||||
mediaUrlProviders,
|
||||
Mock.Of<IUserService>(),
|
||||
TestHelper.IOHelper,
|
||||
TestHelper.UriUtility);
|
||||
TestHelper.UriUtility,
|
||||
httpContextAccessor);
|
||||
|
||||
return umbracoContextFactory.EnsureUmbracoContext(httpContext).UmbracoContext;
|
||||
return umbracoContextFactory.EnsureUmbracoContext().UmbracoContext;
|
||||
}
|
||||
|
||||
public IUmbracoSettingsSection GetUmbracoSettings()
|
||||
@@ -339,15 +335,6 @@ namespace Umbraco.Tests.TestHelpers
|
||||
|
||||
#endregion
|
||||
|
||||
public IHttpContextAccessor GetHttpContextAccessor(HttpContextBase httpContextBase = null)
|
||||
{
|
||||
var mock = new Mock<IHttpContextAccessor>();
|
||||
|
||||
var httpContext = UmbracoContextFactory.EnsureHttpContext(httpContextBase);
|
||||
|
||||
mock.Setup(x => x.HttpContext).Returns(httpContext);
|
||||
|
||||
return mock.Object;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,14 +159,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
return @"Datasource=|DataDirectory|UmbracoNPocoTests.sdf;Flush Interval=1;";
|
||||
}
|
||||
|
||||
protected FakeHttpContextFactory GetHttpContextFactory(string url, RouteData routeData = null)
|
||||
{
|
||||
var factory = routeData != null
|
||||
? new FakeHttpContextFactory(url, routeData)
|
||||
: new FakeHttpContextFactory(url);
|
||||
|
||||
return factory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the SqlCe database if required
|
||||
@@ -361,7 +354,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
}
|
||||
}
|
||||
|
||||
protected IUmbracoContext GetUmbracoContext(string url, int templateId = 1234, RouteData routeData = null, bool setSingleton = false, IUmbracoSettingsSection umbracoSettings = null, IEnumerable<IUrlProvider> urlProviders = null, IEnumerable<IMediaUrlProvider> mediaUrlProviders = null, IGlobalSettings globalSettings = null, IPublishedSnapshotService snapshotService = null)
|
||||
protected IUmbracoContext GetUmbracoContext(string url, int templateId = 1234, RouteData routeData = null, bool setSingleton = false, IGlobalSettings globalSettings = null, IPublishedSnapshotService snapshotService = null)
|
||||
{
|
||||
// ensure we have a PublishedCachesService
|
||||
var service = snapshotService ?? PublishedSnapshotService as XmlPublishedSnapshotService;
|
||||
@@ -380,15 +373,12 @@ namespace Umbraco.Tests.TestHelpers
|
||||
}
|
||||
|
||||
var httpContext = GetHttpContextFactory(url, routeData).HttpContext;
|
||||
|
||||
var httpContextAccessor = TestHelper.GetHttpContextAccessor(httpContext);
|
||||
var umbracoContext = new UmbracoContext(
|
||||
httpContext,
|
||||
httpContextAccessor,
|
||||
service,
|
||||
new WebSecurity(httpContext, Factory.GetInstance<IUserService>(),
|
||||
new WebSecurity(httpContextAccessor, Factory.GetInstance<IUserService>(),
|
||||
Factory.GetInstance<IGlobalSettings>(), IOHelper),
|
||||
umbracoSettings ?? Factory.GetInstance<IUmbracoSettingsSection>(),
|
||||
urlProviders ?? Enumerable.Empty<IUrlProvider>(),
|
||||
mediaUrlProviders ?? Enumerable.Empty<IMediaUrlProvider>(),
|
||||
globalSettings ?? Factory.GetInstance<IGlobalSettings>(),
|
||||
new TestVariationContextAccessor(),
|
||||
IOHelper,
|
||||
|
||||
@@ -16,14 +16,15 @@ namespace Umbraco.Tests.Testing.Objects
|
||||
/// </summary>
|
||||
public class TestUmbracoContextFactory
|
||||
{
|
||||
public static IUmbracoContextFactory Create(IGlobalSettings globalSettings = null, IUrlProvider urlProvider = null,
|
||||
IMediaUrlProvider mediaUrlProvider = null,
|
||||
IUmbracoContextAccessor umbracoContextAccessor = null)
|
||||
public static IUmbracoContextFactory Create(IGlobalSettings globalSettings = null,
|
||||
IUmbracoContextAccessor umbracoContextAccessor = null,
|
||||
IHttpContextAccessor httpContextAccessor = null,
|
||||
IPublishedUrlProvider publishedUrlProvider = null)
|
||||
{
|
||||
if (globalSettings == null) globalSettings = SettingsForTests.GenerateMockGlobalSettings();
|
||||
if (urlProvider == null) urlProvider = Mock.Of<IUrlProvider>();
|
||||
if (mediaUrlProvider == null) mediaUrlProvider = Mock.Of<IMediaUrlProvider>();
|
||||
if (umbracoContextAccessor == null) umbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
if (httpContextAccessor == null) httpContextAccessor = TestHelper.GetHttpContextAccessor();
|
||||
if (publishedUrlProvider == null) publishedUrlProvider = TestHelper.GetPublishedUrlProvider();
|
||||
|
||||
var contentCache = new Mock<IPublishedContentCache>();
|
||||
var mediaCache = new Mock<IPublishedMediaCache>();
|
||||
@@ -33,18 +34,18 @@ namespace Umbraco.Tests.Testing.Objects
|
||||
var snapshotService = new Mock<IPublishedSnapshotService>();
|
||||
snapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny<string>())).Returns(snapshot.Object);
|
||||
|
||||
|
||||
|
||||
var umbracoContextFactory = new UmbracoContextFactory(
|
||||
umbracoContextAccessor,
|
||||
snapshotService.Object,
|
||||
new TestVariationContextAccessor(),
|
||||
new TestDefaultCultureAccessor(),
|
||||
Mock.Of<IUmbracoSettingsSection>(section => section.WebRouting == Mock.Of<IWebRoutingSection>(routingSection => routingSection.UrlProviderMode == "Auto")),
|
||||
globalSettings,
|
||||
new UrlProviderCollection(new[] { urlProvider }),
|
||||
new MediaUrlProviderCollection(new[] { mediaUrlProvider }),
|
||||
Mock.Of<IUserService>(),
|
||||
TestHelper.IOHelper,
|
||||
TestHelper.UriUtility);
|
||||
TestHelper.UriUtility,
|
||||
httpContextAccessor);
|
||||
|
||||
return umbracoContextFactory;
|
||||
}
|
||||
|
||||
@@ -57,8 +57,6 @@ namespace Umbraco.Tests.Testing.TestingTests
|
||||
[Test]
|
||||
public void Can_Mock_Umbraco_Helper()
|
||||
{
|
||||
var umbracoContext = TestObjects.GetUmbracoContextMock();
|
||||
|
||||
// unless we can inject them in MembershipHelper, we need need this
|
||||
Composition.Register(_ => Mock.Of<IMemberService>());
|
||||
Composition.Register(_ => Mock.Of<IMemberTypeService>());
|
||||
@@ -72,7 +70,7 @@ namespace Umbraco.Tests.Testing.TestingTests
|
||||
Mock.Of<ICultureDictionaryFactory>(),
|
||||
Mock.Of<IUmbracoComponentRenderer>(),
|
||||
Mock.Of<IPublishedContentQuery>(),
|
||||
new MembershipHelper(Mock.Of<HttpContextBase>(), Mock.Of<IPublishedMemberCache>(), Mock.Of<MembersMembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>(), ShortStringHelper, Mock.Of<IEntityService>()));
|
||||
new MembershipHelper(Mock.Of<IHttpContextAccessor>(), Mock.Of<IPublishedMemberCache>(), Mock.Of<MembersMembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>(), ShortStringHelper, Mock.Of<IEntityService>()));
|
||||
Assert.Pass();
|
||||
}
|
||||
|
||||
@@ -81,12 +79,18 @@ namespace Umbraco.Tests.Testing.TestingTests
|
||||
{
|
||||
var umbracoContext = TestObjects.GetUmbracoContextMock();
|
||||
|
||||
|
||||
var urlProviderMock = new Mock<IUrlProvider>();
|
||||
urlProviderMock.Setup(provider => provider.GetUrl(It.IsAny<IUmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
urlProviderMock.Setup(provider => provider.GetUrl(It.IsAny<IPublishedContent>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
.Returns(UrlInfo.Url("/hello/world/1234"));
|
||||
var urlProvider = urlProviderMock.Object;
|
||||
|
||||
var theUrlProvider = new UrlProvider(umbracoContext, new [] { urlProvider }, Enumerable.Empty<IMediaUrlProvider>(), umbracoContext.VariationContextAccessor);
|
||||
var theUrlProvider = new UrlProvider(
|
||||
new TestUmbracoContextAccessor(umbracoContext),
|
||||
TestHelper.WebRoutingSection,
|
||||
new UrlProviderCollection(new [] { urlProvider }),
|
||||
new MediaUrlProviderCollection( Enumerable.Empty<IMediaUrlProvider>())
|
||||
, umbracoContext.VariationContextAccessor);
|
||||
|
||||
var contentType = new PublishedContentType(666, "alias", PublishedItemType.Content, Enumerable.Empty<string>(), Enumerable.Empty<PublishedPropertyType>(), ContentVariation.Nothing);
|
||||
var publishedContent = Mock.Of<IPublishedContent>();
|
||||
@@ -98,17 +102,15 @@ namespace Umbraco.Tests.Testing.TestingTests
|
||||
[Test]
|
||||
public void Can_Mock_UmbracoApiController_Dependencies_With_Injected_UmbracoMapper()
|
||||
{
|
||||
var umbracoContext = TestObjects.GetUmbracoContextMock();
|
||||
|
||||
var logger = Mock.Of<IProfilingLogger>();
|
||||
var memberService = Mock.Of<IMemberService>();
|
||||
var memberTypeService = Mock.Of<IMemberTypeService>();
|
||||
var membershipProvider = new MembersMembershipProvider(memberService, memberTypeService, Mock.Of<IUmbracoVersion>(), TestHelper.GetHostingEnvironment(), TestHelper.GetIpResolver());
|
||||
var membershipHelper = new MembershipHelper(Mock.Of<HttpContextBase>(), Mock.Of<IPublishedMemberCache>(), membershipProvider, Mock.Of<RoleProvider>(), memberService, memberTypeService, Mock.Of<IPublicAccessService>(), AppCaches.Disabled, logger, ShortStringHelper, Mock.Of<IEntityService>());
|
||||
var membershipHelper = new MembershipHelper(Mock.Of<IHttpContextAccessor>(), Mock.Of<IPublishedMemberCache>(), membershipProvider, Mock.Of<RoleProvider>(), memberService, memberTypeService, Mock.Of<IPublicAccessService>(), AppCaches.Disabled, logger, ShortStringHelper, Mock.Of<IEntityService>());
|
||||
var umbracoHelper = new UmbracoHelper(Mock.Of<IPublishedContent>(), Mock.Of<ITagQuery>(), Mock.Of<ICultureDictionaryFactory>(), Mock.Of<IUmbracoComponentRenderer>(), Mock.Of<IPublishedContentQuery>(), membershipHelper);
|
||||
var umbracoMapper = new UmbracoMapper(new MapDefinitionCollection(new[] { Mock.Of<IMapDefinition>() }));
|
||||
|
||||
var umbracoApiController = new FakeUmbracoApiController(Mock.Of<IGlobalSettings>(), Mock.Of<IUmbracoContextAccessor>(), Mock.Of<ISqlContext>(), ServiceContext.CreatePartial(), AppCaches.NoCache, logger, Mock.Of<IRuntimeState>(), umbracoHelper, umbracoMapper);
|
||||
var umbracoApiController = new FakeUmbracoApiController(Mock.Of<IGlobalSettings>(), Mock.Of<IUmbracoContextAccessor>(), Mock.Of<ISqlContext>(), ServiceContext.CreatePartial(), AppCaches.NoCache, logger, Mock.Of<IRuntimeState>(), umbracoHelper, umbracoMapper, Mock.Of<IPublishedUrlProvider>());
|
||||
|
||||
Assert.Pass();
|
||||
}
|
||||
@@ -116,6 +118,7 @@ namespace Umbraco.Tests.Testing.TestingTests
|
||||
|
||||
internal class FakeUmbracoApiController : UmbracoApiController
|
||||
{
|
||||
public FakeUmbracoApiController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper, UmbracoMapper umbracoMapper) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper) { }
|
||||
public FakeUmbracoApiController(IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper, UmbracoMapper umbracoMapper, IPublishedUrlProvider publishedUrlProvider)
|
||||
: base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper, publishedUrlProvider) { }
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user