Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/Umbraco.PublishedCache.NuCache/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal class Property : PublishedPropertyBase
// the invariant-neutral source and inter values
private readonly object? _sourceValue;
private readonly ContentVariation _variations;
private bool _sourceValueIsInvariant;
private readonly ContentVariation _sourceVariations;

// the variant and non-variant object values
private CacheValues? _cacheValues;
Expand Down Expand Up @@ -88,7 +88,7 @@ public Property(
// this variable is used for contextualizing the variation level when calculating property values.
// it must be set to the union of variance (the combination of content type and property type variance).
_variations = propertyType.Variations | content.ContentType.Variations;
_sourceValueIsInvariant = propertyType.Variations is ContentVariation.Nothing;
_sourceVariations = propertyType.Variations;
}

// clone for previewing as draft a published content that is published and has no draft
Expand All @@ -104,7 +104,7 @@ public Property(Property origin, PublishedContent content)
_isMember = origin._isMember;
_publishedSnapshotAccessor = origin._publishedSnapshotAccessor;
_variations = origin._variations;
_sourceValueIsInvariant = origin._sourceValueIsInvariant;
_sourceVariations = origin._sourceVariations;
}

// used to cache the CacheValues of this property
Expand Down Expand Up @@ -148,9 +148,14 @@ public override bool HasValue(string? culture = null, string? segment = null)

public override object? GetSourceValue(string? culture = null, string? segment = null)
{
_content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment);
_content.VariationContextAccessor.ContextualizeVariation(_sourceVariations, _content.Id, ref culture, ref segment);

// source values are tightly bound to the property/schema culture and segment configurations, so we need to
// sanitize the contextualized culture/segment states before using them to access the source values.
culture = _sourceVariations.VariesByCulture() ? culture : string.Empty;
segment = _sourceVariations.VariesBySegment() ? segment : string.Empty;

if (_sourceValueIsInvariant || (culture == string.Empty && segment == string.Empty))
if (culture == string.Empty && segment == string.Empty)
{
return _sourceValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ public void Content_Culture_And_Segment_Variation_Can_Get_Culture_And_Segment_Va
Assert.AreEqual(expectedValue, value);
}

[TestCase(DaCulture, Segment1, "DaDk property value")]
[TestCase(DaCulture, Segment2, "DaDk property value")]
[TestCase(EnCulture, Segment1, "EnUs property value")]
[TestCase(EnCulture, Segment2, "EnUs property value")]
public void Content_Culture_And_Segment_Variation_Can_Get_Culture_Variant_Property(string culture, string segment, string expectedValue)
{
var content = CreatePublishedContent(ContentVariation.CultureAndSegment, ContentVariation.Culture, variationContextCulture: culture, variationContextSegment: segment);
var value = GetPropertyValue(content);
Assert.AreEqual(expectedValue, value);
}

[TestCase(DaCulture, Segment1, "Segment1 property value")]
[TestCase(DaCulture, Segment2, "Segment2 property value")]
[TestCase(EnCulture, Segment1, "Segment1 property value")]
[TestCase(EnCulture, Segment2, "Segment2 property value")]
public void Content_Culture_And_Segment_Variation_Can_Get_Segment_Variant_Property(string culture, string segment, string expectedValue)
{
var content = CreatePublishedContent(ContentVariation.CultureAndSegment, ContentVariation.Segment, variationContextCulture: culture, variationContextSegment: segment);
var value = GetPropertyValue(content);
Assert.AreEqual(expectedValue, value);
}

private object? GetPropertyValue(IPublishedContent content) => content.GetProperty(PropertyTypeAlias)!.GetValue();

private IPublishedContent CreatePublishedContent(ContentVariation contentTypeVariation, ContentVariation propertyTypeVariation, string? variationContextCulture = null, string? variationContextSegment = null)
Expand Down