Skip to content

Commit 7e9def9

Browse files
author
nikolajlauridsen
committed
Add tests
1 parent 009b36b commit 7e9def9

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using System.Linq;
2+
using NUnit.Framework;
3+
using Umbraco.Cms.Core.Models.ContentEditing;
4+
using Umbraco.Cms.Tests.Common.Builders;
5+
6+
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Models
7+
{
8+
[TestFixture]
9+
public class ContentTypeHistoryCleanupTests
10+
{
11+
[Test]
12+
public void Changing_Keep_all_Makes_ContentType_Dirty()
13+
{
14+
var contentType = ContentTypeBuilder.CreateBasicContentType();
15+
16+
Assert.IsFalse(contentType.IsDirty());
17+
18+
var newValue = 2;
19+
contentType.HistoryCleanup.KeepAllVersionsNewerThanDays = newValue;
20+
Assert.IsTrue(contentType.IsDirty());
21+
Assert.AreEqual(newValue, contentType.HistoryCleanup.KeepAllVersionsNewerThanDays);
22+
}
23+
24+
[Test]
25+
public void Changing_Keep_latest_Makes_ContentType_Dirty()
26+
{
27+
var contentType = ContentTypeBuilder.CreateBasicContentType();
28+
29+
Assert.IsFalse(contentType.IsDirty());
30+
31+
var newValue = 2;
32+
contentType.HistoryCleanup.KeepLatestVersionPerDayForDays = newValue;
33+
Assert.IsTrue(contentType.IsDirty());
34+
Assert.AreEqual(newValue, contentType.HistoryCleanup.KeepLatestVersionPerDayForDays);
35+
}
36+
37+
[Test]
38+
public void Changing_Prevent_Cleanup_Makes_ContentType_Dirty()
39+
{
40+
var contentType = ContentTypeBuilder.CreateBasicContentType();
41+
42+
Assert.IsFalse(contentType.IsDirty());
43+
44+
var newValue = true;
45+
contentType.HistoryCleanup.PreventCleanup = newValue;
46+
Assert.IsTrue(contentType.IsDirty());
47+
Assert.AreEqual(newValue, contentType.HistoryCleanup.PreventCleanup);
48+
}
49+
50+
[Test]
51+
public void Replacing_History_Cleanup_Registers_As_Dirty()
52+
{
53+
var contentType = ContentTypeBuilder.CreateBasicContentType();
54+
Assert.IsFalse(contentType.IsDirty());
55+
56+
contentType.HistoryCleanup = new HistoryCleanup();
57+
58+
Assert.IsTrue(contentType.IsDirty());
59+
Assert.IsTrue(contentType.IsPropertyDirty(nameof(contentType.HistoryCleanup)));
60+
}
61+
62+
[Test]
63+
public void Replacing_History_Cleanup_Removes_Old_Dirty_History_Properties()
64+
{
65+
var contentType = ContentTypeBuilder.CreateBasicContentType();
66+
67+
contentType.Alias = "NewValue";
68+
contentType.HistoryCleanup.KeepAllVersionsNewerThanDays = 2;
69+
70+
contentType.PropertyChanged += (sender, args) =>
71+
{
72+
// Ensure that property changed is only invoked for history cleanup
73+
Assert.AreEqual(nameof(contentType.HistoryCleanup), args.PropertyName);
74+
};
75+
76+
// Since we're replacing the entire HistoryCleanup the changed property is no longer dirty, the entire HistoryCleanup is
77+
contentType.HistoryCleanup = new HistoryCleanup();
78+
79+
Assert.Multiple(() =>
80+
{
81+
Assert.IsTrue(contentType.IsDirty());
82+
Assert.IsFalse(contentType.WasDirty());
83+
Assert.AreEqual(2, contentType.GetDirtyProperties().Count());
84+
Assert.IsTrue(contentType.IsPropertyDirty(nameof(contentType.HistoryCleanup)));
85+
Assert.IsTrue(contentType.IsPropertyDirty(nameof(contentType.Alias)));
86+
});
87+
}
88+
89+
[Test]
90+
public void Old_History_Cleanup_Reference_Doesnt_Make_Content_Type_Dirty()
91+
{
92+
var contentType = ContentTypeBuilder.CreateBasicContentType();
93+
var oldHistoryCleanup = contentType.HistoryCleanup;
94+
95+
contentType.HistoryCleanup = new HistoryCleanup();
96+
contentType.ResetDirtyProperties();
97+
contentType.ResetWereDirtyProperties();
98+
99+
oldHistoryCleanup.KeepAllVersionsNewerThanDays = 2;
100+
101+
Assert.IsFalse(contentType.IsDirty());
102+
Assert.IsFalse(contentType.WasDirty());
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)