public void GetField_RichText_StringIsReturnedWithScapedUrl()
        {
            //Assign
            var fieldValue = "<p>Test with <a href=\"~/link.aspx?_id=BFD7975DF42F41E19DDA9A38E971555F&amp;_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_RichTextSettingsIsRaw_StringIsReturnedWithoutEscaping()
        {
            //Assign
            var fieldValue = "<p>Test with <a href=\"~/link.aspx?_id=BFD7975DF42F41E19DDA9A38E971555F&amp;_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);
        }
Exemplo n.º 3
0
        public void GetField_ForceRenderFieldPipeline_StringIsReturned()
        {
            //Assign

            var fieldValue = "<p>hello world</p>";
            var expected   = "&lt;p&gt;hello world&lt;/p&gt;";

            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);
        }
Exemplo n.º 4
0
        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_RichText_ValueGoesByRenderFieldPipeline()
        {
            //Assign
            var fieldBase =
                "<p>Test with <a href=\"~/link.aspx?_id=BFD7975DF42F41E19DDA9A38E971555F&amp;_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;
                    }


                    var context = new SitecoreDataMappingContext(null, item, null, new GetItemByPathOptions());


                    //Act
                    var result = mapper.GetField(field, config, context) as string;

                    Sitecore.Context.Site = null;

                    //Assert
                    Assert.AreEqual(expected, result);
                }
            }
        }
        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);

                    var context = new SitecoreDataMappingContext(null, item, null, new GetItemByPathOptions());

                    //Act
                    var result = mapper.GetField(field, config, context) as string;

                    //Assert

                    Sitecore.Context.Site = null;

                    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);
        }