Skip to content

Commit 3d1e17b

Browse files
authored
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.
1 parent ae423de commit 3d1e17b

10 files changed

+1517
-1370
lines changed

tests/Umbraco.Tests.Common/Builders/ContentTypeBaseBuilder.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Umbraco.
22
// See LICENSE for more details.
33

4-
using System;
5-
using System.Collections.Generic;
64
using Umbraco.Cms.Core.Models;
75
using Umbraco.Cms.Core.Strings;
86
using Umbraco.Cms.Tests.Common.Builders.Extensions;
@@ -29,7 +27,8 @@ public abstract class ContentTypeBaseBuilder<TParent, TType>
2927
IWithIconBuilder,
3028
IWithThumbnailBuilder,
3129
IWithTrashedBuilder,
32-
IWithIsContainerBuilder
30+
IWithIsContainerBuilder,
31+
IWithAllowAsRootBuilder
3332
where TParent : IBuildContentTypes
3433
{
3534
private string _alias;
@@ -49,6 +48,7 @@ public abstract class ContentTypeBaseBuilder<TParent, TType>
4948
private string _thumbnail;
5049
private bool? _trashed;
5150
private DateTime? _updateDate;
51+
private bool? _allowedAtRoot;
5252

5353
public ContentTypeBaseBuilder(TParent parentBuilder)
5454
: base(parentBuilder)
@@ -168,6 +168,12 @@ string IWithThumbnailBuilder.Thumbnail
168168
set => _updateDate = value;
169169
}
170170

171+
bool? IWithAllowAsRootBuilder.AllowAsRoot
172+
{
173+
get => _allowedAtRoot;
174+
set => _allowedAtRoot = value;
175+
}
176+
171177
protected int GetId() => _id ?? 0;
172178

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

203209
protected Guid? GetListView() => _listView;
204210

