Fixes U4-2713 Property Editor Value Converters don't get applied to Umbraco.TypedMedia

This commit is contained in:
Shannon
2013-08-29 11:59:07 +10:00
parent 9445f008bc
commit 9fc3efd73a
3 changed files with 54 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ using System.Linq;
using System.Xml.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Dynamics;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
@@ -43,8 +44,9 @@ namespace Umbraco.Core
/// <param name="applicationContext"></param>
/// <param name="docTypeAlias"></param>
/// <param name="propertyAlias"></param>
/// <param name="itemType"></param>
/// <returns></returns>
internal static Guid GetDataType(ApplicationContext applicationContext, string docTypeAlias, string propertyAlias)
internal static Guid GetDataType(ApplicationContext applicationContext, string docTypeAlias, string propertyAlias, PublishedItemType itemType)
{
if (GetDataTypeCallback != null)
return GetDataTypeCallback(docTypeAlias, propertyAlias);
@@ -52,7 +54,19 @@ namespace Umbraco.Core
var key = new Tuple<string, string>(docTypeAlias, propertyAlias);
return PropertyTypeCache.GetOrAdd(key, tuple =>
{
var result = applicationContext.Services.ContentTypeService.GetContentType(docTypeAlias);
IContentTypeComposition result = null;
switch (itemType)
{
case PublishedItemType.Content:
result = applicationContext.Services.ContentTypeService.GetContentType(docTypeAlias);
break;
case PublishedItemType.Media:
applicationContext.Services.ContentTypeService.GetMediaType(docTypeAlias);
break;
default:
throw new ArgumentOutOfRangeException("itemType");
}
if (result == null) return Guid.Empty;
//SD: we need to check for 'any' here because the collection is backed by KeyValuePair which is a struct

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Web;
using System.Xml.Linq;
using System.Xml.XPath;
using Examine;
@@ -16,6 +17,7 @@ using Umbraco.Core.Configuration;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Tests.UmbracoExamine;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
@@ -68,6 +70,38 @@ namespace Umbraco.Tests.PublishedContent
return GetNode(id, GetUmbracoContext("/test", 1234));
}
[Test]
public void Get_Property_Value_Uses_Converter()
{
var mType = MockedContentTypes.CreateImageMediaType();
//lets add an RTE to this
mType.PropertyGroups.First().PropertyTypes.Add(
new PropertyType(new Guid(), DataTypeDatabaseType.Nvarchar)
{
Alias = "content",
Name = "Rich Text",
DataTypeDefinitionId = -87 //tiny mce
});
ServiceContext.ContentTypeService.Save(mType);
var media = MockedMedia.CreateMediaImage(mType, -1);
media.Properties["content"].Value = "<div>This is some content</div>";
ServiceContext.MediaService.Save(media);
var publishedMedia = GetNode(media.Id);
var propVal = publishedMedia.GetPropertyValue("content");
Assert.IsTrue(TypeHelper.IsTypeAssignableFrom<IHtmlString>(propVal.GetType()));
Assert.AreEqual("<div>This is some content</div>", propVal.ToString());
var propVal2 = publishedMedia.GetPropertyValue<IHtmlString>("content");
Assert.IsTrue(TypeHelper.IsTypeAssignableFrom<IHtmlString>(propVal2.GetType()));
Assert.AreEqual("<div>This is some content</div>", propVal2.ToString());
var propVal3 = publishedMedia.GetPropertyValue("Content");
Assert.IsTrue(TypeHelper.IsTypeAssignableFrom<IHtmlString>(propVal3.GetType()));
Assert.AreEqual("<div>This is some content</div>", propVal3.ToString());
}
[Test]
public void Ensure_Children_Sorted_With_Examine()
{
@@ -339,7 +373,6 @@ namespace Umbraco.Tests.PublishedContent
Assert.AreEqual(mChild1.Id, publishedSubChild1.Parent.Id);
}
[Test]
public void Ancestors_Without_Examine()
{

View File

@@ -153,7 +153,10 @@ namespace Umbraco.Web
//Here we need to put the value through the IPropertyEditorValueConverter's
//get the data type id for the current property
var dataType = PublishedContentHelper.GetDataType(ApplicationContext.Current, doc.DocumentTypeAlias, alias);
var dataType = PublishedContentHelper.GetDataType(
ApplicationContext.Current, doc.DocumentTypeAlias, alias,
doc.ItemType);
//convert the string value to a known type
var converted = PublishedContentHelper.ConvertPropertyValue(p.Value, dataType, doc.DocumentTypeAlias, alias);
return converted.Success