Introduce IPublishedPropertyType
This commit is contained in:
@@ -65,17 +65,22 @@ namespace Umbraco.Tests.PublishedContent
|
||||
var welcome2Type = factory.CreatePropertyType("welcomeText2", 1, variations: ContentVariation.Culture);
|
||||
var nopropType = factory.CreatePropertyType("noprop", 1, variations: ContentVariation.Culture);
|
||||
|
||||
var props = new[]
|
||||
{
|
||||
prop1Type,
|
||||
welcomeType,
|
||||
welcome2Type,
|
||||
nopropType
|
||||
};
|
||||
var contentType1 = factory.CreateContentType(1, "ContentType1", Enumerable.Empty<string>(), props);
|
||||
IEnumerable<IPublishedPropertyType> CreatePropertyTypes1(IPublishedContentType contentType)
|
||||
{
|
||||
yield return factory.CreatePropertyType(contentType, "prop1", 1, variations: ContentVariation.Culture);
|
||||
yield return factory.CreatePropertyType(contentType, "welcomeText", 1, variations: ContentVariation.Culture);
|
||||
yield return factory.CreatePropertyType(contentType, "welcomeText2", 1, variations: ContentVariation.Culture);
|
||||
yield return factory.CreatePropertyType(contentType, "noprop", 1, variations: ContentVariation.Culture);
|
||||
}
|
||||
|
||||
var prop3Type = factory.CreatePropertyType("prop3", 1, variations: ContentVariation.Culture);
|
||||
var contentType2 = factory.CreateContentType(2, "contentType2", Enumerable.Empty<string>(), new[] { prop3Type });
|
||||
var contentType1 = factory.CreateContentType(1, "ContentType1", Enumerable.Empty<string>(), CreatePropertyTypes1);
|
||||
|
||||
IEnumerable<IPublishedPropertyType> CreatePropertyTypes2(IPublishedContentType contentType)
|
||||
{
|
||||
yield return factory.CreatePropertyType(contentType, "prop3", 1, variations: ContentVariation.Culture);
|
||||
}
|
||||
|
||||
var contentType2 = factory.CreateContentType(2, "contentType2", Enumerable.Empty<string>(), CreatePropertyTypes2);
|
||||
|
||||
var prop1 = new SolidPublishedPropertyWithLanguageVariants
|
||||
{
|
||||
@@ -150,7 +155,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
var prop4 = new SolidPublishedPropertyWithLanguageVariants
|
||||
{
|
||||
Alias = "prop3",
|
||||
PropertyType = prop3Type
|
||||
PropertyType = contentType2.GetPropertyType("prop3")
|
||||
};
|
||||
prop4.SetSourceValue("en-US", "Oxxo", true);
|
||||
prop4.SetValue("en-US", "Oxxo", true);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
@@ -15,13 +16,14 @@ namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
internal override void PopulateCache(PublishedContentTypeFactory factory, SolidPublishedContentCache cache)
|
||||
{
|
||||
var props = new[]
|
||||
{
|
||||
factory.CreatePropertyType("prop1", 1),
|
||||
};
|
||||
var contentType1 = factory.CreateContentType(1, "ContentType1", Enumerable.Empty<string>(), props);
|
||||
var contentType2 = factory.CreateContentType(2, "ContentType2", Enumerable.Empty<string>(), props);
|
||||
var contentType2Sub = factory.CreateContentType(3, "ContentType2Sub", Enumerable.Empty<string>(), props);
|
||||
IEnumerable<IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
|
||||
{
|
||||
yield return factory.CreatePropertyType(contentType, "prop1", 1);
|
||||
}
|
||||
|
||||
var contentType1 = factory.CreateContentType(1, "ContentType1", Enumerable.Empty<string>(), CreatePropertyTypes);
|
||||
var contentType2 = factory.CreateContentType(2, "ContentType2", Enumerable.Empty<string>(), CreatePropertyTypes);
|
||||
var contentType2Sub = factory.CreateContentType(3, "ContentType2Sub", Enumerable.Empty<string>(), CreatePropertyTypes);
|
||||
|
||||
cache.Add(new SolidPublishedContent(contentType1)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Umbraco.Core;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.PropertyEditors.ValueConverters;
|
||||
@@ -41,13 +42,12 @@ namespace Umbraco.Tests.PublishedContent
|
||||
|
||||
var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), converters, dataTypeService);
|
||||
|
||||
// need to specify a custom callback for unit tests
|
||||
var propertyTypes = new[]
|
||||
IEnumerable<IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
|
||||
{
|
||||
// AutoPublishedContentType will auto-generate other properties
|
||||
publishedContentTypeFactory.CreatePropertyType("content", 1),
|
||||
};
|
||||
var type = new AutoPublishedContentType(0, "anything", propertyTypes);
|
||||
yield return publishedContentTypeFactory.CreatePropertyType(contentType, "content", 1);
|
||||
}
|
||||
|
||||
var type = new AutoPublishedContentType(0, "anything", CreatePropertyTypes);
|
||||
ContentTypesCache.GetPublishedContentTypeByAlias = alias => type;
|
||||
|
||||
var umbracoContext = GetUmbracoContext("/test");
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
@@ -62,18 +63,19 @@ namespace Umbraco.Tests.PublishedContent
|
||||
// when they are requested, but we must declare those that we
|
||||
// explicitely want to be here...
|
||||
|
||||
var propertyTypes = new[]
|
||||
IEnumerable<IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
|
||||
{
|
||||
// AutoPublishedContentType will auto-generate other properties
|
||||
factory.CreatePropertyType("umbracoNaviHide", 1001),
|
||||
factory.CreatePropertyType("selectedNodes", 1),
|
||||
factory.CreatePropertyType("umbracoUrlAlias", 1),
|
||||
factory.CreatePropertyType("content", 1002),
|
||||
factory.CreatePropertyType("testRecursive", 1),
|
||||
};
|
||||
yield return factory.CreatePropertyType(contentType, "umbracoNaviHide", 1001);
|
||||
yield return factory.CreatePropertyType(contentType, "selectedNodes", 1);
|
||||
yield return factory.CreatePropertyType(contentType, "umbracoUrlAlias", 1);
|
||||
yield return factory.CreatePropertyType(contentType, "content", 1002);
|
||||
yield return factory.CreatePropertyType(contentType, "testRecursive", 1);
|
||||
}
|
||||
|
||||
var compositionAliases = new[] { "MyCompositionAlias" };
|
||||
var anythingType = new AutoPublishedContentType(0, "anything", compositionAliases, propertyTypes);
|
||||
var homeType = new AutoPublishedContentType(0, "home", compositionAliases, propertyTypes);
|
||||
var anythingType = new AutoPublishedContentType(0, "anything", compositionAliases, CreatePropertyTypes);
|
||||
var homeType = new AutoPublishedContentType(0, "home", compositionAliases, CreatePropertyTypes);
|
||||
ContentTypesCache.GetPublishedContentTypeByAlias = alias => alias.InvariantEquals("home") ? homeType : anythingType;
|
||||
}
|
||||
|
||||
@@ -887,8 +889,13 @@ namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
var factory = Factory.GetInstance<IPublishedContentTypeFactory>() as PublishedContentTypeFactory;
|
||||
|
||||
var pt = factory.CreatePropertyType("detached", 1003);
|
||||
var ct = factory.CreateContentType(0, "alias", new[] { pt });
|
||||
IEnumerable<IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
|
||||
{
|
||||
yield return factory.CreatePropertyType(contentType, "detached", 1003);
|
||||
}
|
||||
|
||||
var ct = factory.CreateContentType(0, "alias", CreatePropertyTypes);
|
||||
var pt = ct.GetPropertyType("detached");
|
||||
var prop = new PublishedElementPropertyBase(pt, null, false, PropertyCacheLevel.None, 5548);
|
||||
Assert.IsInstanceOf<int>(prop.GetValue());
|
||||
Assert.AreEqual(5548, prop.GetValue());
|
||||
@@ -906,16 +913,20 @@ namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
var factory = Factory.GetInstance<IPublishedContentTypeFactory>() as PublishedContentTypeFactory;
|
||||
|
||||
var pt1 = factory.CreatePropertyType("legend", 1004);
|
||||
var pt2 = factory.CreatePropertyType("image", 1005);
|
||||
var pt3 = factory.CreatePropertyType("size", 1003);
|
||||
IEnumerable<IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
|
||||
{
|
||||
yield return factory.CreatePropertyType(contentType, "legend", 1004);
|
||||
yield return factory.CreatePropertyType(contentType, "image", 1005);
|
||||
yield return factory.CreatePropertyType(contentType, "size", 1003);
|
||||
}
|
||||
|
||||
const string val1 = "boom bam";
|
||||
const int val2 = 0;
|
||||
const int val3 = 666;
|
||||
|
||||
var guid = Guid.NewGuid();
|
||||
|
||||
var ct = factory.CreateContentType(0, "alias", new[] { pt1, pt2, pt3 });
|
||||
var ct = factory.CreateContentType(0, "alias", CreatePropertyTypes);
|
||||
|
||||
var c = new ImageWithLegendModel(ct, guid, new Dictionary<string, object>
|
||||
{
|
||||
|
||||
@@ -253,7 +253,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
|
||||
internal class SolidPublishedProperty : IPublishedProperty
|
||||
{
|
||||
public PublishedPropertyType PropertyType { get; set; }
|
||||
public IPublishedPropertyType PropertyType { get; set; }
|
||||
public string Alias { get; set; }
|
||||
public object SolidSourceValue { get; set; }
|
||||
public object SolidValue { get; set; }
|
||||
@@ -397,7 +397,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
|
||||
class AutoPublishedContentType : PublishedContentType
|
||||
{
|
||||
private static readonly PublishedPropertyType Default;
|
||||
private static readonly IPublishedPropertyType Default;
|
||||
|
||||
static AutoPublishedContentType()
|
||||
{
|
||||
@@ -412,11 +412,19 @@ namespace Umbraco.Tests.PublishedContent
|
||||
: base(id, alias, PublishedItemType.Content, Enumerable.Empty<string>(), propertyTypes, ContentVariation.Nothing)
|
||||
{ }
|
||||
|
||||
public AutoPublishedContentType(int id, string alias, Func<IPublishedContentType, IEnumerable<IPublishedPropertyType>> propertyTypes)
|
||||
: base(id, alias, PublishedItemType.Content, Enumerable.Empty<string>(), propertyTypes, ContentVariation.Nothing)
|
||||
{ }
|
||||
|
||||
public AutoPublishedContentType(int id, string alias, IEnumerable<string> compositionAliases, IEnumerable<PublishedPropertyType> propertyTypes)
|
||||
: base(id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, ContentVariation.Nothing)
|
||||
{ }
|
||||
|
||||
public override PublishedPropertyType GetPropertyType(string alias)
|
||||
public AutoPublishedContentType(int id, string alias, IEnumerable<string> compositionAliases, Func<IPublishedContentType, IEnumerable<IPublishedPropertyType>> propertyTypes)
|
||||
: base(id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, ContentVariation.Nothing)
|
||||
{ }
|
||||
|
||||
public override IPublishedPropertyType GetPropertyType(string alias)
|
||||
{
|
||||
var propertyType = base.GetPropertyType(alias);
|
||||
return propertyType ?? Default;
|
||||
|
||||
Reference in New Issue
Block a user