From 8112e1a9af7b0e4fb05c7e231d11401a75a075ec Mon Sep 17 00:00:00 2001 From: nikolajlauridsen Date: Fri, 8 Oct 2021 13:08:32 +0200 Subject: [PATCH] Add intergration test --- .../Controllers/ContentControllerTests.cs | 85 +++++++++++++++++-- 1 file changed, 77 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs index 59c9b04dd0..aac0f6b416 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs @@ -408,7 +408,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Web.BackOffice.Controllers } [Test] - public async Task PostSave_Validates_Domains() + public async Task PostSave_Validates_Domains_Exist() { ILocalizationService localizationService = GetRequiredService(); localizationService.Save(new LanguageBuilder() @@ -417,32 +417,101 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Web.BackOffice.Controllers .Build()); IContentTypeService contentTypeService = GetRequiredService(); - var contentType = new ContentTypeBuilder().WithContentVariation(ContentVariation.Culture).Build(); + IContentType contentType = new ContentTypeBuilder().WithContentVariation(ContentVariation.Culture).Build(); contentTypeService.Save(contentType); - var content = new ContentBuilder() + Content content = new ContentBuilder() .WithId(1) .WithContentType(contentType) .WithCultureName("en-US", "Root") .WithCultureName("da-DK", "Rod") .Build(); - var model = new ContentItemSaveBuilder() + ContentItemSave model = new ContentItemSaveBuilder() .WithContent(content) .WithAction(ContentSaveAction.PublishNew) .Build(); - string url = PrepareApiControllerUrl(x => x.PostSave(null)); + var url = PrepareApiControllerUrl(x => x.PostSave(null)); HttpResponseMessage response = await Client.PostAsync(url, new MultipartFormDataContent { { new StringContent(JsonConvert.SerializeObject(model)), "contentItem" } }); - string body = await response.Content.ReadAsStringAsync(); + var body = await response.Content.ReadAsStringAsync(); body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix); ContentItemDisplay display = JsonConvert.DeserializeObject(body); - Assert.IsNotNull(display); - Assert.AreEqual(1, display.Notifications.Count(x => x.NotificationType == NotificationStyle.Warning)); + + ILocalizedTextService localizedTextService = GetRequiredService(); + var expectedMessage = localizedTextService.Localize("speechBubbles", "publishWithNoDomains"); + + Assert.Multiple(() => + { + Assert.IsNotNull(display); + Assert.AreEqual(1, display.Notifications.Count(x => x.NotificationType == NotificationStyle.Warning)); + Assert.AreEqual(expectedMessage, display.Notifications.First().Message); + }); + } + + [Test] + public async Task PostSave_Validates_All_Cultures_Has_Domains() + { + var enString = "en-US"; + var dkString = "da-DK"; + + ILocalizationService localizationService = GetRequiredService(); + localizationService.Save(new LanguageBuilder() + .WithCultureInfo(dkString) + .WithIsDefault(false) + .Build()); + + IContentTypeService contentTypeService = GetRequiredService(); + IContentType contentType = new ContentTypeBuilder().WithContentVariation(ContentVariation.Culture).Build(); + contentTypeService.Save(contentType); + + Content content = new ContentBuilder() + .WithoutIdentity() + .WithContentType(contentType) + .WithCultureName(enString, "Root") + .WithCultureName(dkString, "Rod") + .Build(); + + IContentService contentService = GetRequiredService(); + contentService.Save(content); + + ContentItemSave model = new ContentItemSaveBuilder() + .WithContent(content) + .WithAction(ContentSaveAction.Publish) + .Build(); + + ILanguage dkLanguage = localizationService.GetLanguageByIsoCode(dkString); + IDomainService domainService = GetRequiredService(); + var dkDomain = new UmbracoDomain("/") + { + RootContentId = content.Id, + LanguageId = dkLanguage.Id + }; + domainService.Save(dkDomain); + + var url = PrepareApiControllerUrl(x => x.PostSave(null)); + + HttpResponseMessage response = await Client.PostAsync(url, new MultipartFormDataContent + { + { new StringContent(JsonConvert.SerializeObject(model)), "contentItem" } + }); + + var body = await response.Content.ReadAsStringAsync(); + body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix); + ContentItemDisplay display = JsonConvert.DeserializeObject(body); + + ILocalizedTextService localizedTextService = GetRequiredService(); + var expectedMessage = localizedTextService.Localize("speechBubbles", "publishWithMissingDomain", new []{enString}); + Assert.Multiple(() => + { + Assert.NotNull(display); + Assert.AreEqual(1, display.Notifications.Count(x => x.NotificationType == NotificationStyle.Warning)); + Assert.AreEqual(expectedMessage, display.Notifications.FirstOrDefault(x => x.NotificationType == NotificationStyle.Warning)?.Message); + }); } } }