Integration tests for content publishing with ancestor unpublished (#18941)
* Resolved warnings in test class. * Refactor regions into partial classes. * Aligned test names. * Variable name refactoring. * Added tests for unpublished paths. * Adjust tests to verify current behaviour. * Cleaned up project file.
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Strings;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Extensions;
|
||||
@@ -29,7 +27,8 @@ public abstract class ContentTypeBaseBuilder<TParent, TType>
|
||||
IWithIconBuilder,
|
||||
IWithThumbnailBuilder,
|
||||
IWithTrashedBuilder,
|
||||
IWithIsContainerBuilder
|
||||
IWithIsContainerBuilder,
|
||||
IWithAllowAsRootBuilder
|
||||
where TParent : IBuildContentTypes
|
||||
{
|
||||
private string _alias;
|
||||
@@ -49,6 +48,7 @@ public abstract class ContentTypeBaseBuilder<TParent, TType>
|
||||
private string _thumbnail;
|
||||
private bool? _trashed;
|
||||
private DateTime? _updateDate;
|
||||
private bool? _allowedAtRoot;
|
||||
|
||||
public ContentTypeBaseBuilder(TParent parentBuilder)
|
||||
: base(parentBuilder)
|
||||
@@ -168,6 +168,12 @@ public abstract class ContentTypeBaseBuilder<TParent, TType>
|
||||
set => _updateDate = value;
|
||||
}
|
||||
|
||||
bool? IWithAllowAsRootBuilder.AllowAsRoot
|
||||
{
|
||||
get => _allowedAtRoot;
|
||||
set => _allowedAtRoot = value;
|
||||
}
|
||||
|
||||
protected int GetId() => _id ?? 0;
|
||||
|
||||
protected Guid GetKey() => _key ?? Guid.NewGuid();
|
||||
@@ -202,6 +208,8 @@ public abstract class ContentTypeBaseBuilder<TParent, TType>
|
||||
|
||||
protected Guid? GetListView() => _listView;
|
||||
|
||||
protected bool GetAllowedAtRoot() => _allowedAtRoot ?? false;
|
||||
|
||||
protected void BuildPropertyGroups(ContentTypeCompositionBase contentType, IEnumerable<PropertyGroup> propertyGroups)
|
||||
{
|
||||
foreach (var propertyGroup in propertyGroups)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.ContentEditing;
|
||||
@@ -125,6 +123,7 @@ public class ContentTypeBuilder
|
||||
contentType.Trashed = GetTrashed();
|
||||
contentType.ListView = GetListView();
|
||||
contentType.IsElement = _isElement ?? false;
|
||||
contentType.AllowedAsRoot = GetAllowedAtRoot();
|
||||
contentType.HistoryCleanup = new HistoryCleanup();
|
||||
|
||||
contentType.Variations = contentVariation;
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.ContentPublishing;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Tests.Integration.Testing;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
||||
|
||||
public partial class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
[Test]
|
||||
public async Task Can_Clear_Schedule_Invariant()
|
||||
{
|
||||
var doctype = await SetupInvariantDoctypeAsync();
|
||||
var content = await CreateInvariantContentAsync(doctype);
|
||||
|
||||
var scheduleSetupAttempt =
|
||||
await SchedulePublishAndUnPublishInvariantAsync(content);
|
||||
|
||||
if (scheduleSetupAttempt.Success is false)
|
||||
{
|
||||
throw new Exception("Setup failed");
|
||||
}
|
||||
|
||||
var clearScheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = Constants.System.InvariantCulture,
|
||||
Schedule = new ContentScheduleModel(),
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(clearScheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.IsNull(content!.PublishDate);
|
||||
Assert.AreEqual(0, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Clear_Schedule_Single_Culture()
|
||||
{
|
||||
var setupInfo = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
setupInfo.LangEn,
|
||||
setupInfo.LangDa,
|
||||
setupInfo.LangBe,
|
||||
setupInfo.contentType);
|
||||
|
||||
var scheduleSetupAttempt =
|
||||
await SchedulePublishAndUnPublishForAllCulturesAsync(content, setupInfo);
|
||||
|
||||
if (scheduleSetupAttempt.Success is false)
|
||||
{
|
||||
throw new Exception("Setup failed");
|
||||
}
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel(),
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangEn.IsoCode, ContentScheduleAction.Release).Any());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangEn.IsoCode, ContentScheduleAction.Expire).Any());
|
||||
Assert.AreEqual(4, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Clear_Schedule_Some_Cultures()
|
||||
{
|
||||
var setupInfo = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
setupInfo.LangEn,
|
||||
setupInfo.LangDa,
|
||||
setupInfo.LangBe,
|
||||
setupInfo.contentType);
|
||||
|
||||
var scheduleSetupAttempt =
|
||||
await SchedulePublishAndUnPublishForAllCulturesAsync(content, setupInfo);
|
||||
|
||||
if (scheduleSetupAttempt.Success is false)
|
||||
{
|
||||
throw new Exception("Setup failed");
|
||||
}
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel(),
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangDa.IsoCode,
|
||||
Schedule = new ContentScheduleModel(),
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangEn.IsoCode, ContentScheduleAction.Release).Any());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangEn.IsoCode, ContentScheduleAction.Expire).Any());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangDa.IsoCode, ContentScheduleAction.Release).Any());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangDa.IsoCode, ContentScheduleAction.Expire).Any());
|
||||
Assert.AreEqual(2, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Clear_Schedule_All_Cultures()
|
||||
{
|
||||
var setupInfo = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
setupInfo.LangEn,
|
||||
setupInfo.LangDa,
|
||||
setupInfo.LangBe,
|
||||
setupInfo.contentType);
|
||||
|
||||
var scheduleSetupAttempt =
|
||||
await SchedulePublishAndUnPublishForAllCulturesAsync(content, setupInfo);
|
||||
|
||||
if (scheduleSetupAttempt.Success is false)
|
||||
{
|
||||
throw new Exception("Setup failed");
|
||||
}
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel(),
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangDa.IsoCode,
|
||||
Schedule = new ContentScheduleModel(),
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangBe.IsoCode,
|
||||
Schedule = new ContentScheduleModel(),
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.AreEqual(0, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models.ContentPublishing;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
using Umbraco.Cms.Tests.Integration.Testing;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
||||
|
||||
public partial class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
[Test]
|
||||
public async Task Can_Publish_Single_Culture()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var setupData = await CreateVariantContentAsync(langEn, langDa, langBe, contentType);
|
||||
|
||||
var publishAttempt = await ContentPublishingService.PublishAsync(
|
||||
setupData.Key,
|
||||
[new() { Culture = langEn.IsoCode }],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(publishAttempt.Success);
|
||||
var content = ContentService.GetById(setupData.Key);
|
||||
Assert.AreEqual(1, content!.PublishedCultures.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Publish_Some_Cultures()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(langEn, langDa, langBe, contentType);
|
||||
|
||||
var publishAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new() { Culture = langEn.IsoCode }, new() { Culture = langDa.IsoCode },
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(publishAttempt.Success);
|
||||
content = ContentService.GetById(content.Key);
|
||||
Assert.AreEqual(2, content!.PublishedCultures.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Publish_All_Cultures()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(langEn, langDa, langBe, contentType);
|
||||
|
||||
var publishAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new() { Culture = langEn.IsoCode },
|
||||
new() { Culture = langDa.IsoCode },
|
||||
new() { Culture = langBe.IsoCode },
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(publishAttempt.Success);
|
||||
content = ContentService.GetById(content.Key);
|
||||
Assert.AreEqual(3, content!.PublishedCultures.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Cannot_Publish_Invariant_In_Variant_Setup()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
langEn,
|
||||
langDa,
|
||||
langBe,
|
||||
contentType);
|
||||
|
||||
var publishAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[new() { Culture = Constants.System.InvariantCulture }],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsFalse(publishAttempt.Success);
|
||||
Assert.AreEqual(ContentPublishingOperationStatus.CannotPublishInvariantWhenVariant, publishAttempt.Status);
|
||||
|
||||
content = ContentService.GetById(content.Key);
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Publish_Invariant_In_Invariant_Setup()
|
||||
{
|
||||
var doctype = await SetupInvariantDoctypeAsync();
|
||||
var content = await CreateInvariantContentAsync(doctype);
|
||||
|
||||
var publishAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[new() { Culture = Constants.System.InvariantCulture }],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(publishAttempt.Success);
|
||||
|
||||
content = ContentService.GetById(content.Key);
|
||||
Assert.NotNull(content!.PublishDate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Cannot_Publish_Unknown_Culture()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
langEn,
|
||||
langDa,
|
||||
langBe,
|
||||
contentType);
|
||||
|
||||
var publishAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new() { Culture = langEn.IsoCode },
|
||||
new() { Culture = langDa.IsoCode },
|
||||
new() { Culture = UnknownCulture },
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsFalse(publishAttempt.Success);
|
||||
Assert.AreEqual(ContentPublishingOperationStatus.InvalidCulture, publishAttempt.Status);
|
||||
|
||||
content = ContentService.GetById(content.Key);
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Cannot_Publish_Scheduled_Culture()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
langEn,
|
||||
langDa,
|
||||
langBe,
|
||||
contentType);
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = langEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
}
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
if (scheduleAttempt.Success is false)
|
||||
{
|
||||
throw new Exception("Setup failed");
|
||||
}
|
||||
|
||||
var publishAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[new() { Culture = langEn.IsoCode }],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsFalse(publishAttempt.Success);
|
||||
Assert.AreEqual(ContentPublishingOperationStatus.CultureAwaitingRelease, publishAttempt.Status);
|
||||
|
||||
content = ContentService.GetById(content.Key);
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
}
|
||||
|
||||
// TODO: The following three tests verify existing functionality that could be reconsidered.
|
||||
// The existing behaviour, verified on Umbraco 13 and 15 is as follows:
|
||||
// - For invariant content, if a parent is unpublished and I try to publish the child, I get a ContentPublishingOperationStatus.PathNotPublished error.
|
||||
// - For variant content, if I publish the parent in English but not Danish, I can publish the child in Danish.
|
||||
// This is inconsistent so we should consider if this is the desired behaviour.
|
||||
// For now though, the following tests verify the existing behaviour.
|
||||
|
||||
[Test]
|
||||
public async Task Cannot_Publish_With_Unpublished_Parent()
|
||||
{
|
||||
var doctype = await SetupInvariantDoctypeAsync();
|
||||
var parentContent = await CreateInvariantContentAsync(doctype);
|
||||
var childContent = await CreateInvariantContentAsync(doctype, parentContent.Key);
|
||||
|
||||
var publishAttempt = await ContentPublishingService.PublishAsync(
|
||||
childContent.Key,
|
||||
[new() { Culture = Constants.System.InvariantCulture }],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsFalse(publishAttempt.Success);
|
||||
Assert.AreEqual(ContentPublishingOperationStatus.PathNotPublished, publishAttempt.Status);
|
||||
|
||||
// Now publish the parent and re-try publishing the child.
|
||||
publishAttempt = await ContentPublishingService.PublishAsync(
|
||||
parentContent.Key,
|
||||
[new() { Culture = Constants.System.InvariantCulture }],
|
||||
Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(publishAttempt.Success);
|
||||
|
||||
publishAttempt = await ContentPublishingService.PublishAsync(
|
||||
childContent.Key,
|
||||
[new() { Culture = Constants.System.InvariantCulture }],
|
||||
Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(publishAttempt.Success);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Cannot_Publish_Culture_With_Unpublished_Parent()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var parentContent = await CreateVariantContentAsync(
|
||||
langEn,
|
||||
langDa,
|
||||
langBe,
|
||||
contentType);
|
||||
var childContent = await CreateVariantContentAsync(
|
||||
langEn,
|
||||
langDa,
|
||||
langBe,
|
||||
contentType,
|
||||
parentContent.Key);
|
||||
|
||||
// Publish child in English, should not succeed.
|
||||
var publishAttempt = await ContentPublishingService.PublishAsync(
|
||||
childContent.Key,
|
||||
[new() { Culture = langEn.IsoCode }],
|
||||
Constants.Security.SuperUserKey);
|
||||
Assert.IsFalse(publishAttempt.Success);
|
||||
Assert.AreEqual(ContentPublishingOperationStatus.PathNotPublished, publishAttempt.Status);
|
||||
|
||||
// Now publish the parent and re-try publishing the child.
|
||||
publishAttempt = await ContentPublishingService.PublishAsync(
|
||||
parentContent.Key,
|
||||
[new() { Culture = langEn.IsoCode }],
|
||||
Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(publishAttempt.Success);
|
||||
|
||||
publishAttempt = await ContentPublishingService.PublishAsync(
|
||||
childContent.Key,
|
||||
[new() { Culture = langEn.IsoCode }],
|
||||
Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(publishAttempt.Success);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Publish_Culture_With_Unpublished_Parent_Culture()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var parentContent = await CreateVariantContentAsync(
|
||||
langEn,
|
||||
langDa,
|
||||
langBe,
|
||||
contentType);
|
||||
var childContent = await CreateVariantContentAsync(
|
||||
langEn,
|
||||
langDa,
|
||||
langBe,
|
||||
contentType,
|
||||
parentContent.Key);
|
||||
|
||||
// Publish parent in English.
|
||||
var publishAttempt = await ContentPublishingService.PublishAsync(
|
||||
parentContent.Key,
|
||||
[new() { Culture = langEn.IsoCode }],
|
||||
Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(publishAttempt.Success);
|
||||
|
||||
// Publish child in English, should succeed.
|
||||
publishAttempt = await ContentPublishingService.PublishAsync(
|
||||
childContent.Key,
|
||||
[new() { Culture = langEn.IsoCode }],
|
||||
Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(publishAttempt.Success);
|
||||
|
||||
// Publish child in Danish, should also succeed.
|
||||
publishAttempt = await ContentPublishingService.PublishAsync(
|
||||
childContent.Key,
|
||||
[new() { Culture = langDa.IsoCode }],
|
||||
Constants.Security.SuperUserKey);
|
||||
Assert.IsTrue(publishAttempt.Success);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.ContentPublishing;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
using Umbraco.Cms.Tests.Integration.Testing;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
||||
|
||||
public partial class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
[Test]
|
||||
public async Task Can_Schedule_Publish_Invariant()
|
||||
{
|
||||
var doctype = await SetupInvariantDoctypeAsync();
|
||||
var content = await CreateInvariantContentAsync(doctype);
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = Constants.System.InvariantCulture,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.IsNull(content!.PublishDate);
|
||||
Assert.AreEqual(
|
||||
_schedulePublishDate,
|
||||
schedules.GetSchedule(Constants.System.InvariantCulture, ContentScheduleAction.Release).Single().Date);
|
||||
Assert.AreEqual(1, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Schedule_Publish_Single_Culture()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
langEn,
|
||||
langDa,
|
||||
langBe,
|
||||
contentType);
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = langEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.AreEqual(
|
||||
_schedulePublishDate,
|
||||
schedules.GetSchedule(langEn.IsoCode, ContentScheduleAction.Release).Single().Date);
|
||||
Assert.AreEqual(1, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Schedule_Publish_Some_Cultures()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
langEn,
|
||||
langDa,
|
||||
langBe,
|
||||
contentType);
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = langEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = langDa.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.AreEqual(
|
||||
_schedulePublishDate,
|
||||
schedules.GetSchedule(langEn.IsoCode, ContentScheduleAction.Release).Single().Date);
|
||||
Assert.AreEqual(
|
||||
_schedulePublishDate,
|
||||
schedules.GetSchedule(langDa.IsoCode, ContentScheduleAction.Release).Single().Date);
|
||||
Assert.AreEqual(2, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Schedule_Publish_All_Cultures()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
langEn,
|
||||
langDa,
|
||||
langBe,
|
||||
contentType);
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = langEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = langDa.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = langBe.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.AreEqual(
|
||||
_schedulePublishDate,
|
||||
schedules.GetSchedule(langEn.IsoCode, ContentScheduleAction.Release).Single().Date);
|
||||
Assert.AreEqual(
|
||||
_schedulePublishDate,
|
||||
schedules.GetSchedule(langDa.IsoCode, ContentScheduleAction.Release).Single().Date);
|
||||
Assert.AreEqual(
|
||||
_schedulePublishDate,
|
||||
schedules.GetSchedule(langBe.IsoCode, ContentScheduleAction.Release).Single().Date);
|
||||
Assert.AreEqual(3, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Cannot_Schedule_Publish_Unknown_Culture()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
langEn,
|
||||
langDa,
|
||||
langBe,
|
||||
contentType);
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = langEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = langDa.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = UnknownCulture,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate }
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsFalse(scheduleAttempt.Success);
|
||||
Assert.AreEqual(ContentPublishingOperationStatus.InvalidCulture, scheduleAttempt.Status);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.AreEqual(0, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Publish_And_Schedule_Different_Cultures()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
langEn,
|
||||
langDa,
|
||||
langBe,
|
||||
contentType);
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = langEn.IsoCode,
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = langDa.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(1, content!.PublishedCultures.Count());
|
||||
Assert.AreEqual(1, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.ContentPublishing;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
using Umbraco.Cms.Tests.Integration.Testing;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
||||
|
||||
public partial class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
[Test]
|
||||
public async Task Can_Schedule_Unpublish_Invariant()
|
||||
{
|
||||
var doctype = await SetupInvariantDoctypeAsync();
|
||||
var content = await CreateInvariantContentAsync(doctype);
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = Constants.System.InvariantCulture,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _scheduleUnPublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.IsNull(content!.PublishDate);
|
||||
Assert.AreEqual(
|
||||
_scheduleUnPublishDate,
|
||||
schedules.GetSchedule(Constants.System.InvariantCulture, ContentScheduleAction.Expire).Single().Date);
|
||||
Assert.AreEqual(1, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Schedule_Unpublish_Single_Culture()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
langEn,
|
||||
langDa,
|
||||
langBe,
|
||||
contentType);
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = langEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _schedulePublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.AreEqual(
|
||||
_schedulePublishDate,
|
||||
schedules.GetSchedule(langEn.IsoCode, ContentScheduleAction.Expire).Single().Date);
|
||||
Assert.AreEqual(1, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Schedule_Unpublish_Some_Cultures()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
langEn,
|
||||
langDa,
|
||||
langBe,
|
||||
contentType);
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = langEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _schedulePublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = langDa.IsoCode,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _schedulePublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.AreEqual(
|
||||
_schedulePublishDate,
|
||||
schedules.GetSchedule(langEn.IsoCode, ContentScheduleAction.Expire).Single().Date);
|
||||
Assert.AreEqual(
|
||||
_schedulePublishDate,
|
||||
schedules.GetSchedule(langDa.IsoCode, ContentScheduleAction.Expire).Single().Date);
|
||||
Assert.AreEqual(2, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Schedule_Unpublish_All_Cultures()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
langEn,
|
||||
langDa,
|
||||
langBe,
|
||||
contentType);
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = langEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _schedulePublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = langDa.IsoCode,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _schedulePublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = langBe.IsoCode,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _schedulePublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.AreEqual(
|
||||
_schedulePublishDate,
|
||||
schedules.GetSchedule(langEn.IsoCode, ContentScheduleAction.Expire).Single().Date);
|
||||
Assert.AreEqual(
|
||||
_schedulePublishDate,
|
||||
schedules.GetSchedule(langDa.IsoCode, ContentScheduleAction.Expire).Single().Date);
|
||||
Assert.AreEqual(
|
||||
_schedulePublishDate,
|
||||
schedules.GetSchedule(langBe.IsoCode, ContentScheduleAction.Expire).Single().Date);
|
||||
Assert.AreEqual(3, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Cannot_Schedule_Unpublish_Unknown_Culture()
|
||||
{
|
||||
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
langEn,
|
||||
langDa,
|
||||
langBe,
|
||||
contentType);
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = langEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _schedulePublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = langDa.IsoCode,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _schedulePublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = UnknownCulture,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _schedulePublishDate }
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsFalse(scheduleAttempt.Success);
|
||||
Assert.AreEqual(ContentPublishingOperationStatus.InvalidCulture, scheduleAttempt.Status);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.AreEqual(0, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.ContentPublishing;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
using Umbraco.Cms.Tests.Integration.Testing;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
||||
|
||||
public partial class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
[Test]
|
||||
public async Task Can_UnSchedule_Publish_Invariant()
|
||||
{
|
||||
var doctype = await SetupInvariantDoctypeAsync();
|
||||
var content = await CreateInvariantContentAsync(doctype);
|
||||
|
||||
var scheduleSetupAttempt =
|
||||
await SchedulePublishAndUnPublishInvariantAsync(content);
|
||||
|
||||
if (scheduleSetupAttempt.Success is false)
|
||||
{
|
||||
throw new Exception("Setup failed");
|
||||
}
|
||||
|
||||
var unscheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = Constants.System.InvariantCulture,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _scheduleUnPublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(unscheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.IsNull(content!.PublishDate);
|
||||
Assert.IsFalse(schedules.GetSchedule(Constants.System.InvariantCulture, ContentScheduleAction.Release).Any());
|
||||
Assert.IsTrue(schedules.GetSchedule(Constants.System.InvariantCulture, ContentScheduleAction.Expire).Any());
|
||||
Assert.AreEqual(1, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Unschedule_Publish_Single_Culture()
|
||||
{
|
||||
var setupInfo = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
setupInfo.LangEn,
|
||||
setupInfo.LangDa,
|
||||
setupInfo.LangBe,
|
||||
setupInfo.contentType);
|
||||
|
||||
var scheduleSetupAttempt =
|
||||
await SchedulePublishAndUnPublishForAllCulturesAsync(content, setupInfo);
|
||||
|
||||
if (scheduleSetupAttempt.Success is false)
|
||||
{
|
||||
throw new Exception("Setup failed");
|
||||
}
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _scheduleUnPublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangEn.IsoCode, ContentScheduleAction.Release).Any());
|
||||
Assert.AreEqual(5, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Unschedule_Publish_Some_Cultures()
|
||||
{
|
||||
var setupInfo = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
setupInfo.LangEn,
|
||||
setupInfo.LangDa,
|
||||
setupInfo.LangBe,
|
||||
setupInfo.contentType);
|
||||
|
||||
var scheduleSetupAttempt =
|
||||
await SchedulePublishAndUnPublishForAllCulturesAsync(content, setupInfo);
|
||||
|
||||
if (scheduleSetupAttempt.Success is false)
|
||||
{
|
||||
throw new Exception("Setup failed");
|
||||
}
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _scheduleUnPublishDate }
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangDa.IsoCode,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _scheduleUnPublishDate }
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangEn.IsoCode, ContentScheduleAction.Release).Any());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangDa.IsoCode, ContentScheduleAction.Release).Any());
|
||||
Assert.AreEqual(4, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Unschedule_Publish_All_Cultures()
|
||||
{
|
||||
var setupInfo = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
setupInfo.LangEn,
|
||||
setupInfo.LangDa,
|
||||
setupInfo.LangBe,
|
||||
setupInfo.contentType);
|
||||
|
||||
var scheduleSetupAttempt =
|
||||
await SchedulePublishAndUnPublishForAllCulturesAsync(content, setupInfo);
|
||||
|
||||
if (scheduleSetupAttempt.Success is false)
|
||||
{
|
||||
throw new Exception("Setup failed");
|
||||
}
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _scheduleUnPublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangDa.IsoCode,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _scheduleUnPublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangBe.IsoCode,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _scheduleUnPublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangEn.IsoCode, ContentScheduleAction.Release).Any());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangDa.IsoCode, ContentScheduleAction.Release).Any());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangBe.IsoCode, ContentScheduleAction.Release).Any());
|
||||
Assert.AreEqual(3, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Cannot_Unschedule_Publish_Unknown_Culture()
|
||||
{
|
||||
var setupInfo = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
setupInfo.LangEn,
|
||||
setupInfo.LangDa,
|
||||
setupInfo.LangBe,
|
||||
setupInfo.contentType);
|
||||
|
||||
var scheduleSetupAttempt =
|
||||
await SchedulePublishAndUnPublishForAllCulturesAsync(content, setupInfo);
|
||||
|
||||
if (scheduleSetupAttempt.Success is false)
|
||||
{
|
||||
throw new Exception("Setup failed");
|
||||
}
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _scheduleUnPublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangDa.IsoCode,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _scheduleUnPublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = UnknownCulture,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _scheduleUnPublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsFalse(scheduleAttempt.Success);
|
||||
Assert.AreEqual(ContentPublishingOperationStatus.InvalidCulture, scheduleAttempt.Status);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.AreEqual(6, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.ContentPublishing;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.OperationStatus;
|
||||
using Umbraco.Cms.Tests.Integration.Testing;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
||||
|
||||
public partial class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
[Test]
|
||||
public async Task Can_UnSchedule_Unpublish_Invariant()
|
||||
{
|
||||
var doctype = await SetupInvariantDoctypeAsync();
|
||||
var content = await CreateInvariantContentAsync(doctype);
|
||||
|
||||
var scheduleSetupAttempt =
|
||||
await SchedulePublishAndUnPublishInvariantAsync(content);
|
||||
|
||||
if (scheduleSetupAttempt.Success is false)
|
||||
{
|
||||
throw new Exception("Setup failed");
|
||||
}
|
||||
|
||||
var unscheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = Constants.System.InvariantCulture,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(unscheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.IsNull(content!.PublishDate);
|
||||
Assert.IsFalse(schedules.GetSchedule(Constants.System.InvariantCulture, ContentScheduleAction.Expire).Any());
|
||||
Assert.IsTrue(schedules.GetSchedule(Constants.System.InvariantCulture, ContentScheduleAction.Release).Any());
|
||||
Assert.AreEqual(1, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Unschedule_Unpublish_Single_Culture()
|
||||
{
|
||||
var setupInfo = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
setupInfo.LangEn,
|
||||
setupInfo.LangDa,
|
||||
setupInfo.LangBe,
|
||||
setupInfo.contentType);
|
||||
|
||||
var scheduleSetupAttempt =
|
||||
await SchedulePublishAndUnPublishForAllCulturesAsync(content, setupInfo);
|
||||
|
||||
if (scheduleSetupAttempt.Success is false)
|
||||
{
|
||||
throw new Exception("Setup failed");
|
||||
}
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangEn.IsoCode, ContentScheduleAction.Expire).Any());
|
||||
Assert.AreEqual(5, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Unschedule_Unpublish_Some_Cultures()
|
||||
{
|
||||
var setupInfo = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
setupInfo.LangEn,
|
||||
setupInfo.LangDa,
|
||||
setupInfo.LangBe,
|
||||
setupInfo.contentType);
|
||||
|
||||
var scheduleSetupAttempt =
|
||||
await SchedulePublishAndUnPublishForAllCulturesAsync(content, setupInfo);
|
||||
|
||||
if (scheduleSetupAttempt.Success is false)
|
||||
{
|
||||
throw new Exception("Setup failed");
|
||||
}
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate }
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangDa.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate }
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangEn.IsoCode, ContentScheduleAction.Expire).Any());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangDa.IsoCode, ContentScheduleAction.Expire).Any());
|
||||
Assert.AreEqual(4, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Can_Unschedule_Unpublish_All_Cultures()
|
||||
{
|
||||
var setupInfo = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
setupInfo.LangEn,
|
||||
setupInfo.LangDa,
|
||||
setupInfo.LangBe,
|
||||
setupInfo.contentType);
|
||||
|
||||
var scheduleSetupAttempt =
|
||||
await SchedulePublishAndUnPublishForAllCulturesAsync(content, setupInfo);
|
||||
|
||||
if (scheduleSetupAttempt.Success is false)
|
||||
{
|
||||
throw new Exception("Setup failed");
|
||||
}
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangDa.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangBe.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsTrue(scheduleAttempt.Success);
|
||||
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangEn.IsoCode, ContentScheduleAction.Expire).Any());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangDa.IsoCode, ContentScheduleAction.Expire).Any());
|
||||
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangBe.IsoCode, ContentScheduleAction.Expire).Any());
|
||||
Assert.AreEqual(3, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Cannot_Unschedule_Unpublish_Unknown_Culture()
|
||||
{
|
||||
var setupInfo = await SetupVariantDoctypeAsync();
|
||||
var content = await CreateVariantContentAsync(
|
||||
setupInfo.LangEn,
|
||||
setupInfo.LangDa,
|
||||
setupInfo.LangBe,
|
||||
setupInfo.contentType);
|
||||
|
||||
var scheduleSetupAttempt =
|
||||
await SchedulePublishAndUnPublishForAllCulturesAsync(content, setupInfo);
|
||||
|
||||
if (scheduleSetupAttempt.Success is false)
|
||||
{
|
||||
throw new Exception("Setup failed");
|
||||
}
|
||||
|
||||
var scheduleAttempt = await ContentPublishingService.PublishAsync(
|
||||
content.Key,
|
||||
[
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangEn.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = setupInfo.LangDa.IsoCode,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
new()
|
||||
{
|
||||
Culture = UnknownCulture,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
],
|
||||
Constants.Security.SuperUserKey);
|
||||
|
||||
Assert.IsFalse(scheduleAttempt.Success);
|
||||
Assert.AreEqual(ContentPublishingOperationStatus.InvalidCulture, scheduleAttempt.Status);
|
||||
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
|
||||
content = ContentService.GetById(content.Key);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0, content!.PublishedCultures.Count());
|
||||
Assert.AreEqual(6, schedules.FullSchedule.Count);
|
||||
});
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -190,6 +190,24 @@
|
||||
<Compile Update="Umbraco.Infrastructure\PropertyEditors\BlockListElementLevelVariationTests.Validation.cs">
|
||||
<DependentUpon>BlockListElementLevelVariationTests.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Umbraco.Core\Services\ContentPublishingServiceTests.Publish.cs">
|
||||
<DependentUpon>ContentPublishingServiceTests.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Umbraco.Core\Services\ContentPublishingServiceTests.SchedulePublish.cs">
|
||||
<DependentUpon>ContentPublishingServiceTests.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Umbraco.Core\Services\ContentPublishingServiceTests.ScheduleUnpublish.cs">
|
||||
<DependentUpon>ContentPublishingServiceTests.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Umbraco.Core\Services\ContentPublishingServiceTests.UnschedulePublish.cs">
|
||||
<DependentUpon>ContentPublishingServiceTests.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Umbraco.Core\Services\ContentPublishingServiceTests.UnscheduleUnpublish.cs">
|
||||
<DependentUpon>ContentPublishingServiceTests.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Umbraco.Core\Services\ContentPublishingServiceTests.ClearSchedule.cs">
|
||||
<DependentUpon>ContentPublishingServiceTests.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Umbraco.Core\Services\DocumentNavigationServiceTests.Copy.cs">
|
||||
<DependentUpon>DocumentNavigationServiceTests.cs</DependentUpon>
|
||||
</Compile>
|
||||
|
||||
Reference in New Issue
Block a user