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