86 lines
3.5 KiB
C#
86 lines
3.5 KiB
C#
|
|
using NUnit.Framework;
|
|||
|
|
using Umbraco.Cms.Core.Models;
|
|||
|
|
|
|||
|
|
namespace Umbraco.Cms.Tests.Integration.ManagementApi.Services;
|
|||
|
|
|
|||
|
|
public partial class UserStartNodeEntitiesServiceTests
|
|||
|
|
{
|
|||
|
|
[Test]
|
|||
|
|
public async Task RootUserAccessEntities_FirstAndLastRoot_YieldsBoth_AsAllowed()
|
|||
|
|
{
|
|||
|
|
var contentStartNodeIds = await CreateUserAndGetStartNodeIds(_contentByName["1"].Id, _contentByName["5"].Id);
|
|||
|
|
|
|||
|
|
var roots = UserStartNodeEntitiesService
|
|||
|
|
.RootUserAccessEntities(
|
|||
|
|
UmbracoObjectTypes.Document,
|
|||
|
|
contentStartNodeIds)
|
|||
|
|
.ToArray();
|
|||
|
|
|
|||
|
|
// expected total is 2, because only two items at root ("1" amd "10") are allowed
|
|||
|
|
Assert.AreEqual(2, roots.Length);
|
|||
|
|
Assert.Multiple(() =>
|
|||
|
|
{
|
|||
|
|
// first and last content items are the ones allowed
|
|||
|
|
Assert.AreEqual(_contentByName["1"].Key, roots[0].Entity.Key);
|
|||
|
|
Assert.AreEqual(_contentByName["5"].Key, roots[1].Entity.Key);
|
|||
|
|
|
|||
|
|
// explicitly verify the entity sort order, both so we know sorting works,
|
|||
|
|
// and so we know it's actually the first and last item at root
|
|||
|
|
Assert.AreEqual(0, roots[0].Entity.SortOrder);
|
|||
|
|
Assert.AreEqual(4, roots[1].Entity.SortOrder);
|
|||
|
|
|
|||
|
|
// both are allowed (they are the actual start nodes)
|
|||
|
|
Assert.IsTrue(roots[0].HasAccess);
|
|||
|
|
Assert.IsTrue(roots[1].HasAccess);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[Test]
|
|||
|
|
public async Task RootUserAccessEntities_ChildrenAsStartNode_YieldsChildRoots_AsNotAllowed()
|
|||
|
|
{
|
|||
|
|
var contentStartNodeIds = await CreateUserAndGetStartNodeIds(_contentByName["1-3"].Id, _contentByName["3-3"].Id, _contentByName["5-3"].Id);
|
|||
|
|
|
|||
|
|
var roots = UserStartNodeEntitiesService
|
|||
|
|
.RootUserAccessEntities(
|
|||
|
|
UmbracoObjectTypes.Document,
|
|||
|
|
contentStartNodeIds)
|
|||
|
|
.ToArray();
|
|||
|
|
|
|||
|
|
Assert.AreEqual(3, roots.Length);
|
|||
|
|
Assert.Multiple(() =>
|
|||
|
|
{
|
|||
|
|
// the three start nodes are the children of the "1", "3" and "5" roots, respectively, so these are expected as roots
|
|||
|
|
Assert.AreEqual(_contentByName["1"].Key, roots[0].Entity.Key);
|
|||
|
|
Assert.AreEqual(_contentByName["3"].Key, roots[1].Entity.Key);
|
|||
|
|
Assert.AreEqual(_contentByName["5"].Key, roots[2].Entity.Key);
|
|||
|
|
|
|||
|
|
// all are disallowed - only the children (the actual start nodes) are allowed
|
|||
|
|
Assert.IsTrue(roots.All(r => r.HasAccess is false));
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[Test]
|
|||
|
|
public async Task RootUserAccessEntities_GrandchildrenAsStartNode_YieldsGrandchildRoots_AsNotAllowed()
|
|||
|
|
{
|
|||
|
|
var contentStartNodeIds = await CreateUserAndGetStartNodeIds(_contentByName["1-2-3"].Id, _contentByName["2-3-4"].Id, _contentByName["3-4-5"].Id);
|
|||
|
|
|
|||
|
|
var roots = UserStartNodeEntitiesService
|
|||
|
|
.RootUserAccessEntities(
|
|||
|
|
UmbracoObjectTypes.Document,
|
|||
|
|
contentStartNodeIds)
|
|||
|
|
.ToArray();
|
|||
|
|
|
|||
|
|
Assert.AreEqual(3, roots.Length);
|
|||
|
|
Assert.Multiple(() =>
|
|||
|
|
{
|
|||
|
|
// the three start nodes are the grandchildren of the "1", "2" and "3" roots, respectively, so these are expected as roots
|
|||
|
|
Assert.AreEqual(_contentByName["1"].Key, roots[0].Entity.Key);
|
|||
|
|
Assert.AreEqual(_contentByName["2"].Key, roots[1].Entity.Key);
|
|||
|
|
Assert.AreEqual(_contentByName["3"].Key, roots[2].Entity.Key);
|
|||
|
|
|
|||
|
|
// all are disallowed - only the grandchildren (the actual start nodes) are allowed
|
|||
|
|
Assert.IsTrue(roots.All(r => r.HasAccess is false));
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|