2020-12-23 11:35:49 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2021-07-12 10:20:59 -06:00
|
|
|
using System;
|
2020-12-23 11:35:49 +01:00
|
|
|
using System.Linq;
|
2018-03-30 19:31:42 +02:00
|
|
|
using System.Threading;
|
2020-10-05 21:45:33 +02:00
|
|
|
using NUnit.Framework;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
|
|
|
using Umbraco.Cms.Core.Models.Membership;
|
2021-07-12 10:20:59 -06:00
|
|
|
using Umbraco.Cms.Core.Scoping;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Services;
|
|
|
|
|
using Umbraco.Cms.Tests.Common.Testing;
|
|
|
|
|
using Umbraco.Cms.Tests.Integration.Testing;
|
2022-04-26 10:22:37 +01:00
|
|
|
using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider;
|
|
|
|
|
using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope;
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services
|
2017-09-14 19:29:12 +02:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests covering the SectionService
|
|
|
|
|
/// </summary>
|
2018-03-30 19:31:42 +02:00
|
|
|
[TestFixture]
|
2020-09-29 08:14:27 +02:00
|
|
|
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
|
|
|
|
public class SectionServiceTests : UmbracoIntegrationTest
|
2017-09-14 19:29:12 +02:00
|
|
|
{
|
2020-10-06 12:43:24 +02:00
|
|
|
private ISectionService SectionService => GetRequiredService<ISectionService>();
|
2020-12-23 11:35:49 +01:00
|
|
|
|
2020-10-06 12:43:24 +02:00
|
|
|
private IUserService UserService => GetRequiredService<IUserService>();
|
2019-01-18 10:02:47 +01:00
|
|
|
|
2017-09-14 19:29:12 +02:00
|
|
|
[Test]
|
|
|
|
|
public void SectionService_Can_Get_Allowed_Sections_For_User()
|
|
|
|
|
{
|
|
|
|
|
// Arrange
|
2020-12-23 11:35:49 +01:00
|
|
|
IUser user = CreateTestUser();
|
2017-09-14 19:29:12 +02:00
|
|
|
|
|
|
|
|
// Act
|
2020-10-06 12:43:24 +02:00
|
|
|
var result = SectionService.GetAllowedSections(user.Id).ToList();
|
2017-09-14 19:29:12 +02:00
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.AreEqual(3, result.Count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IUser CreateTestUser()
|
|
|
|
|
{
|
2021-07-12 10:20:59 -06:00
|
|
|
using IScope scope = ScopeProvider.CreateScope(autoComplete: true);
|
2021-07-12 11:54:38 -06:00
|
|
|
using IDisposable _ = scope.Notifications.Suppress();
|
2021-07-12 10:20:59 -06:00
|
|
|
|
2020-09-21 21:06:24 +02:00
|
|
|
var globalSettings = new GlobalSettings();
|
2020-08-24 16:06:09 +02:00
|
|
|
var user = new User(globalSettings)
|
2017-09-14 19:29:12 +02:00
|
|
|
{
|
|
|
|
|
Name = "Test user",
|
|
|
|
|
Username = "testUser",
|
|
|
|
|
Email = "testuser@test.com",
|
|
|
|
|
};
|
2021-07-12 10:20:59 -06:00
|
|
|
UserService.Save(user);
|
2017-09-14 19:29:12 +02:00
|
|
|
|
2019-12-09 14:12:06 +01:00
|
|
|
var userGroupA = new UserGroup(ShortStringHelper)
|
2017-09-14 19:29:12 +02:00
|
|
|
{
|
|
|
|
|
Alias = "GroupA",
|
|
|
|
|
Name = "Group A"
|
|
|
|
|
};
|
|
|
|
|
userGroupA.AddAllowedSection("media");
|
|
|
|
|
userGroupA.AddAllowedSection("settings");
|
2020-12-23 11:35:49 +01:00
|
|
|
|
2019-01-27 01:17:32 -05:00
|
|
|
// TODO: This is failing the test
|
2021-07-12 10:20:59 -06:00
|
|
|
UserService.Save(userGroupA, new[] { user.Id });
|
2017-09-14 19:29:12 +02:00
|
|
|
|
2019-12-09 14:12:06 +01:00
|
|
|
var userGroupB = new UserGroup(ShortStringHelper)
|
2017-09-14 19:29:12 +02:00
|
|
|
{
|
|
|
|
|
Alias = "GroupB",
|
|
|
|
|
Name = "Group B"
|
|
|
|
|
};
|
|
|
|
|
userGroupB.AddAllowedSection("settings");
|
2019-01-17 17:50:59 +11:00
|
|
|
userGroupB.AddAllowedSection("member");
|
2021-07-12 10:20:59 -06:00
|
|
|
UserService.Save(userGroupB, new[] { user.Id });
|
2017-09-14 19:29:12 +02:00
|
|
|
|
2020-10-06 12:43:24 +02:00
|
|
|
return UserService.GetUserById(user.Id);
|
2017-09-14 19:29:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
2017-09-23 10:08:18 +02:00
|
|
|
}
|