Cleanup, fix tests

This commit is contained in:
Stephan
2018-04-30 15:11:01 +02:00
parent bcd0c95ec1
commit 038fc87a40
35 changed files with 159 additions and 250 deletions

View File

@@ -5,31 +5,10 @@
/// </summary>
public interface IPublishedValueFallback
{
/// <summary>
/// Gets a value.
/// </summary>
/// <remarks>
/// <para>This is invoked when getting a value for the specified <paramref name="culture"/> and <paramref name="segment"/>
/// could not return a value, and fallback rules should apply to get the value for another language and/or segment.</para>
/// </remarks>
TValue GetValue<TValue>(IPublishedProperty property, string culture, string segment);
}
// todo - define & implement
// fixme question
// this is working at property level at the moment, should we move it up to element,
// so that the decision can be made based upon the entire element, other properties, etc?
// or, would we need the *two* levels?
/// <summary>
/// Provides a default implementation of <see cref="IPublishedValueFallback"/> that does not fall back at all.
/// </summary>
public class NoPublishedValueFallback : IPublishedValueFallback
{
/// <inheritdoc />
public TValue GetValue<TValue>(IPublishedProperty property, string culture, string segment)
{
// we don't implement fallback
return default;
}
// property level ... should we move it up to element,
// so that the decision can be made based upon the entire element, other properties, etc?
// or, would we need the *two* levels?
}
}

View File

@@ -43,9 +43,9 @@ namespace Umbraco.Core.Models.PublishedContent
/// </summary>
/// <remarks>
/// A published content item will only have published cultures, and therefore this
/// value will always be true. On the other hand, fixme drafts?
/// value will always be true. On the other hand, ... ???
/// </remarks>
public bool Published { get; }
public bool Published { get; } // fixme - what is culture.Published?
/// <summary>
/// Gets the date associated with the culture.

View File

@@ -1111,7 +1111,7 @@ namespace Umbraco.Core
/// <param name="alias">The text to filter.</param>
/// <param name="culture">The culture.</param>
/// <returns>The safe alias.</returns>
public static string ToSafeAlias(this string alias, CultureInfo culture)
public static string ToSafeAlias(this string alias, string culture)
{
return Current.ShortStringHelper.CleanStringForSafeAlias(alias, culture);
}
@@ -1134,7 +1134,7 @@ namespace Umbraco.Core
/// <param name="culture">The culture.</param>
/// <returns>The safe alias.</returns>
/// <remarks>Checks <c>UmbracoSettings.ForceSafeAliases</c> to determine whether it should filter the text.</remarks>
public static string ToSafeAliasWithForcingCheck(this string alias, CultureInfo culture)
public static string ToSafeAliasWithForcingCheck(this string alias, string culture)
{
return UmbracoConfig.For.UmbracoSettings().Content.ForceSafeAliases ? alias.ToSafeAlias(culture) : alias;
}
@@ -1158,20 +1158,8 @@ namespace Umbraco.Core
/// <param name="culture">The culture.</param>
/// <returns>The safe url segment.</returns>
public static string ToUrlSegment(this string text, string culture)
=> text.ToUrlSegment(CultureInfo.GetCultureInfo(culture));
=> Current.ShortStringHelper.CleanStringForUrlSegment(text, culture);
/// <summary>
/// Cleans a string, in the context of a specified culture, to produce a string that can safely be used in an url segment.
/// </summary>
/// <param name="text">The text to filter.</param>
/// <param name="culture">The culture.</param>
/// <returns>The safe url segment.</returns>
// todo: obsolete that one and use the string one (requires changes to IShortStringHelper)
public static string ToUrlSegment(this string text, CultureInfo culture)
{
return Current.ShortStringHelper.CleanStringForUrlSegment(text, culture);
}
// the new methods to clean a string (to alias, url segment...)
/// <summary>
@@ -1209,7 +1197,7 @@ namespace Umbraco.Core
/// strings are cleaned up to camelCase and Ascii.</param>
/// <param name="culture">The culture.</param>
/// <returns>The clean string.</returns>
public static string ToCleanString(this string text, CleanStringType stringType, CultureInfo culture)
public static string ToCleanString(this string text, CleanStringType stringType, string culture)
{
return Current.ShortStringHelper.CleanString(text, stringType, culture);
}
@@ -1223,7 +1211,7 @@ namespace Umbraco.Core
/// <param name="separator">The separator.</param>
/// <param name="culture">The culture.</param>
/// <returns>The clean string.</returns>
public static string ToCleanString(this string text, CleanStringType stringType, char separator, CultureInfo culture)
public static string ToCleanString(this string text, CleanStringType stringType, char separator, string culture)
{
return Current.ShortStringHelper.CleanString(text, stringType, separator, culture);
}
@@ -1269,7 +1257,7 @@ namespace Umbraco.Core
/// <param name="text">The text to filter.</param>
/// <param name="culture">The culture.</param>
/// <returns>The safe filename.</returns>
public static string ToSafeFileName(this string text, CultureInfo culture)
public static string ToSafeFileName(this string text, string culture)
{
return Current.ShortStringHelper.CleanStringForSafeFileName(text, culture);
}

View File

