Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.PublishedCache.HybridCache/CacheTestsHelper.cs
Mole c76d764598 V15: Only cache items if all ancestors are published (#18337)
* Introduce IsDocumentPublishedInAnyCulture

Sometimes we don't care about culture

* Check ancestor path when resolving cache items

* Fix tests

* Rebuild NavigationService

* Only set node if it has a published ancestor path

* Remove branch when unpublished

* Add tests

* Add seed test

* Consider published ancestor path when seeding documents

* Introduce MediaBreadthFirstKeyProviderTests

This is needed since the logic of document and media is no longer the same

* Remove unused services

* Move assert page to helper

* Add variant tests

* Add tests

* Filter keys in ContentTypeSeedKeyProvider

* Fix tests

* Add failing test showing refreshing issue

* Don't blow up if we can't resolve the node from navigation cache

Turns out that this can actually happen :D Should be fine to just return false

* Refactor cache refresher check

* Make NavigationQueryService service protected

* Add comment on how to refactor breadth first key provider

* Refactor if statement
2025-02-17 12:51:33 +01:00

55 lines
1.9 KiB
C#

using NUnit.Framework;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.PublishedContent;
namespace Umbraco.Cms.Tests.Integration.Umbraco.PublishedCache.HybridCache;
internal static class CacheTestsHelper
{
internal static void AssertPage(IContent baseContent, IPublishedContent? comparisonContent, bool isPublished = true)
{
Assert.Multiple(() =>
{
Assert.IsNotNull(comparisonContent);
if (baseContent.ContentType.VariesByCulture())
{
foreach (var culture in baseContent.CultureInfos ?? Enumerable.Empty<ContentCultureInfos>())
{
if (comparisonContent.Cultures.TryGetValue(culture.Culture, out var publishedCulture) is false)
{
continue;
}
Assert.That(publishedCulture.Name, Is.EqualTo(culture.Name));
}
}
else
{
Assert.That(comparisonContent.Name, Is.EqualTo(baseContent.Name));
}
Assert.That(comparisonContent.IsPublished(), Is.EqualTo(isPublished));
});
AssertProperties(baseContent.Properties, comparisonContent!.Properties);
}
internal static void AssertProperties(IPropertyCollection propertyCollection,
IEnumerable<IPublishedProperty> publishedProperties)
{
foreach (var prop in propertyCollection)
{
AssertProperty(prop, publishedProperties.First(x => x.Alias == prop.Alias));
}
}
internal static void AssertProperty(IProperty property, IPublishedProperty publishedProperty)
{
Assert.Multiple(() =>
{
Assert.AreEqual(property.Alias, publishedProperty.Alias);
Assert.AreEqual(property.PropertyType.Alias, publishedProperty.PropertyType.Alias);
});
}
}