Adds a couple of tests which yielded some other issues with getting urls by culture, those are now fixed

This commit is contained in:
Shannon
2018-04-27 13:27:15 +10:00
parent 73567ffdce
commit c19dbeda23
11 changed files with 226 additions and 96 deletions

View File

@@ -11,6 +11,7 @@ using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Stubs;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
@@ -99,7 +100,7 @@ namespace Umbraco.Tests.Published
var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary<string, object> { { "prop1", "1234" } }, false);
var cntType1 = contentTypeFactory.CreateContentType(1001, "cnt1", Array.Empty<PublishedPropertyType>());
var cnt1 = new PublishedSnapshotTestObjects.TestPublishedContent(cntType1, 1234, Guid.NewGuid(), new Dictionary<string, object>(), false);
var cnt1 = new TestPublishedContent(cntType1, 1234, Guid.NewGuid(), new Dictionary<string, object>(), false);
cacheContent[cnt1.Id] = cnt1;
Assert.AreSame(cnt1, element1.Value("prop1"));
@@ -200,8 +201,8 @@ namespace Umbraco.Tests.Published
var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary<string, object> { { "prop1", "val1" } }, false);
var element2 = new PublishedElement(elementType2, Guid.NewGuid(), new Dictionary<string, object> { { "prop2", "1003" } }, false);
var cnt1 = new PublishedSnapshotTestObjects.TestPublishedContent(contentType1, 1003, Guid.NewGuid(), new Dictionary<string, object> { { "prop1", "val1" } }, false);
var cnt2 = new PublishedSnapshotTestObjects.TestPublishedContent(contentType2, 1004, Guid.NewGuid(), new Dictionary<string, object> { { "prop2", "1003" } }, false);
var cnt1 = new TestPublishedContent(contentType1, 1003, Guid.NewGuid(), new Dictionary<string, object> { { "prop1", "val1" } }, false);
var cnt2 = new TestPublishedContent(contentType2, 1004, Guid.NewGuid(), new Dictionary<string, object> { { "prop2", "1003" } }, false);
cacheContent[cnt1.Id] = cnt1.CreateModel();
cacheContent[cnt2.Id] = cnt2.CreateModel();

View File

@@ -8,8 +8,6 @@ namespace Umbraco.Tests.Published
{
public class PublishedSnapshotTestObjects
{
#region Published models
[PublishedModel("element1")]
public class TestElementModel1 : PublishedElementModel
{
@@ -49,66 +47,6 @@ namespace Umbraco.Tests.Published
public IEnumerable<TestContentModel1> Prop2 => this.Value<IEnumerable<TestContentModel1>>("prop2");
}
#endregion
#region Support classes
internal class TestPublishedContent : PublishedElement, IPublishedContent
{
public TestPublishedContent(PublishedContentType contentType, int id, Guid key, Dictionary<string, object> values, bool previewing)
: base(contentType, key, values, previewing)
{
Id = id;
}
public int Id { get; }
public int TemplateId { get; set; }
public int SortOrder { get; set; }
public string Name { get; set; }
public IReadOnlyDictionary<string, PublishedCultureName> CultureNames => throw new NotSupportedException();
public string UrlName { get; set; }
public string DocumentTypeAlias => ContentType.Alias;
public int DocumentTypeId { get; set; }
public string WriterName { get; set; }
public string CreatorName { get; set; }
public int WriterId { get; set; }
public int CreatorId { get; set; }
public string Path { get; set; }
public DateTime CreateDate { get; set; }
public DateTime UpdateDate { get; set; }
public Guid Version { get; set; }
public int Level { get; set; }
public string Url { get; set; }
public PublishedItemType ItemType => ContentType.ItemType;
public bool IsDraft { get; set; }
public IPublishedContent Parent { get; set; }
public IEnumerable<IPublishedContent> Children { get; set; }
// copied from PublishedContentBase
public IPublishedProperty GetProperty(string alias, bool recurse)
{
var property = GetProperty(alias);
if (recurse == false) return property;
IPublishedContent content = this;
var firstNonNullProperty = property;
while (content != null && (property == null || property.HasValue() == false))
{
content = content.Parent;
property = content?.GetProperty(alias);
if (firstNonNullProperty == null && property != null) firstNonNullProperty = property;
}
// if we find a content with the property with a value, return that property
// if we find no content with the property, return null
// if we find a content with the property without a value, return that property
// have to save that first property while we look further up, hence firstNonNullProperty
return property != null && property.HasValue() ? property : firstNonNullProperty;
}
}
#endregion
}
}