U4-4373, U4-4374 - finalize fixes
Conflicts: src/Umbraco.Web/umbraco.presentation/CompatibilityHelper.cs
This commit is contained in:
76
src/Umbraco.Tests/PublishedContent/RootNodeTests.cs
Normal file
76
src/Umbraco.Tests/PublishedContent/RootNodeTests.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using umbraco;
|
||||
using umbraco.MacroEngines;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
[TestFixture]
|
||||
public class RootNodeTests : PublishedContentTestBase
|
||||
{
|
||||
[Test]
|
||||
public void PublishedContentHasNoRootNode()
|
||||
{
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
|
||||
// there is no content node with ID -1
|
||||
var content = ctx.ContentCache.GetById(-1);
|
||||
Assert.IsNull(content);
|
||||
|
||||
// content at root has null parent
|
||||
content = ctx.ContentCache.GetById(1046);
|
||||
Assert.IsNotNull(content);
|
||||
Assert.AreEqual(1, content.Level);
|
||||
Assert.IsNull(content.Parent);
|
||||
|
||||
// and yet is has siblings, etc.
|
||||
var siblings = content.Siblings();
|
||||
Assert.AreEqual(2, siblings.Count());
|
||||
|
||||
// non-existing content is null
|
||||
content = ctx.ContentCache.GetById(666);
|
||||
Assert.IsNull(content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LegacyDynamicNodeSortOfHasRootNode()
|
||||
{
|
||||
// there is a node with ID -1
|
||||
var node = new DynamicNode(-1);
|
||||
Assert.IsNotNull(node);
|
||||
Assert.AreEqual(-1, node.Id);
|
||||
|
||||
// content at root
|
||||
node = new DynamicNode(1046);
|
||||
Assert.IsNotNull(node);
|
||||
Assert.AreEqual(1, node.Level);
|
||||
|
||||
// has no parent
|
||||
// (confirmed in 4.7 and 6.1)
|
||||
Assert.IsNull(node.Parent);
|
||||
|
||||
// has siblings etc - no idea how we're supposed to get them?
|
||||
//var siblings = node.Parent.Children;
|
||||
//Assert.AreEqual(2, siblings.Count());
|
||||
|
||||
// non-existing content is "zero node"
|
||||
node = new DynamicNode(666, DynamicBackingItemType.Content); // set type to avoid Examine in tests
|
||||
Assert.IsNotNull(node);
|
||||
Assert.AreEqual(0, node.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Fix_U4_4374()
|
||||
{
|
||||
var node = new DynamicNode(-1);
|
||||
var id = node.DescendantsOrSelf().First().Id;
|
||||
Assert.AreEqual(-1, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -287,6 +287,7 @@
|
||||
<Compile Include="PropertyEditors\LegacyPropertyEditorIdToAliasConverterTests.cs" />
|
||||
<Compile Include="PropertyEditors\PropertyEditorValueEditorTests.cs" />
|
||||
<Compile Include="PublishedContent\PublishedContentRequestEngineTests.cs" />
|
||||
<Compile Include="PublishedContent\RootNodeTests.cs" />
|
||||
<Compile Include="PublishedContent\StronglyTypedModels\CallingMethodTests.cs" />
|
||||
<Compile Include="PublishedContent\StronglyTypedModels\Subpage.cs" />
|
||||
<Compile Include="PublishedContent\StronglyTypedModels\Textpage.cs" />
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Umbraco.Web.umbraco.presentation
|
||||
|
||||
public INode Parent
|
||||
{
|
||||
get { return ConvertToNode(_doc.Parent); }
|
||||
get { return _doc.Parent == null ? null : ConvertToNode(_doc.Parent); }
|
||||
}
|
||||
public int Id { get; private set; }
|
||||
public int template { get; private set; }
|
||||
|
||||
@@ -301,7 +301,12 @@ namespace umbraco.NodeFactory
|
||||
_pageXmlNode = ((IHasXmlNode)library.GetXmlNodeById(NodeId.ToString()).Current).GetNode();
|
||||
else
|
||||
{
|
||||
if (presentation.UmbracoContext.Current != null)
|
||||
if (UmbracoContext.Current != null)
|
||||
{
|
||||
var cache = UmbracoContext.Current.ContentCache.InnerCache as Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache;
|
||||
_pageXmlNode = cache.GetXml(UmbracoContext.Current, false).DocumentElement;
|
||||
}
|
||||
else if (presentation.UmbracoContext.Current != null)
|
||||
{
|
||||
_pageXmlNode = umbraco.presentation.UmbracoContext.Current.GetXml().DocumentElement;
|
||||
}
|
||||
|
||||
@@ -34,9 +34,8 @@ namespace umbraco.MacroEngines
|
||||
{
|
||||
if (Id == -1)
|
||||
{
|
||||
//this is a special check, previously passing in -1 would return a real node, the root node. Though
|
||||
// it has no properties (defaults apply), you could access descendants, children, etc...
|
||||
//This is how this used to work before a large refactor - which I think may have broken other legacy logic too :(
|
||||
// passing in -1 needs to return a real node, the "root" node, which has no
|
||||
// properties (defaults apply) but can be used to access descendants, children, etc.
|
||||
|
||||
this.content = new NodeFactory.Node(Id);
|
||||
return;
|
||||
@@ -69,9 +68,8 @@ namespace umbraco.MacroEngines
|
||||
{
|
||||
if (Id == -1)
|
||||
{
|
||||
//this is a special check, previously passing in -1 would return a real node, the root node. Though
|
||||
// it has no properties (defaults apply), you could access descendants, children, etc...
|
||||
//This is how this used to work before a large refactor - which I think may have broken other legacy logic too :(
|
||||
// passing in -1 needs to return a real node, the "root" node, which has no
|
||||
// properties (defaults apply) but can be used to access descendants, children, etc.
|
||||
|
||||
this.content = new NodeFactory.Node(Id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user