diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs new file mode 100644 index 0000000000..d05599584a --- /dev/null +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs @@ -0,0 +1,93 @@ +using System.Collections.Generic; +using Microsoft.AspNetCore.Authorization; +using Microsoft.Extensions.Logging.Abstractions; +using Moq; +using NUnit.Framework; +using Umbraco.Cms.Core.Actions; +using Umbraco.Cms.Core.Dictionary; +using Umbraco.Cms.Core.Events; +using Umbraco.Cms.Core.Mapping; +using Umbraco.Cms.Core.Models; +using Umbraco.Cms.Core.PropertyEditors; +using Umbraco.Cms.Core.Routing; +using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Core.Security; +using Umbraco.Cms.Core.Serialization; +using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Core.Strings; +using Umbraco.Cms.Infrastructure.Persistence; +using Umbraco.Cms.Tests.Common.Builders; +using Umbraco.Cms.Tests.Common.Builders.Extensions; +using Umbraco.Cms.Web.BackOffice.Controllers; + +namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.BackOffice.Controllers +{ + [TestFixture] + public class ContentControllerTests + { + [Test] + public void Root_Node_With_Domains_Causes_No_Error() + { + // Setup domain service + var domainServiceMock = new Mock(); + domainServiceMock.Setup(x => x.GetAssignedDomains(1060, It.IsAny())) + .Returns(new List{new UmbracoDomain("/", "da-dk"), new UmbracoDomain("/en", "en-us")}); + + // Create content type and content + IContentType contentType = new ContentTypeBuilder().WithContentVariation(ContentVariation.Culture).Build(); + + // Create content, we need to specify and ID configure domain service + Content rootNode = new ContentBuilder() + .WithContentType(contentType) + .WithId(1060) + .AddContentCultureInfosCollection() + .AddCultureInfos() + .WithCultureIso("da-dk") + .Done() + .AddCultureInfos() + .WithCultureIso("en-us") + .Done() + .Done() + .Build(); + + var culturesPublished = new List { "en-us", "da-dk" }; + var publishResult = new PublishResult(new EventMessages(), rootNode); + + ContentController contentController = CreateContentController(domainServiceMock.Object); + contentController.VerifyDomainsForCultures(rootNode, culturesPublished, publishResult); + + IEnumerable eventMessages = publishResult.EventMessages.GetAll(); + Assert.IsEmpty(eventMessages); + } + + private ContentController CreateContentController(IDomainService domainService) + { + var controller = new ContentController( + Mock.Of(), + NullLoggerFactory.Instance, + Mock.Of(), + Mock.Of(), + Mock.Of(), + new PropertyEditorCollection(new DataEditorCollection(() => null)), + Mock.Of(), + Mock.Of(), + Mock.Of(), + Mock.Of(), + Mock.Of(), + Mock.Of(), + domainService, + Mock.Of(), + Mock.Of(), + Mock.Of(), + Mock.Of(), + new ActionCollection(() => null), + Mock.Of(), + Mock.Of(), + Mock.Of(), + Mock.Of() + ); + + return controller; + } + } +} diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs index 78f4e6c06e..0d797760d5 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs @@ -1441,7 +1441,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers /// /// /// - private void VerifyDomainsForCultures(IContent persistedContent, IEnumerable culturesPublished, PublishResult publishResult) + internal void VerifyDomainsForCultures(IContent persistedContent, IEnumerable culturesPublished, PublishResult publishResult) { var publishedCultures = persistedContent.PublishedCultures.ToList(); // If only a single culture is published we shouldn't have any routing issues