@@ -11,23 +11,6 @@ namespace Umbraco.Core.Strings
/// </summary>
internal static class ContentBaseExtensions
{
/// <summary>
/// Gets the default url segment for a specified content.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="urlSegmentProviders"></param>
/// <returns>The url segment.</returns>
public static string GetUrlSegment(this IContentBase content, IEnumerable<IUrlSegmentProvider> urlSegmentProviders)
{
if (content == null) throw new ArgumentNullException("content");
if (urlSegmentProviders == null) throw new ArgumentNullException("urlSegmentProviders");
var url = urlSegmentProviders.Select(p => p.GetUrlSegment(content)).FirstOrDefault(u => u != null);
url = url ?? new DefaultUrlSegmentProvider().GetUrlSegment(content); // be safe
return url;
}
/// <summary>
/// Gets the url segment for a specified content and culture.
/// </summary>
@@ -35,11 +18,11 @@ namespace Umbraco.Core.Strings
/// <param name="culture">The culture.</param>
/// <param name="urlSegmentProviders"></param>
/// <returns>The url segment.</returns>
public static string GetUrlSegment(this IContentBase content, CultureInfo culture, IEnumerable<IUrlSegmentProvider> urlSegmentProviders)
public static string GetUrlSegment(this IContentBase content, IEnumerable<IUrlSegmentProvider> urlSegmentProviders, string culture = null)
{
if (content == null) throw new ArgumentNullException("content");
if (culture == null) throw new ArgumentNullException("culture");
if (urlSegmentProviders == null) throw new ArgumentNullException("urlSegmentProviders");
if (content == null) throw new ArgumentNullException(nameof(content));
if (culture == null) throw new ArgumentNullException(nameof(culture));
if (urlSegmentProviders == null) throw new ArgumentNullException(nameof(urlSegmentProviders));
var url = urlSegmentProviders.Select(p => p.GetUrlSegment(content, culture)).FirstOrDefault(u => u != null);
url = url ?? new DefaultUrlSegmentProvider().GetUrlSegment(content, culture); // be safe

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
@@ -18,7 +17,7 @@ namespace Umbraco.Core.Strings
/// </remarks>
public class DefaultShortStringHelper : IShortStringHelper
{
#region Ctor and vars
#region Ctor, consts and vars
public DefaultShortStringHelper(IUmbracoSettingsSection settings)
{
@@ -31,6 +30,8 @@ namespace Umbraco.Core.Strings
_config = config.Clone();
}
public const string InvariantCulture = "xx-xx";
// see notes for CleanAsciiString
//// beware! the order is quite important here!
//const string ValidStringCharactersSource = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -138,7 +139,7 @@ function validateSafeAlias(input, value, immediate, callback) {{
/// <remarks>
/// <para>Safe aliases are Ascii only.</para>
/// </remarks>
public virtual string CleanStringForSafeAlias(string text, CultureInfo culture)
public virtual string CleanStringForSafeAlias(string text, string culture)
{
return CleanString(text, CleanStringType.Alias, culture);
}
@@ -166,7 +167,7 @@ function validateSafeAlias(input, value, immediate, callback) {{
/// <remarks>
/// <para>Url segments are Ascii only (no accents...).</para>
/// </remarks>
public virtual string CleanStringForUrlSegment(string text, CultureInfo culture)
public virtual string CleanStringForUrlSegment(string text, string culture)
{
return CleanString(text, CleanStringType.UrlSegment, culture);
}
@@ -190,11 +191,12 @@ function validateSafeAlias(input, value, immediate, callback) {{
/// <param name="text">The text to filter.</param>
/// <param name="culture">The culture.</param>
/// <returns>The safe filename.</returns>
public virtual string CleanStringForSafeFileName(string text, CultureInfo culture)
public virtual string CleanStringForSafeFileName(string text, string culture)
{
if (string.IsNullOrWhiteSpace(text))
return string.Empty;
culture = culture ?? InvariantCulture;
text = text.ReplaceMany(Path.GetInvalidFileNameChars(), '-');
var name = Path.GetFileNameWithoutExtension(text);
@@ -266,7 +268,7 @@ function validateSafeAlias(input, value, immediate, callback) {{
/// strings are cleaned up to camelCase and Ascii.</param>
/// <param name="culture">The culture.</param>
/// <returns>The clean string.</returns>
public string CleanString(string text, CleanStringType stringType, CultureInfo culture)
public string CleanString(string text, CleanStringType stringType, string culture)
{
return CleanString(text, stringType, culture, null);
}
@@ -280,16 +282,16 @@ function validateSafeAlias(input, value, immediate, callback) {{
/// <param name="separator">The separator.</param>
/// <param name="culture">The culture.</param>
/// <returns>The clean string.</returns>
public string CleanString(string text, CleanStringType stringType, char separator, CultureInfo culture)
public string CleanString(string text, CleanStringType stringType, char separator, string culture)
{
return CleanString(text, stringType, culture, separator);
}
protected virtual string CleanString(string text, CleanStringType stringType, CultureInfo culture, char? separator)
protected virtual string CleanString(string text, CleanStringType stringType, string culture, char? separator)
{
// be safe
if (text == null) throw new ArgumentNullException(nameof(text));
if (culture == null) throw new ArgumentNullException(nameof(culture));
culture = culture ?? InvariantCulture;
// get config
var config = _config.For(stringType, culture);
@@ -367,11 +369,12 @@ function validateSafeAlias(input, value, immediate, callback) {{
// that the utf8 version. Micro-optimizing sometimes isn't such a good idea.
// note: does NOT support surrogate pairs in text
internal string CleanCodeString(string text, CleanStringType caseType, char separator, CultureInfo culture, DefaultShortStringHelperConfig.Config config)
internal string CleanCodeString(string text, CleanStringType caseType, char separator, string culture, DefaultShortStringHelperConfig.Config config)
{
int opos = 0, ipos = 0;
var state = StateBreak;
culture = culture ?? InvariantCulture;
caseType &= CleanStringType.CaseMask;
// if we apply global ToUpper or ToLower to text here
@@ -501,9 +504,10 @@ function validateSafeAlias(input, value, immediate, callback) {{
// note: supports surrogate pairs in input string
internal void CopyTerm(string input, int ipos, char[] output, ref int opos, int len,
CleanStringType caseType, CultureInfo culture, bool isAcronym)
CleanStringType caseType, string culture, bool isAcronym)
{
var term = input.Substring(ipos, len);
var cultureInfo = culture == null || culture == InvariantCulture ? CultureInfo.InvariantCulture : CultureInfo.GetCultureInfo(culture);
if (isAcronym)
{
@@ -529,13 +533,13 @@ function validateSafeAlias(input, value, immediate, callback) {{
break;
case CleanStringType.LowerCase:
term = term.ToLower(culture);
term = term.ToLower(cultureInfo);
term.CopyTo(0, output, opos, term.Length);
opos += term.Length;
break;
case CleanStringType.UpperCase:
term = term.ToUpper(culture);
term = term.ToUpper(cultureInfo);
term.CopyTo(0, output, opos, term.Length);
opos += term.Length;
break;
@@ -546,18 +550,18 @@ function validateSafeAlias(input, value, immediate, callback) {{
if (char.IsSurrogate(c))
{
s = term.Substring(ipos, 2);
s = opos == 0 ? s.ToLower(culture) : s.ToUpper(culture);
s = opos == 0 ? s.ToLower(cultureInfo) : s.ToUpper(cultureInfo);
s.CopyTo(0, output, opos, s.Length);
opos += s.Length;
i++; // surrogate pair len is 2
}
else
{
output[opos] = opos++ == 0 ? char.ToLower(c, culture) : char.ToUpper(c, culture);
output[opos] = opos++ == 0 ? char.ToLower(c, cultureInfo) : char.ToUpper(c, cultureInfo);
}
if (len > i)
{
term = term.Substring(i).ToLower(culture);
term = term.Substring(i).ToLower(cultureInfo);
term.CopyTo(0, output, opos, term.Length);
opos += term.Length;
}
@@ -569,18 +573,18 @@ function validateSafeAlias(input, value, immediate, callback) {{
if (char.IsSurrogate(c))
{
s = term.Substring(ipos, 2);
s = s.ToUpper(culture);
s = s.ToUpper(cultureInfo);
s.CopyTo(0, output, opos, s.Length);
opos += s.Length;
i++; // surrogate pair len is 2
}
else
{
output[opos++] = char.ToUpper(c, culture);
output[opos++] = char.ToUpper(c, cultureInfo);
}
if (len > i)
{
term = term.Substring(i).ToLower(culture);
term = term.Substring(i).ToLower(cultureInfo);
term.CopyTo(0, output, opos, term.Length);
opos += term.Length;
}
@@ -592,14 +596,14 @@ function validateSafeAlias(input, value, immediate, callback) {{
if (char.IsSurrogate(c))
{
s = term.Substring(ipos, 2);
s = opos == 0 ? s : s.ToUpper(culture);
s = opos == 0 ? s : s.ToUpper(cultureInfo);
s.CopyTo(0, output, opos, s.Length);
opos += s.Length;
i++; // surrogate pair len is 2
}
else
{
output[opos] = opos++ == 0 ? c : char.ToUpper(c, culture);
output[opos] = opos++ == 0 ? c : char.ToUpper(c, cultureInfo);
}
if (len > i)
{
@@ -668,8 +672,6 @@ function validateSafeAlias(input, value, immediate, callback) {{
return new string(output, 0, opos);
}
#endregion
#endregion
}
}

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Umbraco.Core.Configuration.UmbracoSettings;
@@ -8,7 +7,7 @@ namespace Umbraco.Core.Strings
{
public class DefaultShortStringHelperConfig
{
private readonly Dictionary<CultureInfo, Dictionary<CleanStringType, Config>> _configs = new Dictionary<CultureInfo, Dictionary<CleanStringType, Config>>();
private readonly Dictionary<string, Dictionary<CleanStringType, Config>> _configs = new Dictionary<string, Dictionary<CleanStringType, Config>>();
public DefaultShortStringHelperConfig Clone()
{
@@ -29,7 +28,7 @@ namespace Umbraco.Core.Strings
return config;
}
public CultureInfo DefaultCulture { get; set; } = CultureInfo.InvariantCulture;
public string DefaultCulture { get; set; } = DefaultShortStringHelper.InvariantCulture;
public Dictionary<string, string> UrlReplaceCharacters { get; set; }
@@ -45,10 +44,12 @@ namespace Umbraco.Core.Strings
return WithConfig(DefaultCulture, stringRole, config);
}
public DefaultShortStringHelperConfig WithConfig(CultureInfo culture, CleanStringType stringRole, Config config)
public DefaultShortStringHelperConfig WithConfig(string culture, CleanStringType stringRole, Config config)
{
if (config == null) throw new ArgumentNullException(nameof(config));
culture = culture ?? DefaultShortStringHelper.InvariantCulture;
if (_configs.ContainsKey(culture) == false)
_configs[culture] = new Dictionary<CleanStringType, Config>();
_configs[culture][stringRole] = config;
@@ -112,8 +113,9 @@ namespace Umbraco.Core.Strings
// internal: we don't want ppl to retrieve a config and modify it
// (the helper uses a private clone to prevent modifications)
internal Config For(CleanStringType stringType, CultureInfo culture)
internal Config For(CleanStringType stringType, string culture)
{
culture = culture ?? DefaultShortStringHelper.InvariantCulture;
stringType = stringType & CleanStringType.RoleMask;
Dictionary<CleanStringType, Config> config;

View File

@@ -1,5 +1,4 @@
using System.Globalization;
using Umbraco.Core.Models;
using Umbraco.Core.Models;
namespace Umbraco.Core.Strings
{
@@ -8,23 +7,13 @@ namespace Umbraco.Core.Strings
/// </summary>
public class DefaultUrlSegmentProvider : IUrlSegmentProvider
{
/// <summary>
/// Gets the default url segment for a specified content.
/// </summary>
/// <param name="content">The content.</param>
/// <returns>The url segment.</returns>
public string GetUrlSegment(IContentBase content)
{
return GetUrlSegmentSource(content).ToUrlSegment();
}
/// <summary>
/// Gets the url segment for a specified content and culture.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="culture">The culture.</param>
/// <returns>The url segment.</returns>
public string GetUrlSegment(IContentBase content, CultureInfo culture)
public string GetUrlSegment(IContentBase content, string culture = null)
{
return GetUrlSegmentSource(content).ToUrlSegment(culture);
}

View File

@@ -1,7 +1,4 @@
using System.Collections.Generic;
using System.Globalization;
namespace Umbraco.Core.Strings
namespace Umbraco.Core.Strings
{
/// <summary>
/// Provides string functions for short strings such as aliases or url segments.
@@ -31,7 +28,7 @@ namespace Umbraco.Core.Strings
/// <param name="text">The text to filter.</param>
/// <param name="culture">The culture.</param>
/// <returns>The safe alias.</returns>
string CleanStringForSafeAlias(string text, CultureInfo culture);
string CleanStringForSafeAlias(string text, string culture);
/// <summary>
/// Cleans a string to produce a string that can safely be used in an url segment.
@@ -47,7 +44,7 @@ namespace Umbraco.Core.Strings
/// <param name="text">The text to filter.</param>
/// <param name="culture">The culture.</param>
/// <returns>The safe url segment.</returns>
string CleanStringForUrlSegment(string text, CultureInfo culture);
string CleanStringForUrlSegment(string text, string culture);
/// <summary>
/// Cleans a string, in the context of the invariant culture, to produce a string that can safely be used as a filename,
@@ -66,7 +63,7 @@ namespace Umbraco.Core.Strings
/// <param name="culture">The culture.</param>
/// <returns>The safe filename.</returns>
/// <remarks>Legacy says this was used to "overcome an issue when Umbraco is used in IE in an intranet environment" but that issue is not documented.</remarks>
string CleanStringForSafeFileName(string text, CultureInfo culture);
string CleanStringForSafeFileName(string text, string culture);
/// <summary>
/// Splits a pascal-cased string by inserting a separator in between each term.
@@ -106,7 +103,7 @@ namespace Umbraco.Core.Strings
/// strings are cleaned up to camelCase and Ascii.</param>
/// <param name="culture">The culture.</param>
/// <returns>The clean string.</returns>
string CleanString(string text, CleanStringType stringType, CultureInfo culture);
string CleanString(string text, CleanStringType stringType, string culture);
/// <summary>
/// Cleans a string in the context of a specified culture, using a specified separator.
@@ -117,6 +114,6 @@ namespace Umbraco.Core.Strings
/// <param name="separator">The separator.</param>
/// <param name="culture">The culture.</param>
/// <returns>The clean string.</returns>
string CleanString(string text, CleanStringType stringType, char separator, CultureInfo culture);
string CleanString(string text, CleanStringType stringType, char separator, string culture);
}
}

View File

@@ -9,13 +9,6 @@ namespace Umbraco.Core.Strings
/// <remarks>Url segments should comply with IETF RFCs regarding content, encoding, etc.</remarks>
public interface IUrlSegmentProvider
{
/// <summary>
/// Gets the default url segment for a specified content.
/// </summary>
/// <param name="content">The content.</param>
/// <returns>The url segment.</returns>
string GetUrlSegment(IContentBase content); // fixme do we need to have both?
/// <summary>
/// Gets the url segment for a specified content and culture.
/// </summary>
@@ -25,7 +18,7 @@ namespace Umbraco.Core.Strings
/// <remarks>This is for when Umbraco is capable of managing more than one url
/// per content, in 1-to-1 multilingual configurations. Then there would be one
/// url per culture.</remarks>
string GetUrlSegment(IContentBase content, CultureInfo culture);
string GetUrlSegment(IContentBase content, string culture = null);
//TODO: For the 301 tracking, we need to add another extended interface to this so that
// the RedirectTrackingEventHandler can ask the IUrlSegmentProvider if the URL is changing.

View File

@@ -6,6 +6,7 @@ using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Testing;
using Umbraco.Tests.Testing.Objects.Accessors;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.PublishedCache.XmlPublishedCache;
@@ -78,7 +79,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
umbracoSettings,
Enumerable.Empty<IUrlProvider>(),
globalSettings,
ServiceContext.EntityService);
new TestCurrentVariationAccessor());
_cache = _umbracoContext.ContentCache;
}

View File

@@ -18,6 +18,7 @@ using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Testing;
using Umbraco.Tests.Testing.Objects.Accessors;
namespace Umbraco.Tests.PublishedContent
{
@@ -74,8 +75,8 @@ namespace Umbraco.Tests.PublishedContent
new WebSecurity(httpContext, Current.Services.UserService, globalSettings),
TestObjects.GetUmbracoSettings(),
Enumerable.Empty<IUrlProvider>(),
globalSettings,
ServiceContext.EntityService);
globalSettings,
new TestCurrentVariationAccessor());
return umbracoContext;
}

View File

@@ -324,8 +324,8 @@ namespace Umbraco.Tests.PublishedContent
public void GetPropertyValueRecursiveTest()
{
var doc = GetNode(1174);
var rVal = doc.Value("testRecursive", true);
var nullVal = doc.Value("DoNotFindThis", true);
var rVal = doc.Value("testRecursive", recurse: true);
var nullVal = doc.Value("DoNotFindThis", recurse: true);
Assert.AreEqual("This is the recursive val", rVal);
Assert.AreEqual(null, nullVal);
}

View File

@@ -21,6 +21,7 @@ using Umbraco.Core.Services.Implement;
using Umbraco.Core.Sync;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Testing;
using Umbraco.Tests.Testing.Objects.Accessors;
using Umbraco.Web;
using Umbraco.Web.Cache;
using Umbraco.Web.PublishedCache;
@@ -113,7 +114,7 @@ namespace Umbraco.Tests.Scoping
umbracoSettings ?? SettingsForTests.GetDefaultUmbracoSettings(),
urlProviders ?? Enumerable.Empty<IUrlProvider>(),
globalSettings,
Mock.Of<IEntityService>());
new TestCurrentVariationAccessor());
if (setSingleton)
Umbraco.Web.Composing.Current.UmbracoContextAccessor.UmbracoContext = umbracoContext;

View File

@@ -9,6 +9,7 @@ using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Services;
using Umbraco.Tests.Testing;
using Umbraco.Tests.Testing.Objects.Accessors;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
@@ -33,7 +34,7 @@ namespace Umbraco.Tests.Security
Mock.Of<IPublishedSnapshotService>(),
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, globalSettings),
TestObjects.GetUmbracoSettings(), new List<IUrlProvider>(),globalSettings,
Mock.Of<IEntityService>());
new TestCurrentVariationAccessor());
var runtime = Mock.Of<IRuntimeState>(x => x.Level == RuntimeLevel.Install);
var mgr = new BackOfficeCookieManager(
@@ -53,7 +54,7 @@ namespace Umbraco.Tests.Security
Mock.Of<IPublishedSnapshotService>(),
new WebSecurity(Mock.Of<HttpContextBase>(), Current.Services.UserService, globalSettings),
TestObjects.GetUmbracoSettings(), new List<IUrlProvider>(), globalSettings,
Mock.Of<IEntityService>());
new TestCurrentVariationAccessor());
var runtime = Mock.Of<IRuntimeState>(x => x.Level == RuntimeLevel.Run);
var mgr = new BackOfficeCookieManager(Mock.Of<IUmbracoContextAccessor>(accessor => accessor.UmbracoContext == umbCtx), runtime, TestObjects.GetGlobalSettings());

View File

@@ -43,7 +43,7 @@ namespace Umbraco.Tests.Strings
StringType = CleanStringType.LowerCase | CleanStringType.Ascii,
Separator = '-'
})
.WithConfig(new CultureInfo("fr-FR"), CleanStringType.UrlSegment, new DefaultShortStringHelperConfig.Config
.WithConfig("fr-FR", CleanStringType.UrlSegment, new DefaultShortStringHelperConfig.Config
{
PreFilter = FilterFrenchElisions,
IsTerm = (c, leading) => leading ? char.IsLetter(c) : (char.IsLetterOrDigit(c) || c == '_'),
@@ -56,7 +56,7 @@ namespace Umbraco.Tests.Strings
IsTerm = (c, leading) => leading ? char.IsLetter(c) : char.IsLetterOrDigit(c),
StringType = CleanStringType.UmbracoCase | CleanStringType.Ascii
})
.WithConfig(new CultureInfo("fr-FR"), CleanStringType.Alias, new DefaultShortStringHelperConfig.Config
.WithConfig("fr-FR", CleanStringType.Alias, new DefaultShortStringHelperConfig.Config
{
PreFilter = WhiteQuotes,
IsTerm = (c, leading) => leading ? char.IsLetter(c) : char.IsLetterOrDigit(c),
@@ -588,16 +588,12 @@ namespace Umbraco.Tests.Strings
#endregion
public void CleanStringWithTypeAndCulture(string input, string expected, string culture, CleanStringType stringType)
{
var cinfo = culture == null ? CultureInfo.InvariantCulture : new CultureInfo(culture);
// picks the proper config per culture
// and overrides some stringType params (ascii...)
var output = _helper.CleanString(input, stringType, cinfo);
var output = _helper.CleanString(input, stringType, culture);
Assert.AreEqual(expected, output);
}
#region Cases
[TestCase("foo.txt", "foo.txt")]
[TestCase("foo", "foo")]

View File

@@ -19,17 +19,7 @@ namespace Umbraco.Tests.Strings
return "SAFE-ALIAS::" + text;
}
public string CleanStringForSafeCamelAlias(string text)
{
return "SAFE-ALIAS::" + text;
}
public string CleanStringForSafeAlias(string text, System.Globalization.CultureInfo culture)
{
return "SAFE-ALIAS-CULTURE::" + text;
}
public string CleanStringForSafeCamelAlias(string text, System.Globalization.CultureInfo culture)
public string CleanStringForSafeAlias(string text, string culture)
{
return "SAFE-ALIAS-CULTURE::" + text;
}
@@ -39,7 +29,7 @@ namespace Umbraco.Tests.Strings
return "URL-SEGMENT::" + text;
}
public string CleanStringForUrlSegment(string text, System.Globalization.CultureInfo culture)
public string CleanStringForUrlSegment(string text, string culture)
{
return "URL-SEGMENT-CULTURE::" + text;
}
@@ -49,7 +39,7 @@ namespace Umbraco.Tests.Strings
return "SAFE-FILE-NAME::" + text;
}
public string CleanStringForSafeFileName(string text, System.Globalization.CultureInfo culture)
public string CleanStringForSafeFileName(string text, string culture)
{
return "SAFE-FILE-NAME-CULTURE::" + text;
}
@@ -69,12 +59,12 @@ namespace Umbraco.Tests.Strings
return "CLEAN-STRING-B::" + text;
}
public string CleanString(string text, CleanStringType stringType, System.Globalization.CultureInfo culture)
public string CleanString(string text, CleanStringType stringType, string culture)
{
return "CLEAN-STRING-C::" + text;
}
public string CleanString(string text, CleanStringType stringType, char separator, System.Globalization.CultureInfo culture)
public string CleanString(string text, CleanStringType stringType, char separator, string culture)
{
return "CLEAN-STRING-D::" + text;
}

View File

@@ -188,7 +188,7 @@ namespace Umbraco.Tests.Strings
[Test]
public void ToSafeAliasWithCulture()
{
var output = "JUST-ANYTHING".ToSafeAlias(CultureInfo.InvariantCulture);
var output = "JUST-ANYTHING".ToSafeAlias(null);
Assert.AreEqual("SAFE-ALIAS-CULTURE::JUST-ANYTHING", output);
}
@@ -202,7 +202,7 @@ namespace Umbraco.Tests.Strings
[Test]
public void ToUrlSegmentWithCulture()
{
var output = "JUST-ANYTHING".ToUrlSegment(CultureInfo.InvariantCulture);
var output = "JUST-ANYTHING".ToUrlSegment(null);
Assert.AreEqual("URL-SEGMENT-CULTURE::JUST-ANYTHING", output);
}
@@ -216,7 +216,7 @@ namespace Umbraco.Tests.Strings
[Test]
public void ToSafeFileNameWithCulture()
{
var output = "JUST-ANYTHING".ToSafeFileName(CultureInfo.InvariantCulture);
var output = "JUST-ANYTHING".ToSafeFileName(null);
Assert.AreEqual("SAFE-FILE-NAME-CULTURE::JUST-ANYTHING", output);
}

View File

@@ -29,6 +29,7 @@ using Umbraco.Web.Security;
using Umbraco.Web.WebApi;
using LightInject;
using System.Globalization;
using Umbraco.Tests.Testing.Objects.Accessors;
namespace Umbraco.Tests.TestHelpers.ControllerTesting
{
@@ -149,7 +150,7 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting
Mock.Of<IUmbracoSettingsSection>(section => section.WebRouting == Mock.Of<IWebRoutingSection>(routingSection => routingSection.UrlProviderMode == UrlProviderMode.Auto.ToString())),
Enumerable.Empty<IUrlProvider>(),
globalSettings,
mockedEntityService,
new TestCurrentVariationAccessor(),
true); //replace it
var urlHelper = new Mock<IUrlProvider>();

View File

@@ -120,7 +120,7 @@ namespace Umbraco.Tests.TestHelpers
var urlProviders = Enumerable.Empty<IUrlProvider>();
if (accessor == null) accessor = new TestUmbracoContextAccessor();
return UmbracoContext.EnsureContext(accessor, httpContext, publishedSnapshotService, webSecurity, umbracoSettings, urlProviders, globalSettings, Mock.Of<IEntityService>(), true);
return UmbracoContext.EnsureContext(accessor, httpContext, publishedSnapshotService, webSecurity, umbracoSettings, urlProviders, globalSettings, new TestCurrentVariationAccessor(), true);
}
public IUmbracoSettingsSection GetUmbracoSettings()

View File

@@ -379,7 +379,7 @@ namespace Umbraco.Tests.TestHelpers
umbracoSettings ?? Container.GetInstance<IUmbracoSettingsSection>(),
urlProviders ?? Enumerable.Empty<IUrlProvider>(),
globalSettings ?? Container.GetInstance<IGlobalSettings>(),
ServiceContext.EntityService);
new TestCurrentVariationAccessor());
if (setSingleton)
Umbraco.Web.Composing.Current.UmbracoContextAccessor.UmbracoContext = umbracoContext;

View File

@@ -81,7 +81,7 @@ namespace Umbraco.Tests.Testing.TestingTests
.Returns("/hello/world/1234");
var urlProvider = urlProviderMock.Object;
var theUrlProvider = new UrlProvider(umbracoContext, new [] { urlProvider });
var theUrlProvider = new UrlProvider(umbracoContext, new [] { urlProvider }, umbracoContext.CurrentVariationAccessor);
var contentType = new PublishedContentType(666, "alias", PublishedItemType.Content, Enumerable.Empty<string>(), Enumerable.Empty<PublishedPropertyType>(),
ContentVariation.InvariantNeutral);

View File

@@ -73,7 +73,7 @@ namespace Umbraco.Tests.Web.Mvc
TestObjects.GetUmbracoSettings(),
Enumerable.Empty<IUrlProvider>(),
globalSettings,
Mock.Of<IEntityService>(),
new TestCurrentVariationAccessor(),
true);
var ctrl = new MatchesDefaultIndexController { UmbracoContext = umbCtx };
var controllerCtx = new ControllerContext(req, ctrl);
@@ -97,7 +97,7 @@ namespace Umbraco.Tests.Web.Mvc
TestObjects.GetUmbracoSettings(),
Enumerable.Empty<IUrlProvider>(),
globalSettings,
Mock.Of<IEntityService>(),
new TestCurrentVariationAccessor(),
true);
var ctrl = new MatchesOverriddenIndexController { UmbracoContext = umbCtx };
var controllerCtx = new ControllerContext(req, ctrl);
@@ -121,7 +121,7 @@ namespace Umbraco.Tests.Web.Mvc
TestObjects.GetUmbracoSettings(),
Enumerable.Empty<IUrlProvider>(),
globalSettings,
Mock.Of<IEntityService>(),
new TestCurrentVariationAccessor(),
true);
var ctrl = new MatchesCustomIndexController { UmbracoContext = umbCtx };
var controllerCtx = new ControllerContext(req, ctrl);
@@ -145,7 +145,7 @@ namespace Umbraco.Tests.Web.Mvc
TestObjects.GetUmbracoSettings(),
Enumerable.Empty<IUrlProvider>(),
globalSettings,
Mock.Of<IEntityService>(),
new TestCurrentVariationAccessor(),
true);
var ctrl = new MatchesAsyncIndexController { UmbracoContext = umbCtx };
var controllerCtx = new ControllerContext(req, ctrl);

View File

@@ -46,7 +46,7 @@ namespace Umbraco.Tests.Web.Mvc
TestObjects.GetUmbracoSettings(),
Enumerable.Empty<IUrlProvider>(),
globalSettings,
Mock.Of<IEntityService>(),
new TestCurrentVariationAccessor(),
true);
var ctrl = new TestSurfaceController { UmbracoContext = umbracoContext };
@@ -68,7 +68,7 @@ namespace Umbraco.Tests.Web.Mvc
TestObjects.GetUmbracoSettings(),
Enumerable.Empty<IUrlProvider>(),
globalSettings,
Mock.Of<IEntityService>(),
new TestCurrentVariationAccessor(),
true);
var ctrl = new TestSurfaceController { UmbracoContext = umbCtx };
@@ -88,7 +88,7 @@ namespace Umbraco.Tests.Web.Mvc
TestObjects.GetUmbracoSettings(),
Enumerable.Empty<IUrlProvider>(),
globalSettings,
Mock.Of<IEntityService>(),
new TestCurrentVariationAccessor(),
true);
var controller = new TestSurfaceController { UmbracoContext = umbracoContext };
@@ -115,7 +115,7 @@ namespace Umbraco.Tests.Web.Mvc
Mock.Of<IUmbracoSettingsSection>(section => section.WebRouting == Mock.Of<IWebRoutingSection>(routingSection => routingSection.UrlProviderMode == "AutoLegacy")),
Enumerable.Empty<IUrlProvider>(),
globalSettings,
Mock.Of<IEntityService>(),
new TestCurrentVariationAccessor(),
true);
var helper = new UmbracoHelper(
@@ -153,7 +153,7 @@ namespace Umbraco.Tests.Web.Mvc
Mock.Of<IUmbracoSettingsSection>(section => section.WebRouting == webRoutingSettings),
Enumerable.Empty<IUrlProvider>(),
globalSettings,
Mock.Of<IEntityService>(),
new TestCurrentVariationAccessor(),
true);
var content = Mock.Of<IPublishedContent>(publishedContent => publishedContent.Id == 12345);

View File

@@ -441,7 +441,7 @@ namespace Umbraco.Tests.Web.Mvc
TestObjects.GetUmbracoSettings(),
Enumerable.Empty<IUrlProvider>(),
globalSettings,
Mock.Of<IEntityService>());
new TestCurrentVariationAccessor());
//if (setSingleton)
//{

View File

@@ -82,7 +82,7 @@ namespace Umbraco.Tests.Web
var globalSettings = SettingsForTests.GenerateMockGlobalSettings();
var contentType = new PublishedContentType(666, "alia", PublishedItemType.Content, Enumerable.Empty<string>(), Enumerable.Empty<PublishedPropertyType>(), ContentVariation.InvariantNeutral);
var contentType = new PublishedContentType(666, "alias", PublishedItemType.Content, Enumerable.Empty<string>(), Enumerable.Empty<PublishedPropertyType>(), ContentVariation.InvariantNeutral);
var publishedContent = Mock.Of<IPublishedContent>();
Mock.Get(publishedContent).Setup(x => x.Id).Returns(1234);
Mock.Get(publishedContent).Setup(x => x.ContentType).Returns(contentType);
@@ -104,7 +104,7 @@ namespace Umbraco.Tests.Web
//pass in the custom url provider
new[]{ testUrlProvider.Object },
globalSettings,
entityService.Object,
new TestCurrentVariationAccessor(),
true))
{
var output = TemplateUtilities.ParseInternalLinks(input, umbCtx.UrlProvider);

View File

@@ -32,7 +32,7 @@ namespace Umbraco.Tests.Web
TestObjects.GetUmbracoSettings(),
new List<IUrlProvider>(),
TestObjects.GetGlobalSettings(),
Mock.Of<IEntityService>());
new TestCurrentVariationAccessor());
var r1 = new RouteData();
r1.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx);
@@ -50,7 +50,7 @@ namespace Umbraco.Tests.Web
TestObjects.GetUmbracoSettings(),
new List<IUrlProvider>(),
TestObjects.GetGlobalSettings(),
Mock.Of<IEntityService>());
new TestCurrentVariationAccessor());
var r1 = new RouteData();
r1.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx);
@@ -78,7 +78,7 @@ namespace Umbraco.Tests.Web
TestObjects.GetUmbracoSettings(),
new List<IUrlProvider>(),
TestObjects.GetGlobalSettings(),
Mock.Of<IEntityService>());
new TestCurrentVariationAccessor());
var httpContext = Mock.Of<HttpContextBase>();

