Merge branch 'v15/dev' into v16/dev

# Conflicts:
#	src/Umbraco.Cms.Api.Management/Controllers/PublishedCache/RebuildPublishedCacheController.cs
#	src/Umbraco.Core/Configuration/Models/ContentSettings.cs
This commit is contained in:
Niels Lyngsø
2025-03-09 21:28:23 +01:00
251 changed files with 5512 additions and 2742 deletions

View File

@@ -0,0 +1,35 @@
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Services.OperationStatus;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
public class
ContentTypeEditingServiceModelsBuilderDisabledTests : ContentTypeEditingServiceModelsBuilderDisabledTestsBase
{
// test some properties from IPublishedContent
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { nameof(IPublishedContent.Id) })]
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { nameof(IPublishedContent.Name) })]
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { nameof(IPublishedContent.SortOrder) })]
// test some properties from IPublishedElement
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { nameof(IPublishedContent.Properties) })]
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { nameof(IPublishedContent.ContentType) })]
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { nameof(IPublishedContent.Key) })]
// test some methods from IPublishedContent
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { nameof(IPublishedContent.IsDraft) })]
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { nameof(IPublishedContent.IsPublished) })]
public async Task Can_Use_Invalid_ModelsBuilder_PropertyType_Alias_When_ModelsBuilderIsDisabled(
string propertyTypeAlias)
{
var propertyType = ContentTypePropertyTypeModel("Test Property", propertyTypeAlias);
var createModel = ContentTypeCreateModel("Test", propertyTypes: new[] { propertyType });
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
Assert.Multiple(() =>
{
Assert.IsTrue(result.Success);
Assert.AreEqual(ContentTypeOperationStatus.Success, result.Status);
});
}
}

View File

@@ -0,0 +1,11 @@
using Umbraco.Cms.Infrastructure.ModelsBuilder.Options;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
/// <summary>
/// Unlike <see cref="ContentTypeEditingServiceModelsBuilderEnabledTestsBase"/> this testbase does not configure the modelsbuilder based <see cref="ConfigurePropertySettingsOptions"/>
/// which has the same effect as disabling it completely as <see cref="ContentTypeEditingServiceModelsBuilderEnabledTestsBase"/> only loads in that part anyway.
/// </summary>
public class ContentTypeEditingServiceModelsBuilderDisabledTestsBase : ContentTypeEditingServiceTestsBase
{
}

View File

@@ -0,0 +1,34 @@
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Services.OperationStatus;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
public class ContentTypeEditingServiceModelsBuilderEnabledTests : ContentTypeEditingServiceModelsBuilderEnabledTestsBase
{
// test some properties from IPublishedContent
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { nameof(IPublishedContent.Id) })]
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { nameof(IPublishedContent.Name) })]
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { nameof(IPublishedContent.SortOrder) })]
// test some properties from IPublishedElement
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { nameof(IPublishedContent.Properties) })]
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { nameof(IPublishedContent.ContentType) })]
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { nameof(IPublishedContent.Key) })]
// test some methods from IPublishedContent
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { nameof(IPublishedContent.IsDraft) })]
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { nameof(IPublishedContent.IsPublished) })]
public async Task Cannot_Use_Invalid_ModelsBuilder_PropertyType_Alias_When_ModelsBuilderIsEnabled(
string propertyTypeAlias)
{
var propertyType = ContentTypePropertyTypeModel("Test Property", propertyTypeAlias);
var createModel = ContentTypeCreateModel("Test", propertyTypes: new[] { propertyType });
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
Assert.Multiple(() =>
{
Assert.IsFalse(result.Success);
Assert.AreEqual(ContentTypeOperationStatus.InvalidPropertyTypeAlias, result.Status);
});
}
}

View File

@@ -0,0 +1,15 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Infrastructure.ModelsBuilder.Options;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
public class ContentTypeEditingServiceModelsBuilderEnabledTestsBase : ContentTypeEditingServiceTestsBase
{
protected override void CustomTestSetup(IUmbracoBuilder builder)
{
builder.Services.ConfigureOptions<ConfigurePropertySettingsOptions>();
}
}

View File

