From b0ff096a8a8b7ba8699ae179b7c68d6f1e082ff1 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 29 Oct 2021 13:58:50 +0200 Subject: [PATCH] Fixed Tests --- src/Umbraco.Core/Models/ContentType.cs | 2 ++ .../Repositories/ContentTypeRepositoryTest.cs | 3 +- .../ContentTypeServiceVariantsTests.cs | 30 ++++++++++--------- .../Entities/MockedContentTypes.cs | 5 +++- .../Models/ContentEditing/HistoryCleanup.cs | 22 +++++++++----- .../Mapping/ContentTypeMapDefinition.cs | 1 + 6 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/Umbraco.Core/Models/ContentType.cs b/src/Umbraco.Core/Models/ContentType.cs index 70bc9eaa4af3..ac8b90630656 100644 --- a/src/Umbraco.Core/Models/ContentType.cs +++ b/src/Umbraco.Core/Models/ContentType.cs @@ -27,6 +27,7 @@ public class ContentType : ContentTypeCompositionBase, IContentType public ContentType(int parentId) : base(parentId) { _allowedTemplates = new List(); + HistoryCleanup = new HistoryCleanup(); } @@ -40,6 +41,7 @@ public ContentType(IContentType parent, string alias) : base(parent, alias) { _allowedTemplates = new List(); + HistoryCleanup = new HistoryCleanup(); } /// diff --git a/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs index 6b35a79eb28d..5a45239f14a5 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs @@ -304,7 +304,7 @@ public void Can_Perform_Add_On_ContentTypeRepository() 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 @@ private DocumentTypeSave MapToContentTypeSave(DocumentTypeDisplay display) //Alias = display.Alias, Path = display.Path, //AdditionalData = display.AdditionalData, + HistoryCleanup = display.HistoryCleanup, // ContentTypeBasic Alias = display.Alias, diff --git a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs index a3735c0ac336..f4e8bcac9248 100644 --- a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs +++ b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs @@ -9,6 +9,7 @@ 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 @@ protected override IPublishedSnapshotService CreatePublishedSnapshotService() var runtimeStateMock = new Mock(); runtimeStateMock.Setup(x => x.Level).Returns(() => RuntimeLevel.Run); - var contentTypeFactory = Factory.GetInstance(); + var contentTypeFactory = Factory.GetInstance(); var documentRepository = Factory.GetInstance(); var mediaRepository = Mock.Of(); var memberRepository = Mock.Of(); @@ -128,8 +129,8 @@ private string GetJson(int id) [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 @@ public void Change_Property_Type_From_Invariant_Variant(ContentVariation invaria 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 @@ public void Change_Property_Type_From_Variant_Invariant(ContentVariation variant { //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 @@ public void Change_Property_Type_From_Variant_Invariant_On_A_Composition(Content { //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 @@ public void Change_Property_Variations_From_Variant_To_Invariant_And_Ensure_Edit // 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 @@ public void Change_Property_Variations_From_Variant_To_Invariant_And_Ensure_Edit // 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 @@ public void Change_Property_Variations_From_Invariant_To_Variant_And_Ensure_Edit 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 @@ public void Change_Property_Variations_From_Invariant_To_Variant_And_Ensure_Edit 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 @@ public void Change_Property_Variations_From_Invariant_To_Variant_And_Ensure_Edit 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 @@ private void CreateFrenchAndEnglishLangs() { Alias = alias, Name = alias, - Variations = variance + Variations = variance, + HistoryCleanup = new HistoryCleanup() }; private PropertyTypeCollection CreatePropertyCollection(params (string alias, ContentVariation variance)[] props) diff --git a/src/Umbraco.Tests/TestHelpers/Entities/MockedContentTypes.cs b/src/Umbraco.Tests/TestHelpers/Entities/MockedContentTypes.cs index 123f59fae8ec..557676cd11f6 100644 --- a/src/Umbraco.Tests/TestHelpers/Entities/MockedContentTypes.cs +++ b/src/Umbraco.Tests/TestHelpers/Entities/MockedContentTypes.cs @@ -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 @@ public static ContentType CreateBasicContentType(string alias = "basePage", stri 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 @@ public static ContentType CreateSeoContentType() Thumbnail = "doc.png", SortOrder = 1, CreatorId = 0, - Trashed = false + Trashed = false, + HistoryCleanup = new HistoryCleanup() }; var metaCollection = new PropertyTypeCollection(true); diff --git a/src/Umbraco.Web/Models/ContentEditing/HistoryCleanup.cs b/src/Umbraco.Web/Models/ContentEditing/HistoryCleanup.cs index c56b02d755f1..7580ee826aee 100644 --- a/src/Umbraco.Web/Models/ContentEditing/HistoryCleanup.cs +++ b/src/Umbraco.Web/Models/ContentEditing/HistoryCleanup.cs @@ -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;} } + diff --git a/src/Umbraco.Web/Models/Mapping/ContentTypeMapDefinition.cs b/src/Umbraco.Web/Models/Mapping/ContentTypeMapDefinition.cs index 647aa0d1297a..45c6bdfde3a5 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentTypeMapDefinition.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentTypeMapDefinition.cs @@ -135,6 +135,7 @@ private void Map(IContentType source, DocumentTypeDisplay target, MapperContext KeepLatestVersionPerDayForDays = source.HistoryCleanup.KeepLatestVersionPerDayForDays, GlobalKeepAllVersionsNewerThanDays = _umbracoSettingsSection.Content.ContentVersionCleanupPolicyGlobalSettings.KeepAllVersionsNewerThanDays, GlobalKeepLatestVersionPerDayForDays = _umbracoSettingsSection.Content.ContentVersionCleanupPolicyGlobalSettings.KeepLatestVersionPerDayForDays, + GlobalEnableCleanup = _umbracoSettingsSection.Content.ContentVersionCleanupPolicyGlobalSettings.EnableCleanup, }; target.AllowCultureVariant = source.VariesByCulture();