public void ContentPublishValuesWithMixedPropertyTypeVariations() { var propertyValidationService = new PropertyValidationService( Current.Factory.GetInstance <PropertyEditorCollection>(), Current.Factory.GetInstance <ServiceContext>().DataTypeService, Current.Factory.GetInstance <ServiceContext>().TextService); const string langFr = "fr-FR"; // content type varies by Culture // prop1 varies by Culture // prop2 is invariant var contentType = new ContentType(-1) { Alias = "contentType" }; contentType.Variations |= ContentVariation.Culture; var variantPropType = new PropertyType("editor", ValueStorageType.Nvarchar) { Alias = "prop1", Variations = ContentVariation.Culture, Mandatory = true }; var invariantPropType = new PropertyType("editor", ValueStorageType.Nvarchar) { Alias = "prop2", Variations = ContentVariation.Nothing, Mandatory = true }; contentType.AddPropertyType(variantPropType); contentType.AddPropertyType(invariantPropType); var content = new Content("content", -1, contentType) { Id = 1, VersionId = 1 }; content.SetCultureName("hello", langFr); //for this test we'll make the french culture the default one - this is needed for publishing invariant property values var langFrImpact = CultureImpact.Explicit(langFr, true); Assert.IsTrue(content.PublishCulture(langFrImpact)); // succeeds because names are ok (not validating properties here) Assert.IsFalse(propertyValidationService.IsPropertyDataValid(content, out _, langFrImpact)); // fails because prop1 is mandatory content.SetValue("prop1", "a", langFr); Assert.IsTrue(content.PublishCulture(langFrImpact)); // succeeds because names are ok (not validating properties here) // fails because prop2 is mandatory and invariant and the item isn't published. // Invariant is validated against the default language except when there isn't a published version, in that case it's always validated. Assert.IsFalse(propertyValidationService.IsPropertyDataValid(content, out _, langFrImpact)); content.SetValue("prop2", "x"); Assert.IsTrue(content.PublishCulture(langFrImpact)); // still ok... Assert.IsTrue(propertyValidationService.IsPropertyDataValid(content, out _, langFrImpact)); // now it's ok Assert.AreEqual("a", content.GetValue("prop1", langFr, published: true)); Assert.AreEqual("x", content.GetValue("prop2", published: true)); }
public void ContentPublishValuesWithMixedPropertyTypeVariations() { PropertyValidationService propertyValidationService = GetPropertyValidationService(); const string langFr = "fr-FR"; // content type varies by Culture // prop1 varies by Culture // prop2 is invariant IContentType contentType = new ContentTypeBuilder() .WithAlias("contentType") .Build(); contentType.Variations |= ContentVariation.Culture; PropertyType variantPropType = new PropertyTypeBuilder() .WithAlias("prop1") .WithVariations(ContentVariation.Culture) .WithMandatory(true) .Build(); PropertyType invariantPropType = new PropertyTypeBuilder() .WithAlias("prop2") .WithVariations(ContentVariation.Nothing) .WithMandatory(true) .Build(); contentType.AddPropertyType(variantPropType); contentType.AddPropertyType(invariantPropType); Content content = CreateContent(contentType); content.SetCultureName("hello", langFr); // for this test we'll make the french culture the default one - this is needed for publishing invariant property values var langFrImpact = CultureImpact.Explicit(langFr, true); Assert.IsTrue(content.PublishCulture(langFrImpact)); // succeeds because names are ok (not validating properties here) Assert.IsFalse(propertyValidationService.IsPropertyDataValid(content, out _, langFrImpact)); // fails because prop1 is mandatory content.SetValue("prop1", "a", langFr); Assert.IsTrue(content.PublishCulture(langFrImpact)); // succeeds because names are ok (not validating properties here) // Fails because prop2 is mandatory and invariant and the item isn't published. // Invariant is validated against the default language except when there isn't a published version, in that case it's always validated. Assert.IsFalse(propertyValidationService.IsPropertyDataValid(content, out _, langFrImpact)); content.SetValue("prop2", "x"); Assert.IsTrue(content.PublishCulture(langFrImpact)); // still ok... Assert.IsTrue(propertyValidationService.IsPropertyDataValid(content, out _, langFrImpact)); // now it's ok Assert.AreEqual("a", content.GetValue("prop1", langFr, published: true)); Assert.AreEqual("x", content.GetValue("prop2", published: true)); }
public void ContentPublishValuesWithMixedPropertyTypeVariations() { var propertyValidationService = new PropertyValidationService(Current.Factory.GetInstance <PropertyEditorCollection>(), Current.Factory.GetInstance <ServiceContext>().DataTypeService); const string langFr = "fr-FR"; // content type varies by Culture // prop1 varies by Culture // prop2 is invariant var contentType = new ContentType(-1) { Alias = "contentType" }; contentType.Variations |= ContentVariation.Culture; var variantPropType = new PropertyType("editor", ValueStorageType.Nvarchar) { Alias = "prop1", Variations = ContentVariation.Culture, Mandatory = true }; var invariantPropType = new PropertyType("editor", ValueStorageType.Nvarchar) { Alias = "prop2", Variations = ContentVariation.Nothing, Mandatory = true }; contentType.AddPropertyType(variantPropType); contentType.AddPropertyType(invariantPropType); var content = new Content("content", -1, contentType) { Id = 1, VersionId = 1 }; content.SetCultureName("hello", langFr); Assert.IsTrue(content.PublishCulture(langFr)); // succeeds because names are ok (not validating properties here) Assert.IsFalse(propertyValidationService.IsPropertyDataValid(content, out _, langFr)); // fails because prop1 is mandatory content.SetValue("prop1", "a", langFr); Assert.IsTrue(content.PublishCulture(langFr)); // succeeds because names are ok (not validating properties here) Assert.IsFalse(propertyValidationService.IsPropertyDataValid(content, out _, langFr)); // fails because prop2 is mandatory and invariant content.SetValue("prop2", "x"); Assert.IsTrue(content.PublishCulture(langFr)); // still ok... Assert.IsTrue(propertyValidationService.IsPropertyDataValid(content, out _, langFr)); // now it's ok Assert.AreEqual("a", content.GetValue("prop1", langFr, published: true)); Assert.AreEqual("x", content.GetValue("prop2", published: true)); }