public void MapPropertyToCms_PageEditorOnly_FieldNotUpdated() { //Assign var templateId = ID.NewID; var fieldId = ID.NewID; var targetId = ID.NewID; using (Db database = new Db { new DbTemplate(templateId) { { "Field", "" } }, new Sitecore.FakeDb.DbItem("Target", targetId, templateId), }) { var fieldValue = "test value set"; var fieldName = "Field"; var item = database.GetItem("/sitecore/content/Target"); var options = new GetItemOptionsParams(); var config = new SitecoreFieldConfiguration(); config.FieldName = fieldName; config.PropertyInfo = typeof(Stub).GetProperty("Property"); config.ReadOnly = false; config.Setting = SitecoreFieldSettings.PageEditorOnly; var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = fieldValue; Assert.IsFalse(mapper.ReadOnly); var context = new SitecoreDataMappingContext(new Stub(), item, null, options); using (new SecurityDisabler()) { item.Editing.BeginEdit(); item[fieldName] = string.Empty; item.Editing.EndEdit(); } //Act using (new SecurityDisabler()) { item.Editing.BeginEdit(); mapper.MapPropertyToCms(context); item.Editing.EndEdit(); } //Assert var itemAfter = database.GetItem("/sitecore/content/Target"); Assert.AreNotEqual(mapper.Value, itemAfter[fieldName]); Assert.AreEqual(item[fieldName], itemAfter[fieldName]); } }
public void MapPropertyToCms_PageEditorOnly_FieldNotUpdated() { //Assign var fieldValue = "test value set"; var fieldName = "Field"; var database = Sitecore.Configuration.Factory.GetDatabase("master"); var item = database.GetItem("/sitecore/content/Tests/DataMappers/AbstractSitecoreFieldMapper/MapToCms"); var config = new SitecoreFieldConfiguration(); config.FieldName = fieldName; config.PropertyInfo = typeof(Stub).GetProperty("Property"); config.ReadOnly = false; config.Setting = SitecoreFieldSettings.PageEditorOnly; var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = fieldValue; Assert.IsFalse(mapper.ReadOnly); var context = new SitecoreDataMappingContext(new Stub(), item, null); using (new SecurityDisabler()) { item.Editing.BeginEdit(); item[fieldName] = string.Empty; item.Editing.EndEdit(); } //Act using (new SecurityDisabler()) { item.Editing.BeginEdit(); mapper.MapPropertyToCms(context); item.Editing.EndEdit(); } //Assert var itemAfter = database.GetItem("/sitecore/content/Tests/DataMappers/AbstractSitecoreFieldMapper/MapToCms"); Assert.AreNotEqual(mapper.Value, itemAfter[fieldName]); Assert.AreEqual(item[fieldName], itemAfter[fieldName]); }
public void MapPropertyToCms_PageEditorOnly_FieldNotUpdated() { //Assign var templateId = ID.NewID; var fieldId = ID.NewID; var targetId = ID.NewID; using (Db database = new Db { new DbTemplate(templateId) { {"Field", ""} }, new Sitecore.FakeDb.DbItem("Target", targetId, templateId), }) { var fieldValue = "test value set"; var fieldName = "Field"; var item = database.GetItem("/sitecore/content/Target"); var config = new SitecoreFieldConfiguration(); config.FieldName = fieldName; config.PropertyInfo = typeof(Stub).GetProperty("Property"); config.ReadOnly = false; config.Setting = SitecoreFieldSettings.PageEditorOnly; var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = fieldValue; Assert.IsFalse(mapper.ReadOnly); var context = new SitecoreDataMappingContext(new Stub(), item, null); using (new SecurityDisabler()) { item.Editing.BeginEdit(); item[fieldName] = string.Empty; item.Editing.EndEdit(); } //Act using (new SecurityDisabler()) { item.Editing.BeginEdit(); mapper.MapPropertyToCms(context); item.Editing.EndEdit(); } //Assert var itemAfter = database.GetItem("/sitecore/content/Target"); Assert.AreNotEqual(mapper.Value, itemAfter[fieldName]); Assert.AreEqual(item[fieldName], itemAfter[fieldName]); } }