Skip to content

Commit

Permalink
Fixed issues with publishing in cache and reintroduced tests (#17168)
Browse files Browse the repository at this point in the history
* Fixed issues with publishing in cache and reintroduced tests

* Fixed issue with republishing and templates
  • Loading branch information
bergmania authored Oct 2, 2024
1 parent d6c54b3 commit 668f4e1
Show file tree
Hide file tree
Showing 3 changed files with 539 additions and 539 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private bool GetPublishedValue(IContent content, bool preview)
switch (content.PublishedState)
{
case PublishedState.Published:
return preview;
return preview is false;
case PublishedState.Publishing:
return preview is false || content.Published; // The type changes after this operation
case PublishedState.Unpublished:
Expand All @@ -62,9 +62,10 @@ private bool GetPublishedValue(IContent content, bool preview)
case PublishedState.Published:
return preview ? content.TemplateId : content.PublishTemplateId;
case PublishedState.Publishing:
return content.TemplateId;// The type changes after this operation is we need to read the draft values
case PublishedState.Unpublished:
case PublishedState.Unpublishing:
return content.TemplateId;

default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
// using NUnit.Framework;
// using Umbraco.Cms.Core;
// using Umbraco.Cms.Core.Models.ContentEditing;
// using Umbraco.Cms.Core.PublishedCache;
// using Umbraco.Cms.Core.Services;
// using Umbraco.Cms.Core.Services.OperationStatus;
// using Umbraco.Cms.Tests.Common.Testing;
// using Umbraco.Cms.Tests.Integration.Testing;
// FIXME
// namespace Umbraco.Cms.Tests.Integration.Umbraco.PublishedCache.HybridCache;
//
// [TestFixture]
// [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
// public class DocumentHybridCacheTemplateTests : UmbracoIntegrationTestWithContentEditing
// {
// protected override void CustomTestSetup(IUmbracoBuilder builder) => builder.AddUmbracoHybridCache();
//
// private IPublishedContentCache PublishedContentHybridCache => GetRequiredService<IPublishedContentCache>();
//
// private IContentEditingService ContentEditingService => GetRequiredService<IContentEditingService>();
//
// [Test]
// public async Task Can_Get_Document_After_Removing_Template()
// {
// // Arrange
// var textPageBefore = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
// Assert.AreEqual(textPageBefore.TemplateId, TemplateId);
// var updateModel = new ContentUpdateModel();
// {
// updateModel.TemplateKey = null;
// updateModel.InvariantName = textPageBefore.Name;
// }
//
// // Act
// var updateContentResult = await ContentEditingService.UpdateAsync(textPageBefore.Key, updateModel, Constants.Security.SuperUserKey);
//
// // Assert
// Assert.AreEqual(updateContentResult.Status, ContentEditingOperationStatus.Success);
// var textPageAfter = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
// // Should this not be null?
// Assert.AreEqual(textPageAfter.TemplateId, null);
// }
// }
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
namespace Umbraco.Cms.Tests.Integration.Umbraco.PublishedCache.HybridCache;

[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
public class DocumentHybridCacheTemplateTests : UmbracoIntegrationTestWithContentEditing
{
protected override void CustomTestSetup(IUmbracoBuilder builder) => builder.AddUmbracoHybridCache();

private IPublishedContentCache PublishedContentHybridCache => GetRequiredService<IPublishedContentCache>();

private IContentEditingService ContentEditingService => GetRequiredService<IContentEditingService>();

[Test]
public async Task Can_Get_Document_After_Removing_Template()
{
// Arrange
var textPageBefore = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
Assert.AreEqual(textPageBefore.TemplateId, TemplateId);
var updateModel = new ContentUpdateModel();
{
updateModel.TemplateKey = null;
updateModel.InvariantName = textPageBefore.Name;
}

// Act
var updateContentResult = await ContentEditingService.UpdateAsync(textPageBefore.Key, updateModel, Constants.Security.SuperUserKey);

// Assert
Assert.AreEqual(updateContentResult.Status, ContentEditingOperationStatus.Success);
var textPageAfter = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
// Should this not be null?
Assert.AreEqual(textPageAfter.TemplateId, null);
}
}
Loading

0 comments on commit 668f4e1

Please sign in to comment.