View File

@@ -6,7 +6,6 @@ using Umbraco.Core;
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Services;
using System.Linq;
using System.Reflection;
@@ -15,12 +14,13 @@ using System.Web.Hosting;
using Umbraco.Core.Components;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Services.Changes;
using Umbraco.Core.Services.Implement;
using Umbraco.Web.Composing;
using Umbraco.Web.Security;
using Umbraco.Web.Services;
using Content = Umbraco.Core.Models.Content;
using LightInject;
using ApplicationTree = Umbraco.Core.Models.ApplicationTree;
namespace Umbraco.Web.Cache
@@ -237,7 +237,7 @@ namespace Umbraco.Web.Cache
UmbracoConfig.For.UmbracoSettings(),
Current.UrlProviders,
UmbracoConfig.For.GlobalSettings(),
Current.Services.EntityService,
Current.Container.GetInstance<ICurrentVariationAccessor>(),
true);
}

View File

@@ -15,7 +15,7 @@ namespace Umbraco.Web.Models
[DebuggerDisplay("Content Id: {Id}, Name: {Name}")]
public abstract class PublishedContentBase : IPublishedContent
{
private string _url; // fixme meaning?
private string _url; // fixme - cannot cache urls! depends on the current request!
#region ContentType
@@ -84,7 +84,7 @@ namespace Umbraco.Web.Models
switch (ItemType)
{
case PublishedItemType.Content:
// fixme inject an umbraco context accessor!
// fixme - consider injecting an umbraco context accessor
if (UmbracoContext.Current == null)
throw new InvalidOperationException("Cannot compute Url for a content item when UmbracoContext.Current is null.");
if (UmbracoContext.Current.UrlProvider == null)
@@ -103,7 +103,8 @@ namespace Umbraco.Web.Models
var propType = ContentType.GetPropertyType(Constants.Conventions.Media.File);
// fixme this is horrible we need url providers for media too + this does NOT support variations
// fixme - consider implementing media url providers
// note: that one does not support variations
//This is a hack - since we now have 2 properties that support a URL: upload and cropper, we need to detect this since we always
// want to return the normal URL and the cropper stores data as json
switch (propType.EditorAlias)
@@ -130,7 +131,7 @@ namespace Umbraco.Web.Models
throw new NotSupportedException();
}
}
/// <inheritdoc />
public abstract PublishedCultureInfos GetCulture(string culture = ".");
@@ -166,7 +167,7 @@ namespace Umbraco.Web.Models
/// <inheritdoc cref="IPublishedContent.GetProperty(string, bool)"/>
public virtual IPublishedProperty GetProperty(string alias, bool recurse)
{
// fixme - but can recurse work with variants?
// fixme - refactor with fallback
var property = GetProperty(alias);
if (recurse == false) return property;

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Web;
using Examine;
@@ -123,28 +122,6 @@ namespace Umbraco.Web
#region Value
// fixme missing variations, but recurse/variations/fallback = ?
/// <summary>
/// Recursively gets the value of a content's property identified by its alias.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="alias">The property alias.</param>
/// <param name="recurse">A value indicating whether to recurse.</param>
/// <returns>The recursive value of the content's property identified by the alias.</returns>
/// <remarks>
/// <para>Recursively means: walking up the tree from <paramref name="content"/>, get the first value that can be found.</para>
/// <para>The value comes from <c>IPublishedProperty</c> field <c>Value</c> ie it is suitable for use when rendering content.</para>
/// <para>If no property with the specified alias exists, or if the property has no value, returns <c>null</c>.</para>
/// <para>If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter.</para>
/// <para>The alias is case-insensitive.</para>
/// </remarks>
public static object Value(this IPublishedContent content, string alias, bool recurse)
{
var property = content.GetProperty(alias, recurse);
return property?.GetValue();
}
/// <summary>
/// Recursively the value of a content's property identified by its alias, if it exists, otherwise a default value.
/// </summary>
@@ -164,7 +141,7 @@ namespace Umbraco.Web
/// </remarks>
public static object Value(this IPublishedContent content, string alias, string culture = ".", string segment = ".", object defaultValue = default, bool recurse = false)
{
// fixme - variations+recurse not implemented here
// fixme - refactor with fallback
var property = content.GetProperty(alias, recurse);
return property == null || property.HasValue(culture, segment) == false ? defaultValue : property.GetValue();
}
@@ -193,7 +170,7 @@ namespace Umbraco.Web
/// </remarks>
public static T Value<T>(this IPublishedContent content, string alias, string culture = ".", string segment = ".", T defaultValue = default, bool recurse = false)
{
// fixme - variations+recurse not implemented here
// fixme - refactor with fallback
var property = content.GetProperty(alias, recurse);
if (property == null) return defaultValue;
@@ -209,8 +186,8 @@ namespace Umbraco.Web
//TODO: we should pass in the IExamineManager?
var searcher = string.IsNullOrEmpty(indexName)
? Examine.ExamineManager.Instance.GetSearcher(Constants.Examine.ExternalIndexer)
: Examine.ExamineManager.Instance.GetSearcher(indexName);
? ExamineManager.Instance.GetSearcher(Constants.Examine.ExternalIndexer)
: ExamineManager.Instance.GetSearcher(indexName);
if (searcher == null)
throw new InvalidOperationException("No searcher found for index " + indexName);
@@ -235,8 +212,8 @@ namespace Umbraco.Web
//TODO: we should pass in the IExamineManager?
var searcher = string.IsNullOrEmpty(indexName)
? Examine.ExamineManager.Instance.GetSearcher(Constants.Examine.ExternalIndexer)
: Examine.ExamineManager.Instance.GetSearcher(indexName);
? ExamineManager.Instance.GetSearcher(Constants.Examine.ExternalIndexer)
: ExamineManager.Instance.GetSearcher(indexName);
if (searcher == null)
throw new InvalidOperationException("No searcher found for index " + indexName);
@@ -255,7 +232,7 @@ namespace Umbraco.Web
{
//TODO: we should pass in the IExamineManager?
var s = searchProvider ?? Examine.ExamineManager.Instance.GetSearcher(Constants.Examine.ExternalIndexer);
var s = searchProvider ?? ExamineManager.Instance.GetSearcher(Constants.Examine.ExternalIndexer);
var results = s.Search(criteria);
return results.ToPublishedSearchResults(UmbracoContext.Current.ContentCache);
@@ -1170,8 +1147,8 @@ namespace Umbraco.Web
/// </summary>
internal static Func<ServiceContext, string, Dictionary<string, string>> GetPropertyAliasesAndNames
{
get { return _getPropertyAliasesAndNames ?? GetAliasesAndNames; }
set { _getPropertyAliasesAndNames = value; }
get => _getPropertyAliasesAndNames ?? GetAliasesAndNames;
set => _getPropertyAliasesAndNames = value;
}
private static Dictionary<string, string> GetAliasesAndNames(ServiceContext services, string alias)

View File

@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Web;
using Umbraco.Core.Models.PublishedContent;
@@ -56,7 +54,9 @@ namespace Umbraco.Web
return prop != null && prop.HasValue(culture, segment);
}
// fixme - that one is missing variations
// fixme - .Value() refactoring - in progress
// missing variations...
/// <summary>
/// Returns one of two strings depending on whether the content has a value for a property identified by its alias.
/// </summary>
@@ -134,7 +134,7 @@ namespace Umbraco.Web
#region Value or Umbraco.Field - WORK IN PROGRESS
// fixme - more work-in-progress for element.Value() and element.Value<T>() here
// fixme - .Value() refactoring - in progress
// trying to reproduce Umbraco.Field so we can get rid of it
//
// what we want:
@@ -150,10 +150,10 @@ namespace Umbraco.Web
// see UmbracoComponentRenderer.Field - which is ugly ;-(
// recurse first, on each alias (that's how it's done in Field)
// TODO: strongly typed properties howto?
//
// there is no strongly typed recurse, etc => needs to be in ModelsBuilder?
// todo - that one can only happen in ModelsBuilder as that's where the attributes are defined
// that one can only happen in ModelsBuilder as that's where the attributes are defined
// the attribute that carries the alias is in ModelsBuilder!
//public static TValue Value<TModel, TValue>(this TModel content, Expression<Func<TModel, TValue>> propertySelector, ...)
// where TModel : IPublishedElement
@@ -164,6 +164,8 @@ namespace Umbraco.Web
// return content.Value<TValue>(alias, ...)
//}
// recurse should be implemented via fallback
// todo - that one should be refactored, missing culture and so many things
public static IHtmlString Value<T>(this IPublishedElement content, string aliases, Func<T, string> format, string alt = "")
{

View File

@@ -20,15 +20,16 @@ namespace Umbraco.Web.Routing
/// 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="routingSettings"></param>
/// <param name="routingSettings">Routing settings.</param>
/// <param name="urlProviders">The list of url providers.</param>
public UrlProvider(UmbracoContext umbracoContext, IWebRoutingSection routingSettings, IEnumerable<IUrlProvider> urlProviders, IEntityService entityService)
/// <param name="variationAccessor">The current variation accessor.</param>
public UrlProvider(UmbracoContext umbracoContext, IWebRoutingSection routingSettings, IEnumerable<IUrlProvider> urlProviders, ICurrentVariationAccessor variationAccessor)
{
if (routingSettings == null) throw new ArgumentNullException(nameof(routingSettings));
_umbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext));
_urlProviders = urlProviders;
_entityService = entityService ?? throw new ArgumentNullException(nameof(entityService));
_urlProviders = urlProviders;
_variationAccessor = variationAccessor ?? throw new ArgumentNullException(nameof(variationAccessor));
var provider = UrlProviderMode.Auto;
Mode = provider;
@@ -43,19 +44,20 @@ namespace Umbraco.Web.Routing
/// </summary>
/// <param name="umbracoContext">The Umbraco context.</param>
/// <param name="urlProviders">The list of url providers.</param>
/// <param name="provider"></param>
public UrlProvider(UmbracoContext umbracoContext, IEnumerable<IUrlProvider> urlProviders, UrlProviderMode provider = UrlProviderMode.Auto)
/// <param name="variationAccessor">The current variation accessor.</param>
/// <param name="mode">An optional provider mode.</param>
public UrlProvider(UmbracoContext umbracoContext, IEnumerable<IUrlProvider> urlProviders, ICurrentVariationAccessor variationAccessor, UrlProviderMode mode = UrlProviderMode.Auto)
{
_umbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext));
_urlProviders = urlProviders;
_variationAccessor = variationAccessor;
Mode = provider;
Mode = mode;
}
private readonly UmbracoContext _umbracoContext;
private readonly IEnumerable<IUrlProvider> _urlProviders;
private readonly IEntityService _entityService;
private readonly ICurrentVariationAccessor _variationAccessor; // fixme set!
private readonly ICurrentVariationAccessor _variationAccessor;
/// <summary>
/// Gets or sets the provider url mode.

