Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Core/Variants/ContentVariantAllowedActionTests.cs
Kenn Jacobsen 012b43a1c2 Publishing in the Management API (#14774)
* make CoreScopeProvider available for derived classes

* Create publish controller

* Add publish functionality

* Remove unneeded using

* Implement publish for multiple cultures

* support multiple cultures in controler

* Dont validate properties

* Refactor to use PublishingOperationStatus

* refactor to use proper publish async methods

* Refactor publish logic into own service

* Commit some demo code

* Add notes about what errors can happen when publishing

* Rework ContentPublishingService and introduce explicit Publish and PublishBranch methods in ContentService

* Fix merge

* Allow the publishing strategy to do its job

* Improved check for unsaved changes

* Make the old content controller work (as best possible)

* Remove SaveAndPublish (SaveAndPublishBranch) from all tests

* Proper guards for invalid cultures when publishing

* Fix edge cases for property validation and content unpublishing + add unpublishing to ContentPublishingService

* Clear out a few TODOs - we'll accept the behavior for now

* Unpublish controller

* Fix merge

* Fix branch publish notifications

* Added extra test for publishing unpublished cultures and added FIXME comments for when we fix the state of published cultures in content

---------

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>
Co-authored-by: Zeegaan <nge@umbraco.dk>
2023-11-22 12:52:08 +01:00

91 lines
3.3 KiB
C#

using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Tests.Common.Attributes;
using Umbraco.Cms.Tests.Common.Builders;
using Umbraco.Cms.Tests.Common.Builders.Extensions;
using Umbraco.Cms.Tests.Integration.TestServerTest;
using Language = Umbraco.Cms.Core.Models.Language;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Extensions;
[TestFixture]
public class ContentVariantAllowedActionTests : UmbracoTestServerTestBase
{
private const string UsIso = "en-US";
private const string DkIso = "da-DK";
private ILanguageService LanguageService => GetRequiredService<ILanguageService>();
private IUserService UserService => GetRequiredService<IUserService>();
private IUmbracoMapper UmbracoMapper => GetRequiredService<IUmbracoMapper>();
[SetUp]
public async Task SetUpTestDate()
{
var dk = new Language(DkIso, "Danish");
await LanguageService.CreateAsync(dk, Constants.Security.SuperUserKey);
}
[Test]
[LongRunning]
public async Task CanCheckIfUserHasAccessToLanguage()
{
// setup user groups
var user = UserBuilder.CreateUser();
UserService.Save(user);
var userGroup = UserGroupBuilder.CreateUserGroup();
var languageId = (await LanguageService.GetAsync(DkIso))?.Id;
userGroup.AddAllowedLanguage(languageId!.Value);
UserService.Save(userGroup, new []{ user.Id});
var currentUser = UserService.GetUserById(user.Id);
var result = CreateContent(currentUser);
var danishVariant = result.Variants.FirstOrDefault(x => x.Language!.IsoCode is DkIso);
var usVariant = result.Variants.FirstOrDefault(x => x.Language!.IsoCode is UsIso);
// Right now we duplicate allowedActions if you have access, this should be changed
// when we implement granular permissions for languages
Assert.AreEqual(danishVariant!.AllowedActions, result.AllowedActions);
Assert.AreEqual(usVariant!.AllowedActions, new [] { ActionBrowse.ActionLetter.ToString() });
}
private ContentItemDisplay CreateContent(IUser user)
{
var contentTypeService = GetRequiredService<IContentTypeService>();
var contentType = new ContentTypeBuilder().WithContentVariation(ContentVariation.Culture).Build();
contentTypeService.Save(contentType);
var rootNode = new ContentBuilder()
.WithoutIdentity()
.WithContentType(contentType)
.WithCultureName(UsIso, "Root")
.WithCultureName(DkIso, "Rod")
.Build();
var contentService = GetRequiredService<IContentService>();
contentService.Save(rootNode);
contentService.Publish(rootNode, new[] { "*" });
ContentItemDisplay? display = UmbracoMapper.Map<ContentItemDisplay>(rootNode, context =>
{
context.Items["CurrentUser"] = user;
});
if (display is not null)
{
display.AllowPreview = display.AllowPreview && rootNode?.Trashed == false &&
rootNode.ContentType.IsElement == false;
}
return display;
}
}