Using IIOHelper in ManifestParser
This commit is contained in:
@@ -39,6 +39,22 @@ namespace Umbraco.Core.Composing
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets <see cref="Current"/>. Indented for testing only, and not supported in production code.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>For UNIT TESTS exclusively.</para>
|
||||
/// <para>Resets everything that is 'current'.</para>
|
||||
/// </remarks>
|
||||
public static void Reset()
|
||||
{
|
||||
_factory.DisposeIfDisposable();
|
||||
_factory = null;
|
||||
|
||||
_logger = null;
|
||||
_profiler = null;
|
||||
_profilingLogger = null;
|
||||
}
|
||||
public static bool HasFactory => _factory != null;
|
||||
|
||||
#region Getters
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using System.IO;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.Grid;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Manifest;
|
||||
@@ -16,9 +14,9 @@ namespace Umbraco.Core
|
||||
public static class ConfigsExtensions
|
||||
{
|
||||
|
||||
public static void AddCoreConfigs(this Configs configs)
|
||||
public static void AddCoreConfigs(this Configs configs, IIOHelper ioHelper)
|
||||
{
|
||||
var configDir = new DirectoryInfo(Current.IOHelper.MapPath(SystemDirectories.Config));
|
||||
var configDir = new DirectoryInfo(ioHelper.MapPath(SystemDirectories.Config));
|
||||
|
||||
// GridConfig depends on runtime caches, manifest parsers... and cannot be available during composition
|
||||
configs.Add<IGridConfig>(factory => new GridConfig(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Configuration;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration.HealthChecks;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
|
||||
@@ -6,6 +7,8 @@ namespace Umbraco.Core.Configuration
|
||||
{
|
||||
public class ConfigsFactory : IConfigsFactory
|
||||
{
|
||||
|
||||
|
||||
public Configs Create() {
|
||||
var configs = new Configs(section => ConfigurationManager.GetSection(section));
|
||||
configs.Add<IGlobalSettings>(() => new GlobalSettings());
|
||||
@@ -13,7 +16,7 @@ namespace Umbraco.Core.Configuration
|
||||
configs.Add<IHealthChecks>("umbracoConfiguration/HealthChecks");
|
||||
|
||||
configs.Add(() => new CoreDebug());
|
||||
configs.AddCoreConfigs();
|
||||
configs.AddCoreConfigs(Current.IOHelper);
|
||||
return configs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration.Grid;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
@@ -23,6 +22,7 @@ namespace Umbraco.Core.Manifest
|
||||
|
||||
private readonly IAppPolicyCache _cache;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly ManifestValueValidatorCollection _validators;
|
||||
private readonly ManifestFilterCollection _filters;
|
||||
|
||||
@@ -31,28 +31,30 @@ namespace Umbraco.Core.Manifest
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ManifestParser"/> class.
|
||||
/// </summary>
|
||||
public ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, ILogger logger)
|
||||
: this(appCaches, validators, filters, "~/App_Plugins", logger)
|
||||
public ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, ILogger logger, IIOHelper ioHelper)
|
||||
: this(appCaches, validators, filters, SystemDirectories.AppPlugins, logger, ioHelper)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ManifestParser"/> class.
|
||||
/// </summary>
|
||||
private ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, string path, ILogger logger)
|
||||
private ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, string path, ILogger logger, IIOHelper ioHelper)
|
||||
{
|
||||
if (appCaches == null) throw new ArgumentNullException(nameof(appCaches));
|
||||
_cache = appCaches.RuntimeCache;
|
||||
_validators = validators ?? throw new ArgumentNullException(nameof(validators));
|
||||
_filters = filters ?? throw new ArgumentNullException(nameof(filters));
|
||||
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentNullOrEmptyException(nameof(path));
|
||||
_ioHelper = ioHelper;
|
||||
Path = path;
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
}
|
||||
|
||||
public string Path
|
||||
{
|
||||
get => _path;
|
||||
set => _path = value.StartsWith("~/") ? Current.IOHelper.MapPath(value) : value;
|
||||
set => _path = value.StartsWith("~/") ? _ioHelper.MapPath(value) : value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -167,9 +169,9 @@ namespace Umbraco.Core.Manifest
|
||||
|
||||
// scripts and stylesheets are raw string, must process here
|
||||
for (var i = 0; i < manifest.Scripts.Length; i++)
|
||||
manifest.Scripts[i] = Current.IOHelper.ResolveVirtualUrl(manifest.Scripts[i]);
|
||||
manifest.Scripts[i] = _ioHelper.ResolveVirtualUrl(manifest.Scripts[i]);
|
||||
for (var i = 0; i < manifest.Stylesheets.Length; i++)
|
||||
manifest.Stylesheets[i] = Current.IOHelper.ResolveVirtualUrl(manifest.Stylesheets[i]);
|
||||
manifest.Stylesheets[i] = _ioHelper.ResolveVirtualUrl(manifest.Stylesheets[i]);
|
||||
|
||||
// add property editors that are also parameter editors, to the parameter editors list
|
||||
// (the manifest format is kinda legacy)
|
||||
|
||||
@@ -244,7 +244,10 @@
|
||||
<Compile Include="Models\Packaging\PackageDefinition.cs" />
|
||||
<Compile Include="Models\Property.cs" />
|
||||
<Compile Include="Models\PropertyCollection.cs" />
|
||||
<Compile Include="Models\PropertyGroup.cs" />
|
||||
<Compile Include="Models\PropertyGroupCollection.cs" />
|
||||
<Compile Include="Models\PropertyType.cs" />
|
||||
<Compile Include="Models\PropertyTypeCollection.cs" />
|
||||
<Compile Include="Models\PublicAccessEntry.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\FixLanguageIsoCodeLength.cs" />
|
||||
<Compile Include="Models\CultureImpact.cs" />
|
||||
@@ -538,11 +541,6 @@
|
||||
<Compile Include="Models\Packaging\InstallationSummary.cs" />
|
||||
<Compile Include="Models\Packaging\PreInstallWarnings.cs" />
|
||||
<Compile Include="Models\PagedResultOfT.cs" />
|
||||
<Compile Include="Models\Property.cs" />
|
||||
<Compile Include="Models\PropertyCollection.cs" />
|
||||
<Compile Include="Models\PropertyGroup.cs" />
|
||||
<Compile Include="Models\PropertyGroupCollection.cs" />
|
||||
<Compile Include="Models\PropertyTypeCollection.cs" />
|
||||
<Compile Include="Models\PublishedContent\NoopPublishedModelFactory.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedContentTypeFactory.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedContentExtensionsForModels.cs" />
|
||||
|
||||
@@ -13,6 +13,7 @@ using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.PropertyEditors.Validators;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Dashboards;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Tests.Manifest
|
||||
{
|
||||
@@ -25,6 +26,7 @@ namespace Umbraco.Tests.Manifest
|
||||
public void Setup()
|
||||
{
|
||||
Current.Reset();
|
||||
CurrentCore.Reset();
|
||||
var factory = Mock.Of<IFactory>();
|
||||
Current.Factory = factory;
|
||||
CurrentCore.Factory = factory;
|
||||
@@ -45,7 +47,7 @@ namespace Umbraco.Tests.Manifest
|
||||
new RequiredValidator(Mock.Of<ILocalizedTextService>()),
|
||||
new RegexValidator(Mock.Of<ILocalizedTextService>(), null)
|
||||
};
|
||||
_parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), new ManifestFilterCollection(Array.Empty<IManifestFilter>()), Mock.Of<ILogger>());
|
||||
_parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), new ManifestFilterCollection(Array.Empty<IManifestFilter>()), Mock.Of<ILogger>(), Mock.Of<IIOHelper>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in New Issue
Block a user