View File

@@ -218,6 +218,7 @@ namespace Umbraco.Web.Runtime
IUmbracoSettingsSection umbracoSettings,
IGlobalSettings globalSettings,
IEntityService entityService,
ICurrentVariationAccessor variationAccessor,
UrlProviderCollection urlProviders)
{
// setup mvc and webapi services
@@ -255,7 +256,7 @@ namespace Umbraco.Web.Runtime
umbracoSettings,
urlProviders,
globalSettings,
entityService);
variationAccessor);
// ensure WebAPI is initialized, after everything
GlobalConfiguration.Configuration.EnsureInitialized();

View File

@@ -4,6 +4,7 @@ using System.Web;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Services;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
@@ -67,9 +68,9 @@ namespace Umbraco.Web
IPublishedSnapshotService publishedSnapshotService,
WebSecurity webSecurity,
IUmbracoSettingsSection umbracoSettings,
IEnumerable<IUrlProvider> urlProviders,
IGlobalSettings globalSettings,
IEntityService entityService,
IEnumerable<IUrlProvider> urlProviders,
IGlobalSettings globalSettings,
ICurrentVariationAccessor variationAccessor,
bool replace = false)
{
if (umbracoContextAccessor == null) throw new ArgumentNullException(nameof(umbracoContextAccessor));
@@ -87,7 +88,7 @@ namespace Umbraco.Web
// create & assign to accessor, dispose existing if any
umbracoContextAccessor.UmbracoContext?.Dispose();
return umbracoContextAccessor.UmbracoContext = new UmbracoContext(httpContext, publishedSnapshotService, webSecurity, umbracoSettings, urlProviders, globalSettings, entityService);
return umbracoContextAccessor.UmbracoContext = new UmbracoContext(httpContext, publishedSnapshotService, webSecurity, umbracoSettings, urlProviders, globalSettings, variationAccessor);
}
// initializes a new instance of the UmbracoContext class
@@ -100,13 +101,14 @@ namespace Umbraco.Web
IUmbracoSettingsSection umbracoSettings,
IEnumerable<IUrlProvider> urlProviders,
IGlobalSettings globalSettings,
IEntityService entityService)
ICurrentVariationAccessor variationAccessor)
{
if (httpContext == null) throw new ArgumentNullException(nameof(httpContext));
if (publishedSnapshotService == null) throw new ArgumentNullException(nameof(publishedSnapshotService));
if (webSecurity == null) throw new ArgumentNullException(nameof(webSecurity));
if (umbracoSettings == null) throw new ArgumentNullException(nameof(umbracoSettings));
if (urlProviders == null) throw new ArgumentNullException(nameof(urlProviders));
CurrentVariationAccessor = variationAccessor ?? throw new ArgumentNullException(nameof(variationAccessor));
_globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings));
// ensure that this instance is disposed when the request terminates, though we *also* ensure
@@ -136,7 +138,7 @@ namespace Umbraco.Web
//
OriginalRequestUrl = GetRequestFromContext()?.Url ?? new Uri("http://localhost");
CleanedUmbracoUrl = UriUtility.UriToUmbraco(OriginalRequestUrl);
UrlProvider = new UrlProvider(this, umbracoSettings.WebRouting, urlProviders, entityService);
UrlProvider = new UrlProvider(this, umbracoSettings.WebRouting, urlProviders, variationAccessor);
}
#endregion
@@ -213,6 +215,8 @@ namespace Umbraco.Web
/// </summary>
public HttpContextBase HttpContext { get; }
public ICurrentVariationAccessor CurrentVariationAccessor { get; }
/// <summary>
/// Creates and caches an instance of a DomainHelper
/// </summary>

