Fix issue with preview in delivery API for MNTP property editor (#19668)
* Passes the preview flag to the cache retrieval when resolving the delivery API object for the MNTP property editor. * Added unit test verifying fix and adjusted mocks for tests to acoomodate. * Provided preview flag for Razor rendering.
This commit is contained in:
@@ -115,7 +115,7 @@ public class MultiNodeTreePickerValueConverter : PropertyValueConverterBase, IDe
|
||||
udi,
|
||||
ref objectType,
|
||||
UmbracoObjectTypes.Document,
|
||||
id => _contentCache.GetById(guidUdi.Guid));
|
||||
id => _contentCache.GetById(preview, guidUdi.Guid));
|
||||
break;
|
||||
case Constants.UdiEntityType.Media:
|
||||
multiNodeTreePickerItem = GetPublishedContent(
|
||||
@@ -205,7 +205,7 @@ public class MultiNodeTreePickerValueConverter : PropertyValueConverterBase, IDe
|
||||
{
|
||||
Constants.UdiEntityType.Document => entityTypeUdis.Select(udi =>
|
||||
{
|
||||
IPublishedContent? content = _contentCache.GetById(udi.Guid);
|
||||
IPublishedContent? content = _contentCache.GetById(preview, udi.Guid);
|
||||
return content != null
|
||||
? _apiContentBuilder.Build(content)
|
||||
: null;
|
||||
|
||||
@@ -73,7 +73,7 @@ public class MultiNodeTreePickerValueConverterTests : PropertyValueConverterTest
|
||||
|
||||
var otherContentKey = Guid.NewGuid();
|
||||
var otherContent = SetupPublishedContent("The other page", otherContentKey, PublishedItemType.Content, PublishedContentType);
|
||||
RegisterContentWithProviders(otherContent.Object);
|
||||
RegisterContentWithProviders(otherContent.Object, false);
|
||||
|
||||
var valueConverter = MultiNodeTreePickerValueConverter();
|
||||
|
||||
@@ -94,6 +94,28 @@ public class MultiNodeTreePickerValueConverterTests : PropertyValueConverterTest
|
||||
Assert.AreEqual("TheContentType", result.Last().ContentType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MultiNodeTreePickerValueConverter_InSingleMode_WithPreview_ConvertsValueToListOfContent()
|
||||
{
|
||||
var publishedDataType = MultiNodePickerPublishedDataType(false, Constants.UdiEntityType.Document);
|
||||
var publishedPropertyType = new Mock<IPublishedPropertyType>();
|
||||
publishedPropertyType.SetupGet(p => p.DataType).Returns(publishedDataType);
|
||||
|
||||
var valueConverter = MultiNodeTreePickerValueConverter();
|
||||
|
||||
Assert.AreEqual(typeof(IEnumerable<IApiContent>), valueConverter.GetDeliveryApiPropertyValueType(publishedPropertyType.Object));
|
||||
|
||||
var inter = new Udi[] { new GuidUdi(Constants.UdiEntityType.Document, DraftContent.Key) };
|
||||
var result = valueConverter.ConvertIntermediateToDeliveryApiObject(Mock.Of<IPublishedElement>(), publishedPropertyType.Object, PropertyCacheLevel.Element, inter, true, false) as IEnumerable<IApiContent>;
|
||||
Assert.NotNull(result);
|
||||
Assert.AreEqual(1, result.Count());
|
||||
Assert.AreEqual(DraftContent.Name, result.First().Name);
|
||||
Assert.AreEqual(DraftContent.Key, result.First().Id);
|
||||
Assert.AreEqual("/the-draft-page-url/", result.First().Route.Path);
|
||||
Assert.AreEqual("TheContentType", result.First().ContentType);
|
||||
Assert.IsEmpty(result.First().Properties);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase(Constants.UdiEntityType.Document)]
|
||||
[TestCase("content")]
|
||||
@@ -113,7 +135,7 @@ public class MultiNodeTreePickerValueConverterTests : PropertyValueConverterTest
|
||||
.Setup(p => p.GetUrl(content.Object, It.IsAny<UrlMode>(), It.IsAny<string?>(), It.IsAny<Uri?>()))
|
||||
.Returns(content.Object.UrlSegment);
|
||||
PublishedContentCacheMock
|
||||
.Setup(pcc => pcc.GetById(key))
|
||||
.Setup(pcc => pcc.GetById(false, key))
|
||||
.Returns(content.Object);
|
||||
|
||||
var publishedDataType = MultiNodePickerPublishedDataType(false, entityType);
|
||||
|
||||
@@ -327,7 +327,7 @@ public abstract class OutputExpansionStrategyTestBase : PropertyValueConverterTe
|
||||
var urlSegment = "url-segment";
|
||||
ConfigurePublishedContentMock(content, key, name, urlSegment, _contentType, properties);
|
||||
|
||||
RegisterContentWithProviders(content.Object);
|
||||
RegisterContentWithProviders(content.Object, false);
|
||||
}
|
||||
|
||||
protected void SetupMediaMock(Mock<IPublishedContent> media, params IPublishedProperty[] properties)
|
||||
|
||||
@@ -23,6 +23,8 @@ public class PropertyValueConverterTests : DeliveryApiTests
|
||||
|
||||
protected IPublishedContent PublishedMedia { get; private set; }
|
||||
|
||||
protected IPublishedContent DraftContent { get; private set; }
|
||||
|
||||
protected IPublishedContentType PublishedContentType { get; private set; }
|
||||
|
||||
protected IPublishedContentType PublishedMediaType { get; private set; }
|
||||
@@ -59,10 +61,21 @@ public class PropertyValueConverterTests : DeliveryApiTests
|
||||
var publishedMedia = SetupPublishedContent("The media", mediaKey, PublishedItemType.Media, publishedMediaType.Object);
|
||||
PublishedMedia = publishedMedia.Object;
|
||||
|
||||
var draftContentKey = Guid.NewGuid();
|
||||
var draftContent = SetupPublishedContent("The page (draft)", draftContentKey, PublishedItemType.Content, publishedContentType.Object);
|
||||
DraftContent = draftContent.Object;
|
||||
|
||||
PublishedContentCacheMock = new Mock<IPublishedContentCache>();
|
||||
PublishedContentCacheMock
|
||||
.Setup(pcc => pcc.GetById(contentKey))
|
||||
.Returns(publishedContent.Object);
|
||||
PublishedContentCacheMock
|
||||
.Setup(pcc => pcc.GetById(false, contentKey))
|
||||
.Returns(publishedContent.Object);
|
||||
PublishedContentCacheMock
|
||||
.Setup(pcc => pcc.GetById(true, draftContentKey))
|
||||
.Returns(draftContent.Object);
|
||||
|
||||
PublishedMediaCacheMock = new Mock<IPublishedMediaCache>();
|
||||
PublishedMediaCacheMock
|
||||
.Setup(pcc => pcc.GetById(mediaKey))
|
||||
@@ -77,6 +90,9 @@ public class PropertyValueConverterTests : DeliveryApiTests
|
||||
PublishedUrlProviderMock
|
||||
.Setup(p => p.GetUrl(publishedContent.Object, It.IsAny<UrlMode>(), It.IsAny<string?>(), It.IsAny<Uri?>()))
|
||||
.Returns("the-page-url");
|
||||
PublishedUrlProviderMock
|
||||
.Setup(p => p.GetUrl(draftContent.Object, It.IsAny<UrlMode>(), It.IsAny<string?>(), It.IsAny<Uri?>()))
|
||||
.Returns("the-draft-page-url");
|
||||
PublishedUrlProviderMock
|
||||
.Setup(p => p.GetMediaUrl(publishedMedia.Object, It.IsAny<UrlMode>(), It.IsAny<string?>(), It.IsAny<string?>(), It.IsAny<Uri?>()))
|
||||
.Returns("the-media-url");
|
||||
@@ -97,14 +113,20 @@ public class PropertyValueConverterTests : DeliveryApiTests
|
||||
return content;
|
||||
}
|
||||
|
||||
protected void RegisterContentWithProviders(IPublishedContent content)
|
||||
protected void RegisterContentWithProviders(IPublishedContent content, bool preview)
|
||||
{
|
||||
PublishedUrlProviderMock
|
||||
.Setup(p => p.GetUrl(content, It.IsAny<UrlMode>(), It.IsAny<string?>(), It.IsAny<Uri?>()))
|
||||
.Returns(content.UrlSegment);
|
||||
PublishedContentCacheMock
|
||||
.Setup(pcc => pcc.GetById(content.Key))
|
||||
.Setup(pcc => pcc.GetById(preview, content.Key))
|
||||
.Returns(content);
|
||||
if (preview is false)
|
||||
{
|
||||
PublishedContentCacheMock
|
||||
.Setup(pcc => pcc.GetById(content.Key))
|
||||
.Returns(content);
|
||||
}
|
||||
}
|
||||
|
||||
protected void RegisterMediaWithProviders(IPublishedContent media)
|
||||
|
||||
Reference in New Issue
Block a user