Changes EnumExtensions to ContentVariationExtensions and adds more helper methods to replace a lot of the duplicate checking in our code. Adds code to enforce unique naming for culture names, adds supporting tests.

This commit is contained in:
Shannon
2018-06-01 15:20:16 +10:00
parent e907a085bd
commit b75cf3bc76
10 changed files with 230 additions and 50 deletions

View File

@@ -180,7 +180,7 @@ namespace Umbraco.Core.Models
return;
}
if (!ContentTypeBase.Variations.HasAny(ContentVariation.CultureNeutral | ContentVariation.CultureSegment))
if (ContentTypeBase.Variations.DoesNotSupportCulture())
throw new NotSupportedException("Content type does not support varying name by culture.");
if (_cultureInfos == null)
@@ -210,7 +210,7 @@ namespace Umbraco.Core.Models
return;
}
if (!ContentTypeBase.Variations.HasAny(ContentVariation.CultureNeutral | ContentVariation.CultureSegment))
if (ContentTypeBase.Variations.DoesNotSupportCulture())
throw new NotSupportedException("Content type does not support varying name by culture.");
if (_cultureInfos == null) return;
@@ -224,7 +224,7 @@ namespace Umbraco.Core.Models
protected virtual void ClearNames()
{
if (!ContentTypeBase.Variations.HasAny(ContentVariation.CultureNeutral | ContentVariation.CultureSegment))
if (ContentTypeBase.Variations.DoesNotSupportCulture())
throw new NotSupportedException("Content type does not support varying name by culture.");
_cultureInfos = null;
@@ -327,13 +327,13 @@ namespace Umbraco.Core.Models
{
return Properties.Where(x =>
{
if (!culture.IsNullOrWhiteSpace() && !x.PropertyType.Variations.HasAny(ContentVariation.CultureNeutral | ContentVariation.CultureSegment))
if (!culture.IsNullOrWhiteSpace() && x.PropertyType.Variations.DoesNotSupportCulture())
return false; //has a culture, this prop is only culture invariant, ignore
if (culture.IsNullOrWhiteSpace() && !x.PropertyType.Variations.HasAny(ContentVariation.InvariantNeutral | ContentVariation.InvariantSegment))
if (culture.IsNullOrWhiteSpace() && x.PropertyType.Variations.DoesNotSupportInvariant())
return false; //no culture, this prop is only culture variant, ignore
if (!segment.IsNullOrWhiteSpace() && !x.PropertyType.Variations.HasAny(ContentVariation.InvariantSegment | ContentVariation.CultureSegment))
if (!segment.IsNullOrWhiteSpace() && x.PropertyType.Variations.DoesNotSupportSegment())
return false; //has segment, this prop is only segment neutral, ignore
if (segment.IsNullOrWhiteSpace() && !x.PropertyType.Variations.HasAny(ContentVariation.InvariantNeutral | ContentVariation.CultureNeutral))
if (segment.IsNullOrWhiteSpace() && x.PropertyType.Variations.DoesNotSupportNeutral())
return false; //no segment, this prop is only non segment neutral, ignore
return !x.IsValid(culture, segment);
}).ToArray();