Skip to content

Commit b0ff096

Browse files
committed
Fixed Tests
1 parent 698e6b1 commit b0ff096

File tree

6 files changed

+39
-24
lines changed

6 files changed

+39
-24
lines changed

src/Umbraco.Core/Models/ContentType.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class ContentType : ContentTypeCompositionBase, IContentType
2727
public ContentType(int parentId) : base(parentId)
2828
{
2929
_allowedTemplates = new List<ITemplate>();
30+
HistoryCleanup = new HistoryCleanup();
3031
}
3132

3233

@@ -40,6 +41,7 @@ public ContentType(IContentType parent, string alias)
4041
: base(parent, alias)
4142
{
4243
_allowedTemplates = new List<ITemplate>();
44+
HistoryCleanup = new HistoryCleanup();
4345
}
4446

4547
/// <inheritdoc />

src/Umbraco.Tests/Persistence/Repositories/ContentTypeRepositoryTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public void Can_Perform_Add_On_ContentTypeRepository()
304304
Assert.AreNotEqual(propertyType.Key, Guid.Empty);
305305
}
306306

307-
TestHelper.AssertPropertyValuesAreEqual(fetched, contentType, "yyyy-MM-dd HH:mm:ss", ignoreProperties: new [] { "DefaultTemplate", "AllowedTemplates", "UpdateDate" });
307+
TestHelper.AssertPropertyValuesAreEqual(fetched, contentType, "yyyy-MM-dd HH:mm:ss", ignoreProperties: new [] { "DefaultTemplate", "AllowedTemplates", "UpdateDate", "HistoryCleanup" });
308308
}
309309
}
310310

@@ -415,6 +415,7 @@ private DocumentTypeSave MapToContentTypeSave(DocumentTypeDisplay display)
415415
//Alias = display.Alias,
416416
Path = display.Path,
417417
//AdditionalData = display.AdditionalData,
418+
HistoryCleanup = display.HistoryCleanup,
418419

419420
// ContentTypeBasic
420421
Alias = display.Alias,

src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Umbraco.Core.Composing;
1010
using Umbraco.Core.Configuration;
1111
using Umbraco.Core.Models;
12+
using Umbraco.Core.Models.ContentEditing;
1213
using Umbraco.Core.Models.PublishedContent;
1314
using Umbraco.Core.Persistence;
1415
using Umbraco.Core.Persistence.Dtos;
@@ -49,7 +50,7 @@ protected override IPublishedSnapshotService CreatePublishedSnapshotService()
4950
var runtimeStateMock = new Mock<IRuntimeState>();
5051
runtimeStateMock.Setup(x => x.Level).Returns(() => RuntimeLevel.Run);
5152

