Fixed Tests

This commit is contained in:
Bjarke Berg
2021-10-29 13:58:50 +02:00
parent 698e6b1533
commit b0ff096a8a
6 changed files with 39 additions and 24 deletions

View File

@@ -27,6 +27,7 @@ namespace Umbraco.Core.Models
public ContentType(int parentId) : base(parentId)
{
_allowedTemplates = new List<ITemplate>();
HistoryCleanup = new HistoryCleanup();
}
@@ -40,6 +41,7 @@ namespace Umbraco.Core.Models
: base(parent, alias)
{
_allowedTemplates = new List<ITemplate>();
HistoryCleanup = new HistoryCleanup();
}
/// <inheritdoc />

View File

@@ -304,7 +304,7 @@ namespace Umbraco.Tests.Persistence.Repositories
Assert.AreNotEqual(propertyType.Key, Guid.Empty);
}
TestHelper.AssertPropertyValuesAreEqual(fetched, contentType, "yyyy-MM-dd HH:mm:ss", ignoreProperties: new [] { "DefaultTemplate", "AllowedTemplates", "UpdateDate" });
TestHelper.AssertPropertyValuesAreEqual(fetched, contentType, "yyyy-MM-dd HH:mm:ss", ignoreProperties: new [] { "DefaultTemplate", "AllowedTemplates", "UpdateDate", "HistoryCleanup" });
}
}
@@ -415,6 +415,7 @@ namespace Umbraco.Tests.Persistence.Repositories
//Alias = display.Alias,
Path = display.Path,
//AdditionalData = display.AdditionalData,
HistoryCleanup = display.HistoryCleanup,
// ContentTypeBasic
Alias = display.Alias,

View File

