Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions tests/Umbraco.Tests.Common/Builders/ContentTypeBaseBuilder.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -29,7 +27,8 @@ public abstract class ContentTypeBaseBuilder<TParent, TType>
IWithIconBuilder,
IWithThumbnailBuilder,
IWithTrashedBuilder,
IWithIsContainerBuilder
IWithIsContainerBuilder,
IWithAllowAsRootBuilder
where TParent : IBuildContentTypes
{
private string _alias;
Expand All @@ -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)
Expand Down Expand Up @@ -168,6 +168,12 @@ string IWithThumbnailBuilder.Thumbnail
set => _updateDate = value;
}

bool? IWithAllowAsRootBuilder.AllowAsRoot
{
get => _allowedAtRoot;
set => _allowedAtRoot = value;
}

protected int GetId() => _id ?? 0;

protected Guid GetKey() => _key ?? Guid.NewGuid();
Expand Down Expand Up @@ -202,6 +208,8 @@ string IWithThumbnailBuilder.Thumbnail

protected Guid? GetListView() => _listView;

protected bool GetAllowedAtRoot() => _allowedAtRoot ?? false;

protected void BuildPropertyGroups(ContentTypeCompositionBase contentType, IEnumerable<PropertyGroup> propertyGroups)
{
foreach (var propertyGroup in propertyGroups)
Expand Down
3 changes: 1 addition & 2 deletions tests/Umbraco.Tests.Common/Builders/ContentTypeBuilder.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -125,6 +123,7 @@ public override IContentType Build()
contentType.Trashed = GetTrashed();
contentType.ListView = GetListView();
contentType.IsElement = _isElement ?? false;
contentType.AllowedAsRoot = GetAllowedAtRoot();
contentType.HistoryCleanup = new HistoryCleanup();

contentType.Variations = contentVariation;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
}
}
Loading