Merge branch 'v15/dev' into contrib
This commit is contained in:
169
tests/Umbraco.Tests.Common/Builders/ContentEditingBuilder.cs
Normal file
169
tests/Umbraco.Tests.Common/Builders/ContentEditingBuilder.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using Umbraco.Cms.Core.Models.ContentEditing;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Interfaces.ContentCreateModel;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Common.Builders;
|
||||
|
||||
public class ContentEditingBuilder
|
||||
: BuilderBase<ContentCreateModel>,
|
||||
IWithInvariantNameBuilder,
|
||||
IWithInvariantPropertiesBuilder,
|
||||
IWithVariantsBuilder,
|
||||
IWithKeyBuilder,
|
||||
IWithContentTypeKeyBuilder,
|
||||
IWithParentKeyBuilder,
|
||||
IWithTemplateKeyBuilder,
|
||||
IBuildContentTypes
|
||||
{
|
||||
private ContentTypeEditingBuilder _contentTypeEditingBuilder;
|
||||
private IEnumerable<PropertyValueModel> _invariantProperties = [];
|
||||
private IEnumerable<VariantModel> _variants = [];
|
||||
private Guid _contentTypeKey;
|
||||
private Guid? _parentKey;
|
||||
private Guid? _templateKey;
|
||||
private Guid? _key;
|
||||
private string _invariantName;
|
||||
|
||||
Guid? IWithKeyBuilder.Key
|
||||
{
|
||||
get => _key;
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
string IWithInvariantNameBuilder.InvariantName
|
||||
{
|
||||
get => _invariantName;
|
||||
set => _invariantName = value;
|
||||
}
|
||||
|
||||
IEnumerable<PropertyValueModel> IWithInvariantPropertiesBuilder.InvariantProperties
|
||||
{
|
||||
get => _invariantProperties;
|
||||
set => _invariantProperties = value;
|
||||
}
|
||||
|
||||
IEnumerable<VariantModel> IWithVariantsBuilder.Variants
|
||||
{
|
||||
get => _variants;
|
||||
set => _variants = value;
|
||||
}
|
||||
|
||||
Guid? IWithParentKeyBuilder.ParentKey
|
||||
{
|
||||
get => _parentKey;
|
||||
set => _parentKey = value;
|
||||
}
|
||||
|
||||
Guid IWithContentTypeKeyBuilder.ContentTypeKey
|
||||
{
|
||||
get => _contentTypeKey;
|
||||
set => _contentTypeKey = value;
|
||||
}
|
||||
|
||||
Guid? IWithTemplateKeyBuilder.TemplateKey
|
||||
{
|
||||
get => _templateKey;
|
||||
set => _templateKey = value;
|
||||
}
|
||||
|
||||
public ContentEditingBuilder WithInvariantName(string invariantName)
|
||||
{
|
||||
_invariantName = invariantName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContentEditingBuilder WithInvariantProperty(string alias, object value)
|
||||
{
|
||||
var property = new PropertyValueModel { Alias = alias, Value = value };
|
||||
_invariantProperties = _invariantProperties.Concat(new[] { property });
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContentEditingBuilder AddVariant(string culture, string segment, string name, IEnumerable<PropertyValueModel> properties)
|
||||
{
|
||||
var variant = new VariantModel { Culture = culture, Segment = segment, Name = name, Properties = properties };
|
||||
_variants = _variants.Concat(new[] { variant });
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContentEditingBuilder WithParentKey(Guid parentKey)
|
||||
{
|
||||
_parentKey = parentKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContentEditingBuilder WithTemplateKey(Guid templateKey)
|
||||
{
|
||||
_templateKey = templateKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override ContentCreateModel Build()
|
||||
{
|
||||
var key = _key ?? Guid.NewGuid();
|
||||
var parentKey = _parentKey;
|
||||
var templateKey = _templateKey;
|
||||
var invariantName = _invariantName ?? Guid.NewGuid().ToString();
|
||||
var invariantProperties = _invariantProperties;
|
||||
var variants = _variants;
|
||||
|
||||
var content = new ContentCreateModel();
|
||||
content.InvariantName = invariantName;
|
||||
if (parentKey is not null)
|
||||
{
|
||||
content.ParentKey = parentKey;
|
||||
}
|
||||
|
||||
if (templateKey is not null)
|
||||
{
|
||||
content.TemplateKey = templateKey;
|
||||
}
|
||||
|
||||
content.ContentTypeKey = _contentTypeKey;
|
||||
content.Key = key;
|
||||
content.InvariantProperties = invariantProperties;
|
||||
content.Variants = variants;
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
public static ContentCreateModel CreateBasicContent(Guid contentTypeKey, Guid? key) =>
|
||||
new ContentEditingBuilder()
|
||||
.WithKey(key)
|
||||
.WithContentTypeKey(contentTypeKey)
|
||||
.WithInvariantName("Home")
|
||||
.Build();
|
||||
|
||||
public static ContentCreateModel CreateSimpleContent(Guid contentTypeKey) =>
|
||||
new ContentEditingBuilder()
|
||||
.WithContentTypeKey(contentTypeKey)
|
||||
.WithInvariantName("Home")
|
||||
.WithInvariantProperty("title", "Welcome to our Home page")
|
||||
.Build();
|
||||
|
||||
public static ContentCreateModel CreateSimpleContent(Guid contentTypeKey, string name, Guid? parentKey) =>
|
||||
new ContentEditingBuilder()
|
||||
.WithContentTypeKey(contentTypeKey)
|
||||
.WithInvariantName(name)
|
||||
.WithParentKey(parentKey)
|
||||
.WithInvariantProperty("title", "Welcome to our Home page")
|
||||
.Build();
|
||||
|
||||
public static ContentCreateModel CreateSimpleContent(Guid contentTypeKey, string name) =>
|
||||
new ContentEditingBuilder()
|
||||
.WithContentTypeKey(contentTypeKey)
|
||||
.WithInvariantName(name)
|
||||
.WithInvariantProperty("title", "Welcome to our Home page")
|
||||
.Build();
|
||||
|
||||
public static ContentCreateModel CreateContentWithTwoVariantProperties(Guid contentTypeKey, string firstCulture, string secondCulture, string propertyAlias, string propertyName) =>
|
||||
new ContentEditingBuilder()
|
||||
.WithContentTypeKey(contentTypeKey)
|
||||
.AddVariant(firstCulture, null, firstCulture, new[] { new PropertyValueModel { Alias = propertyAlias, Value = propertyName } })
|
||||
.AddVariant(secondCulture, null, secondCulture, new[] { new PropertyValueModel { Alias = propertyAlias, Value = propertyName } })
|
||||
.Build();
|
||||
}
|
||||
240
tests/Umbraco.Tests.Common/Builders/ContentTypeEditingBuilder.cs
Normal file
240
tests/Umbraco.Tests.Common/Builders/ContentTypeEditingBuilder.cs
Normal file
@@ -0,0 +1,240 @@
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.ContentTypeEditing;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Common.Builders;
|
||||
|
||||
public class ContentTypeEditingBuilder
|
||||
: ContentTypeBaseBuilder<ContentEditingBuilder, ContentTypeCreateModel>,
|
||||
IBuildPropertyTypes
|
||||
{
|
||||
private Guid? _key;
|
||||
private Guid? _containerKey;
|
||||
private ContentTypeCleanup _cleanup = new();
|
||||
private IEnumerable<Guid> _allowedTemplateKeys;
|
||||
private Guid? _defaultTemplateKey;
|
||||
private bool? _allowAtRoot;
|
||||
private bool? _isElement;
|
||||
private bool? _variesByCulture;
|
||||
private bool? _variesBySegment;
|
||||
private readonly List<PropertyTypeEditingBuilder> _propertyTypeBuilders = [];
|
||||
private readonly List<PropertyTypeContainerBuilder<ContentTypeEditingBuilder>> _propertyTypeContainerBuilders = [];
|
||||
private readonly List<ContentTypeSortBuilder> _allowedContentTypeBuilders = [];
|
||||
|
||||
public ContentTypeEditingBuilder()
|
||||
: base(null)
|
||||
{
|
||||
}
|
||||
|
||||
public ContentTypeEditingBuilder(ContentEditingBuilder parentBuilder)
|
||||
: base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
public ContentTypeEditingBuilder WithDefaultTemplateKey(Guid templateKey)
|
||||
{
|
||||
_defaultTemplateKey = templateKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContentTypeEditingBuilder WithIsElement(bool isElement)
|
||||
{
|
||||
_isElement = isElement;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyTypeContainerBuilder<ContentTypeEditingBuilder> AddPropertyGroup()
|
||||
{
|
||||
var builder = new PropertyTypeContainerBuilder<ContentTypeEditingBuilder>(this);
|
||||
_propertyTypeContainerBuilders.Add(builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public PropertyTypeEditingBuilder AddPropertyType()
|
||||
{
|
||||
var builder = new PropertyTypeEditingBuilder(this);
|
||||
_propertyTypeBuilders.Add(builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
public ContentTypeSortBuilder AddAllowedContentType()
|
||||
{
|
||||
var builder = new ContentTypeSortBuilder(this);
|
||||
_allowedContentTypeBuilders.Add(builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public ContentTypeEditingBuilder AddAllowedTemplateKeys(IEnumerable<Guid> templateKeys)
|
||||
{
|
||||
_allowedTemplateKeys = templateKeys;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContentTypeEditingBuilder WithAllowAtRoot(bool allowAtRoot)
|
||||
{
|
||||
_allowAtRoot = allowAtRoot;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContentTypeEditingBuilder WithVariesByCulture(bool variesByCulture)
|
||||
{
|
||||
_variesByCulture = variesByCulture;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContentTypeEditingBuilder WithVariesBySegment(bool variesBySegment)
|
||||
{
|
||||
_variesBySegment = variesBySegment;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override ContentTypeCreateModel Build()
|
||||
{
|
||||
ContentTypeCreateModel contentType = new ContentTypeCreateModel();
|
||||
contentType.Name = GetName();
|
||||
contentType.Alias = GetAlias();
|
||||
contentType.Key = GetKey();
|
||||
contentType.ContainerKey = _containerKey;
|
||||
contentType.Cleanup = _cleanup;
|
||||
contentType.AllowedTemplateKeys = _allowedTemplateKeys ?? Array.Empty<Guid>();
|
||||
contentType.DefaultTemplateKey = _defaultTemplateKey;
|
||||
contentType.IsElement = _isElement ?? false;
|
||||
contentType.VariesByCulture = _variesByCulture ?? false;
|
||||
contentType.VariesBySegment = _variesBySegment ?? false;
|
||||
contentType.AllowedAsRoot = _allowAtRoot ?? false;
|
||||
contentType.Properties = _propertyTypeBuilders.Select(x => x.Build());
|
||||
contentType.Containers = _propertyTypeContainerBuilders.Select(x => x.Build());
|
||||
contentType.AllowedContentTypes = _allowedContentTypeBuilders.Select(x => x.Build());
|
||||
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public static ContentTypeCreateModel CreateBasicContentType(string alias = "umbTextpage", string name = "TextPage", IContentType parent = null)
|
||||
{
|
||||
var builder = new ContentTypeEditingBuilder();
|
||||
return (ContentTypeCreateModel)builder
|
||||
.WithAlias(alias)
|
||||
.WithName(name)
|
||||
.WithParentContentType(parent)
|
||||
.Build();
|
||||
}
|
||||
|
||||
public static ContentTypeCreateModel CreateSimpleContentType(string alias = "umbTextpage", string name = "TextPage", IContentType parent = null, string propertyGroupName = "Content", Guid? defaultTemplateKey = null)
|
||||
{
|
||||
var containerKey = Guid.NewGuid();
|
||||
var builder = new ContentTypeEditingBuilder();
|
||||
return (ContentTypeCreateModel)builder
|
||||
.WithAlias(alias)
|
||||
.WithName(name)
|
||||
.WithAllowAtRoot(true)
|
||||
.WithParentContentType(parent)
|
||||
.AddPropertyGroup()
|
||||
.WithKey(containerKey)
|
||||
.WithName(propertyGroupName)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithAlias("title")
|
||||
.WithDataTypeKey(Constants.DataTypes.Guids.TextareaGuid)
|
||||
.WithName("Title")
|
||||
.WithContainerKey(containerKey)
|
||||
.Done()
|
||||
.WithDefaultTemplateKey(defaultTemplateKey ?? Guid.Empty)
|
||||
.AddAllowedTemplateKeys([defaultTemplateKey ?? Guid.Empty])
|
||||
.Build();
|
||||
}
|
||||
|
||||
public static ContentTypeCreateModel CreateTextPageContentType(string alias = "textPage", string name = "Text Page", Guid defaultTemplateKey = default)
|
||||
{
|
||||
var containerKeyOne = Guid.NewGuid();
|
||||
var containerKeyTwo = Guid.NewGuid();
|
||||
|
||||
var builder = new ContentTypeEditingBuilder();
|
||||
return (ContentTypeCreateModel)builder
|
||||
.WithAlias(alias)
|
||||
.WithName(name)
|
||||
.WithAllowAtRoot(true)
|
||||
.AddPropertyGroup()
|
||||
.WithName("Content")
|
||||
.WithKey(containerKeyOne)
|
||||
.WithSortOrder(1)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithAlias("title")
|
||||
.WithName("Title")
|
||||
.WithContainerKey(containerKeyOne)
|
||||
.WithSortOrder(1)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithDataTypeKey(Constants.DataTypes.Guids.RichtextEditorGuid)
|
||||
.WithAlias("bodyText")
|
||||
.WithName("Body text")
|
||||
.WithContainerKey(containerKeyOne)
|
||||
.WithSortOrder(2)
|
||||
.Done()
|
||||
.AddPropertyGroup()
|
||||
.WithName("Meta")
|
||||
.WithSortOrder(2)
|
||||
.WithKey(containerKeyTwo)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithAlias("keywords")
|
||||
.WithName("Keywords")
|
||||
.WithContainerKey(containerKeyTwo)
|
||||
.WithSortOrder(1)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithAlias("description")
|
||||
.WithName("Description")
|
||||
.WithContainerKey(containerKeyTwo)
|
||||
.WithSortOrder(2)
|
||||
.Done()
|
||||
.AddAllowedTemplateKeys([defaultTemplateKey])
|
||||
.WithDefaultTemplateKey(defaultTemplateKey)
|
||||
.Build();
|
||||
}
|
||||
|
||||
public static ContentTypeCreateModel CreateElementType(string alias = "textElement", string name = "Text Element")
|
||||
{
|
||||
var containerKey = Guid.NewGuid();
|
||||
var builder = new ContentTypeEditingBuilder();
|
||||
return (ContentTypeCreateModel)builder
|
||||
.WithAlias(alias)
|
||||
.WithName(name)
|
||||
.WithIsElement(true)
|
||||
.AddPropertyGroup()
|
||||
.WithName("Content")
|
||||
.WithKey(containerKey)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithDataTypeKey(Constants.DataTypes.Guids.RichtextEditorGuid)
|
||||
.WithAlias("bodyText")
|
||||
.WithName("Body text")
|
||||
.WithContainerKey(containerKey)
|
||||
.Done()
|
||||
.Build();
|
||||
}
|
||||
|
||||
public static ContentTypeCreateModel CreateContentTypeWithDataTypeKey(Guid dataTypeKey, string alias = "textElement", string name = "Text Element" )
|
||||
{
|
||||
var containerKey = Guid.NewGuid();
|
||||
var builder = new ContentTypeEditingBuilder();
|
||||
return (ContentTypeCreateModel)builder
|
||||
.WithAlias(alias)
|
||||
.WithName(name)
|
||||
.WithIsElement(true)
|
||||
.AddPropertyGroup()
|
||||
.WithName("Content")
|
||||
.WithKey(containerKey)
|
||||
.Done()
|
||||
.AddPropertyType()
|
||||
.WithDataTypeKey(dataTypeKey)
|
||||
.WithAlias("dataType")
|
||||
.WithName("Data Type")
|
||||
.WithContainerKey(containerKey)
|
||||
.Done()
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,11 @@ public class ContentTypeSortBuilder
|
||||
{
|
||||
}
|
||||
|
||||
public ContentTypeSortBuilder(ContentTypeEditingBuilder parentBuilder)
|
||||
: base(null)
|
||||
{
|
||||
}
|
||||
|
||||
string IWithAliasBuilder.Alias
|
||||
{
|
||||
get => _alias;
|
||||
|
||||
@@ -80,6 +80,13 @@ public static class BuilderExtensions
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithDataTypeKey<T>(this T builder, Guid key)
|
||||
where T : IWithDataTypeKeyBuilder
|
||||
{
|
||||
builder.DataTypeKey = key;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithParentId<T>(this T builder, int parentId)
|
||||
where T : IWithParentIdBuilder
|
||||
{
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
using Umbraco.Cms.Core.Models.ContentEditing;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Interfaces.ContentCreateModel;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Extensions;
|
||||
|
||||
public static class ContentEditingBuilderExtensions
|
||||
{
|
||||
public static T WithInvariantName<T>(this T Builder, string invariantName)
|
||||
where T : IWithInvariantNameBuilder
|
||||
{
|
||||
Builder.InvariantName = invariantName;
|
||||
return Builder;
|
||||
}
|
||||
|
||||
public static T WithInvariantProperties<T>(this T Builder, IEnumerable<PropertyValueModel> invariantProperties)
|
||||
where T : IWithInvariantPropertiesBuilder
|
||||
{
|
||||
Builder.InvariantProperties = invariantProperties;
|
||||
return Builder;
|
||||
}
|
||||
|
||||
public static T WithVariants<T>(this T Builder, IEnumerable<VariantModel> variants)
|
||||
where T : IWithVariantsBuilder
|
||||
{
|
||||
Builder.Variants = variants;
|
||||
return Builder;
|
||||
}
|
||||
|
||||
public static T WithKey<T>(this T Builder, Guid? key)
|
||||
where T : IWithKeyBuilder
|
||||
{
|
||||
Builder.Key = key;
|
||||
return Builder;
|
||||
}
|
||||
|
||||
public static T WithContentTypeKey<T>(this T Builder, Guid contentTypeKey)
|
||||
where T : IWithContentTypeKeyBuilder
|
||||
{
|
||||
Builder.ContentTypeKey = contentTypeKey;
|
||||
return Builder;
|
||||
}
|
||||
|
||||
public static T WithParentKey<T>(this T Builder, Guid? parentKey)
|
||||
where T : IWithParentKeyBuilder
|
||||
{
|
||||
Builder.ParentKey = parentKey;
|
||||
return Builder;
|
||||
}
|
||||
|
||||
|
||||
public static T WithTemplateKey<T>(this T Builder, Guid? templateKey)
|
||||
where T : IWithTemplateKeyBuilder
|
||||
{
|
||||
Builder.TemplateKey = templateKey;
|
||||
return Builder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces.ContentCreateModel;
|
||||
|
||||
public interface IWithContentTypeKeyBuilder
|
||||
{
|
||||
public Guid ContentTypeKey { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces.ContentCreateModel;
|
||||
|
||||
public interface IWithInvariantNameBuilder
|
||||
{
|
||||
public string? InvariantName { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Umbraco.Cms.Core.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces.ContentCreateModel;
|
||||
|
||||
public interface IWithInvariantPropertiesBuilder
|
||||
{
|
||||
public IEnumerable<PropertyValueModel> InvariantProperties { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
public interface IWithParentKeyBuilder
|
||||
{
|
||||
Guid? ParentKey { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces.ContentCreateModel;
|
||||
|
||||
public interface IWithTemplateKeyBuilder
|
||||
{
|
||||
public Guid? TemplateKey { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Umbraco.Cms.Core.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces.ContentCreateModel;
|
||||
|
||||
public interface IWithVariantsBuilder
|
||||
{
|
||||
public IEnumerable<VariantModel> Variants { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
public interface IWIthContainerKeyBuilder
|
||||
{
|
||||
Guid? ContainerKey { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
public interface IWithDataTypeKeyBuilder
|
||||
{
|
||||
Guid? DataTypeKey { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
public interface IWithLabelOnTop
|
||||
{
|
||||
public bool? LabelOnTop { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
public interface IWithMandatoryBuilder
|
||||
{
|
||||
bool? Mandatory { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
public interface IWithMandatoryMessageBuilder
|
||||
{
|
||||
string MandatoryMessage { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
public interface IWithRegularExpressionBuilder
|
||||
{
|
||||
string RegularExpression { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
public interface IWithRegularExpressionMessage
|
||||
{
|
||||
string RegularExpressionMessage { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
public interface IWithTypeBuilder
|
||||
{
|
||||
public string Type { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
public interface IWithVariesByCultureBuilder
|
||||
{
|
||||
bool VariesByCulture { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
public interface IWithVariesBySegmentBuilder
|
||||
{
|
||||
bool VariesBySegment { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Umbraco.Cms.Core.Models.ContentTypeEditing;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Common.Builders;
|
||||
|
||||
public class PropertyTypeAppearanceBuilder
|
||||
: ChildBuilderBase<PropertyTypeEditingBuilder, PropertyTypeAppearance>, IBuildPropertyTypes, IWithLabelOnTop
|
||||
{
|
||||
private bool? _labelOnTop;
|
||||
|
||||
public PropertyTypeAppearanceBuilder(PropertyTypeEditingBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
bool? IWithLabelOnTop.LabelOnTop
|
||||
{
|
||||
get => _labelOnTop;
|
||||
set => _labelOnTop = value;
|
||||
}
|
||||
|
||||
public override PropertyTypeAppearance Build() => new() { LabelOnTop = _labelOnTop ?? false };
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.ContentTypeEditing;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Common.Builders;
|
||||
|
||||
public class PropertyTypeContainerBuilder<TParent>(TParent parentBuilder)
|
||||
: ChildBuilderBase<TParent, ContentTypePropertyContainerModel>(parentBuilder),
|
||||
IBuildPropertyTypes, IWithKeyBuilder, IWithParentKeyBuilder, IWithNameBuilder, IWithTypeBuilder,
|
||||
IWithSortOrderBuilder
|
||||
{
|
||||
private Guid? _key;
|
||||
private Guid? _parentKey;
|
||||
private string _name;
|
||||
private string _type;
|
||||
private int? _sortOrder;
|
||||
|
||||
Guid? IWithKeyBuilder.Key
|
||||
{
|
||||
get => _key;
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
Guid? IWithParentKeyBuilder.ParentKey
|
||||
{
|
||||
get => _parentKey;
|
||||
set => _parentKey = value;
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
|
||||
string IWithTypeBuilder.Type
|
||||
{
|
||||
get => _type;
|
||||
set => _type = value;
|
||||
}
|
||||
|
||||
int? IWithSortOrderBuilder.SortOrder
|
||||
{
|
||||
get => _sortOrder;
|
||||
set => _sortOrder = value;
|
||||
}
|
||||
|
||||
public override ContentTypePropertyContainerModel Build()
|
||||
{
|
||||
var key = _key ?? Guid.NewGuid();
|
||||
var parentKey = _parentKey;
|
||||
var name = _name ?? "Container";
|
||||
var type = _type ?? "Group";
|
||||
var sortOrder = _sortOrder ?? 0;
|
||||
|
||||
|
||||
return new ContentTypePropertyContainerModel
|
||||
{
|
||||
Key = key,
|
||||
ParentKey = parentKey,
|
||||
Name = name,
|
||||
Type = type,
|
||||
SortOrder = sortOrder,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models.ContentTypeEditing;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Common.Builders;
|
||||
|
||||
public class PropertyTypeEditingBuilder
|
||||
: ChildBuilderBase<ContentTypeEditingBuilder, ContentTypePropertyTypeModel>, IBuildPropertyTypes, IWithKeyBuilder,
|
||||
IWIthContainerKeyBuilder,
|
||||
IWithSortOrderBuilder, IWithAliasBuilder, IWithNameBuilder, IWithDescriptionBuilder, IWithDataTypeKeyBuilder,
|
||||
IWithVariesByCultureBuilder, IWithVariesBySegmentBuilder
|
||||
{
|
||||
private Guid? _key;
|
||||
private Guid? _containerKey;
|
||||
private int? _sortOrder;
|
||||
private string _alias;
|
||||
private string? _name;
|
||||
private string? _description;
|
||||
private Guid? _dataTypeKey;
|
||||
private bool _variesByCulture;
|
||||
private bool _variesBySegment;
|
||||
private PropertyTypeValidationEditingBuilder _validationBuilder;
|
||||
private PropertyTypeAppearanceBuilder _appearanceBuilder;
|
||||
|
||||
public PropertyTypeEditingBuilder(ContentTypeEditingBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
_validationBuilder = new PropertyTypeValidationEditingBuilder(this);
|
||||
_appearanceBuilder = new PropertyTypeAppearanceBuilder(this);
|
||||
}
|
||||
|
||||
Guid? IWithKeyBuilder.Key
|
||||
{
|
||||
get => _key;
|
||||
set => _key = value;
|
||||
}
|
||||
|
||||
Guid? IWIthContainerKeyBuilder.ContainerKey
|
||||
{
|
||||
get => _containerKey;
|
||||
set => _containerKey = value;
|
||||
}
|
||||
|
||||
int? IWithSortOrderBuilder.SortOrder
|
||||
{
|
||||
get => _sortOrder;
|
||||
set => _sortOrder = value;
|
||||
}
|
||||
|
||||
string IWithAliasBuilder.Alias
|
||||
{
|
||||
get => _alias;
|
||||
set => _alias = value;
|
||||
}
|
||||
|
||||
string IWithNameBuilder.Name
|
||||
{
|
||||
get => _name;
|
||||
set => _name = value;
|
||||
}
|
||||
|
||||
string IWithDescriptionBuilder.Description
|
||||
{
|
||||
get => _description;
|
||||
set => _description = value;
|
||||
}
|
||||
|
||||
Guid? IWithDataTypeKeyBuilder.DataTypeKey
|
||||
{
|
||||
get => _dataTypeKey;
|
||||
set => _dataTypeKey = value;
|
||||
}
|
||||
|
||||
bool IWithVariesByCultureBuilder.VariesByCulture
|
||||
{
|
||||
get => _variesByCulture;
|
||||
set => _variesByCulture = value;
|
||||
}
|
||||
|
||||
bool IWithVariesBySegmentBuilder.VariesBySegment
|
||||
{
|
||||
get => _variesBySegment;
|
||||
set => _variesBySegment = value;
|
||||
}
|
||||
|
||||
public PropertyTypeValidationEditingBuilder AddValidation()
|
||||
{
|
||||
var builder = new PropertyTypeValidationEditingBuilder(this);
|
||||
_validationBuilder = builder;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public PropertyTypeAppearanceBuilder AddAppearance()
|
||||
{
|
||||
var builder = new PropertyTypeAppearanceBuilder(this);
|
||||
_appearanceBuilder = builder;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public PropertyTypeEditingBuilder WithContainerKey(Guid? containerKey)
|
||||
{
|
||||
_containerKey = containerKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyTypeEditingBuilder WithSortOrder(int sortOrder)
|
||||
{
|
||||
_sortOrder = sortOrder;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyTypeEditingBuilder WithAlias(string alias)
|
||||
{
|
||||
_alias = alias;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyTypeEditingBuilder WithName(string name)
|
||||
{
|
||||
_name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyTypeEditingBuilder WithDescription(string description)
|
||||
{
|
||||
_description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyTypeEditingBuilder WithDataTypeKey(Guid dataTypeKey)
|
||||
{
|
||||
_dataTypeKey = dataTypeKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyTypeEditingBuilder WithVariesByCulture(bool variesByCulture)
|
||||
{
|
||||
_variesByCulture = variesByCulture;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyTypeEditingBuilder WithVariesBySegment(bool variesBySegment)
|
||||
{
|
||||
_variesBySegment = variesBySegment;
|
||||
return this;
|
||||
}
|
||||
|
||||
public override ContentTypePropertyTypeModel Build()
|
||||
{
|
||||
var key = _key ?? Guid.NewGuid();
|
||||
var containerKey = _containerKey;
|
||||
var sortOrder = _sortOrder ?? 0;
|
||||
var alias = _alias ?? "title";
|
||||
var name = _name ?? "Title";
|
||||
var description = _description;
|
||||
var dataTypeKey = _dataTypeKey ?? Constants.DataTypes.Guids.TextareaGuid;
|
||||
var variesByCulture = _variesByCulture;
|
||||
var variesBySegment = _variesBySegment;
|
||||
var validation = _validationBuilder.Build();
|
||||
var appearance = _appearanceBuilder.Build();
|
||||
|
||||
return new ContentTypePropertyTypeModel
|
||||
{
|
||||
Key = key,
|
||||
ContainerKey = containerKey,
|
||||
SortOrder = sortOrder,
|
||||
Alias = alias,
|
||||
Name = name,
|
||||
Description = description,
|
||||
DataTypeKey = dataTypeKey,
|
||||
VariesByCulture = variesByCulture,
|
||||
VariesBySegment = variesBySegment,
|
||||
Validation = validation,
|
||||
Appearance = appearance,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Umbraco.Cms.Core.Models.ContentTypeEditing;
|
||||
using Umbraco.Cms.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Common.Builders;
|
||||
|
||||
public class PropertyTypeValidationEditingBuilder
|
||||
: ChildBuilderBase<PropertyTypeEditingBuilder, PropertyTypeValidation>, IBuildPropertyTypes, IWithMandatoryBuilder,
|
||||
IWithMandatoryMessageBuilder, IWithRegularExpressionBuilder, IWithRegularExpressionMessage
|
||||
{
|
||||
private bool? _mandatory;
|
||||
private string? _mandatoryMessage;
|
||||
private string? _regularExpression;
|
||||
private string? _regularExpressionMessage;
|
||||
|
||||
public PropertyTypeValidationEditingBuilder(PropertyTypeEditingBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
bool? IWithMandatoryBuilder.Mandatory
|
||||
{
|
||||
get => _mandatory;
|
||||
set => _mandatory = value;
|
||||
}
|
||||
|
||||
string? IWithMandatoryMessageBuilder.MandatoryMessage
|
||||
{
|
||||
get => _mandatoryMessage;
|
||||
set => _mandatoryMessage = value;
|
||||
}
|
||||
|
||||
string? IWithRegularExpressionBuilder.RegularExpression
|
||||
{
|
||||
get => _regularExpression;
|
||||
set => _regularExpression = value;
|
||||
}
|
||||
|
||||
string? IWithRegularExpressionMessage.RegularExpressionMessage
|
||||
{
|
||||
get => _regularExpressionMessage;
|
||||
set => _regularExpressionMessage = value;
|
||||
}
|
||||
|
||||
public override PropertyTypeValidation Build()
|
||||
{
|
||||
var validation = new PropertyTypeValidation
|
||||
{
|
||||
Mandatory = _mandatory ?? false,
|
||||
MandatoryMessage = _mandatoryMessage ?? null,
|
||||
RegularExpression = _regularExpression ?? null,
|
||||
RegularExpressionMessage = _regularExpressionMessage ?? null,
|
||||
};
|
||||
|
||||
return validation;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.ContentTypeEditing;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Common.TestHelpers;
|
||||
|
||||
public class ContentTypeUpdateHelper
|
||||
{
|
||||
public ContentTypeUpdateModel CreateContentTypeUpdateModel(IContentType contentType)
|
||||
{
|
||||
var updateModel = new ContentTypeUpdateModel();
|
||||
var model = MapBaseProperties<ContentTypeUpdateModel>(contentType, updateModel);
|
||||
return model;
|
||||
}
|
||||
|
||||
private T MapBaseProperties<T>(IContentType contentType, T model) where T : ContentTypeModelBase
|
||||
{
|
||||
model.Alias = contentType.Alias;
|
||||
model.Name = contentType.Name;
|
||||
model.Description = contentType.Description;
|
||||
model.Icon = contentType.Icon;
|
||||
model.AllowedAsRoot = contentType.AllowedAsRoot;
|
||||
model.VariesByCulture = contentType.VariesByCulture();
|
||||
model.VariesBySegment = contentType.VariesBySegment();
|
||||
model.IsElement = contentType.IsElement;
|
||||
model.ListView = contentType.ListView;
|
||||
model.Cleanup = new ContentTypeCleanup()
|
||||
{
|
||||
PreventCleanup = contentType.HistoryCleanup.PreventCleanup,
|
||||
KeepAllVersionsNewerThanDays = contentType.HistoryCleanup.KeepAllVersionsNewerThanDays,
|
||||
KeepLatestVersionPerDayForDays = contentType.HistoryCleanup.KeepLatestVersionPerDayForDays
|
||||
};
|
||||
|
||||
model.AllowedTemplateKeys = contentType.AllowedTemplates.Select(x => x.Key);
|
||||
model.DefaultTemplateKey = contentType.DefaultTemplate?.Key;
|
||||
|
||||
var tempContainerList = model.Containers.ToList();
|
||||
|
||||
foreach (var container in contentType.PropertyGroups)
|
||||
{
|
||||
var containerModel = new ContentTypePropertyContainerModel()
|
||||
{
|
||||
Key = container.Key,
|
||||
Name = container.Name,
|
||||
SortOrder = container.SortOrder,
|
||||
Type = container.Type.ToString()
|
||||
};
|
||||
tempContainerList.Add(containerModel);
|
||||
}
|
||||
|
||||
model.Containers = tempContainerList.AsEnumerable();
|
||||
|
||||
var tempPropertyList = model.Properties.ToList();
|
||||
|
||||
foreach (var propertyType in contentType.PropertyTypes)
|
||||
{
|
||||
var propertyModel = new ContentTypePropertyTypeModel
|
||||
{
|
||||
Key = propertyType.Key,
|
||||
ContainerKey = contentType.PropertyGroups.Single(x => x.PropertyTypes.Contains(propertyType)).Key,
|
||||
SortOrder = propertyType.SortOrder,
|
||||
Alias = propertyType.Alias,
|
||||
Name = propertyType.Name,
|
||||
Description = propertyType.Description,
|
||||
DataTypeKey = propertyType.DataTypeKey,
|
||||
VariesByCulture = propertyType.VariesByCulture(),
|
||||
VariesBySegment = propertyType.VariesBySegment(),
|
||||
Validation = new PropertyTypeValidation()
|
||||
{
|
||||
Mandatory = propertyType.Mandatory,
|
||||
MandatoryMessage = propertyType.ValidationRegExp,
|
||||
RegularExpression = propertyType.ValidationRegExp,
|
||||
RegularExpressionMessage = propertyType.ValidationRegExpMessage,
|
||||
},
|
||||
Appearance = new PropertyTypeAppearance() { LabelOnTop = propertyType.LabelOnTop, }
|
||||
};
|
||||
tempPropertyList.Add(propertyModel);
|
||||
}
|
||||
|
||||
model.Properties = tempPropertyList.AsEnumerable();
|
||||
return model;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user