Web.PublishedCache - move XML away from UmbracoContext
This commit is contained in:
@@ -102,8 +102,11 @@ namespace Umbraco.Tests
|
||||
/// <returns></returns>
|
||||
private string LegacyGetItem(int nodeId, string alias)
|
||||
{
|
||||
var umbracoXML = UmbracoContext.Current.GetXml();
|
||||
string xpath = UmbracoSettings.UseLegacyXmlSchema ? "./data [@alias='{0}']" : "./{0}";
|
||||
var cache = PublishedContentCacheResolver.Current.PublishedContentCache as PublishedContentCache;
|
||||
if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the legacy one is supported.");
|
||||
var umbracoXML = cache.GetXml(UmbracoContext.Current); // = UmbracoContext.Current.GetXml();
|
||||
|
||||
string xpath = UmbracoSettings.UseLegacyXmlSchema ? "./data [@alias='{0}']" : "./{0}";
|
||||
if (umbracoXML.GetElementById(nodeId.ToString()) != null)
|
||||
if (
|
||||
",id,parentID,level,writerID,template,sortOrder,createDate,updateDate,nodeName,writerName,path,"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using NUnit.Framework;
|
||||
@@ -79,7 +80,8 @@ namespace Umbraco.Tests.PublishedCache
|
||||
new PublishedContentCache(),
|
||||
new PublishedMediaCache());
|
||||
|
||||
_umbracoContext.GetXmlDelegate = () =>
|
||||
var cache = new PublishedContentCache();
|
||||
cache.GetXmlDelegate = (user, preview) =>
|
||||
{
|
||||
var xDoc = new XmlDocument();
|
||||
|
||||
@@ -90,14 +92,18 @@ namespace Umbraco.Tests.PublishedCache
|
||||
return xDoc;
|
||||
};
|
||||
|
||||
_cache = new ContextualPublishedContentCache(new PublishedContentCache(), _umbracoContext);
|
||||
_cache = new ContextualPublishedContentCache(cache, _umbracoContext);
|
||||
}
|
||||
|
||||
private void SetupForLegacy()
|
||||
{
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseLegacyXmlSchema = true;
|
||||
_umbracoContext.GetXmlDelegate = () =>
|
||||
{
|
||||
|
||||
var cache = PublishedContentCacheResolver.Current.PublishedContentCache as PublishedContentCache;
|
||||
if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the legacy one is supported.");
|
||||
|
||||
cache.GetXmlDelegate = (user, preview) =>
|
||||
{
|
||||
var xDoc = new XmlDocument();
|
||||
|
||||
//create a custom xml structure to return
|
||||
|
||||
@@ -6,6 +6,7 @@ using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.PublishedCache.LegacyXmlCache;
|
||||
using umbraco.MacroEngines;
|
||||
using umbraco.NodeFactory;
|
||||
@@ -83,10 +84,13 @@ namespace Umbraco.Tests.PublishedContent
|
||||
//var template = Template.MakeNew("test", new User(0));
|
||||
//var ctx = GetUmbracoContext("/test", template.Id);
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
var cache = new PublishedContentCache();
|
||||
|
||||
var cache = PublishedContentCacheResolver.Current.PublishedContentCache as PublishedContentCache;
|
||||
if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the legacy one is supported.");
|
||||
|
||||
var node = new DynamicNode(
|
||||
new DynamicBackingItem(
|
||||
new Node(ctx.GetXml().SelectSingleNode("//*[@id='" + id + "' and @isDoc]"))));
|
||||
new Node(cache.GetXml(ctx).SelectSingleNode("//*[@id='" + id + "' and @isDoc]"))));
|
||||
Assert.IsNotNull(node);
|
||||
return (dynamic)node;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ using Umbraco.Core.Publishing;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Stubs;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.PublishedCache.LegacyXmlCache;
|
||||
using Umbraco.Web.Routing;
|
||||
using umbraco.BusinessLogic;
|
||||
@@ -312,7 +313,9 @@ namespace Umbraco.Tests.TestHelpers
|
||||
/// <param name="templateId"></param>
|
||||
protected void SetupUmbracoContextForTest(UmbracoContext umbracoContext, int templateId)
|
||||
{
|
||||
umbracoContext.GetXmlDelegate = () =>
|
||||
var cache = PublishedContentCacheResolver.Current.PublishedContentCache as PublishedContentCache;
|
||||
if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the legacy one is supported.");
|
||||
cache.GetXmlDelegate = (user, preview) =>
|
||||
{
|
||||
var xDoc = new XmlDocument();
|
||||
|
||||
|
||||
@@ -232,53 +232,6 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
internal ContextualPublishedMediaCache MediaCache { get; private set; }
|
||||
|
||||
private Func<XmlDocument> _xmlDelegate;
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the delegate used to retreive the Xml content, generally the setter is only used for unit tests
|
||||
/// and by default if it is not set will use the standard delegate which ONLY works when in the context an Http Request
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If not defined, we will use the standard delegate which ONLY works when in the context an Http Request
|
||||
/// mostly because the 'content' object heavily relies on HttpContext, SQL connections and a bunch of other stuff
|
||||
/// that when run inside of a unit test fails.
|
||||
/// </remarks>
|
||||
internal Func<XmlDocument> GetXmlDelegate
|
||||
{
|
||||
get
|
||||
{
|
||||
return _xmlDelegate ?? (_xmlDelegate = () =>
|
||||
{
|
||||
if (InPreviewMode)
|
||||
{
|
||||
if (_previewContent == null)
|
||||
{
|
||||
_previewContent = new PreviewContent(UmbracoUser, new Guid(StateHelper.Cookies.Preview.GetValue()), true);
|
||||
if (_previewContent.ValidPreviewSet)
|
||||
_previewContent.LoadPreviewset();
|
||||
}
|
||||
if (_previewContent.ValidPreviewSet)
|
||||
return _previewContent.XmlContent;
|
||||
}
|
||||
return content.Instance.XmlContent;
|
||||
});
|
||||
}
|
||||
set { _xmlDelegate = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the XML Cache document
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// This is marked internal for now because perhaps we might return a wrapper like CacheData so that it doesn't have a reliance
|
||||
/// specifically on XML.
|
||||
/// </remarks>
|
||||
internal XmlDocument GetXml()
|
||||
{
|
||||
return GetXmlDelegate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Boolean value indicating whether the current request is a front-end umbraco request
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user