@@ -9,6 +9,7 @@ using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Models;
using Umbraco.Core.Models.ContentEditing;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Dtos;
@@ -49,7 +50,7 @@ namespace Umbraco.Tests.Services
var runtimeStateMock = new Mock<IRuntimeState>();
runtimeStateMock.Setup(x => x.Level).Returns(() => RuntimeLevel.Run);
var contentTypeFactory = Factory.GetInstance<IPublishedContentTypeFactory>();
var contentTypeFactory = Factory.GetInstance<IPublishedContentTypeFactory>();
var documentRepository = Factory.GetInstance<IDocumentRepository>();
var mediaRepository = Mock.Of<IMediaRepository>();
var memberRepository = Mock.Of<IMemberRepository>();
@@ -128,8 +129,8 @@ namespace Umbraco.Tests.Services
[TestCase(ContentVariation.CultureAndSegment, ContentVariation.CultureAndSegment, false)]
public void Change_Content_Type_Variation_Clears_Redirects(ContentVariation startingContentTypeVariation, ContentVariation changedContentTypeVariation, bool shouldUrlRedirectsBeCleared)
{
var contentType = MockedContentTypes.CreateBasicContentType();
contentType.Variations = startingContentTypeVariation;
var contentType = MockedContentTypes.CreateBasicContentType();
contentType.Variations = startingContentTypeVariation;
ServiceContext.ContentTypeService.Save(contentType);
var contentType2 = MockedContentTypes.CreateBasicContentType("test");
ServiceContext.ContentTypeService.Save(contentType2);
@@ -408,7 +409,7 @@ namespace Umbraco.Tests.Services
Assert.AreEqual("hello world", doc.GetValue("title"));
Assert.IsTrue(doc.IsCultureEdited("en-US")); //invariant prop changes show up on default lang
Assert.IsTrue(doc.Edited);
//change the property type to be variant
contentType.PropertyTypes.First().Variations = variant;
ServiceContext.ContentTypeService.Save(contentType);
@@ -436,7 +437,7 @@ namespace Umbraco.Tests.Services
{
//create content type with a property type that varies by culture
var contentType = MockedContentTypes.CreateBasicContentType();
// content type supports all variations
// content type supports all variations
contentType.Variations = ContentVariation.Culture | ContentVariation.Segment;
var properties = CreatePropertyCollection(("title", variant));
contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" });
@@ -473,7 +474,7 @@ namespace Umbraco.Tests.Services
{
//create content type with a property type that varies by culture
var contentType = MockedContentTypes.CreateBasicContentType();
// content type supports all variations
// content type supports all variations
contentType.Variations = ContentVariation.Culture | ContentVariation.Segment;
var properties = CreatePropertyCollection(("title", variant));
contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" });
@@ -880,14 +881,14 @@ namespace Umbraco.Tests.Services
// switch property type to Invariant
contentType.PropertyTypes.First(x => x.Alias == "value1").Variations = invariant;
ServiceContext.ContentTypeService.Save(contentType); //This is going to have to re-normalize the "Edited" flag
document = ServiceContext.ContentService.GetById(document.Id);
Assert.IsTrue(document.IsCultureEdited("en")); //This will remain true because there is now a pending change for the invariant property data which is flagged under the default lang
Assert.IsFalse(document.IsCultureEdited("fr")); //This will be false because nothing has changed for this culture and the property no longer reflects variant changes
Assert.IsTrue(document.Edited);
//update the invariant value and publish
document.SetValue("value1", "v1inv");
document.SetValue("value1", "v1inv");
ServiceContext.ContentService.SaveAndPublish(document);
document = ServiceContext.ContentService.GetById(document.Id);
@@ -907,7 +908,7 @@ namespace Umbraco.Tests.Services
// switch property back to Culture
contentType.PropertyTypes.First(x => x.Alias == "value1").Variations = variant;
ServiceContext.ContentTypeService.Save(contentType);
document = ServiceContext.ContentService.GetById(document.Id);
Assert.AreEqual("v1inv", document.GetValue("value1", "en")); //The invariant property value gets copied over to the default language
Assert.AreEqual("v1inv", document.GetValue("value1", "en", published: true));
@@ -971,9 +972,9 @@ namespace Umbraco.Tests.Services
Assert.AreEqual("doc1en", document.GetCultureName("en"));
Assert.AreEqual("doc1fr", document.GetCultureName("fr"));
Assert.AreEqual("v1en", document.GetValue("value1"));
Assert.AreEqual("v1en-init", document.GetValue("value1", published: true));
Assert.AreEqual("v1en-init", document.GetValue("value1", published: true));
Assert.IsTrue(document.IsCultureEdited("en")); //This is true because the invariant property reflects changes on the default lang
Assert.IsFalse(document.IsCultureEdited("fr"));
Assert.IsFalse(document.IsCultureEdited("fr"));
Assert.IsTrue(document.Edited);
// switch property type to Culture
@@ -981,7 +982,7 @@ namespace Umbraco.Tests.Services
ServiceContext.ContentTypeService.Save(contentType); //This is going to have to re-normalize the "Edited" flag
document = ServiceContext.ContentService.GetById(document.Id);
Assert.IsTrue(document.IsCultureEdited("en")); //Remains true
Assert.IsTrue(document.IsCultureEdited("en")); //Remains true
Assert.IsFalse(document.IsCultureEdited("fr")); //False because no french property has ever been edited
Assert.IsTrue(document.Edited);
@@ -1011,7 +1012,7 @@ namespace Umbraco.Tests.Services
Assert.IsNull(document.GetValue("value1", "fr")); //The values are there but the business logic returns null
Assert.IsNull(document.GetValue("value1", "fr", published: true)); //The values are there but the business logic returns null
Assert.IsFalse(document.IsCultureEdited("en")); //The variant published AND edited values are copied over to the invariant
Assert.IsFalse(document.IsCultureEdited("fr"));
Assert.IsFalse(document.IsCultureEdited("fr"));
Assert.IsFalse(document.Edited);
}
@@ -1263,7 +1264,8 @@ namespace Umbraco.Tests.Services
{
Alias = alias,
Name = alias,
Variations = variance
Variations = variance,
HistoryCleanup = new HistoryCleanup()
};
private PropertyTypeCollection CreatePropertyCollection(params (string alias, ContentVariation variance)[] props)

View File

@@ -2,6 +2,7 @@
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.ContentEditing;
namespace Umbraco.Tests.TestHelpers.Entities
{
@@ -19,6 +20,7 @@ namespace Umbraco.Tests.TestHelpers.Entities
contentType.SortOrder = 1;
contentType.CreatorId = 0;
contentType.Trashed = false;
contentType.HistoryCleanup = new HistoryCleanup();
//ensure that nothing is marked as dirty
contentType.ResetDirtyProperties(false);
@@ -121,7 +123,8 @@ namespace Umbraco.Tests.TestHelpers.Entities
Thumbnail = "doc.png",
SortOrder = 1,
CreatorId = 0,
Trashed = false
Trashed = false,
HistoryCleanup = new HistoryCleanup()
};
var metaCollection = new PropertyTypeCollection(true);

View File

@@ -1,14 +1,20 @@
using System.Runtime.Serialization;
using Umbraco.Core.Models.ContentEditing;
namespace Umbraco.Web.Models.ContentEditing;
[DataContract(Name = "historyCleanup", Namespace = "")]
public class HistoryCleanupViewModel : HistoryCleanup
namespace Umbraco.Web.Models.ContentEditing
{
[DataMember(Name = "globalKeepAllVersionsNewerThanDays")]
public int? GlobalKeepAllVersionsNewerThanDays { get;set; }
[DataContract(Name = "historyCleanup", Namespace = "")]
public class HistoryCleanupViewModel : HistoryCleanup
{
[DataMember(Name = "globalKeepAllVersionsNewerThanDays")]
public int? GlobalKeepAllVersionsNewerThanDays { get;set; }
[DataMember(Name = "globalKeepLatestVersionPerDayForDays")]
public int? GlobalKeepLatestVersionPerDayForDays { get; set;}
[DataMember(Name = "GlobalEnableCleanup")]
public bool GlobalEnableCleanup { get; set; }
}
[DataMember(Name = "globalKeepLatestVersionPerDayForDays")]
public int? GlobalKeepLatestVersionPerDayForDays { get; set;}
}

View File

@@ -135,6 +135,7 @@ namespace Umbraco.Web.Models.Mapping
KeepLatestVersionPerDayForDays = source.HistoryCleanup.KeepLatestVersionPerDayForDays,
GlobalKeepAllVersionsNewerThanDays = _umbracoSettingsSection.Content.ContentVersionCleanupPolicyGlobalSettings.KeepAllVersionsNewerThanDays,
GlobalKeepLatestVersionPerDayForDays = _umbracoSettingsSection.Content.ContentVersionCleanupPolicyGlobalSettings.KeepLatestVersionPerDayForDays,
GlobalEnableCleanup = _umbracoSettingsSection.Content.ContentVersionCleanupPolicyGlobalSettings.EnableCleanup,
};
target.AllowCultureVariant = source.VariesByCulture();