Skip to content

Commit 668f4e1

Browse files
authored
Fixed issues with publishing in cache and reintroduced tests (#17168)
* Fixed issues with publishing in cache and reintroduced tests * Fixed issue with republishing and templates
1 parent d6c54b3 commit 668f4e1

File tree

3 files changed

+539
-539
lines changed

3 files changed

+539
-539
lines changed

src/Umbraco.PublishedCache.HybridCache/Factories/CacheNodeFactory.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private bool GetPublishedValue(IContent content, bool preview)
4545
switch (content.PublishedState)
4646
{
4747
case PublishedState.Published:
48-
return preview;
48+
return preview is false;
4949
case PublishedState.Publishing:
5050
return preview is false || content.Published; // The type changes after this operation
5151
case PublishedState.Unpublished:
@@ -62,9 +62,10 @@ private bool GetPublishedValue(IContent content, bool preview)
6262
case PublishedState.Published:
6363
return preview ? content.TemplateId : content.PublishTemplateId;
6464
case PublishedState.Publishing:
65-
return content.TemplateId;// The type changes after this operation is we need to read the draft values
6665
case PublishedState.Unpublished:
6766
case PublishedState.Unpublishing:
67+
return content.TemplateId;
68+
6869
default:
6970
return null;
7071
}
Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
1-
// using NUnit.Framework;
2-
// using Umbraco.Cms.Core;
3-
// using Umbraco.Cms.Core.Models.ContentEditing;
4-
// using Umbraco.Cms.Core.PublishedCache;
5-
// using Umbraco.Cms.Core.Services;
6-
// using Umbraco.Cms.Core.Services.OperationStatus;
7-
// using Umbraco.Cms.Tests.Common.Testing;
8-
// using Umbraco.Cms.Tests.Integration.Testing;
9-
// FIXME
10-
// namespace Umbraco.Cms.Tests.Integration.Umbraco.PublishedCache.HybridCache;
11-
//
12-
// [TestFixture]
13-
// [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
14-
// public class DocumentHybridCacheTemplateTests : UmbracoIntegrationTestWithContentEditing
15-
// {
16-
// protected override void CustomTestSetup(IUmbracoBuilder builder) => builder.AddUmbracoHybridCache();
17-
//
18-
// private IPublishedContentCache PublishedContentHybridCache => GetRequiredService<IPublishedContentCache>();
19-
//
20-
// private IContentEditingService ContentEditingService => GetRequiredService<IContentEditingService>();
21-
//
22-
// [Test]
23-
// public async Task Can_Get_Document_After_Removing_Template()
24-
// {
25-
// // Arrange
26-
// var textPageBefore = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
27-
// Assert.AreEqual(textPageBefore.TemplateId, TemplateId);
28-
// var updateModel = new ContentUpdateModel();
29-
// {
30-
// updateModel.TemplateKey = null;
31-
// updateModel.InvariantName = textPageBefore.Name;
32-
// }
33-
//
34-
// // Act
35-
// var updateContentResult = await ContentEditingService.UpdateAsync(textPageBefore.Key, updateModel, Constants.Security.SuperUserKey);
36-
//
37-
// // Assert
38-
// Assert.AreEqual(updateContentResult.Status, ContentEditingOperationStatus.Success);
39-
// var textPageAfter = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
40-
// // Should this not be null?
41-
// Assert.AreEqual(textPageAfter.TemplateId, null);
42-
// }
43-
// }
1+
using NUnit.Framework;
2+
using Umbraco.Cms.Core;
3+
using Umbraco.Cms.Core.Models.ContentEditing;
4+
using Umbraco.Cms.Core.PublishedCache;
5+
using Umbraco.Cms.Core.Services;
6+
using Umbraco.Cms.Core.Services.OperationStatus;
7+
using Umbraco.Cms.Tests.Common.Testing;
8+
using Umbraco.Cms.Tests.Integration.Testing;
9+
namespace Umbraco.Cms.Tests.Integration.Umbraco.PublishedCache.HybridCache;
10+
11+
[TestFixture]
12+
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
13+
public class DocumentHybridCacheTemplateTests : UmbracoIntegrationTestWithContentEditing
14+
{
15+
protected override void CustomTestSetup(IUmbracoBuilder builder) => builder.AddUmbracoHybridCache();
16+
17+
private IPublishedContentCache PublishedContentHybridCache => GetRequiredService<IPublishedContentCache>();
18+
19+
private IContentEditingService ContentEditingService => GetRequiredService<IContentEditingService>();
20+
21+
[Test]
22+
public async Task Can_Get_Document_After_Removing_Template()
23+
{
24+
// Arrange
25+
var textPageBefore = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
26+
Assert.AreEqual(textPageBefore.TemplateId, TemplateId);
27+
var updateModel = new ContentUpdateModel();
28+
{
29+
updateModel.TemplateKey = null;
30+
updateModel.InvariantName = textPageBefore.Name;
31+
}
32+
33+
// Act
34+
var updateContentResult = await ContentEditingService.UpdateAsync(textPageBefore.Key, updateModel, Constants.Security.SuperUserKey);
35+
36+
// Assert
37+
Assert.AreEqual(updateContentResult.Status, ContentEditingOperationStatus.Success);
38+
var textPageAfter = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
39+
// Should this not be null?
40+
Assert.AreEqual(textPageAfter.TemplateId, null);
41+
}
42+
}

0 commit comments

Comments
 (0)