Skip to content

Commit

Permalink
Fixed Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bergmania committed Oct 29, 2021
1 parent 698e6b1 commit b0ff096
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/Umbraco.Core/Models/ContentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ContentType : ContentTypeCompositionBase, IContentType
public ContentType(int parentId) : base(parentId)
{
_allowedTemplates = new List<ITemplate>();
HistoryCleanup = new HistoryCleanup();
}


Expand All @@ -40,6 +41,7 @@ public ContentType(IContentType parent, string alias)
: base(parent, alias)
{
_allowedTemplates = new List<ITemplate>();
HistoryCleanup = new HistoryCleanup();
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
}
}

Expand Down Expand Up @@ -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,
Expand Down
30 changes: 16 additions & 14 deletions src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,7 +50,7 @@ protected override IPublishedSnapshotService CreatePublishedSnapshotService()
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>();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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" });
Expand Down Expand Up @@ -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" });
Expand Down Expand Up @@ -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);
Expand All @@ -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));
Expand Down Expand Up @@ -971,17 +972,17 @@ 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
contentType.PropertyTypes.First(x => x.Alias == "value1").Variations = variant;
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);

Expand Down Expand Up @@ -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);

}
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/Umbraco.Tests/TestHelpers/Entities/MockedContentTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.ContentEditing;

namespace Umbraco.Tests.TestHelpers.Entities
{
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 14 additions & 8 deletions src/Umbraco.Web/Models/ContentEditing/HistoryCleanup.cs
Original file line number Diff line number Diff line change
@@ -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;}
}

1 change: 1 addition & 0 deletions src/Umbraco.Web/Models/Mapping/ContentTypeMapDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b0ff096

Please sign in to comment.