Adds overload of SaveAndPublish to accept multiple cultures, renames SavePublishing to CommitDocumentChanges, removes IContent.ChangeContentType

This commit is contained in:
Shannon
2019-02-04 16:55:35 +11:00
parent 9be6acf449
commit b51d3036e3
10 changed files with 122 additions and 133 deletions

View File

@@ -704,20 +704,23 @@ namespace Umbraco.Tests.Models
}
[Test]
[Ignore("Need to reimplement this logic for v8")]
public void Can_Change_ContentType_On_Content_And_Clear_Old_PropertyTypes()
{
// Arrange
var contentType = MockedContentTypes.CreateTextPageContentType();
var simpleContentType = MockedContentTypes.CreateSimpleContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
throw new NotImplementedException();
// Act
content.ChangeContentType(simpleContentType, true);
//// Arrange
//var contentType = MockedContentTypes.CreateTextPageContentType();
//var simpleContentType = MockedContentTypes.CreateSimpleContentType();
//var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Assert
Assert.That(content.Properties.Contains("author"), Is.True);
Assert.That(content.Properties.Contains("keywords"), Is.False);
Assert.That(content.Properties.Contains("description"), Is.False);
//// Act
//content.ChangeContentType(simpleContentType, true);
//// Assert
//Assert.That(content.Properties.Contains("author"), Is.True);
//Assert.That(content.Properties.Contains("keywords"), Is.False);
//Assert.That(content.Properties.Contains("description"), Is.False);
}
[Test]

View File

@@ -264,9 +264,7 @@ namespace Umbraco.Tests.Services
vRoot.SetValue("vp", "changed.es", "es");
ServiceContext.ContentService.Save(vRoot); // now root has drafts in all cultures
iv1.PublishCulture("de");
iv1.PublishCulture("ru");
ServiceContext.ContentService.SavePublishing(iv1); // now iv1 de and ru are published
ServiceContext.ContentService.SaveAndPublish(iv1, new []{"de", "ru"}); // now iv1 de and ru are published
iv1.SetValue("ip", "changed");
iv1.SetValue("vp", "changed.de", "de");
@@ -345,10 +343,8 @@ namespace Umbraco.Tests.Services
iv11.SetValue("vp", "iv11.es", "es");
ServiceContext.ContentService.Save(iv11);
iv11.PublishCulture("de");
iv11.SetCultureName("iv11.ru", "ru");
iv11.PublishCulture("ru");
ServiceContext.ContentService.SavePublishing(iv11);
ServiceContext.ContentService.SaveAndPublish(iv11, new []{"de", "ru"});
Assert.AreEqual("iv11.de", iv11.GetValue("vp", "de", published: true));
Assert.AreEqual("iv11.ru", iv11.GetValue("vp", "ru", published: true));

View File