View File

@@ -1,10 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.Routing;
using LightInject;
@@ -17,12 +15,12 @@ using Umbraco.Web.Security;
using Umbraco.Core.Collections;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Persistence;
using Umbraco.Core.Security;
using Umbraco.Core.Services;
using Umbraco.Web.Composing;
using Umbraco.Web.PublishedCache;
using GlobalSettings = Umbraco.Core.Configuration.GlobalSettings;
namespace Umbraco.Web
{
@@ -55,9 +53,6 @@ namespace Umbraco.Web
[Inject]
public IUserService UserService { get; set; }
[Inject]
public IEntityService EntityService { get; set; }
[Inject]
public UrlProviderCollection UrlProviders { get; set; }
@@ -71,7 +66,10 @@ namespace Umbraco.Web
internal PublishedRouter PublishedRouter { get; set; }
[Inject]
internal IUmbracoDatabaseFactory DatabaseFactory { get; set; }
internal IUmbracoDatabaseFactory DatabaseFactory { get; set; }
[Inject]
internal ICurrentVariationAccessor CurrentVariationAccessor { get; set; }
#endregion
@@ -114,8 +112,8 @@ namespace Umbraco.Web
new WebSecurity(httpContext, UserService, GlobalSettings),
UmbracoConfig.For.UmbracoSettings(),
UrlProviders,
GlobalSettings,
EntityService,
GlobalSettings,
CurrentVariationAccessor,
true);
}

View File

@@ -75,7 +75,7 @@ namespace umbraco
//check for published content and get its value using that
if (publishedContent != null && (publishedContent.HasProperty(_fieldName) || recursive))
{
var pval = publishedContent.Value(_fieldName, recursive);
var pval = publishedContent.Value(_fieldName, recurse: recursive);
var rval = pval == null ? string.Empty : pval.ToString();
_fieldContent = rval.IsNullOrWhiteSpace() ? _fieldContent : rval;
}
@@ -95,7 +95,7 @@ namespace umbraco
{
if (publishedContent != null && (publishedContent.HasProperty(altFieldName) || recursive))
{
var pval = publishedContent.Value(altFieldName, recursive);
var pval = publishedContent.Value(altFieldName, recurse: recursive);
var rval = pval == null ? string.Empty : pval.ToString();
_fieldContent = rval.IsNullOrWhiteSpace() ? _fieldContent : rval;
}