From dea47dfafee205ecd920666d5b1c9ac533937017 Mon Sep 17 00:00:00 2001 From: Stephan Date: Wed, 18 Apr 2018 18:28:47 +0200 Subject: [PATCH] Fix availability and names --- .../Implement/DocumentRepository.cs | 4 ++ .../Services/ContentServiceTests.cs | 38 ++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/DocumentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/DocumentRepository.cs index 8463010d0f..cc6247210b 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/DocumentRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/DocumentRepository.cs @@ -290,6 +290,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var contentVersionDto = dto.DocumentVersionDto.ContentVersionDto; contentVersionDto.NodeId = nodeDto.NodeId; contentVersionDto.Current = !publishing; + contentVersionDto.Text = publishing ? content.PublishName : content.Name; Database.Insert(contentVersionDto); content.VersionId = contentVersionDto.Id; @@ -306,6 +307,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement content.PublishedVersionId = content.VersionId; contentVersionDto.Id = 0; contentVersionDto.Current = true; + contentVersionDto.Text = content.Name; Database.Insert(contentVersionDto); content.VersionId = contentVersionDto.Id; @@ -434,6 +436,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement { documentVersionDto.Published = true; // now published contentVersionDto.Current = false; // no more current + contentVersionDto.Text = content.PublishName; } Database.Update(contentVersionDto); Database.Update(documentVersionDto); @@ -445,6 +448,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement contentVersionDto.Id = 0; // want a new id contentVersionDto.Current = true; // current version + contentVersionDto.Text = content.Name; Database.Insert(contentVersionDto); content.VersionId = documentVersionDto.Id = contentVersionDto.Id; // get the new id diff --git a/src/Umbraco.Tests/Services/ContentServiceTests.cs b/src/Umbraco.Tests/Services/ContentServiceTests.cs index 88a3f7821d..79929ff29d 100644 --- a/src/Umbraco.Tests/Services/ContentServiceTests.cs +++ b/src/Umbraco.Tests/Services/ContentServiceTests.cs @@ -2488,8 +2488,18 @@ namespace Umbraco.Tests.Services var contentTypeService = ServiceContext.ContentTypeService; + // fixme + // contentType.Variations is InvariantNeutral | CultureNeutral + // propertyType.Variations can only be a subset of contentType.Variations - ie cannot *add* anything + // (at least, we should validate this) + // but then, + // if the contentType supports InvariantNeutral | CultureNeutral, + // the propertyType should support InvariantNeutral, or both, but not solely CultureNeutral? + // but does this mean that CultureNeutral implies InvariantNeutral? + // can a contentType *not* support InvariantNeutral? + var contentType = contentTypeService.Get("umbTextpage"); - contentType.Variations = ContentVariation.CultureNeutral; + contentType.Variations = ContentVariation.InvariantNeutral | ContentVariation.CultureNeutral; contentType.AddPropertyType(new PropertyType(Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Nvarchar, "prop") { Variations = ContentVariation.CultureNeutral }); contentTypeService.Save(contentType); @@ -2546,7 +2556,7 @@ namespace Umbraco.Tests.Services Assert.AreEqual("name-fr", content2.GetName(langFr.Id)); Assert.AreEqual("name-uk", content2.GetName(langUk.Id)); - Assert.AreEqual("Home US", content2.PublishName); + Assert.IsNull(content2.PublishName); // we haven't published InvariantNeutral Assert.AreEqual("name-fr", content2.GetPublishName(langFr.Id)); Assert.AreEqual("name-uk", content2.GetPublishName(langUk.Id)); @@ -2556,7 +2566,18 @@ namespace Umbraco.Tests.Services Assert.AreEqual("value-uk1", content2.GetValue("prop", langUk.Id, published: true)); Assert.IsTrue(content.IsCulturePublished(langFr.Id)); - Assert.IsTrue(content.IsCulturePublished(langUk.Id)); + Assert.IsTrue(content.IsCulturePublished(langUk.Id)); + + // act + + content.PublishValues(); + contentService.SaveAndPublish(content); + + // now it has publish name for invariant neutral + + content2 = contentService.GetById(content.Id); + + Assert.AreEqual("Home US", content2.PublishName); // act @@ -2582,7 +2603,7 @@ namespace Umbraco.Tests.Services Assert.AreEqual("name-uk", content2.GetPublishName(langUk.Id)); Assert.AreEqual("Barack Obama2", content2.GetValue("author")); - Assert.IsNull(content2.GetValue("author", published: true)); // because, we never published the InvariantNeutral variation + Assert.AreEqual("Barack Obama", content2.GetValue("author", published: true)); Assert.AreEqual("value-fr2", content2.GetValue("prop", langFr.Id)); Assert.AreEqual("value-uk2", content2.GetValue("prop", langUk.Id)); @@ -2607,7 +2628,7 @@ namespace Umbraco.Tests.Services Assert.AreEqual("name-fr2", content2.GetName(langFr.Id)); Assert.AreEqual("name-uk2", content2.GetName(langUk.Id)); - Assert.AreEqual("Home US2", content2.PublishName); // fixme why? -- and what about properties? -- we haven't published invariants?! + Assert.AreEqual("Home US", content2.PublishName); Assert.IsNull(content2.GetPublishName(langFr.Id)); Assert.AreEqual("name-uk", content2.GetPublishName(langUk.Id)); @@ -2632,9 +2653,6 @@ namespace Umbraco.Tests.Services // its exact previous state, properties and names etc. retain their published // values even though the content is not published - hence many things being // non-null or true below - always check against content.Published to be sure - - // FIXME - // still, we have some inconsistencies, publishName should go NULL when unpublishing it whole, see repository? content2 = contentService.GetById(content.Id); @@ -2644,7 +2662,7 @@ namespace Umbraco.Tests.Services Assert.AreEqual("name-fr2", content2.GetName(langFr.Id)); Assert.AreEqual("name-uk2", content2.GetName(langUk.Id)); - Assert.AreEqual("Home US2", content2.PublishName); // not null, see note above + Assert.AreEqual("Home US", content2.PublishName); // not null, see note above Assert.IsNull(content2.GetPublishName(langFr.Id)); Assert.AreEqual("name-uk", content2.GetPublishName(langUk.Id)); // not null, see note above @@ -2671,7 +2689,7 @@ namespace Umbraco.Tests.Services Assert.AreEqual("name-fr2", content2.GetName(langFr.Id)); Assert.AreEqual("name-uk2", content2.GetName(langUk.Id)); - Assert.AreEqual("Home US2", content2.PublishName); + Assert.AreEqual("Home US", content2.PublishName); Assert.IsNull(content2.GetPublishName(langFr.Id)); Assert.AreEqual("name-uk", content2.GetPublishName(langUk.Id));