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
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
udi,
ref objectType,
UmbracoObjectTypes.Document,
id => _contentCache.GetById(guidUdi.Guid));
id => _contentCache.GetById(preview, guidUdi.Guid));
break;
case Constants.UdiEntityType.Media:
multiNodeTreePickerItem = GetPublishedContent(
Expand Down Expand Up @@ -205,7 +205,7 @@ public Type GetDeliveryApiPropertyValueType(IPublishedPropertyType propertyType)
{
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void MultiNodeTreePickerValueConverter_InMultiMode_ConvertsValueToListOfC

var otherContentKey = Guid.NewGuid();
var otherContent = SetupPublishedContent("The other page", otherContentKey, PublishedItemType.Content, PublishedContentType);
RegisterContentWithProviders(otherContent.Object);
RegisterContentWithProviders(otherContent.Object, false);

var valueConverter = MultiNodeTreePickerValueConverter();

Expand All @@ -94,6 +94,28 @@ public void MultiNodeTreePickerValueConverter_InMultiMode_ConvertsValueToListOfC
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")]
Expand All @@ -113,7 +135,7 @@ public void MultiNodeTreePickerValueConverter_RendersContentProperties(string en
.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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ protected void SetupContentMock(Mock<IPublishedContent> content, params IPublish
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -59,10 +61,21 @@ public override void Setup()
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))
Expand All @@ -77,6 +90,9 @@ public override void Setup()
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");
Expand All @@ -97,14 +113,20 @@ protected Mock<IPublishedContent> SetupPublishedContent(string name, Guid key, P
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)
Expand Down