Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/NuCacheRebuildTests.cs
Kenn Jacobsen 012b43a1c2 Publishing in the Management API (#14774)
* make CoreScopeProvider available for derived classes

* Create publish controller

* Add publish functionality

* Remove unneeded using

* Implement publish for multiple cultures

* support multiple cultures in controler

* Dont validate properties

* Refactor to use PublishingOperationStatus

* refactor to use proper publish async methods

* Refactor publish logic into own service

* Commit some demo code

* Add notes about what errors can happen when publishing

* Rework ContentPublishingService and introduce explicit Publish and PublishBranch methods in ContentService

* Fix merge

* Allow the publishing strategy to do its job

* Improved check for unsaved changes

* Make the old content controller work (as best possible)

* Remove SaveAndPublish (SaveAndPublishBranch) from all tests

* Proper guards for invalid cultures when publishing

* Fix edge cases for property validation and content unpublishing + add unpublishing to ContentPublishingService

* Clear out a few TODOs - we'll accept the behavior for now

* Unpublish controller

* Fix merge

* Fix branch publish notifications

* Added extra test for publishing unpublished cultures and added FIXME comments for when we fix the state of published cultures in content

---------

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>
Co-authored-by: Zeegaan <nge@umbraco.dk>
2023-11-22 12:52:08 +01:00

89 lines
3.3 KiB
C#

using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;
using Umbraco.Cms.Tests.Common.Builders;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services;
[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true,
WithApplication = true)]
public class NuCacheRebuildTests : UmbracoIntegrationTest
{
private IFileService FileService => GetRequiredService<IFileService>();
private IContentService ContentService => GetRequiredService<IContentService>();
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
private IPublishedSnapshotService PublishedSnapshotService => GetRequiredService<IPublishedSnapshotService>();
[Test]
public void UnpublishedNameChanges()
{
var urlSegmentProvider = new DefaultUrlSegmentProvider(ShortStringHelper);
var template = TemplateBuilder.CreateTextPageTemplate();
FileService.SaveTemplate(template);
var contentType = ContentTypeBuilder.CreateTextPageContentType(defaultTemplateId: template.Id);
ContentTypeService.Save(contentType);
var content = ContentBuilder.CreateTextpageContent(contentType, "hello", Constants.System.Root);
ContentService.Save(content);
ContentService.Publish(content, Array.Empty<string>());
var cachedContent = ContentService.GetById(content.Id);
var segment = urlSegmentProvider.GetUrlSegment(cachedContent);
// Does a new node work?
Assert.AreEqual("hello", segment);
content.Name = "goodbye";
cachedContent = ContentService.GetById(content.Id);
segment = urlSegmentProvider.GetUrlSegment(cachedContent);
// We didn't save anything, so all should still be the same
Assert.AreEqual("hello", segment);
ContentService.Save(content);
cachedContent = ContentService.GetById(content.Id);
segment = urlSegmentProvider.GetUrlSegment(cachedContent);
// At this point we have saved the new name, but not published. The url should still be the previous name
Assert.AreEqual("hello", segment);
PublishedSnapshotService.RebuildAll();
cachedContent = ContentService.GetById(content.Id);
segment = urlSegmentProvider.GetUrlSegment(cachedContent);
// After a rebuild, the unpublished name should still not be the url.
// This was previously incorrect, per #11074
Assert.AreEqual("hello", segment);
ContentService.Save(content);
ContentService.Publish(content, Array.Empty<string>());
cachedContent = ContentService.GetById(content.Id);
segment = urlSegmentProvider.GetUrlSegment(cachedContent);
// The page has now been published, so we should see the new url segment
Assert.AreEqual("goodbye", segment);
PublishedSnapshotService.RebuildAll();
cachedContent = ContentService.GetById(content.Id);
segment = urlSegmentProvider.GetUrlSegment(cachedContent);
// Just double checking that things remain after a rebuild
Assert.AreEqual("goodbye", segment);
}
}