Migrate ContentServicePublishBranchTests
This commit is contained in:
@@ -7,6 +7,7 @@ using Umbraco.Core.Configuration.Models;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
@@ -16,8 +17,12 @@ namespace Umbraco.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true, WithApplication = true)]
|
||||
public class ContentServicePublishBranchTests : TestWithDatabaseBase
|
||||
public class ContentServicePublishBranchTests : UmbracoIntegrationTest
|
||||
{
|
||||
private IContentService ContentService => GetRequiredService<IContentService>();
|
||||
private ILocalizationService LocalizationService => GetRequiredService<ILocalizationService>();
|
||||
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
|
||||
|
||||
[TestCase(1)] // use overload w/ culture: "*"
|
||||
[TestCase(2)] // use overload w/ cultures: new [] { "*" }
|
||||
public void Can_Publish_Invariant_Branch(int method)
|
||||
@@ -26,13 +31,13 @@ namespace Umbraco.Tests.Services
|
||||
|
||||
IContent iRoot = new Content("iroot", -1, iContentType);
|
||||
iRoot.SetValue("ip", "iroot");
|
||||
ServiceContext.ContentService.Save(iRoot);
|
||||
ContentService.Save(iRoot);
|
||||
IContent ii1 = new Content("ii1", iRoot, iContentType);
|
||||
ii1.SetValue("ip", "vii1");
|
||||
ServiceContext.ContentService.Save(ii1);
|
||||
ContentService.Save(ii1);
|
||||
IContent ii2 = new Content("ii2", iRoot, iContentType);
|
||||
ii2.SetValue("ip", "vii2");
|
||||
ServiceContext.ContentService.Save(ii2);
|
||||
ContentService.Save(ii2);
|
||||
|
||||
// iroot !published !edited
|
||||
// ii1 !published !edited
|
||||
@@ -51,24 +56,24 @@ namespace Umbraco.Tests.Services
|
||||
|
||||
// prepare
|
||||
|
||||
ServiceContext.ContentService.SaveAndPublish(iRoot);
|
||||
ServiceContext.ContentService.SaveAndPublish(ii1);
|
||||
ContentService.SaveAndPublish(iRoot);
|
||||
ContentService.SaveAndPublish(ii1);
|
||||
|
||||
IContent ii11 = new Content("ii11", ii1, iContentType);
|
||||
ii11.SetValue("ip", "vii11");
|
||||
ServiceContext.ContentService.SaveAndPublish(ii11);
|
||||
ContentService.SaveAndPublish(ii11);
|
||||
IContent ii12 = new Content("ii12", ii1, iContentType);
|
||||
ii11.SetValue("ip", "vii12");
|
||||
ServiceContext.ContentService.Save(ii12);
|
||||
ContentService.Save(ii12);
|
||||
|
||||
ServiceContext.ContentService.SaveAndPublish(ii2);
|
||||
ContentService.SaveAndPublish(ii2);
|
||||
IContent ii21 = new Content("ii21", ii2, iContentType);
|
||||
ii21.SetValue("ip", "vii21");
|
||||
ServiceContext.ContentService.SaveAndPublish(ii21);
|
||||
ContentService.SaveAndPublish(ii21);
|
||||
IContent ii22 = new Content("ii22", ii2, iContentType);
|
||||
ii22.SetValue("ip", "vii22");
|
||||
ServiceContext.ContentService.Save(ii22);
|
||||
ServiceContext.ContentService.Unpublish(ii2);
|
||||
ContentService.Save(ii22);
|
||||
ContentService.Unpublish(ii2);
|
||||
|
||||
// iroot published !edited
|
||||
// ii1 published !edited
|
||||
@@ -94,9 +99,9 @@ namespace Umbraco.Tests.Services
|
||||
// prepare
|
||||
|
||||
iRoot.SetValue("ip", "changed");
|
||||
ServiceContext.ContentService.Save(iRoot);
|
||||
ContentService.Save(iRoot);
|
||||
ii11.SetValue("ip", "changed");
|
||||
ServiceContext.ContentService.Save(ii11);
|
||||
ContentService.Save(ii11);
|
||||
|
||||
// iroot published edited ***
|
||||
// ii1 published !edited
|
||||
@@ -133,7 +138,7 @@ namespace Umbraco.Tests.Services
|
||||
PublishResultType.SuccessPublishAlready, // was masked
|
||||
PublishResultType.SuccessPublish);
|
||||
|
||||
ii21 = ServiceContext.ContentService.GetById(ii21.Id);
|
||||
ii21 = ContentService.GetById(ii21.Id);
|
||||
Assert.IsTrue(ii21.Published);
|
||||
}
|
||||
|
||||
@@ -151,7 +156,7 @@ namespace Umbraco.Tests.Services
|
||||
vRoot.SetValue("vp", "vroot.de", "de");
|
||||
vRoot.SetValue("vp", "vroot.ru", "ru");
|
||||
vRoot.SetValue("vp", "vroot.es", "es");
|
||||
ServiceContext.ContentService.SaveAndPublish(vRoot);
|
||||
ContentService.SaveAndPublish(vRoot);
|
||||
|
||||
//create/publish child
|
||||
IContent iv1 = new Content("iv1", vRoot, vContentType, "de");
|
||||
@@ -162,13 +167,13 @@ namespace Umbraco.Tests.Services
|
||||
iv1.SetValue("vp", "iv1.de", "de");
|
||||
iv1.SetValue("vp", "iv1.ru", "ru");
|
||||
iv1.SetValue("vp", "iv1.es", "es");
|
||||
ServiceContext.ContentService.SaveAndPublish(iv1);
|
||||
ContentService.SaveAndPublish(iv1);
|
||||
|
||||
//update the child
|
||||
iv1.SetValue("vp", "UPDATED-iv1.de", "de");
|
||||
ServiceContext.ContentService.Save(iv1);
|
||||
ContentService.Save(iv1);
|
||||
|
||||
var r = ServiceContext.ContentService.SaveAndPublishBranch(vRoot, false).ToArray(); //no culture specified so "*" is used, so all cultures
|
||||
var r = ContentService.SaveAndPublishBranch(vRoot, false).ToArray(); //no culture specified so "*" is used, so all cultures
|
||||
Assert.AreEqual(PublishResultType.SuccessPublishAlready, r[0].Result);
|
||||
Assert.AreEqual(PublishResultType.SuccessPublishCulture, r[1].Result);
|
||||
}
|
||||
@@ -187,7 +192,7 @@ namespace Umbraco.Tests.Services
|
||||
vRoot.SetValue("vp", "vroot.de", "de");
|
||||
vRoot.SetValue("vp", "vroot.ru", "ru");
|
||||
vRoot.SetValue("vp", "vroot.es", "es");
|
||||
ServiceContext.ContentService.SaveAndPublish(vRoot);
|
||||
ContentService.SaveAndPublish(vRoot);
|
||||
|
||||
//create/publish child
|
||||
IContent iv1 = new Content("iv1", vRoot, vContentType, "de");
|
||||
@@ -198,13 +203,13 @@ namespace Umbraco.Tests.Services
|
||||
iv1.SetValue("vp", "iv1.de", "de");
|
||||
iv1.SetValue("vp", "iv1.ru", "ru");
|
||||
iv1.SetValue("vp", "iv1.es", "es");
|
||||
ServiceContext.ContentService.SaveAndPublish(iv1);
|
||||
ContentService.SaveAndPublish(iv1);
|
||||
|
||||
//update the child
|
||||
iv1.SetValue("vp", "UPDATED-iv1.de", "de");
|
||||
var saveResult = ServiceContext.ContentService.Save(iv1);
|
||||
var saveResult = ContentService.Save(iv1);
|
||||
|
||||
var r = ServiceContext.ContentService.SaveAndPublishBranch(vRoot, false, "de").ToArray();
|
||||
var r = ContentService.SaveAndPublishBranch(vRoot, false, "de").ToArray();
|
||||
Assert.AreEqual(PublishResultType.SuccessPublishAlready, r[0].Result);
|
||||
Assert.AreEqual(PublishResultType.SuccessPublishCulture, r[1].Result);
|
||||
}
|
||||
@@ -222,7 +227,7 @@ namespace Umbraco.Tests.Services
|
||||
vRoot.SetValue("vp", "vroot.de", "de");
|
||||
vRoot.SetValue("vp", "vroot.ru", "ru");
|
||||
vRoot.SetValue("vp", "vroot.es", "es");
|
||||
ServiceContext.ContentService.Save(vRoot);
|
||||
ContentService.Save(vRoot);
|
||||
|
||||
IContent iv1 = new Content("iv1", vRoot, vContentType, "de");
|
||||
iv1.SetCultureName("iv1.de", "de");
|
||||
@@ -232,7 +237,7 @@ namespace Umbraco.Tests.Services
|
||||
iv1.SetValue("vp", "iv1.de", "de");
|
||||
iv1.SetValue("vp", "iv1.ru", "ru");
|
||||
iv1.SetValue("vp", "iv1.es", "es");
|
||||
ServiceContext.ContentService.Save(iv1);
|
||||
ContentService.Save(iv1);
|
||||
|
||||
IContent iv2 = new Content("iv2", vRoot, vContentType, "de");
|
||||
iv2.SetCultureName("iv2.de", "de");
|
||||
@@ -242,7 +247,7 @@ namespace Umbraco.Tests.Services
|
||||
iv2.SetValue("vp", "iv2.de", "de");
|
||||
iv2.SetValue("vp", "iv2.ru", "ru");
|
||||
iv2.SetValue("vp", "iv2.es", "es");
|
||||
ServiceContext.ContentService.Save(iv2);
|
||||
ContentService.Save(iv2);
|
||||
|
||||
// vroot !published !edited
|
||||
// iv1 !published !edited
|
||||
@@ -251,7 +256,7 @@ namespace Umbraco.Tests.Services
|
||||
// !force = publishes those that are actually published, and have changes
|
||||
// here: nothing
|
||||
|
||||
var r = ServiceContext.ContentService.SaveAndPublishBranch(vRoot, false).ToArray(); // no culture specified = all cultures
|
||||
var r = ContentService.SaveAndPublishBranch(vRoot, false).ToArray(); // no culture specified = all cultures
|
||||
|
||||
// not forcing, iv1 and iv2 not published yet: only root got published
|
||||
AssertPublishResults(r, x => x.Content.Name,
|
||||
@@ -264,15 +269,15 @@ namespace Umbraco.Tests.Services
|
||||
vRoot.SetValue("vp", "changed.de", "de");
|
||||
vRoot.SetValue("vp", "changed.ru", "ru");
|
||||
vRoot.SetValue("vp", "changed.es", "es");
|
||||
ServiceContext.ContentService.Save(vRoot); // now root has drafts in all cultures
|
||||
ContentService.Save(vRoot); // now root has drafts in all cultures
|
||||
|
||||
ServiceContext.ContentService.SaveAndPublish(iv1, new []{"de", "ru"}); // now iv1 de and ru are published
|
||||
ContentService.SaveAndPublish(iv1, new []{"de", "ru"}); // now iv1 de and ru are published
|
||||
|
||||
iv1.SetValue("ip", "changed");
|
||||
iv1.SetValue("vp", "changed.de", "de");
|
||||
iv1.SetValue("vp", "changed.ru", "ru");
|
||||
iv1.SetValue("vp", "changed.es", "es");
|
||||
ServiceContext.ContentService.Save(iv1); // now iv1 has drafts in all cultures
|
||||
ContentService.Save(iv1); // now iv1 has drafts in all cultures
|
||||
|
||||
// validate - everything published for root, because no culture was specified = all
|
||||
Assert.IsTrue(vRoot.Published);
|
||||
@@ -286,7 +291,7 @@ namespace Umbraco.Tests.Services
|
||||
Assert.IsTrue(iv1.IsCulturePublished("ru"));
|
||||
Assert.IsFalse(iv1.IsCulturePublished("es"));
|
||||
|
||||
r = ServiceContext.ContentService.SaveAndPublishBranch(vRoot, false, "de").ToArray();
|
||||
r = ContentService.SaveAndPublishBranch(vRoot, false, "de").ToArray();
|
||||
|
||||
// not forcing, iv2 not published yet: only root and iv1 got published
|
||||
AssertPublishResults(r, x => x.Content.Name,
|
||||
@@ -332,21 +337,21 @@ namespace Umbraco.Tests.Services
|
||||
// invariant root -> invariant -> variant
|
||||
iRoot = new Content("iroot", -1, iContentType);
|
||||
iRoot.SetValue("ip", "iroot");
|
||||
ServiceContext.ContentService.SaveAndPublish(iRoot);
|
||||
ContentService.SaveAndPublish(iRoot);
|
||||
ii1 = new Content("ii1", iRoot, iContentType);
|
||||
ii1.SetValue("ip", "vii1");
|
||||
ServiceContext.ContentService.SaveAndPublish(ii1);
|
||||
ContentService.SaveAndPublish(ii1);
|
||||
ii1.SetValue("ip", "changed");
|
||||
ServiceContext.ContentService.Save(ii1);
|
||||
ContentService.Save(ii1);
|
||||
iv11 = new Content("iv11.de", ii1, vContentType, "de");
|
||||
iv11.SetValue("ip", "iv11");
|
||||
iv11.SetValue("vp", "iv11.de", "de");
|
||||
iv11.SetValue("vp", "iv11.ru", "ru");
|
||||
iv11.SetValue("vp", "iv11.es", "es");
|
||||
ServiceContext.ContentService.Save(iv11);
|
||||
ContentService.Save(iv11);
|
||||
|
||||
iv11.SetCultureName("iv11.ru", "ru");
|
||||
var xxx = ServiceContext.ContentService.SaveAndPublish(iv11, new []{"de", "ru"});
|
||||
var xxx = 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));
|
||||
@@ -354,7 +359,7 @@ namespace Umbraco.Tests.Services
|
||||
iv11.SetValue("ip", "changed");
|
||||
iv11.SetValue("vp", "changed.de", "de");
|
||||
iv11.SetValue("vp", "changed.ru", "ru");
|
||||
ServiceContext.ContentService.Save(iv11);
|
||||
ContentService.Save(iv11);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -362,7 +367,7 @@ namespace Umbraco.Tests.Services
|
||||
{
|
||||
Can_Publish_Mixed_Branch(out var iRoot, out var ii1, out var iv11);
|
||||
|
||||
var r = ServiceContext.ContentService.SaveAndPublishBranch(iRoot, false, "de").ToArray();
|
||||
var r = ContentService.SaveAndPublishBranch(iRoot, false, "de").ToArray();
|
||||
AssertPublishResults(r, x => x.Content.Name,
|
||||
"iroot", "ii1", "iv11.de");
|
||||
AssertPublishResults(r, x => x.Result,
|
||||
@@ -388,7 +393,7 @@ namespace Umbraco.Tests.Services
|
||||
{
|
||||
Can_Publish_Mixed_Branch(out var iRoot, out var ii1, out var iv11);
|
||||
|
||||
var r = ServiceContext.ContentService.SaveAndPublishBranch(iRoot, false, new[] { "de", "ru" }).ToArray();
|
||||
var r = ContentService.SaveAndPublishBranch(iRoot, false, new[] { "de", "ru" }).ToArray();
|
||||
AssertPublishResults(r, x => x.Content.Name,
|
||||
"iroot", "ii1", "iv11.de");
|
||||
AssertPublishResults(r, x => x.Result,
|
||||
@@ -423,18 +428,18 @@ namespace Umbraco.Tests.Services
|
||||
}
|
||||
|
||||
private void Reload(ref IContent document)
|
||||
=> document = ServiceContext.ContentService.GetById(document.Id);
|
||||
=> document = ContentService.GetById(document.Id);
|
||||
|
||||
private void CreateTypes(out IContentType iContentType, out IContentType vContentType)
|
||||
{
|
||||
var globalSettings = new GlobalSettings();
|
||||
|
||||
var langDe = new Language(globalSettings, "de") { IsDefault = true };
|
||||
ServiceContext.LocalizationService.Save(langDe);
|
||||
LocalizationService.Save(langDe);
|
||||
var langRu = new Language(globalSettings, "ru");
|
||||
ServiceContext.LocalizationService.Save(langRu);
|
||||
LocalizationService.Save(langRu);
|
||||
var langEs = new Language(globalSettings, "es");
|
||||
ServiceContext.LocalizationService.Save(langEs);
|
||||
LocalizationService.Save(langEs);
|
||||
|
||||
iContentType = new ContentType(ShortStringHelper, -1)
|
||||
{
|
||||
@@ -443,7 +448,7 @@ namespace Umbraco.Tests.Services
|
||||
Variations = ContentVariation.Nothing
|
||||
};
|
||||
iContentType.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Nvarchar, "ip") { Variations = ContentVariation.Nothing });
|
||||
ServiceContext.ContentTypeService.Save(iContentType);
|
||||
ContentTypeService.Save(iContentType);
|
||||
|
||||
vContentType = new ContentType(ShortStringHelper, -1)
|
||||
{
|
||||
@@ -453,7 +458,7 @@ namespace Umbraco.Tests.Services
|
||||
};
|
||||
vContentType.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Nvarchar, "ip") { Variations = ContentVariation.Nothing });
|
||||
vContentType.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Nvarchar, "vp") { Variations = ContentVariation.Culture });
|
||||
ServiceContext.ContentTypeService.Save(vContentType);
|
||||
ContentTypeService.Save(vContentType);
|
||||
}
|
||||
|
||||
private IEnumerable<PublishResult> SaveAndPublishInvariantBranch(IContent content, bool force, int method)
|
||||
@@ -463,9 +468,9 @@ namespace Umbraco.Tests.Services
|
||||
switch (method)
|
||||
{
|
||||
case 1:
|
||||
return ServiceContext.ContentService.SaveAndPublishBranch(content, force, culture: "*");
|
||||
return ContentService.SaveAndPublishBranch(content, force, culture: "*");
|
||||
case 2:
|
||||
return ServiceContext.ContentService.SaveAndPublishBranch(content, force, cultures: new [] { "*" });
|
||||
return ContentService.SaveAndPublishBranch(content, force, cultures: new [] { "*" });
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(method));
|
||||
}
|
||||
@@ -77,6 +77,8 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
{
|
||||
foreach (var a in _testTeardown) a();
|
||||
_testTeardown = null;
|
||||
FirstTestInFixture = false;
|
||||
FirstTestInSession = false;
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
@@ -246,6 +248,13 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
{
|
||||
Services.GetRequiredService<IBackofficeSecurityFactory>().EnsureBackofficeSecurity();
|
||||
Services.GetRequiredService<IUmbracoContextFactory>().EnsureUmbracoContext();
|
||||
OnTestTearDown(() =>
|
||||
{
|
||||
var caches = GetRequiredService<AppCaches>();
|
||||
caches.IsolatedCaches.ClearAllCaches();
|
||||
caches.RuntimeCache.Clear();
|
||||
caches.RequestCache.Clear();
|
||||
});
|
||||
|
||||
// get the currently set ptions
|
||||
var testOptions = TestOptionAttributeBase.GetTestOptions<UmbracoTestAttribute>();
|
||||
@@ -370,7 +379,7 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
// Probably because the DB is blocked because it hasn't been detached
|
||||
// Also if we attach a new schema for every test isn't it just essentially
|
||||
// the same as NewSchemaPerTest?
|
||||
if (db.CanAttachSchema)
|
||||
if (FirstTestInFixture)
|
||||
{
|
||||
// New DB + Schema
|
||||
var newSchemaFixtureDbId = db.AttachSchema();
|
||||
@@ -456,5 +465,9 @@ namespace Umbraco.Tests.Integration.Testing
|
||||
protected UserGroupBuilder UserGroupBuilder = new UserGroupBuilder();
|
||||
|
||||
#endregion
|
||||
|
||||
protected static bool FirstTestInSession = true;
|
||||
|
||||
protected bool FirstTestInFixture = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +155,6 @@
|
||||
<Compile Include="Routing\GetContentUrlsTests.cs" />
|
||||
<Compile Include="Services\AmbiguousEventTests.cs" />
|
||||
<Compile Include="Services\ContentServiceEventTests.cs" />
|
||||
<Compile Include="Services\ContentServicePublishBranchTests.cs" />
|
||||
<Compile Include="Services\ContentServiceTagsTests.cs" />
|
||||
<Compile Include="Services\ContentTypeServiceVariantsTests.cs" />
|
||||
<Compile Include="Services\EntityXmlSerializerTests.cs" />
|
||||
|
||||
Reference in New Issue
Block a user