@@ -767,7 +767,7 @@ namespace Umbraco.Tests.Services
Assert.IsTrue(content.IsCulturePublished(langUk.IsoCode));
Assert.IsFalse(content.WasCulturePublished(langUk.IsoCode)); //not persisted yet, will be false
var published = ServiceContext.ContentService.SavePublishing(content);
var published = ServiceContext.ContentService.SaveAndPublish(content, new[]{ langFr.IsoCode , langUk.IsoCode });
//re-get
content = ServiceContext.ContentService.GetById(content.Id);
Assert.IsTrue(published.Success);
@@ -819,9 +819,8 @@ namespace Umbraco.Tests.Services
IContent content = new Content("content", -1, contentType);
content.SetCultureName("content-en", langGB.IsoCode);
content.SetCultureName("content-fr", langFr.IsoCode);
content.PublishCulture(langGB.IsoCode);
content.PublishCulture(langFr.IsoCode);
Assert.IsTrue(ServiceContext.ContentService.SavePublishing(content).Success);
Assert.IsTrue(ServiceContext.ContentService.SaveAndPublish(content, new []{ langGB.IsoCode , langFr.IsoCode }).Success);
//re-get
content = ServiceContext.ContentService.GetById(content.Id);
@@ -861,8 +860,7 @@ namespace Umbraco.Tests.Services
IContent content = new Content("content", -1, contentType);
content.SetCultureName("content-fr", langFr.IsoCode);
content.PublishCulture(langFr.IsoCode);
var published = ServiceContext.ContentService.SavePublishing(content);
var published = ServiceContext.ContentService.SaveAndPublish(content, langFr.IsoCode);
//audit log will only show that french was published
var lastLog = ServiceContext.AuditService.GetLogs(content.Id).Last();
Assert.AreEqual($"Published languages: French (France)", lastLog.Comment);
@@ -870,8 +868,7 @@ namespace Umbraco.Tests.Services
//re-get
content = ServiceContext.ContentService.GetById(content.Id);
content.SetCultureName("content-en", langGB.IsoCode);
content.PublishCulture(langGB.IsoCode);
published = ServiceContext.ContentService.SavePublishing(content);
published = ServiceContext.ContentService.SaveAndPublish(content, langGB.IsoCode);
//audit log will only show that english was published
lastLog = ServiceContext.AuditService.GetLogs(content.Id).Last();
Assert.AreEqual($"Published languages: English (United Kingdom)", lastLog.Comment);
@@ -895,15 +892,12 @@ namespace Umbraco.Tests.Services
IContent content = new Content("content", -1, contentType);
content.SetCultureName("content-fr", langFr.IsoCode);
content.SetCultureName("content-gb", langGB.IsoCode);
content.PublishCulture(langGB.IsoCode);
content.PublishCulture(langFr.IsoCode);
var published = ServiceContext.ContentService.SavePublishing(content);
var published = ServiceContext.ContentService.SaveAndPublish(content, new[] {langGB.IsoCode, langFr.IsoCode});
Assert.IsTrue(published.Success);
//re-get
content = ServiceContext.ContentService.GetById(content.Id);
content.UnpublishCulture(langFr.IsoCode); //unpublish non-mandatory lang
var unpublished = ServiceContext.ContentService.SavePublishing(content);
var unpublished = ServiceContext.ContentService.Unpublish(content, langFr.IsoCode);
//audit log will only show that french was unpublished
var lastLog = ServiceContext.AuditService.GetLogs(content.Id).Last();
Assert.AreEqual($"Unpublished languages: French (France)", lastLog.Comment);
@@ -911,8 +905,7 @@ namespace Umbraco.Tests.Services
//re-get
content = ServiceContext.ContentService.GetById(content.Id);
content.SetCultureName("content-en", langGB.IsoCode);
content.UnpublishCulture(langGB.IsoCode); //unpublish mandatory lang
unpublished = ServiceContext.ContentService.SavePublishing(content);
unpublished = ServiceContext.ContentService.Unpublish(content, langGB.IsoCode);
//audit log will only show that english was published
var logs = ServiceContext.AuditService.GetLogs(content.Id).ToList();
Assert.AreEqual($"Unpublished languages: English (United Kingdom)", logs[logs.Count - 2].Comment);
@@ -927,8 +920,7 @@ namespace Umbraco.Tests.Services
var content = contentService.GetById(NodeDto.NodeIdSeed + 2);
// Act
content.PublishCulture();
var published = contentService.SavePublishing(content, Constants.Security.SuperUserId);
var published = contentService.SaveAndPublish(content, userId: Constants.Security.SuperUserId);
// Assert
Assert.That(published.Success, Is.True);
@@ -982,8 +974,7 @@ namespace Umbraco.Tests.Services
Assert.AreEqual("Home", content.Name);
content.Name = "foo";
content.PublishCulture();
var published = contentService.SavePublishing(content, Constants.Security.SuperUserId);
var published = contentService.SaveAndPublish(content, userId: Constants.Security.SuperUserId);
Assert.That(published.Success, Is.True);
Assert.That(content.Published, Is.True);
@@ -1030,10 +1021,7 @@ namespace Umbraco.Tests.Services
Assert.IsTrue(parentPublished.Success);
Assert.IsTrue(parent.Published);
var contentCanPublishValues = content.PublishCulture();
// content cannot publish values because they are invalid
Assert.IsFalse(contentCanPublishValues);
Assert.IsNotEmpty(content.ValidateProperties());
// and therefore cannot be published,
@@ -1061,7 +1049,7 @@ namespace Umbraco.Tests.Services
content.SetCultureName("name-da", langDa.IsoCode);
content.PublishCulture(langFr.IsoCode);
var result = ServiceContext.ContentService.SavePublishing(content);
var result = ServiceContext.ContentService.CommitDocumentChanges(content);
Assert.IsTrue(result.Success);
content = ServiceContext.ContentService.GetById(content.Id);
Assert.IsTrue(content.IsCulturePublished(langFr.IsoCode));
@@ -1070,7 +1058,7 @@ namespace Umbraco.Tests.Services
content.UnpublishCulture(langFr.IsoCode);
content.PublishCulture(langDa.IsoCode);
result = ServiceContext.ContentService.SavePublishing(content);
result = ServiceContext.ContentService.CommitDocumentChanges(content);
Assert.IsTrue(result.Success);
Assert.AreEqual(PublishResultType.SuccessMixedCulture, result.Result);
@@ -1149,12 +1137,10 @@ namespace Umbraco.Tests.Services
contentService.Save(content);
var parent = contentService.GetById(NodeDto.NodeIdSeed + 2);
parent.PublishCulture();
var parentPublished = contentService.SavePublishing(parent, Constants.Security.SuperUserId);//Publish root Home node to enable publishing of 'NodeDto.NodeIdSeed + 3'
var parentPublished = contentService.SaveAndPublish(parent, userId: Constants.Security.SuperUserId);//Publish root Home node to enable publishing of 'NodeDto.NodeIdSeed + 3'
// Act
content.PublishCulture();
var published = contentService.SavePublishing(content, Constants.Security.SuperUserId);
var published = contentService.SaveAndPublish(content, userId: Constants.Security.SuperUserId);
// Assert
Assert.That(parentPublished.Success, Is.True);
@@ -1192,12 +1178,10 @@ namespace Umbraco.Tests.Services
contentService.Save(content, Constants.Security.SuperUserId);
var parent = contentService.GetById(NodeDto.NodeIdSeed + 2);
parent.PublishCulture();
var parentPublished = contentService.SavePublishing(parent, Constants.Security.SuperUserId);//Publish root Home node to enable publishing of 'NodeDto.NodeIdSeed + 3'
var parentPublished = contentService.SaveAndPublish(parent, userId: Constants.Security.SuperUserId);//Publish root Home node to enable publishing of 'NodeDto.NodeIdSeed + 3'
// Act
content.PublishCulture();
var published = contentService.SavePublishing(content, Constants.Security.SuperUserId);
var published = contentService.SaveAndPublish(content, userId: Constants.Security.SuperUserId);
// Assert
Assert.That(parentPublished.Success, Is.True);
@@ -1249,8 +1233,7 @@ namespace Umbraco.Tests.Services
var content = contentService.GetById(NodeDto.NodeIdSeed + 5);
// Act
content.PublishCulture();
var published = contentService.SavePublishing(content, Constants.Security.SuperUserId);
var published = contentService.SaveAndPublish(content, userId: Constants.Security.SuperUserId);
// Assert
Assert.That(published.Success, Is.False);
@@ -1267,8 +1250,7 @@ namespace Umbraco.Tests.Services
content.SetValue("author", "Barack Obama");
// Act
content.PublishCulture();
var published = contentService.SavePublishing(content, Constants.Security.SuperUserId);
var published = contentService.SaveAndPublish(content, userId: Constants.Security.SuperUserId);
// Assert
Assert.That(content.HasIdentity, Is.True);
@@ -1292,15 +1274,13 @@ namespace Umbraco.Tests.Services
content.SetValue("author", "Barack Obama");
// Act
content.PublishCulture();
var published = contentService.SavePublishing(content, Constants.Security.SuperUserId);
var published = contentService.SaveAndPublish(content, userId: Constants.Security.SuperUserId);
var childContent = contentService.Create("Child", content.Id, "umbTextpage", Constants.Security.SuperUserId);
// Reset all identity properties
childContent.Id = 0;
childContent.Path = null;
((Content)childContent).ResetIdentity();
childContent.PublishCulture();
var childPublished = contentService.SavePublishing(childContent, Constants.Security.SuperUserId);
var childPublished = contentService.SaveAndPublish(childContent, userId: Constants.Security.SuperUserId);
// Assert
Assert.That(content.HasIdentity, Is.True);
@@ -1639,14 +1619,12 @@ namespace Umbraco.Tests.Services
content1.PropertyValues(obj);
content1.ResetDirtyProperties(false);
ServiceContext.ContentService.Save(content1, Constants.Security.SuperUserId);
content1.PublishCulture();
Assert.IsTrue(ServiceContext.ContentService.SavePublishing(content1, 0).Success);
Assert.IsTrue(ServiceContext.ContentService.SaveAndPublish(content1, userId: 0).Success);
var content2 = MockedContent.CreateBasicContent(contentType);
content2.PropertyValues(obj);
content2.ResetDirtyProperties(false);
ServiceContext.ContentService.Save(content2, Constants.Security.SuperUserId);
content2.PublishCulture();
Assert.IsTrue(ServiceContext.ContentService.SavePublishing(content2, 0).Success);
Assert.IsTrue(ServiceContext.ContentService.SaveAndPublish(content2, userId: 0).Success);
var editorGroup = ServiceContext.UserService.GetUserGroupByAlias("editor");
editorGroup.StartContentId = content1.Id;
@@ -2721,9 +2699,7 @@ namespace Umbraco.Tests.Services
// act
content.PublishCulture(langFr.IsoCode);
content.PublishCulture(langUk.IsoCode);
contentService.SavePublishing(content);
contentService.SaveAndPublish(content, new[]{ langFr.IsoCode, langUk.IsoCode });
// both FR and UK have been published,
// and content has been published,
@@ -2827,8 +2803,7 @@ namespace Umbraco.Tests.Services
// act
// cannot just 'save' since we are changing what's published!
content.UnpublishCulture(langFr.IsoCode);
contentService.SavePublishing(content);
contentService.Unpublish(content, langFr.IsoCode);
// content has been published,
// the french culture is gone
@@ -2919,7 +2894,7 @@ namespace Umbraco.Tests.Services
// that HAS to be SavePublishing, because SaveAndPublish would just republish everything!
contentService.SavePublishing(content);
contentService.CommitDocumentChanges(content);
// content has been re-published,
// everything is back to what it was before being unpublished
@@ -2959,8 +2934,7 @@ namespace Umbraco.Tests.Services
// act
content.PublishCulture(langUk.IsoCode);
contentService.SavePublishing(content);
contentService.SaveAndPublish(content, langUk.IsoCode);
content2 = contentService.GetById(content.Id);