|
| 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