Removed library.cs and it cache settings

This commit is contained in:
Anthony
2018-06-29 13:56:00 +01:00
parent 69d1f4e0cd
commit b3a8161b25
11 changed files with 3490 additions and 3680 deletions
@@ -1,146 +1,141 @@
using System.Collections.Generic;
using System.Configuration;
using Umbraco.Core.Macros;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class ContentElement : UmbracoConfigurationElement, IContentSection
{
private const string DefaultPreviewBadge = @"<a id=""umbracoPreviewBadge"" style=""position: absolute; top: 0; right: 0; border: 0; width: 149px; height: 149px; background: url('{0}/assets/img/preview-mode-badge.png') no-repeat;"" href=""{0}/endPreview.aspx?redir={1}""><span style=""display:none;"">In Preview Mode - click to end</span></a>";
[ConfigurationProperty("imaging")]
internal ContentImagingElement Imaging => (ContentImagingElement) this["imaging"];
[ConfigurationProperty("scripteditor")]
internal ContentScriptEditorElement ScriptEditor => (ContentScriptEditorElement) this["scripteditor"];
[ConfigurationProperty("ResolveUrlsFromTextString")]
internal InnerTextConfigurationElement<bool> ResolveUrlsFromTextString => GetOptionalTextElement("ResolveUrlsFromTextString", false);
[ConfigurationProperty("UploadAllowDirectories")]
internal InnerTextConfigurationElement<bool> UploadAllowDirectories => GetOptionalTextElement("UploadAllowDirectories", true);
public IEnumerable<IContentErrorPage> Error404Collection => Errors.Error404Collection;
[ConfigurationProperty("errors", IsRequired = true)]
internal ContentErrorsElement Errors => (ContentErrorsElement) base["errors"];
[ConfigurationProperty("notifications", IsRequired = true)]
internal NotificationsElement Notifications => (NotificationsElement) base["notifications"];
[ConfigurationProperty("ensureUniqueNaming")]
internal InnerTextConfigurationElement<bool> EnsureUniqueNaming => GetOptionalTextElement("ensureUniqueNaming", true);
[ConfigurationProperty("XmlCacheEnabled")]
internal InnerTextConfigurationElement<bool> XmlCacheEnabled => GetOptionalTextElement("XmlCacheEnabled", true);
[ConfigurationProperty("ContinouslyUpdateXmlDiskCache")]
internal InnerTextConfigurationElement<bool> ContinouslyUpdateXmlDiskCache => GetOptionalTextElement("ContinouslyUpdateXmlDiskCache", true);
[ConfigurationProperty("XmlContentCheckForDiskChanges")]
internal InnerTextConfigurationElement<bool> XmlContentCheckForDiskChanges => GetOptionalTextElement("XmlContentCheckForDiskChanges", false);
[ConfigurationProperty("EnableSplashWhileLoading")]
internal InnerTextConfigurationElement<bool> EnableSplashWhileLoading => GetOptionalTextElement("EnableSplashWhileLoading", false);
[ConfigurationProperty("PropertyContextHelpOption")]
internal InnerTextConfigurationElement<string> PropertyContextHelpOption => GetOptionalTextElement("PropertyContextHelpOption", "text");
[ConfigurationProperty("ForceSafeAliases")]
internal InnerTextConfigurationElement<bool> ForceSafeAliases => GetOptionalTextElement("ForceSafeAliases", true);
[ConfigurationProperty("PreviewBadge")]
internal InnerTextConfigurationElement<string> PreviewBadge => GetOptionalTextElement("PreviewBadge", DefaultPreviewBadge);
[ConfigurationProperty("UmbracoLibraryCacheDuration")]
internal InnerTextConfigurationElement<int> UmbracoLibraryCacheDuration => GetOptionalTextElement("UmbracoLibraryCacheDuration", 1800);
[ConfigurationProperty("MacroErrors")]
internal InnerTextConfigurationElement<MacroErrorBehaviour> MacroErrors => GetOptionalTextElement("MacroErrors", MacroErrorBehaviour.Inline);
[ConfigurationProperty("disallowedUploadFiles")]
internal CommaDelimitedConfigurationElement DisallowedUploadFiles => GetOptionalDelimitedElement("disallowedUploadFiles", new[] {"ashx", "aspx", "ascx", "config", "cshtml", "vbhtml", "asmx", "air", "axd"});
[ConfigurationProperty("allowedUploadFiles")]
internal CommaDelimitedConfigurationElement AllowedUploadFiles => GetOptionalDelimitedElement("allowedUploadFiles", new string[0]);
[ConfigurationProperty("cloneXmlContent")]
internal InnerTextConfigurationElement<bool> CloneXmlContent => GetOptionalTextElement("cloneXmlContent", true);
[ConfigurationProperty("GlobalPreviewStorageEnabled")]
internal InnerTextConfigurationElement<bool> GlobalPreviewStorageEnabled => GetOptionalTextElement("GlobalPreviewStorageEnabled", false);
[ConfigurationProperty("defaultDocumentTypeProperty")]
internal InnerTextConfigurationElement<string> DefaultDocumentTypeProperty => GetOptionalTextElement("defaultDocumentTypeProperty", "Textstring");
[ConfigurationProperty("showDeprecatedPropertyEditors")]
internal InnerTextConfigurationElement<bool> ShowDeprecatedPropertyEditors => GetOptionalTextElement("showDeprecatedPropertyEditors", false);
[ConfigurationProperty("EnableInheritedDocumentTypes")]
internal InnerTextConfigurationElement<bool> EnableInheritedDocumentTypes => GetOptionalTextElement("EnableInheritedDocumentTypes", true);
[ConfigurationProperty("EnableInheritedMediaTypes")]
internal InnerTextConfigurationElement<bool> EnableInheritedMediaTypes => GetOptionalTextElement("EnableInheritedMediaTypes", true);
[ConfigurationProperty("loginBackgroundImage")]
internal InnerTextConfigurationElement<string> LoginBackgroundImage => GetOptionalTextElement("loginBackgroundImage", string.Empty);
string IContentSection.NotificationEmailAddress => Notifications.NotificationEmailAddress;
bool IContentSection.DisableHtmlEmail => Notifications.DisableHtmlEmail;
IEnumerable<string> IContentSection.ImageFileTypes => Imaging.ImageFileTypes;
IEnumerable<string> IContentSection.ImageTagAllowedAttributes => Imaging.ImageTagAllowedAttributes;
IEnumerable<IImagingAutoFillUploadField> IContentSection.ImageAutoFillProperties => Imaging.ImageAutoFillProperties;
bool IContentSection.ScriptEditorDisable => ScriptEditor.ScriptEditorDisable;
string IContentSection.ScriptFolderPath => ScriptEditor.ScriptFolderPath;
IEnumerable<string> IContentSection.ScriptFileTypes => ScriptEditor.ScriptFileTypes;
bool IContentSection.ResolveUrlsFromTextString => ResolveUrlsFromTextString;
bool IContentSection.UploadAllowDirectories => UploadAllowDirectories;
bool IContentSection.EnsureUniqueNaming => EnsureUniqueNaming;
bool IContentSection.XmlCacheEnabled => XmlCacheEnabled;
bool IContentSection.ContinouslyUpdateXmlDiskCache => ContinouslyUpdateXmlDiskCache;
bool IContentSection.XmlContentCheckForDiskChanges => XmlContentCheckForDiskChanges;
bool IContentSection.EnableSplashWhileLoading => EnableSplashWhileLoading;
string IContentSection.PropertyContextHelpOption => PropertyContextHelpOption;
bool IContentSection.ForceSafeAliases => ForceSafeAliases;
string IContentSection.PreviewBadge => PreviewBadge;
int IContentSection.UmbracoLibraryCacheDuration => UmbracoLibraryCacheDuration;
MacroErrorBehaviour IContentSection.MacroErrorBehaviour => MacroErrors;
IEnumerable<string> IContentSection.DisallowedUploadFiles => DisallowedUploadFiles;
IEnumerable<string> IContentSection.AllowedUploadFiles => AllowedUploadFiles;
bool IContentSection.CloneXmlContent => CloneXmlContent;
bool IContentSection.GlobalPreviewStorageEnabled => GlobalPreviewStorageEnabled;
string IContentSection.DefaultDocumentTypeProperty => DefaultDocumentTypeProperty;
bool IContentSection.ShowDeprecatedPropertyEditors => ShowDeprecatedPropertyEditors;
bool IContentSection.EnableInheritedDocumentTypes => EnableInheritedDocumentTypes;
bool IContentSection.EnableInheritedMediaTypes => EnableInheritedMediaTypes;
string IContentSection.LoginBackgroundImage => LoginBackgroundImage;
}
}
using System.Collections.Generic;
using System.Configuration;
using Umbraco.Core.Macros;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
internal class ContentElement : UmbracoConfigurationElement, IContentSection
{
private const string DefaultPreviewBadge = @"<a id=""umbracoPreviewBadge"" style=""position: absolute; top: 0; right: 0; border: 0; width: 149px; height: 149px; background: url('{0}/assets/img/preview-mode-badge.png') no-repeat;"" href=""{0}/endPreview.aspx?redir={1}""><span style=""display:none;"">In Preview Mode - click to end</span></a>";
[ConfigurationProperty("imaging")]
internal ContentImagingElement Imaging => (ContentImagingElement) this["imaging"];
[ConfigurationProperty("scripteditor")]
internal ContentScriptEditorElement ScriptEditor => (ContentScriptEditorElement) this["scripteditor"];
[ConfigurationProperty("ResolveUrlsFromTextString")]
internal InnerTextConfigurationElement<bool> ResolveUrlsFromTextString => GetOptionalTextElement("ResolveUrlsFromTextString", false);
[ConfigurationProperty("UploadAllowDirectories")]
internal InnerTextConfigurationElement<bool> UploadAllowDirectories => GetOptionalTextElement("UploadAllowDirectories", true);
public IEnumerable<IContentErrorPage> Error404Collection => Errors.Error404Collection;
[ConfigurationProperty("errors", IsRequired = true)]
internal ContentErrorsElement Errors => (ContentErrorsElement) base["errors"];
[ConfigurationProperty("notifications", IsRequired = true)]
internal NotificationsElement Notifications => (NotificationsElement) base["notifications"];
[ConfigurationProperty("ensureUniqueNaming")]
internal InnerTextConfigurationElement<bool> EnsureUniqueNaming => GetOptionalTextElement("ensureUniqueNaming", true);
[ConfigurationProperty("XmlCacheEnabled")]
internal InnerTextConfigurationElement<bool> XmlCacheEnabled => GetOptionalTextElement("XmlCacheEnabled", true);
[ConfigurationProperty("ContinouslyUpdateXmlDiskCache")]
internal InnerTextConfigurationElement<bool> ContinouslyUpdateXmlDiskCache => GetOptionalTextElement("ContinouslyUpdateXmlDiskCache", true);
[ConfigurationProperty("XmlContentCheckForDiskChanges")]
internal InnerTextConfigurationElement<bool> XmlContentCheckForDiskChanges => GetOptionalTextElement("XmlContentCheckForDiskChanges", false);
[ConfigurationProperty("EnableSplashWhileLoading")]
internal InnerTextConfigurationElement<bool> EnableSplashWhileLoading => GetOptionalTextElement("EnableSplashWhileLoading", false);
[ConfigurationProperty("PropertyContextHelpOption")]
internal InnerTextConfigurationElement<string> PropertyContextHelpOption => GetOptionalTextElement("PropertyContextHelpOption", "text");
[ConfigurationProperty("ForceSafeAliases")]
internal InnerTextConfigurationElement<bool> ForceSafeAliases => GetOptionalTextElement("ForceSafeAliases", true);
[ConfigurationProperty("PreviewBadge")]
internal InnerTextConfigurationElement<string> PreviewBadge => GetOptionalTextElement("PreviewBadge", DefaultPreviewBadge);
[ConfigurationProperty("MacroErrors")]
internal InnerTextConfigurationElement<MacroErrorBehaviour> MacroErrors => GetOptionalTextElement("MacroErrors", MacroErrorBehaviour.Inline);
[ConfigurationProperty("disallowedUploadFiles")]
internal CommaDelimitedConfigurationElement DisallowedUploadFiles => GetOptionalDelimitedElement("disallowedUploadFiles", new[] {"ashx", "aspx", "ascx", "config", "cshtml", "vbhtml", "asmx", "air", "axd"});
[ConfigurationProperty("allowedUploadFiles")]
internal CommaDelimitedConfigurationElement AllowedUploadFiles => GetOptionalDelimitedElement("allowedUploadFiles", new string[0]);
[ConfigurationProperty("cloneXmlContent")]
internal InnerTextConfigurationElement<bool> CloneXmlContent => GetOptionalTextElement("cloneXmlContent", true);
[ConfigurationProperty("GlobalPreviewStorageEnabled")]
internal InnerTextConfigurationElement<bool> GlobalPreviewStorageEnabled => GetOptionalTextElement("GlobalPreviewStorageEnabled", false);
[ConfigurationProperty("defaultDocumentTypeProperty")]
internal InnerTextConfigurationElement<string> DefaultDocumentTypeProperty => GetOptionalTextElement("defaultDocumentTypeProperty", "Textstring");
[ConfigurationProperty("showDeprecatedPropertyEditors")]
internal InnerTextConfigurationElement<bool> ShowDeprecatedPropertyEditors => GetOptionalTextElement("showDeprecatedPropertyEditors", false);
[ConfigurationProperty("EnableInheritedDocumentTypes")]
internal InnerTextConfigurationElement<bool> EnableInheritedDocumentTypes => GetOptionalTextElement("EnableInheritedDocumentTypes", true);
[ConfigurationProperty("EnableInheritedMediaTypes")]
internal InnerTextConfigurationElement<bool> EnableInheritedMediaTypes => GetOptionalTextElement("EnableInheritedMediaTypes", true);
[ConfigurationProperty("loginBackgroundImage")]
internal InnerTextConfigurationElement<string> LoginBackgroundImage => GetOptionalTextElement("loginBackgroundImage", string.Empty);
string IContentSection.NotificationEmailAddress => Notifications.NotificationEmailAddress;
bool IContentSection.DisableHtmlEmail => Notifications.DisableHtmlEmail;
IEnumerable<string> IContentSection.ImageFileTypes => Imaging.ImageFileTypes;
IEnumerable<string> IContentSection.ImageTagAllowedAttributes => Imaging.ImageTagAllowedAttributes;
IEnumerable<IImagingAutoFillUploadField> IContentSection.ImageAutoFillProperties => Imaging.ImageAutoFillProperties;
bool IContentSection.ScriptEditorDisable => ScriptEditor.ScriptEditorDisable;
string IContentSection.ScriptFolderPath => ScriptEditor.ScriptFolderPath;
IEnumerable<string> IContentSection.ScriptFileTypes => ScriptEditor.ScriptFileTypes;
bool IContentSection.ResolveUrlsFromTextString => ResolveUrlsFromTextString;
bool IContentSection.UploadAllowDirectories => UploadAllowDirectories;
bool IContentSection.EnsureUniqueNaming => EnsureUniqueNaming;
bool IContentSection.XmlCacheEnabled => XmlCacheEnabled;
bool IContentSection.ContinouslyUpdateXmlDiskCache => ContinouslyUpdateXmlDiskCache;
bool IContentSection.XmlContentCheckForDiskChanges => XmlContentCheckForDiskChanges;
bool IContentSection.EnableSplashWhileLoading => EnableSplashWhileLoading;
string IContentSection.PropertyContextHelpOption => PropertyContextHelpOption;
bool IContentSection.ForceSafeAliases => ForceSafeAliases;
string IContentSection.PreviewBadge => PreviewBadge;
MacroErrorBehaviour IContentSection.MacroErrorBehaviour => MacroErrors;
IEnumerable<string> IContentSection.DisallowedUploadFiles => DisallowedUploadFiles;
IEnumerable<string> IContentSection.AllowedUploadFiles => AllowedUploadFiles;
bool IContentSection.CloneXmlContent => CloneXmlContent;
bool IContentSection.GlobalPreviewStorageEnabled => GlobalPreviewStorageEnabled;
string IContentSection.DefaultDocumentTypeProperty => DefaultDocumentTypeProperty;
bool IContentSection.ShowDeprecatedPropertyEditors => ShowDeprecatedPropertyEditors;
bool IContentSection.EnableInheritedDocumentTypes => EnableInheritedDocumentTypes;
bool IContentSection.EnableInheritedMediaTypes => EnableInheritedMediaTypes;
string IContentSection.LoginBackgroundImage => LoginBackgroundImage;
}
}
@@ -1,72 +1,70 @@
using System.Collections.Generic;
using Umbraco.Core.Macros;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
public interface IContentSection : IUmbracoConfigurationSection
{
string NotificationEmailAddress { get; }
bool DisableHtmlEmail { get; }
IEnumerable<string> ImageFileTypes { get; }
IEnumerable<string> ImageTagAllowedAttributes { get; }
IEnumerable<IImagingAutoFillUploadField> ImageAutoFillProperties { get; }
string ScriptFolderPath { get; }
IEnumerable<string> ScriptFileTypes { get; }
bool ScriptEditorDisable { get; }
bool ResolveUrlsFromTextString { get; }
using System.Collections.Generic;
using Umbraco.Core.Macros;
namespace Umbraco.Core.Configuration.UmbracoSettings
{
public interface IContentSection : IUmbracoConfigurationSection
{
string NotificationEmailAddress { get; }
bool DisableHtmlEmail { get; }
IEnumerable<string> ImageFileTypes { get; }
IEnumerable<string> ImageTagAllowedAttributes { get; }
IEnumerable<IImagingAutoFillUploadField> ImageAutoFillProperties { get; }
string ScriptFolderPath { get; }
IEnumerable<string> ScriptFileTypes { get; }
bool ScriptEditorDisable { get; }
bool ResolveUrlsFromTextString { get; }
bool UploadAllowDirectories { get; }
IEnumerable<IContentErrorPage> Error404Collection { get; }
bool EnsureUniqueNaming { get; }
bool XmlCacheEnabled { get; }
bool ContinouslyUpdateXmlDiskCache { get; }
bool XmlContentCheckForDiskChanges { get; }
bool EnableSplashWhileLoading { get; }
string PropertyContextHelpOption { get; }
bool ForceSafeAliases { get; }
string PreviewBadge { get; }
int UmbracoLibraryCacheDuration { get; }
MacroErrorBehaviour MacroErrorBehaviour { get; }
IEnumerable<string> DisallowedUploadFiles { get; }
IEnumerable<string> AllowedUploadFiles { get; }
bool CloneXmlContent { get; }
bool GlobalPreviewStorageEnabled { get; }
string DefaultDocumentTypeProperty { get; }
/// <summary>
/// Gets a value indicating whether to show deprecated property editors in
/// a datatype list of available editors.
/// </summary>
bool ShowDeprecatedPropertyEditors { get; }
bool EnableInheritedDocumentTypes { get; }
bool EnableInheritedMediaTypes { get; }
string LoginBackgroundImage { get; }
}
}
IEnumerable<IContentErrorPage> Error404Collection { get; }
bool EnsureUniqueNaming { get; }
bool XmlCacheEnabled { get; }
bool ContinouslyUpdateXmlDiskCache { get; }
bool XmlContentCheckForDiskChanges { get; }
bool EnableSplashWhileLoading { get; }
string PropertyContextHelpOption { get; }
bool ForceSafeAliases { get; }
string PreviewBadge { get; }
MacroErrorBehaviour MacroErrorBehaviour { get; }
IEnumerable<string> DisallowedUploadFiles { get; }
IEnumerable<string> AllowedUploadFiles { get; }
bool CloneXmlContent { get; }
bool GlobalPreviewStorageEnabled { get; }
string DefaultDocumentTypeProperty { get; }
/// <summary>
/// Gets a value indicating whether to show deprecated property editors in
/// a datatype list of available editors.
/// </summary>
bool ShowDeprecatedPropertyEditors { get; }
bool EnableInheritedDocumentTypes { get; }
bool EnableInheritedMediaTypes { get; }
string LoginBackgroundImage { get; }
}
}
@@ -1,204 +1,199 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Macros;
namespace Umbraco.Tests.Configurations.UmbracoSettings
{
[TestFixture]
public class ContentElementTests : UmbracoSettingsTests
{
[Test]
public void EmailAddress()
{
Assert.IsTrue(SettingsSection.Content.NotificationEmailAddress == "robot@umbraco.dk");
}
[Test]
public virtual void DisableHtmlEmail()
{
Assert.IsTrue(SettingsSection.Content.DisableHtmlEmail == true);
}
[Test]
public virtual void Can_Set_Multiple()
{
Assert.IsTrue(SettingsSection.Content.Error404Collection.Count() == 3);
Assert.IsTrue(SettingsSection.Content.Error404Collection.ElementAt(0).Culture == "default");
Assert.IsTrue(SettingsSection.Content.Error404Collection.ElementAt(0).ContentId == 1047);
Assert.IsTrue(SettingsSection.Content.Error404Collection.ElementAt(0).HasContentId);
Assert.IsFalse(SettingsSection.Content.Error404Collection.ElementAt(0).HasContentKey);
Assert.IsTrue(SettingsSection.Content.Error404Collection.ElementAt(1).Culture == "en-US");
Assert.IsTrue(SettingsSection.Content.Error404Collection.ElementAt(1).ContentXPath == "$site/error [@name = 'error']");
Assert.IsFalse(SettingsSection.Content.Error404Collection.ElementAt(1).HasContentId);
Assert.IsFalse(SettingsSection.Content.Error404Collection.ElementAt(1).HasContentKey);
Assert.IsTrue(SettingsSection.Content.Error404Collection.ElementAt(2).Culture == "en-UK");
Assert.IsTrue(SettingsSection.Content.Error404Collection.ElementAt(2).ContentKey == new Guid("8560867F-B88F-4C74-A9A4-679D8E5B3BFC"));
Assert.IsTrue(SettingsSection.Content.Error404Collection.ElementAt(2).HasContentKey);
Assert.IsFalse(SettingsSection.Content.Error404Collection.ElementAt(2).HasContentId);
}
[Test]
public void ScriptFolderPath()
{
Assert.IsTrue(SettingsSection.Content.ScriptFolderPath == "/scripts");
}
[Test]
public void ScriptFileTypes()
{
Assert.IsTrue(SettingsSection.Content.ScriptFileTypes.All(x => "js,xml".Split(',').Contains(x)));
}
[Test]
public void DisableScriptEditor()
{
Assert.IsTrue(SettingsSection.Content.ScriptEditorDisable == false);
}
[Test]
public void ImageFileTypes()
{
Assert.IsTrue(SettingsSection.Content.ImageFileTypes.All(x => "jpeg,jpg,gif,bmp,png,tiff,tif".Split(',').Contains(x)));
}
[Test]
public void AllowedAttributes()
{
Assert.IsTrue(SettingsSection.Content.ImageTagAllowedAttributes.All(x => "src,alt,border,class,style,align,id,name,onclick,usemap".Split(',').Contains(x)));
}
[Test]
public virtual void ImageAutoFillProperties()
{
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.Count() == 2);
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(0).Alias == "umbracoFile");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(0).WidthFieldAlias == "umbracoWidth");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(0).HeightFieldAlias == "umbracoHeight");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(0).LengthFieldAlias == "umbracoBytes");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(0).ExtensionFieldAlias == "umbracoExtension");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(1).Alias == "umbracoFile2");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(1).WidthFieldAlias == "umbracoWidth2");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(1).HeightFieldAlias == "umbracoHeight2");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(1).LengthFieldAlias == "umbracoBytes2");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(1).ExtensionFieldAlias == "umbracoExtension2");
}
[Test]
public void UploadAllowDirectories()
{
Assert.IsTrue(SettingsSection.Content.UploadAllowDirectories == true);
}
[Test]
public void DefaultDocumentTypeProperty()
{
Assert.IsTrue(SettingsSection.Content.DefaultDocumentTypeProperty == "Textstring");
}
[Test]
public void GlobalPreviewStorageEnabled()
{
Assert.IsTrue(SettingsSection.Content.GlobalPreviewStorageEnabled == false);
}
[Test]
public void CloneXmlContent()
{
Assert.IsTrue(SettingsSection.Content.CloneXmlContent == true);
}
[Test]
public void EnsureUniqueNaming()
{
Assert.IsTrue(SettingsSection.Content.EnsureUniqueNaming == true);
}
[Test]
public void ForceSafeAliases()
{
Assert.IsTrue(SettingsSection.Content.ForceSafeAliases == true);
}
[Test]
public void XmlCacheEnabled()
{
Assert.IsTrue(SettingsSection.Content.XmlCacheEnabled == true);
}
[Test]
public void ContinouslyUpdateXmlDiskCache()
{
Assert.IsTrue(SettingsSection.Content.ContinouslyUpdateXmlDiskCache == true);
}
[Test]
public virtual void XmlContentCheckForDiskChanges()
{
Assert.IsTrue(SettingsSection.Content.XmlContentCheckForDiskChanges == true);
}
[Test]
public void EnableSplashWhileLoading()
{
Assert.IsTrue(SettingsSection.Content.EnableSplashWhileLoading == false);
}
[Test]
public void PropertyContextHelpOption()
{
Assert.IsTrue(SettingsSection.Content.PropertyContextHelpOption == "text");
}
[Test]
public void PreviewBadge()
{
Assert.IsTrue(SettingsSection.Content.PreviewBadge == @"<a id=""umbracoPreviewBadge"" style=""position: absolute; top: 0; right: 0; border: 0; width: 149px; height: 149px; background: url('{0}/assets/img/preview-mode-badge.png') no-repeat;"" href=""{0}/endPreview.aspx?redir={1}""><span style=""display:none;"">In Preview Mode - click to end</span></a>");
}
[Test]
public void UmbracoLibraryCacheDuration()
{
Assert.IsTrue(SettingsSection.Content.UmbracoLibraryCacheDuration == 1800);
}
[Test]
public void ResolveUrlsFromTextString()
{
Assert.IsFalse(SettingsSection.Content.ResolveUrlsFromTextString);
}
[Test]
public void MacroErrors()
{
Assert.IsTrue(SettingsSection.Content.MacroErrorBehaviour == MacroErrorBehaviour.Inline);
}
[Test]
public void DisallowedUploadFiles()
{
Assert.IsTrue(SettingsSection.Content.DisallowedUploadFiles.All(x => "ashx,aspx,ascx,config,cshtml,vbhtml,asmx,air,axd".Split(',').Contains(x)));
}
[Test]
public void AllowedUploadFiles()
{
Assert.IsTrue(SettingsSection.Content.AllowedUploadFiles.All(x => "jpg,gif,png".Split(',').Contains(x)));
}
[Test]
[TestCase("png", true)]
[TestCase("jpg", true)]
[TestCase("gif", true)]
// TODO: Why does it flip to TestingDefaults=true for these two tests on AppVeyor. WHY?
//[TestCase("bmp", false)]
//[TestCase("php", false)]
[TestCase("ashx", false)]
[TestCase("config", false)]
public void IsFileAllowedForUpload_WithWhitelist(string extension, bool expected)
{
// Make really sure that defaults are NOT used
TestingDefaults = false;
Debug.WriteLine("Extension being tested", extension);
Debug.WriteLine("AllowedUploadFiles: {0}", SettingsSection.Content.AllowedUploadFiles);
Debug.WriteLine("DisallowedUploadFiles: {0}", SettingsSection.Content.DisallowedUploadFiles);
var allowedContainsExtension = SettingsSection.Content.AllowedUploadFiles.Any(x => x.InvariantEquals(extension));
var disallowedContainsExtension = SettingsSection.Content.DisallowedUploadFiles.Any(x => x.InvariantEquals(extension));
Debug.WriteLine("AllowedContainsExtension: {0}", allowedContainsExtension);
Debug.WriteLine("DisallowedContainsExtension: {0}", disallowedContainsExtension);
Assert.AreEqual(SettingsSection.Content.IsFileAllowedForUpload(extension), expected);
}
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Macros;
namespace Umbraco.Tests.Configurations.UmbracoSettings
{
[TestFixture]
public class ContentElementTests : UmbracoSettingsTests
{
[Test]
public void EmailAddress()
{
Assert.IsTrue(SettingsSection.Content.NotificationEmailAddress == "robot@umbraco.dk");
}
[Test]
public virtual void DisableHtmlEmail()
{
Assert.IsTrue(SettingsSection.Content.DisableHtmlEmail == true);
}
[Test]
public virtual void Can_Set_Multiple()
{
Assert.IsTrue(SettingsSection.Content.Error404Collection.Count() == 3);
Assert.IsTrue(SettingsSection.Content.Error404Collection.ElementAt(0).Culture == "default");
Assert.IsTrue(SettingsSection.Content.Error404Collection.ElementAt(0).ContentId == 1047);
Assert.IsTrue(SettingsSection.Content.Error404Collection.ElementAt(0).HasContentId);
Assert.IsFalse(SettingsSection.Content.Error404Collection.ElementAt(0).HasContentKey);
Assert.IsTrue(SettingsSection.Content.Error404Collection.ElementAt(1).Culture == "en-US");
Assert.IsTrue(SettingsSection.Content.Error404Collection.ElementAt(1).ContentXPath == "$site/error [@name = 'error']");
Assert.IsFalse(SettingsSection.Content.Error404Collection.ElementAt(1).HasContentId);
Assert.IsFalse(SettingsSection.Content.Error404Collection.ElementAt(1).HasContentKey);
Assert.IsTrue(SettingsSection.Content.Error404Collection.ElementAt(2).Culture == "en-UK");
Assert.IsTrue(SettingsSection.Content.Error404Collection.ElementAt(2).ContentKey == new Guid("8560867F-B88F-4C74-A9A4-679D8E5B3BFC"));
Assert.IsTrue(SettingsSection.Content.Error404Collection.ElementAt(2).HasContentKey);
Assert.IsFalse(SettingsSection.Content.Error404Collection.ElementAt(2).HasContentId);
}
[Test]
public void ScriptFolderPath()
{
Assert.IsTrue(SettingsSection.Content.ScriptFolderPath == "/scripts");
}
[Test]
public void ScriptFileTypes()
{
Assert.IsTrue(SettingsSection.Content.ScriptFileTypes.All(x => "js,xml".Split(',').Contains(x)));
}
[Test]
public void DisableScriptEditor()
{
Assert.IsTrue(SettingsSection.Content.ScriptEditorDisable == false);
}
[Test]
public void ImageFileTypes()
{
Assert.IsTrue(SettingsSection.Content.ImageFileTypes.All(x => "jpeg,jpg,gif,bmp,png,tiff,tif".Split(',').Contains(x)));
}
[Test]
public void AllowedAttributes()
{
Assert.IsTrue(SettingsSection.Content.ImageTagAllowedAttributes.All(x => "src,alt,border,class,style,align,id,name,onclick,usemap".Split(',').Contains(x)));
}
[Test]
public virtual void ImageAutoFillProperties()
{
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.Count() == 2);
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(0).Alias == "umbracoFile");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(0).WidthFieldAlias == "umbracoWidth");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(0).HeightFieldAlias == "umbracoHeight");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(0).LengthFieldAlias == "umbracoBytes");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(0).ExtensionFieldAlias == "umbracoExtension");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(1).Alias == "umbracoFile2");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(1).WidthFieldAlias == "umbracoWidth2");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(1).HeightFieldAlias == "umbracoHeight2");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(1).LengthFieldAlias == "umbracoBytes2");
Assert.IsTrue(SettingsSection.Content.ImageAutoFillProperties.ElementAt(1).ExtensionFieldAlias == "umbracoExtension2");
}
[Test]
public void UploadAllowDirectories()
{
Assert.IsTrue(SettingsSection.Content.UploadAllowDirectories == true);
}
[Test]
public void DefaultDocumentTypeProperty()
{
Assert.IsTrue(SettingsSection.Content.DefaultDocumentTypeProperty == "Textstring");
}
[Test]
public void GlobalPreviewStorageEnabled()
{
Assert.IsTrue(SettingsSection.Content.GlobalPreviewStorageEnabled == false);
}
[Test]
public void CloneXmlContent()
{
Assert.IsTrue(SettingsSection.Content.CloneXmlContent == true);
}
[Test]
public void EnsureUniqueNaming()
{
Assert.IsTrue(SettingsSection.Content.EnsureUniqueNaming == true);
}
[Test]
public void ForceSafeAliases()
{
Assert.IsTrue(SettingsSection.Content.ForceSafeAliases == true);
}
[Test]
public void XmlCacheEnabled()
{
Assert.IsTrue(SettingsSection.Content.XmlCacheEnabled == true);
}
[Test]
public void ContinouslyUpdateXmlDiskCache()
{
Assert.IsTrue(SettingsSection.Content.ContinouslyUpdateXmlDiskCache == true);
}
[Test]
public virtual void XmlContentCheckForDiskChanges()
{
Assert.IsTrue(SettingsSection.Content.XmlContentCheckForDiskChanges == true);
}
[Test]
public void EnableSplashWhileLoading()
{
Assert.IsTrue(SettingsSection.Content.EnableSplashWhileLoading == false);
}
[Test]
public void PropertyContextHelpOption()
{
Assert.IsTrue(SettingsSection.Content.PropertyContextHelpOption == "text");
}
[Test]
public void PreviewBadge()
{
Assert.IsTrue(SettingsSection.Content.PreviewBadge == @"<a id=""umbracoPreviewBadge"" style=""position: absolute; top: 0; right: 0; border: 0; width: 149px; height: 149px; background: url('{0}/assets/img/preview-mode-badge.png') no-repeat;"" href=""{0}/endPreview.aspx?redir={1}""><span style=""display:none;"">In Preview Mode - click to end</span></a>");
}
[Test]
public void ResolveUrlsFromTextString()
{
Assert.IsFalse(SettingsSection.Content.ResolveUrlsFromTextString);
}
[Test]
public void MacroErrors()
{
Assert.IsTrue(SettingsSection.Content.MacroErrorBehaviour == MacroErrorBehaviour.Inline);
}
[Test]
public void DisallowedUploadFiles()
{
Assert.IsTrue(SettingsSection.Content.DisallowedUploadFiles.All(x => "ashx,aspx,ascx,config,cshtml,vbhtml,asmx,air,axd".Split(',').Contains(x)));
}
[Test]
public void AllowedUploadFiles()
{
Assert.IsTrue(SettingsSection.Content.AllowedUploadFiles.All(x => "jpg,gif,png".Split(',').Contains(x)));
}
[Test]
[TestCase("png", true)]
[TestCase("jpg", true)]
[TestCase("gif", true)]
// TODO: Why does it flip to TestingDefaults=true for these two tests on AppVeyor. WHY?
//[TestCase("bmp", false)]
//[TestCase("php", false)]
[TestCase("ashx", false)]
[TestCase("config", false)]
public void IsFileAllowedForUpload_WithWhitelist(string extension, bool expected)
{
// Make really sure that defaults are NOT used
TestingDefaults = false;
Debug.WriteLine("Extension being tested", extension);
Debug.WriteLine("AllowedUploadFiles: {0}", SettingsSection.Content.AllowedUploadFiles);
Debug.WriteLine("DisallowedUploadFiles: {0}", SettingsSection.Content.DisallowedUploadFiles);
var allowedContainsExtension = SettingsSection.Content.AllowedUploadFiles.Any(x => x.InvariantEquals(extension));
var disallowedContainsExtension = SettingsSection.Content.DisallowedUploadFiles.Any(x => x.InvariantEquals(extension));
Debug.WriteLine("AllowedContainsExtension: {0}", allowedContainsExtension);
Debug.WriteLine("DisallowedContainsExtension: {0}", disallowedContainsExtension);
Assert.AreEqual(SettingsSection.Content.IsFileAllowedForUpload(extension), expected);
}
}
}
@@ -77,10 +77,6 @@
<PreviewBadge><![CDATA[<a id="umbracoPreviewBadge" style="position: absolute; top: 0; right: 0; border: 0; width: 149px; height: 149px; background: url('{0}/assets/img/preview-mode-badge.png') no-repeat;" href="{0}/endPreview.aspx?redir={1}"><span style="display:none;">In Preview Mode - click to end</span></a>]]></PreviewBadge>
<!-- Cache cycle of Media and Member data fetched from the umbraco.library methods -->
<!-- In seconds. 0 will disable cache -->
<UmbracoLibraryCacheDuration>1800</UmbracoLibraryCacheDuration>
<!-- How Umbraco should handle errors during macro execution. Can be one of the following values:
- inline - show an inline error within the macro but allow the page to continue rendering. Historial Umbraco behaviour.
- silent - Silently suppress the error and do not render the offending macro.
-100
View File
@@ -1,100 +0,0 @@
using System;
using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
using umbraco;
using Umbraco.Core.Composing;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Tests.PublishedContent;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
using Umbraco.Web.PublishedCache.XmlPublishedCache;
using LightInject;
using Moq;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
namespace Umbraco.Tests.Misc
{
/// <summary>
/// Tests for the legacy library class
/// </summary>
[TestFixture]
public class LibraryTests : BaseWebTest
{
public override void SetUp()
{
base.SetUp();
var dataTypeService = new TestObjects.TestDataTypeService(
new DataType(new VoidEditor(Mock.Of<ILogger>())) { Id = 1 });
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), dataTypeService);
// need to specify a custom callback for unit tests
// AutoPublishedContentTypes generates properties automatically
// when they are requested, but we must declare those that we
// explicitely want to be here...
var propertyTypes = new[]
{
// AutoPublishedContentType will auto-generate other properties
factory.CreatePropertyType("content", 1),
};
var type = new AutoPublishedContentType(0, "anything", propertyTypes);
ContentTypesCache.GetPublishedContentTypeByAlias = (alias) => type;
Debug.Print("INIT LIB {0}",
ContentTypesCache.Get(PublishedItemType.Content, "anything")
.PropertyTypes.Count());
var umbracoContext = GetUmbracoContext("/test");
Umbraco.Web.Composing.Current.UmbracoContextAccessor.UmbracoContext = umbracoContext;
}
/// <summary>
/// sets up resolvers before resolution is frozen
/// </summary>
protected override void Compose()
{
base.Compose();
// required so we can access property.Value
if (Container.TryGetInstance<PropertyValueConverterCollectionBuilder>() == null)
Container.RegisterCollectionBuilder<PropertyValueConverterCollectionBuilder>();
}
/// <summary>
/// The old method, just using this to make sure we're returning the correct exact data as before.
/// </summary>
/// <param name="nodeId"></param>
/// <param name="alias"></param>
/// <returns></returns>
private string LegacyGetItem(int nodeId, string alias)
{
var cache = UmbracoContext.Current.ContentCache as PublishedContentCache;
if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported.");
var umbracoXML = cache.GetXml(UmbracoContext.Current.InPreviewMode);
string xpath = "./{0}";
if (umbracoXML.GetElementById(nodeId.ToString()) != null)
if (
",id,parentID,level,writerID,template,sortOrder,createDate,updateDate,nodeName,writerName,path,"
.
IndexOf("," + alias + ",") > -1)
return umbracoXML.GetElementById(nodeId.ToString()).Attributes.GetNamedItem(alias).Value;
else if (
umbracoXML.GetElementById(nodeId.ToString()).SelectSingleNode(string.Format(xpath, alias)) !=
null)
return
umbracoXML.GetElementById(nodeId.ToString()).SelectSingleNode(string.Format(xpath, alias)).ChildNodes[0].
Value; //.Value + "*";
else
return string.Empty;
else
return string.Empty;
}
}
}
+158 -159
View File
@@ -1,167 +1,166 @@
using System.Collections.Generic;
using System.IO;
using System.Configuration;
using Moq;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.IO;
namespace Umbraco.Tests.TestHelpers
{
public class SettingsForTests
{
public static void ConfigureSettings(IGlobalSettings settings)
{
UmbracoConfig.For.SetGlobalConfig(settings);
using System.Collections.Generic;
using System.IO;
using System.Configuration;
using Moq;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.IO;
namespace Umbraco.Tests.TestHelpers
{
public class SettingsForTests
{
public static void ConfigureSettings(IGlobalSettings settings)
{
UmbracoConfig.For.SetGlobalConfig(settings);
}
// umbracoSettings
/// <summary>
/// Sets the umbraco settings singleton to the object specified
/// </summary>
/// <param name="settings"></param>
public static void ConfigureSettings(IUmbracoSettingsSection settings)
{
UmbracoConfig.For.SetUmbracoSettings(settings);
}
public static IGlobalSettings GenerateMockGlobalSettings()
{
var config = Mock.Of<IGlobalSettings>(
settings =>
settings.ConfigurationStatus == UmbracoVersion.SemanticVersion.ToSemanticString() &&
settings.UseHttps == false &&
settings.HideTopLevelNodeFromPath == false &&
settings.Path == IOHelper.ResolveUrl("~/umbraco") &&
settings.UseDirectoryUrls == true &&
settings.TimeOutInMinutes == 20 &&
// umbracoSettings
/// <summary>
/// Sets the umbraco settings singleton to the object specified
/// </summary>
/// <param name="settings"></param>
public static void ConfigureSettings(IUmbracoSettingsSection settings)
{
UmbracoConfig.For.SetUmbracoSettings(settings);
}
public static IGlobalSettings GenerateMockGlobalSettings()
{
var config = Mock.Of<IGlobalSettings>(
settings =>
settings.ConfigurationStatus == UmbracoVersion.SemanticVersion.ToSemanticString() &&
settings.UseHttps == false &&
settings.HideTopLevelNodeFromPath == false &&
settings.Path == IOHelper.ResolveUrl("~/umbraco") &&
settings.UseDirectoryUrls == true &&
settings.TimeOutInMinutes == 20 &&
settings.DefaultUILanguage == "en" &&
settings.LocalTempStorageLocation == LocalTempStorage.Default &&
settings.ReservedPaths == (GlobalSettings.StaticReservedPaths + "~/umbraco") &&
settings.ReservedUrls == GlobalSettings.StaticReservedUrls);
return config;
settings.ReservedUrls == GlobalSettings.StaticReservedUrls);
return config;
}
/// <summary>
/// Returns generated settings which can be stubbed to return whatever values necessary
/// </summary>
/// <returns></returns>
public static IUmbracoSettingsSection GenerateMockUmbracoSettings()
{
var settings = new Mock<IUmbracoSettingsSection>();
var content = new Mock<IContentSection>();
var security = new Mock<ISecuritySection>();
var requestHandler = new Mock<IRequestHandlerSection>();
var templates = new Mock<ITemplatesSection>();
var logging = new Mock<ILoggingSection>();
var tasks = new Mock<IScheduledTasksSection>();
var providers = new Mock<IProvidersSection>();
var routing = new Mock<IWebRoutingSection>();
settings.Setup(x => x.Content).Returns(content.Object);
settings.Setup(x => x.Security).Returns(security.Object);
settings.Setup(x => x.RequestHandler).Returns(requestHandler.Object);
settings.Setup(x => x.Templates).Returns(templates.Object);
settings.Setup(x => x.Logging).Returns(logging.Object);
settings.Setup(x => x.ScheduledTasks).Returns(tasks.Object);
settings.Setup(x => x.Providers).Returns(providers.Object);
settings.Setup(x => x.WebRouting).Returns(routing.Object);
//Now configure some defaults - the defaults in the config section classes do NOT pertain to the mocked data!!
settings.Setup(x => x.Content.ForceSafeAliases).Returns(true);
settings.Setup(x => x.Content.ImageAutoFillProperties).Returns(ContentImagingElement.GetDefaultImageAutoFillProperties());
settings.Setup(x => x.Content.ImageFileTypes).Returns(ContentImagingElement.GetDefaultImageFileTypes());
settings.Setup(x => x.RequestHandler.AddTrailingSlash).Returns(true);
settings.Setup(x => x.RequestHandler.UseDomainPrefixes).Returns(false);
settings.Setup(x => x.RequestHandler.CharCollection).Returns(RequestHandlerElement.GetDefaultCharReplacements());
settings.Setup(x => x.Content.UmbracoLibraryCacheDuration).Returns(1800);
settings.Setup(x => x.WebRouting.UrlProviderMode).Returns("AutoLegacy");
settings.Setup(x => x.Templates.DefaultRenderingEngine).Returns(RenderingEngine.Mvc);
settings.Setup(x => x.Providers.DefaultBackOfficeUserProvider).Returns("UsersMembershipProvider");
return settings.Object;
}
//// from appSettings
//private static readonly IDictionary<string, string> SavedAppSettings = new Dictionary<string, string>();
//static void SaveSetting(string key)
//{
// SavedAppSettings[key] = ConfigurationManager.AppSettings[key];
//}
//static void SaveSettings()
//{
// SaveSetting("umbracoHideTopLevelNodeFromPath");
// SaveSetting("umbracoUseDirectoryUrls");
// SaveSetting("umbracoPath");
// SaveSetting("umbracoReservedPaths");
// SaveSetting("umbracoReservedUrls");
// SaveSetting("umbracoConfigurationStatus");
//}
// reset & defaults
//static SettingsForTests()
//{
// //SaveSettings();
//}
public static void Reset()
{
ResetSettings();
GlobalSettings.Reset();
//foreach (var kvp in SavedAppSettings)
// ConfigurationManager.AppSettings.Set(kvp.Key, kvp.Value);
//// set some defaults that are wrong in the config file?!
//// this is annoying, really
//HideTopLevelNodeFromPath = false;
}
/// <summary>
/// This sets all settings back to default settings
/// </summary>
private static void ResetSettings()
{
_defaultGlobalSettings = null;
ConfigureSettings(GetDefaultUmbracoSettings());
ConfigureSettings(GetDefaultGlobalSettings());
}
private static IUmbracoSettingsSection _defaultUmbracoSettings;
private static IGlobalSettings _defaultGlobalSettings;
internal static IGlobalSettings GetDefaultGlobalSettings()
{
if (_defaultGlobalSettings == null)
{
_defaultGlobalSettings = GenerateMockGlobalSettings();
}
return _defaultGlobalSettings;
/// <summary>
/// Returns generated settings which can be stubbed to return whatever values necessary
/// </summary>
/// <returns></returns>
public static IUmbracoSettingsSection GenerateMockUmbracoSettings()
{
var settings = new Mock<IUmbracoSettingsSection>();
var content = new Mock<IContentSection>();
var security = new Mock<ISecuritySection>();
var requestHandler = new Mock<IRequestHandlerSection>();
var templates = new Mock<ITemplatesSection>();
var logging = new Mock<ILoggingSection>();
var tasks = new Mock<IScheduledTasksSection>();
var providers = new Mock<IProvidersSection>();
var routing = new Mock<IWebRoutingSection>();
settings.Setup(x => x.Content).Returns(content.Object);
settings.Setup(x => x.Security).Returns(security.Object);
settings.Setup(x => x.RequestHandler).Returns(requestHandler.Object);
settings.Setup(x => x.Templates).Returns(templates.Object);
settings.Setup(x => x.Logging).Returns(logging.Object);
settings.Setup(x => x.ScheduledTasks).Returns(tasks.Object);
settings.Setup(x => x.Providers).Returns(providers.Object);
settings.Setup(x => x.WebRouting).Returns(routing.Object);
//Now configure some defaults - the defaults in the config section classes do NOT pertain to the mocked data!!
settings.Setup(x => x.Content.ForceSafeAliases).Returns(true);
settings.Setup(x => x.Content.ImageAutoFillProperties).Returns(ContentImagingElement.GetDefaultImageAutoFillProperties());
settings.Setup(x => x.Content.ImageFileTypes).Returns(ContentImagingElement.GetDefaultImageFileTypes());
settings.Setup(x => x.RequestHandler.AddTrailingSlash).Returns(true);
settings.Setup(x => x.RequestHandler.UseDomainPrefixes).Returns(false);
settings.Setup(x => x.RequestHandler.CharCollection).Returns(RequestHandlerElement.GetDefaultCharReplacements());
settings.Setup(x => x.WebRouting.UrlProviderMode).Returns("AutoLegacy");
settings.Setup(x => x.Templates.DefaultRenderingEngine).Returns(RenderingEngine.Mvc);
settings.Setup(x => x.Providers.DefaultBackOfficeUserProvider).Returns("UsersMembershipProvider");
return settings.Object;
}
internal static IUmbracoSettingsSection GetDefaultUmbracoSettings()
{
if (_defaultUmbracoSettings == null)
//// from appSettings
//private static readonly IDictionary<string, string> SavedAppSettings = new Dictionary<string, string>();
//static void SaveSetting(string key)
//{
// SavedAppSettings[key] = ConfigurationManager.AppSettings[key];
//}
//static void SaveSettings()
//{
// SaveSetting("umbracoHideTopLevelNodeFromPath");
// SaveSetting("umbracoUseDirectoryUrls");
// SaveSetting("umbracoPath");
// SaveSetting("umbracoReservedPaths");
// SaveSetting("umbracoReservedUrls");
// SaveSetting("umbracoConfigurationStatus");
//}
// reset & defaults
//static SettingsForTests()
//{
// //SaveSettings();
//}
public static void Reset()
{
ResetSettings();
GlobalSettings.Reset();
//foreach (var kvp in SavedAppSettings)
// ConfigurationManager.AppSettings.Set(kvp.Key, kvp.Value);
//// set some defaults that are wrong in the config file?!
//// this is annoying, really
//HideTopLevelNodeFromPath = false;
}
/// <summary>
/// This sets all settings back to default settings
/// </summary>
private static void ResetSettings()
{
_defaultGlobalSettings = null;
ConfigureSettings(GetDefaultUmbracoSettings());
ConfigureSettings(GetDefaultGlobalSettings());
}
private static IUmbracoSettingsSection _defaultUmbracoSettings;
private static IGlobalSettings _defaultGlobalSettings;
internal static IGlobalSettings GetDefaultGlobalSettings()
{
if (_defaultGlobalSettings == null)
{
_defaultGlobalSettings = GenerateMockGlobalSettings();
}
return _defaultGlobalSettings;
}
internal static IUmbracoSettingsSection GetDefaultUmbracoSettings()
{
if (_defaultUmbracoSettings == null)
{
//TODO: Just make this mocks instead of reading from the config
var config = new FileInfo(TestHelper.MapPathForTest("~/Configurations/UmbracoSettings/web.config"));
var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = config.FullName };
var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
_defaultUmbracoSettings = configuration.GetSection("umbracoConfiguration/defaultSettings") as UmbracoSettingsSection;
}
return _defaultUmbracoSettings;
}
}
}
var config = new FileInfo(TestHelper.MapPathForTest("~/Configurations/UmbracoSettings/web.config"));
var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = config.FullName };
var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
_defaultUmbracoSettings = configuration.GetSection("umbracoConfiguration/defaultSettings") as UmbracoSettingsSection;
}
return _defaultUmbracoSettings;
}
}
}
File diff suppressed because it is too large Load Diff
@@ -78,9 +78,6 @@
<![CDATA[<a id="umbracoPreviewBadge" style="position: absolute; top: 0; right: 0; border: 0; width: 149px; height: 149px; background: url('{0}/assets/img/preview-mode-badge.png') no-repeat;" href="#" OnClick="javascript:window.top.location.href = '{0}/endPreview.aspx?redir={1}'"><span style="display:none;">In Preview Mode - click to end</span></a>
]]></PreviewBadge>
<!-- Cache cycle of Media and Member data fetched from the umbraco.library methods -->
<!-- In seconds. 0 will disable cache -->
<UmbracoLibraryCacheDuration>1800</UmbracoLibraryCacheDuration>
<!-- Url Resolving ensures that all links works if you run Umbraco in virtual directories -->
<!-- Setting this to true can increase render time for pages with a large number of links -->
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,82 +0,0 @@
using System;
using System.Xml.Linq;
using System.Xml.XPath;
using Umbraco.Core.Cache;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Services;
using Umbraco.Web.Composing;
namespace umbraco
{
/// <summary>
/// Function library for umbraco. Includes various helper-methods and methods to
/// save and load data from umbraco.
///
/// Especially usefull in XSLT where any of these methods can be accesed using the umbraco.library name-space. Example:
/// &lt;xsl:value-of select="umbraco.library:NiceUrl(@id)"/&gt;
/// </summary>
[Obsolete("v8.kill.kill")]
public class library
{
/// <summary>
/// Get a media object as an xml object
/// </summary>
/// <param name="MediaId">The identifier of the media object to be returned</param>
/// <param name="deep">If true, children of the media object is returned</param>
/// <returns>An umbraco xml node of the media (same format as a document node)</returns>
public static XPathNodeIterator GetMedia(int MediaId, bool deep)
{
try
{
if (UmbracoConfig.For.UmbracoSettings().Content.UmbracoLibraryCacheDuration > 0)
{
var xml = Current.ApplicationCache.RuntimeCache.GetCacheItem<XElement>(
$"{CacheKeys.MediaCacheKey}_{MediaId}_{deep}",
timeout: TimeSpan.FromSeconds(UmbracoConfig.For.UmbracoSettings().Content.UmbracoLibraryCacheDuration),
getCacheItem: () => GetMediaDo(MediaId, deep).Item1);
if (xml != null)
{
//returning the root element of the Media item fixes the problem
return xml.CreateNavigator().Select("/");
}
}
else
{
var xml = GetMediaDo(MediaId, deep).Item1;
//returning the root element of the Media item fixes the problem
return xml.CreateNavigator().Select("/");
}
}
catch(Exception ex)
{
Current.Logger.Error<library>("An error occurred looking up media", ex);
}
Current.Logger.Debug<library>(() => $"No media result for id {MediaId}");
var errorXml = new XElement("error", string.Format("No media is maching '{0}'", MediaId));
return errorXml.CreateNavigator().Select("/");
}
private static Tuple<XElement, string> GetMediaDo(int mediaId, bool deep)
{
var media = Current.Services.MediaService.GetById(mediaId);
if (media == null) return null;
var serialized = EntityXmlSerializer.Serialize(
Current.Services.MediaService,
Current.Services.DataTypeService,
Current.Services.UserService,
Current.Services.LocalizationService,
Current.UrlSegmentProviders,
media,
deep);
return Tuple.Create(serialized, media.Path);
}
}
}