Added integration tests for publishing service with invalid content (#19095)

* Added integration tests for publishing service with invalid content.

* Amend test to new create/update models

---------

Co-authored-by: Kenn Jacobsen <kja@umbraco.dk>
This commit is contained in:
Andy Butland
2025-04-23 17:09:39 +02:00
committed by GitHub
parent 9246ecbb08
commit 024a450377
2 changed files with 117 additions and 15 deletions

View File

@@ -13,15 +13,15 @@ public partial class ContentPublishingServiceTests : UmbracoIntegrationTestWithC
public async Task Can_Publish_Single_Culture()
{
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
var setupData = await CreateVariantContentAsync(langEn, langDa, langBe, contentType);
var content = await CreateVariantContentAsync(langEn, langDa, langBe, contentType);
var publishAttempt = await ContentPublishingService.PublishAsync(
setupData.Key,
content.Key,
[new() { Culture = langEn.IsoCode }],
Constants.Security.SuperUserKey);
Assert.IsTrue(publishAttempt.Success);
var content = ContentService.GetById(setupData.Key);
content = ContentService.GetById(content.Key);
Assert.AreEqual(1, content!.PublishedCultures.Count());
}
@@ -34,7 +34,8 @@ public partial class ContentPublishingServiceTests : UmbracoIntegrationTestWithC
var publishAttempt = await ContentPublishingService.PublishAsync(
content.Key,
[
new() { Culture = langEn.IsoCode }, new() { Culture = langDa.IsoCode },
new() { Culture = langEn.IsoCode },
new() { Culture = langDa.IsoCode },
],
Constants.Security.SuperUserKey);
@@ -102,6 +103,75 @@ public partial class ContentPublishingServiceTests : UmbracoIntegrationTestWithC
Assert.NotNull(content!.PublishDate);
}
[Test]
public async Task Cannot_Publish_Invalid_Content_In_Invariant_Setup()
{
var doctype = await SetupInvariantDoctypeAsync();
var content = await CreateInvariantContentAsync(doctype, titleValue: null);
var publishAttempt = await ContentPublishingService.PublishAsync(
content.Key,
[new() { Culture = Constants.System.InvariantCulture }],
Constants.Security.SuperUserKey);
Assert.IsFalse(publishAttempt.Success);
Assert.AreEqual(ContentPublishingOperationStatus.ContentInvalid, publishAttempt.Status);
content = ContentService.GetById(content.Key);
Assert.Null(content!.PublishDate);
}
[Test]
public async Task Cannot_Publish_Invalid_Content_In_Variant_Setup()
{
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
var content = await CreateVariantContentAsync(
langEn,
langDa,
langBe,
contentType,
englishTitleValue: null); // English is invalid, Danish is valid.
var publishAttempt = await ContentPublishingService.PublishAsync(
content.Key,
[
new() { Culture = langEn.IsoCode },
new() { Culture = langDa.IsoCode },
],
Constants.Security.SuperUserKey);
Assert.IsFalse(publishAttempt.Success);
Assert.AreEqual(ContentPublishingOperationStatus.ContentInvalid, publishAttempt.Status);
Assert.AreEqual("title", string.Join(",", publishAttempt.Result.InvalidPropertyAliases));
content = ContentService.GetById(content.Key);
Assert.AreEqual(0, content!.PublishedCultures.Count()); // Even though the Danish culture was valid, we still don't publish if if any are invalid.
}
[Test]
public async Task Can_Publish_Valid_Content_In_One_Culture_When_Another_Is_Invalid_In_Variant_Setup()
{
var (langEn, langDa, langBe, contentType) = await SetupVariantDoctypeAsync();
var content = await CreateVariantContentAsync(
langEn,
langDa,
langBe,
contentType,
englishTitleValue: null); // English is invalid, Danish is valid.
var publishAttempt = await ContentPublishingService.PublishAsync(
content.Key,
[
new() { Culture = langDa.IsoCode },
],
Constants.Security.SuperUserKey);
Assert.IsTrue(publishAttempt.Success);
content = ContentService.GetById(content.Key);
Assert.AreEqual(1, content!.PublishedCultures.Count());
Assert.AreEqual(langDa.IsoCode, content!.PublishedCultures.First());
}
[Test]
public async Task Cannot_Publish_Unknown_Culture()
{

View File

@@ -63,6 +63,12 @@ public partial class ContentPublishingServiceTests : UmbracoIntegrationTestWithC
.WithName("Content")
.WithSupportsPublishing(true)
.Done()
.AddPropertyType()
.WithAlias("title")
.WithName("Title")
.WithMandatory(true)
.WithVariations(ContentVariation.Culture)
.Done()
.Build();
contentType.AllowedAsRoot = true;
@@ -82,7 +88,13 @@ public partial class ContentPublishingServiceTests : UmbracoIntegrationTestWithC
return (langEn, langDa, langBe, contentType);
}
private async Task<IContent> CreateVariantContentAsync(ILanguage langEn, ILanguage langDa, ILanguage langBe, IContentType contentType, Guid? parentKey = null)
private async Task<IContent> CreateVariantContentAsync(
ILanguage langEn,
ILanguage langDa,
ILanguage langBe,
IContentType contentType,
Guid? parentKey = null,
string? englishTitleValue = "Test title")
{
var documentKey = Guid.NewGuid();
@@ -91,24 +103,31 @@ public partial class ContentPublishingServiceTests : UmbracoIntegrationTestWithC
Key = documentKey,
ContentTypeKey = contentType.Key,
ParentKey = parentKey,
Properties = [],
Variants =
[
new VariantModel
Properties = [
new PropertyValueModel
{
Name = langEn.CultureName,
Alias = "title",
Value = englishTitleValue,
Culture = langEn.IsoCode
},
new VariantModel
new PropertyValueModel
{
Name = langDa.CultureName,
Alias = "title",
Value = "Test titel",
Culture = langDa.IsoCode
},
new VariantModel
new PropertyValueModel
{
Name = langBe.CultureName,
Alias = "title",
Value = "Titel van de test",
Culture = langBe.IsoCode
}
],
Variants =
[
new VariantModel { Name = langEn.CultureName, Culture = langEn.IsoCode },
new VariantModel { Name = langDa.CultureName, Culture = langDa.IsoCode },
new VariantModel { Name = langBe.CultureName, Culture = langBe.IsoCode }
]
};
@@ -135,6 +154,11 @@ public partial class ContentPublishingServiceTests : UmbracoIntegrationTestWithC
.WithName("Content")
.WithSupportsPublishing(true)
.Done()
.AddPropertyType()
.WithAlias("title")
.WithName("Title")
.WithMandatory(true)
.Done()
.Build();
var createAttempt = await ContentTypeService.CreateAsync(contentType, Constants.Security.SuperUserKey);
@@ -153,7 +177,7 @@ public partial class ContentPublishingServiceTests : UmbracoIntegrationTestWithC
return contentType;
}
private async Task<IContent> CreateInvariantContentAsync(IContentType contentType, Guid? parentKey = null)
private async Task<IContent> CreateInvariantContentAsync(IContentType contentType, Guid? parentKey = null, string? titleValue = "Test title")
{
var documentKey = Guid.NewGuid();
@@ -163,6 +187,14 @@ public partial class ContentPublishingServiceTests : UmbracoIntegrationTestWithC
ContentTypeKey = contentType.Key,
Variants = [new () { Name = "Test" }],
ParentKey = parentKey,
Properties =
[
new PropertyValueModel
{
Alias = "title",
Value = titleValue,
}
],
};
var createAttempt = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);