52-
var contentTypeFactory = Factory.GetInstance<IPublishedContentTypeFactory>();
53+
var contentTypeFactory = Factory.GetInstance<IPublishedContentTypeFactory>();
5354
var documentRepository = Factory.GetInstance<IDocumentRepository>();
5455
var mediaRepository = Mock.Of<IMediaRepository>();
5556
var memberRepository = Mock.Of<IMemberRepository>();
@@ -128,8 +129,8 @@ private string GetJson(int id)
128129
[TestCase(ContentVariation.CultureAndSegment, ContentVariation.CultureAndSegment, false)]
129130
public void Change_Content_Type_Variation_Clears_Redirects(ContentVariation startingContentTypeVariation, ContentVariation changedContentTypeVariation, bool shouldUrlRedirectsBeCleared)
130131
{
131-
var contentType = MockedContentTypes.CreateBasicContentType();
132-
contentType.Variations = startingContentTypeVariation;
132+
var contentType = MockedContentTypes.CreateBasicContentType();
133+
contentType.Variations = startingContentTypeVariation;
133134
ServiceContext.ContentTypeService.Save(contentType);
134135
var contentType2 = MockedContentTypes.CreateBasicContentType("test");
135136
ServiceContext.ContentTypeService.Save(contentType2);
@@ -408,7 +409,7 @@ public void Change_Property_Type_From_Invariant_Variant(ContentVariation invaria
408409
Assert.AreEqual("hello world", doc.GetValue("title"));
409410
Assert.IsTrue(doc.IsCultureEdited("en-US")); //invariant prop changes show up on default lang
410411
Assert.IsTrue(doc.Edited);
411-
412+
412413
//change the property type to be variant
413414
contentType.PropertyTypes.First().Variations = variant;
414415
ServiceContext.ContentTypeService.Save(contentType);
@@ -436,7 +437,7 @@ public void Change_Property_Type_From_Variant_Invariant(ContentVariation variant
436437
{
437438
//create content type with a property type that varies by culture
438439
var contentType = MockedContentTypes.CreateBasicContentType();
439-
// content type supports all variations
440+
// content type supports all variations
440441
contentType.Variations = ContentVariation.Culture | ContentVariation.Segment;
441442
var properties = CreatePropertyCollection(("title", variant));
442443
contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" });
@@ -473,7 +474,7 @@ public void Change_Property_Type_From_Variant_Invariant_On_A_Composition(Content
473474
{
474475
//create content type with a property type that varies by culture
475476
var contentType = MockedContentTypes.CreateBasicContentType();
476-
// content type supports all variations
477+
// content type supports all variations
477478
contentType.Variations = ContentVariation.Culture | ContentVariation.Segment;
478479
var properties = CreatePropertyCollection(("title", variant));
479480
contentType.PropertyGroups.Add(new PropertyGroup(properties) { Name = "Content" });
@@ -880,14 +881,14 @@ public void Change_Property_Variations_From_Variant_To_Invariant_And_Ensure_Edit
880881
// switch property type to Invariant
881882
contentType.PropertyTypes.First(x => x.Alias == "value1").Variations = invariant;
882883
ServiceContext.ContentTypeService.Save(contentType); //This is going to have to re-normalize the "Edited" flag
883-
884+
884885
document = ServiceContext.ContentService.GetById(document.Id);
885886
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
886887
Assert.IsFalse(document.IsCultureEdited("fr")); //This will be false because nothing has changed for this culture and the property no longer reflects variant changes
887888
Assert.IsTrue(document.Edited);
888889

889890
//update the invariant value and publish
890-
document.SetValue("value1", "v1inv");
891+
document.SetValue("value1", "v1inv");
891892
ServiceContext.ContentService.SaveAndPublish(document);
892893

893894
document = ServiceContext.ContentService.GetById(document.Id);
@@ -907,7 +908,7 @@ public void Change_Property_Variations_From_Variant_To_Invariant_And_Ensure_Edit
907908
// switch property back to Culture
908909
contentType.PropertyTypes.First(x => x.Alias == "value1").Variations = variant;
909910
ServiceContext.ContentTypeService.Save(contentType);
910-
911+
911912
document = ServiceContext.ContentService.GetById(document.Id);
912913
Assert.AreEqual("v1inv", document.GetValue("value1", "en")); //The invariant property value gets copied over to the default language
913914
Assert.AreEqual("v1inv", document.GetValue("value1", "en", published: true));
@@ -971,17 +972,17 @@ public void Change_Property_Variations_From_Invariant_To_Variant_And_Ensure_Edit
971972
Assert.AreEqual("doc1en", document.GetCultureName("en"));
972973
Assert.AreEqual("doc1fr", document.GetCultureName("fr"));
973974
Assert.AreEqual("v1en", document.GetValue("value1"));
974-
Assert.AreEqual("v1en-init", document.GetValue("value1", published: true));
975+
Assert.AreEqual("v1en-init", document.GetValue("value1", published: true));
975976
Assert.IsTrue(document.IsCultureEdited("en")); //This is true because the invariant property reflects changes on the default lang
976-
Assert.IsFalse(document.IsCultureEdited("fr"));
977+
Assert.IsFalse(document.IsCultureEdited("fr"));
977978
Assert.IsTrue(document.Edited);
978979

979980
// switch property type to Culture
980981
contentType.PropertyTypes.First(x => x.Alias == "value1").Variations = variant;
981982
ServiceContext.ContentTypeService.Save(contentType); //This is going to have to re-normalize the "Edited" flag
982983

983984
document = ServiceContext.ContentService.GetById(document.Id);
984-
Assert.IsTrue(document.IsCultureEdited("en")); //Remains true
985+
Assert.IsTrue(document.IsCultureEdited("en")); //Remains true
985986
Assert.IsFalse(document.IsCultureEdited("fr")); //False because no french property has ever been edited
986987
Assert.IsTrue(document.Edited);
987988

@@ -1011,7 +1012,7 @@ public void Change_Property_Variations_From_Invariant_To_Variant_And_Ensure_Edit
10111012
Assert.IsNull(document.GetValue("value1", "fr")); //The values are there but the business logic returns null
10121013
Assert.IsNull(document.GetValue("value1", "fr", published: true)); //The values are there but the business logic returns null
10131014
Assert.IsFalse(document.IsCultureEdited("en")); //The variant published AND edited values are copied over to the invariant
1014-
Assert.IsFalse(document.IsCultureEdited("fr"));
1015+
Assert.IsFalse(document.IsCultureEdited("fr"));
10151016
Assert.IsFalse(document.Edited);
10161017

10171018
}
@@ -1263,7 +1264,8 @@ private void CreateFrenchAndEnglishLangs()
12631264
{
12641265
Alias = alias,
12651266
Name = alias,
1266-
Variations = variance
1267+
Variations = variance,
1268+
HistoryCleanup = new HistoryCleanup()
12671269
};
12681270

12691271
private PropertyTypeCollection CreatePropertyCollection(params (string alias, ContentVariation variance)[] props)

src/Umbraco.Tests/TestHelpers/Entities/MockedContentTypes.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using Umbraco.Core;
44
using Umbraco.Core.Models;
5+
using Umbraco.Core.Models.ContentEditing;
56

67
namespace Umbraco.Tests.TestHelpers.Entities
78
{
@@ -19,6 +20,7 @@ public static ContentType CreateBasicContentType(string alias = "basePage", stri
1920
contentType.SortOrder = 1;
2021
contentType.CreatorId = 0;
2122
contentType.Trashed = false;
23+
contentType.HistoryCleanup = new HistoryCleanup();
2224

2325
//ensure that nothing is marked as dirty
2426
contentType.ResetDirtyProperties(false);
@@ -121,7 +123,8 @@ public static ContentType CreateSeoContentType()
121123
Thumbnail = "doc.png",
122124
SortOrder = 1,
123125
CreatorId = 0,
124-
Trashed = false
126+
Trashed = false,
127+
HistoryCleanup = new HistoryCleanup()
125128
};
126129

127130
var metaCollection = new PropertyTypeCollection(true);
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
using System.Runtime.Serialization;
22
using Umbraco.Core.Models.ContentEditing;
33

4-
namespace Umbraco.Web.Models.ContentEditing;
5-
6-
[DataContract(Name = "historyCleanup", Namespace = "")]
7-
public class HistoryCleanupViewModel : HistoryCleanup
4+
namespace Umbraco.Web.Models.ContentEditing
85
{
9-
[DataMember(Name = "globalKeepAllVersionsNewerThanDays")]
10-
public int? GlobalKeepAllVersionsNewerThanDays { get;set; }
6+
[DataContract(Name = "historyCleanup", Namespace = "")]
7+
public class HistoryCleanupViewModel : HistoryCleanup
8+
{
9+
[DataMember(Name = "globalKeepAllVersionsNewerThanDays")]
10+
public int? GlobalKeepAllVersionsNewerThanDays { get;set; }
11+
12+
[DataMember(Name = "globalKeepLatestVersionPerDayForDays")]
13+
public int? GlobalKeepLatestVersionPerDayForDays { get; set;}
14+
15+
[DataMember(Name = "GlobalEnableCleanup")]
16+
public bool GlobalEnableCleanup { get; set; }
17+
}
1118

12-
[DataMember(Name = "globalKeepLatestVersionPerDayForDays")]
13-
public int? GlobalKeepLatestVersionPerDayForDays { get; set;}
1419
}
20+

src/Umbraco.Web/Models/Mapping/ContentTypeMapDefinition.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ private void Map(IContentType source, DocumentTypeDisplay target, MapperContext
135135
KeepLatestVersionPerDayForDays = source.HistoryCleanup.KeepLatestVersionPerDayForDays,
136136
GlobalKeepAllVersionsNewerThanDays = _umbracoSettingsSection.Content.ContentVersionCleanupPolicyGlobalSettings.KeepAllVersionsNewerThanDays,
137137
GlobalKeepLatestVersionPerDayForDays = _umbracoSettingsSection.Content.ContentVersionCleanupPolicyGlobalSettings.KeepLatestVersionPerDayForDays,
138+
GlobalEnableCleanup = _umbracoSettingsSection.Content.ContentVersionCleanupPolicyGlobalSettings.EnableCleanup,
138139
};
139140

140141
target.AllowCultureVariant = source.VariesByCulture();

0 commit comments

Comments
 (0)