@@ -708,17 +708,6 @@ public partial class ContentTypeEditingServiceTests
Assert.AreEqual(ContentTypeOperationStatus.InvalidParent, result.Status);
}
// test some properties from IPublishedContent
[TestCase(nameof(IPublishedContent.Id))]
[TestCase(nameof(IPublishedContent.Name))]
[TestCase(nameof(IPublishedContent.SortOrder))]
// test some properties from IPublishedElement
[TestCase(nameof(IPublishedElement.Properties))]
[TestCase(nameof(IPublishedElement.ContentType))]
[TestCase(nameof(IPublishedElement.Key))]
// test some methods from IPublishedContent
[TestCase(nameof(IPublishedContent.IsDraft))]
[TestCase(nameof(IPublishedContent.IsPublished))]
[TestCase("")]
[TestCase(" ")]
[TestCase(" ")]
@@ -727,21 +716,12 @@ public partial class ContentTypeEditingServiceTests
[TestCase("!\"#¤%&/()=)?`")]
public async Task Cannot_Use_Invalid_PropertyType_Alias(string propertyTypeAlias)
{
// ensure that property casing is ignored when handling reserved property aliases
var propertyTypeAliases = new[]
{
propertyTypeAlias, propertyTypeAlias.ToLowerInvariant(), propertyTypeAlias.ToUpperInvariant()
};
var propertyType = ContentTypePropertyTypeModel("Test Property", propertyTypeAlias);
var createModel = ContentTypeCreateModel("Test", propertyTypes: new[] { propertyType });
foreach (var alias in propertyTypeAliases)
{
var propertyType = ContentTypePropertyTypeModel("Test Property", alias);
var createModel = ContentTypeCreateModel("Test", propertyTypes: new[] { propertyType });
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
Assert.IsFalse(result.Success);
Assert.AreEqual(ContentTypeOperationStatus.InvalidPropertyTypeAlias, result.Status);
}
var result = await ContentTypeEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey);
Assert.IsFalse(result.Success);
Assert.AreEqual(ContentTypeOperationStatus.InvalidPropertyTypeAlias, result.Status);
}
[TestCase("testProperty", "testProperty")]
@@ -816,9 +796,7 @@ public partial class ContentTypeEditingServiceTests
[TestCase(".")]
[TestCase("-")]
[TestCase("!\"#¤%&/()=)?`")]
[TestCase("system")]
[TestCase("System")]
[TestCase("SYSTEM")]
[TestCaseSource(nameof(DifferentCapitalizedAlias), new object[] { "System"})]
public async Task Cannot_Use_Invalid_Alias(string contentTypeAlias)
{
var createModel = ContentTypeCreateModel("Test", contentTypeAlias);
@@ -1095,4 +1073,32 @@ public partial class ContentTypeEditingServiceTests
Assert.IsFalse(result.Success);
Assert.AreEqual(ContentTypeOperationStatus.InvalidContainerType, result.Status);
}
[TestCase(false, true)]
[TestCase(true, false)]
public async Task Cannot_Have_Element_Type_Mismatched_Inheritance(bool parentIsElement, bool childIsElement)
{
var parentModel = ContentTypeCreateModel("Parent1", isElement: parentIsElement);
var parentKey = (await ContentTypeEditingService.CreateAsync(parentModel, Constants.Security.SuperUserKey)).Result?.Key;
Assert.IsTrue(parentKey.HasValue);
Composition[] composition =
{
new()
{
CompositionType = CompositionType.Inheritance, Key = parentKey.Value,
}
};
var childModel = ContentTypeCreateModel(
"Child",
compositions: composition,
isElement: childIsElement);
var result = await ContentTypeEditingService.CreateAsync(childModel, Constants.Security.SuperUserKey);
Assert.IsFalse(result.Success);
Assert.AreEqual(ContentTypeOperationStatus.InvalidElementFlagComparedToParent, result.Status);
}
}

View File

@@ -180,4 +180,11 @@ public abstract class ContentTypeEditingServiceTestsBase : UmbracoIntegrationTes
Type = type,
Key = key ?? Guid.NewGuid(),
};
protected static IEnumerable<string> DifferentCapitalizedAlias(string baseAlias)
{
yield return baseAlias;
yield return baseAlias.ToLowerInvariant();
yield return baseAlias.ToUpperInvariant();
}
}