211+
protected bool GetAllowedAtRoot() => _allowedAtRoot ?? false;
212+
205213
protected void BuildPropertyGroups(ContentTypeCompositionBase contentType, IEnumerable<PropertyGroup> propertyGroups)
206214
{
207215
foreach (var propertyGroup in propertyGroups)

tests/Umbraco.Tests.Common/Builders/ContentTypeBuilder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Umbraco.
22
// See LICENSE for more details.
33

4-
using System.Collections.Generic;
5-
using System.Linq;
64
using Umbraco.Cms.Core;
75
using Umbraco.Cms.Core.Models;
86
using Umbraco.Cms.Core.Models.ContentEditing;
@@ -125,6 +123,7 @@ public override IContentType Build()
125123
contentType.Trashed = GetTrashed();
126124
contentType.ListView = GetListView();
127125
contentType.IsElement = _isElement ?? false;
126+
contentType.AllowedAsRoot = GetAllowedAtRoot();
128127
contentType.HistoryCleanup = new HistoryCleanup();
129128

130129
contentType.Variations = contentVariation;
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
using NUnit.Framework;
2+
using Umbraco.Cms.Core;
3+
using Umbraco.Cms.Core.Models;
4+
using Umbraco.Cms.Core.Models.ContentPublishing;
5+
using Umbraco.Cms.Core.Services;
6+
using Umbraco.Cms.Tests.Integration.Testing;
7+
8+
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
9+
10+
public partial class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
11+
{
12+
[Test]
13+
public async Task Can_Clear_Schedule_Invariant()
14+
{
15+
var doctype = await SetupInvariantDoctypeAsync();
16+
var content = await CreateInvariantContentAsync(doctype);
17+
18+
var scheduleSetupAttempt =
19+
await SchedulePublishAndUnPublishInvariantAsync(content);
20+
21+
if (scheduleSetupAttempt.Success is false)
22+
{
23+
throw new Exception("Setup failed");
24+
}
25+
26+
var clearScheduleAttempt = await ContentPublishingService.PublishAsync(
27+
content.Key,
28+
[
29+
new()
30+
{
31+
Culture = Constants.System.InvariantCulture,
32+
Schedule = new ContentScheduleModel(),
33+
},
34+
],
35+
Constants.Security.SuperUserKey);
36+
37+
Assert.IsTrue(clearScheduleAttempt.Success);
38+
39+
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
40+
content = ContentService.GetById(content.Key);
41+
42+
Assert.Multiple(() =>
43+
{
44+
Assert.AreEqual(0, content!.PublishedCultures.Count());
45+
Assert.IsNull(content!.PublishDate);
46+
Assert.AreEqual(0, schedules.FullSchedule.Count);
47+
});
48+
}
49+
50+
[Test]
51+
public async Task Can_Clear_Schedule_Single_Culture()
52+
{
53+
var setupInfo = await SetupVariantDoctypeAsync();
54+
var content = await CreateVariantContentAsync(
55+
setupInfo.LangEn,
56+
setupInfo.LangDa,
57+
setupInfo.LangBe,
58+
setupInfo.contentType);
59+
60+
var scheduleSetupAttempt =
61+
await SchedulePublishAndUnPublishForAllCulturesAsync(content, setupInfo);
62+
63+
if (scheduleSetupAttempt.Success is false)
64+
{
65+
throw new Exception("Setup failed");
66+
}
67+
68+
var scheduleAttempt = await ContentPublishingService.PublishAsync(
69+
content.Key,
70+
[
71+
new()
72+
{
73+
Culture = setupInfo.LangEn.IsoCode,
74+
Schedule = new ContentScheduleModel(),
75+
},
76+
],
77+
Constants.Security.SuperUserKey);
78+
79+
Assert.IsTrue(scheduleAttempt.Success);
80+
81+
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
82+
content = ContentService.GetById(content.Key);
83+
84+
Assert.Multiple(() =>
85+
{
86+
Assert.AreEqual(0, content!.PublishedCultures.Count());
87+
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangEn.IsoCode, ContentScheduleAction.Release).Any());
88+
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangEn.IsoCode, ContentScheduleAction.Expire).Any());
89+
Assert.AreEqual(4, schedules.FullSchedule.Count);
90+
});
91+
}
92+
93+
[Test]
94+
public async Task Can_Clear_Schedule_Some_Cultures()
95+
{
96+
var setupInfo = await SetupVariantDoctypeAsync();
97+
var content = await CreateVariantContentAsync(
98+
setupInfo.LangEn,
99+
setupInfo.LangDa,
100+
setupInfo.LangBe,
101+
setupInfo.contentType);
102+
103+
var scheduleSetupAttempt =
104+
await SchedulePublishAndUnPublishForAllCulturesAsync(content, setupInfo);
105+
106+
if (scheduleSetupAttempt.Success is false)
107+
{
108+
throw new Exception("Setup failed");
109+
}
110+
111+
var scheduleAttempt = await ContentPublishingService.PublishAsync(
112+
content.Key,
113+
[
114+
new()
115+
{
116+
Culture = setupInfo.LangEn.IsoCode,
117+
Schedule = new ContentScheduleModel(),
118+
},
119+
new()
120+
{
121+
Culture = setupInfo.LangDa.IsoCode,
122+
Schedule = new ContentScheduleModel(),
123+
},
124+
],
125+
Constants.Security.SuperUserKey);
126+
127+
Assert.IsTrue(scheduleAttempt.Success);
128+
129+
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
130+
content = ContentService.GetById(content.Key);
131+
132+
Assert.Multiple(() =>
133+
{
134+
Assert.AreEqual(0, content!.PublishedCultures.Count());
135+
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangEn.IsoCode, ContentScheduleAction.Release).Any());
136+
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangEn.IsoCode, ContentScheduleAction.Expire).Any());
137+
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangDa.IsoCode, ContentScheduleAction.Release).Any());
138+
Assert.IsFalse(schedules.GetSchedule(setupInfo.LangDa.IsoCode, ContentScheduleAction.Expire).Any());
139+
Assert.AreEqual(2, schedules.FullSchedule.Count);
140+
});
141+
}
142+
143+
[Test]
144+
public async Task Can_Clear_Schedule_All_Cultures()
145+
{
146+
var setupInfo = await SetupVariantDoctypeAsync();
147+
var content = await CreateVariantContentAsync(
148+
setupInfo.LangEn,
149+
setupInfo.LangDa,
150+
setupInfo.LangBe,
151+
setupInfo.contentType);
152+
153+
var scheduleSetupAttempt =
154+
await SchedulePublishAndUnPublishForAllCulturesAsync(content, setupInfo);
155+
156+
if (scheduleSetupAttempt.Success is false)
157+
{
158+
throw new Exception("Setup failed");
159+
}
160+
161+
var scheduleAttempt = await ContentPublishingService.PublishAsync(
162+
content.Key,
163+
[
164+
new()
165+
{
166+
Culture = setupInfo.LangEn.IsoCode,
167+
Schedule = new ContentScheduleModel(),
168+
},
169+
new()
170+
{
171+
Culture = setupInfo.LangDa.IsoCode,
172+
Schedule = new ContentScheduleModel(),
173+
},
174+
new()
175+
{
176+
Culture = setupInfo.LangBe.IsoCode,
177+
Schedule = new ContentScheduleModel(),
178+
},
179+
],
180+
Constants.Security.SuperUserKey);
181+
182+
Assert.IsTrue(scheduleAttempt.Success);
183+
184+
var schedules = ContentService.GetContentScheduleByContentId(content.Id);
185+
content = ContentService.GetById(content.Key);
186+
187+
Assert.Multiple(() =>
188+
{
189+
Assert.AreEqual(0, content!.PublishedCultures.Count());
190+
Assert.AreEqual(0, schedules.FullSchedule.Count);
191+
});
192+
}
193+
}

0 commit comments

Comments
 (0)