public void GetField_ForceRenderFieldPipeline_StringIsReturned() { //Assign var fieldValue = "<p>hello world</p>"; var expected = "<p>hello world</p>"; var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldStringMapper/GetField"); var field = item.Fields[FieldName]; var mapper = new SitecoreFieldStringMapper(); var config = new SitecoreFieldConfiguration(); config.Setting = SitecoreFieldSettings.ForceRenderField; using (new ItemEditing(item, true)) { field.Value = fieldValue; } Sitecore.Context.Site = Sitecore.Configuration.Factory.GetSite("website"); Sitecore.Context.Site.SetDisplayMode(DisplayMode.Preview, DisplayModeDuration.Remember); //Act var result = mapper.GetField(field, config, null) as string; //Assert Sitecore.Context.Site = null; Assert.AreEqual(expected, result); }
public void GetField_RichText_StringIsReturnedWithScapedUrl() { //Assign var fieldValue = "<p>Test with <a href=\"~/link.aspx?_id=BFD7975DF42F41E19DDA9A38E971555F&_z=z\">link</a></p>"; var expected = "<p>Test with <a href=\"/en/Tests/DataMappers/SitecoreFieldStringMapper/GetField.aspx\">link</a></p>"; var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldStringMapper/GetFieldRichText"); var field = item.Fields[FieldName]; var mapper = new SitecoreFieldStringMapper(); var config = new SitecoreFieldConfiguration(); Sitecore.Context.Site = Sitecore.Configuration.Factory.GetSite("website"); Sitecore.Context.Site.SetDisplayMode(DisplayMode.Preview, DisplayModeDuration.Remember); using (new ItemEditing(item, true)) { field.Value = fieldValue; } //Act var result = mapper.GetField(field, config, null) as string; Sitecore.Context.Site = null; //Assert Assert.AreEqual(expected, result); }
public void GetField_FieldContainsData_StringIsReturned() { //Assign var fieldValue = "hello world"; var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldStringMapper/GetField"); var field = item.Fields[FieldName]; var mapper = new SitecoreFieldStringMapper(); var config = new SitecoreFieldConfiguration(); using (new ItemEditing(item, true)) { field.Value = fieldValue; } //Act var result = mapper.GetField(field, config, null) as string; //Assert Assert.AreEqual(fieldValue, result); }
public void GetField_FieldContainsData_StringIsReturned() { //Assign var fieldValue = "<p>hello world</p>"; using (Db database = new Db { new Sitecore.FakeDb.DbItem("TestItem") { new DbField(FieldName) { Value = fieldValue } } }) { var item = database.GetItem("/sitecore/content/TestItem"); var field = item.Fields[FieldName]; var mapper = new SitecoreFieldStringMapper(); var config = new SitecoreFieldConfiguration(); using (new ItemEditing(item, true)) { field.Value = fieldValue; } //Act var result = mapper.GetField(field, config, null) as string; //Assert Assert.AreEqual(fieldValue, result); } }
public void GetField_RichTextSettingsIsRaw_StringIsReturnedWithoutEscaping() { //Assign var fieldValue = "<p>Test with <a href=\"~/link.aspx?_id=BFD7975DF42F41E19DDA9A38E971555F&_z=z\">link</a></p>"; var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldStringMapper/GetFieldRichText"); var field = item.Fields[FieldName]; var mapper = new SitecoreFieldStringMapper(); var config = new SitecoreFieldConfiguration(); config.Setting = SitecoreFieldSettings.RichTextRaw; Sitecore.Context.Site = Sitecore.Configuration.Factory.GetSite("website"); using (new ItemEditing(item, true)) { field.Value = fieldValue; } //Act var result = mapper.GetField(field, config, null) as string; Sitecore.Context.Site = null; //Assert Assert.AreEqual(fieldValue, result); }
public void CanHandle_StreamType_ReturnsTrue() { //Assign var mapper = new SitecoreFieldStringMapper(); var config = new SitecoreFieldConfiguration(); config.PropertyInfo = typeof (StubClass).GetProperty("String"); //Act var result = mapper.CanHandle(config, null); //Assert Assert.IsTrue(result); }
public void SetField_FielNonRichText_ValueWrittenToField() { //Assign var expected = "<p>Test with <a href=\"~/link.aspx?_id=BFD7975DF42F41E19DDA9A38E971555F&_z=z\">link</a></p>"; var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldStringMapper/SetField"); var field = item.Fields[FieldName]; var mapper = new SitecoreFieldStringMapper(); var config = new SitecoreFieldConfiguration(); config.Setting = SitecoreFieldSettings.RichTextRaw; Sitecore.Context.Site = Sitecore.Configuration.Factory.GetSite("website"); using (new ItemEditing(item, true)) { field.Value = string.Empty; } //Act using (new ItemEditing(item, true)) { mapper.SetField(field, expected, config, null); } Sitecore.Context.Site = null; //Assert Assert.AreEqual(expected, field.Value); }
public void SetField_ForceRenderFieldPipeline_ThrowsException() { //Assign var fieldValue = "<p>hello world</p>"; var expected = "<p>hello world</p>"; var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldStringMapper/GetField"); var field = item.Fields[FieldName]; var mapper = new SitecoreFieldStringMapper(); var config = new SitecoreFieldConfiguration(); config.Setting = SitecoreFieldSettings.ForceRenderField; config.PropertyInfo = new FakePropertyInfo(typeof(string), "String", typeof(StubClass)); using (new ItemEditing(item, true)) { field.Value = fieldValue; } //Act mapper.SetField(field, fieldValue, config, null); //Assert }
public void GetField_ForceRenderFieldPipeline_StringIsReturned() { //Assign var fieldValue = SimpleRenderField.ReplacementKey + "<p>hello world</p>"; var expected = SimpleRenderField.ReplacementValue + "<p>hello world</p>"; using (Db database = new Db { new Sitecore.FakeDb.DbItem("TestItem") { new DbField(FieldName) { Value = fieldValue } } }) { using (new FakeSite()) { var item = database.GetItem("/sitecore/content/TestItem"); var field = item.Fields[FieldName]; var mapper = new SitecoreFieldStringMapper(); var config = new SitecoreFieldConfiguration(); config.Setting = SitecoreFieldSettings.ForceRenderField; using (new ItemEditing(item, true)) { field.Value = fieldValue; } Sitecore.Context.Site = Sitecore.Configuration.Factory.GetSite("website"); Sitecore.Context.Site.SetDisplayMode(DisplayMode.Preview, DisplayModeDuration.Remember); //Act var result = mapper.GetField(field, config, null) as string; //Assert Sitecore.Context.Site = null; Assert.AreEqual(expected, result); } } }
public void SetField_RichText_ThrowsException() { //Assign var expected = "<p>Test with <a href=\"~/link.aspx?_id=BFD7975DF42F41E19DDA9A38E971555F&_z=z\">link</a></p>"; using (Db database = new Db { new Sitecore.FakeDb.DbItem("TestItem") { new DbField(FieldName) { Type = "Rich Text" } } }) { using (new FakeSite()) { var item = database.GetItem("/sitecore/content/TestItem"); var field = item.Fields[FieldName]; var mapper = new SitecoreFieldStringMapper(); var config = new SitecoreFieldConfiguration(); config.PropertyInfo = typeof(StubClass).GetProperty("String"); Sitecore.Context.Site = Sitecore.Configuration.Factory.GetSite("website"); using (new ItemEditing(item, true)) { field.Value = string.Empty; } //Act using (new ItemEditing(item, true)) { //Rich text not raw throws exception Assert.Throws<NotSupportedException>(() => mapper.SetField(field, expected, config, null)); } Sitecore.Context.Site = null; //Assert Assert.AreEqual(string.Empty, field.Value); } } }
public void GetField_RichText_ValueGoesByRenderFieldPipeline() { //Assign var fieldBase = "<p>Test with <a href=\"~/link.aspx?_id=BFD7975DF42F41E19DDA9A38E971555F&_z=z\">link</a></p>"; var fieldValue = SimpleRenderField.ReplacementKey + fieldBase; ; var expected = SimpleRenderField.ReplacementValue + fieldBase; using (Db database = new Db { new Sitecore.FakeDb.DbItem("TestItem") { new DbField(FieldName) { Value = fieldValue, Type = "Rich Text" } } }) { using (new FakeSite()) { var item = database.GetItem("/sitecore/content/TestItem"); var field = item.Fields[FieldName]; var mapper = new SitecoreFieldStringMapper(); var config = new SitecoreFieldConfiguration(); Sitecore.Context.Site = Sitecore.Configuration.Factory.GetSite("website"); Sitecore.Context.Site.SetDisplayMode(DisplayMode.Preview, DisplayModeDuration.Remember); using (new ItemEditing(item, true)) { field.Value = fieldValue; } //Act var result = mapper.GetField(field, config, null) as string; Sitecore.Context.Site = null; //Assert Assert.AreEqual(expected, result); } } }
public void SetField_ForceRenderFieldPipeline_ThrowsException() { //Assign var fieldValue = "<p>hello world</p>"; var expected = "<p>hello world</p>"; using (Db database = new Db { new Sitecore.FakeDb.DbItem("TestItem") { new DbField(FieldName) { Value = fieldValue } } }) { var item = database.GetItem("/sitecore/content/TestItem"); var field = item.Fields[FieldName]; var mapper = new SitecoreFieldStringMapper(); var config = new SitecoreFieldConfiguration(); config.Setting = SitecoreFieldSettings.ForceRenderField; config.PropertyInfo = new FakePropertyInfo(typeof(string), "String", typeof(StubClass)); using (new ItemEditing(item, true)) { field.Value = fieldValue; } //Act Assert.Throws<NotSupportedException>(()=> mapper.SetField(field, fieldValue, config, null)); //Assert } }