Пример #1
0
        [Category("Exclude82")] //Required FakeDB fix
        public void GetField_FieldContainsInternalAbsoluteUrl_ReturnsInternalLink()
        {
            //Assign
            var templateId = ID.NewID;
            var targetId   = ID.NewID;
            var fieldName  = "Field";

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { fieldName, "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var mapper     = new SitecoreFieldLinkMapper(new FakeUrlOptionsResolver());
                var fieldValue =
                    "<link text=\"Test description\" linktype=\"internal\" url=\"/Tests/DataMappers/SitecoreFieldLinkMapper/Target.aspx\" anchor=\"testAnchor\" querystring=\"q=s\" title=\"test alternative\" class=\"testClass\" target=\"testTarget\" id=\"{0}\" />"
                    .Formatted(targetId);

                Sitecore.Context.Site = null;


                var item   = database.GetItem("/sitecore/content/Target");
                var field  = item.Fields[fieldName];
                var config = new SitecoreFieldConfiguration();
                config.UrlOptions = SitecoreInfoUrlOptions.LanguageEmbeddingNever;

                using (new ItemEditing(item, true))
                {
                    field.Value = fieldValue;
                }

                Sitecore.Links.LinkProvider provider =
                    Substitute.For <Sitecore.Links.LinkProvider>();
                provider
                .GetItemUrl(item, Arg.Is <Sitecore.Links.UrlOptions>(x => x.LanguageEmbedding == LanguageEmbedding.Never))
                .Returns("/target.aspx");


                using (new Sitecore.FakeDb.Links.LinkProviderSwitcher(provider))
                {
                    //Act
                    var result = mapper.GetField(field, config, null) as Link;

                    //Assert
                    Assert.AreEqual("testAnchor", result.Anchor);
                    Assert.AreEqual("testClass", result.Class);
                    Assert.AreEqual("q=s", result.Query);
                    Assert.AreEqual("testTarget", result.Target);
                    Assert.AreEqual(targetId.Guid, result.TargetId);
                    Assert.AreEqual("Test description", result.Text);
                    Assert.AreEqual("test alternative", result.Title);
                    Assert.AreEqual(LinkType.Internal, result.Type);
                    Assert.AreEqual("/target.aspx",
                                    result.Url);
                }
            }
        }
Пример #2
0
        public void GetField_FieldContainsJavaScript_ReturnsJavascriptLink()
        {
            //Assign
            var mapper     = new SitecoreFieldLinkMapper();
            var fieldValue =
                "<link text=\"Test description\" linktype=\"javascript\" url=\"javascript:alert('hello world');\" anchor=\"\" title=\"test alternate\" class=\"testClass\" />";

            var item  = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldLinkMapper/GetField");
            var field = item.Fields[FieldName];

            using (new ItemEditing(item, true))
            {
                field.Value = fieldValue;
            }

            //Act
            var result = mapper.GetField(field, null, null) as Link;

            //Assert
            Assert.AreEqual("", result.Anchor);
            Assert.AreEqual("testClass", result.Class);
            Assert.AreEqual("", result.Query);
            Assert.AreEqual("", result.Target);
            Assert.AreEqual(Guid.Empty, result.TargetId);
            Assert.AreEqual("Test description", result.Text);
            Assert.AreEqual("test alternate", result.Title);
            Assert.AreEqual(LinkType.JavaScript, result.Type);
            Assert.AreEqual("javascript:alert('hello world');", result.Url);
        }
Пример #3
0
        public void GetField_FieldContainsExternal_ReturnsExternalLink()
        {
            //Assign
            var mapper     = new SitecoreFieldLinkMapper();
            var fieldValue =
                "<link text=\"Test description\" linktype=\"external\" url=\"http://www.google.com\" anchor=\"\" title=\"test alternative\" class=\"testClass\" target=\"_blank\" />";

            var item  = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldLinkMapper/GetField");
            var field = item.Fields[FieldName];

            using (new ItemEditing(item, true))
            {
                field.Value = fieldValue;
            }

            //Act
            var result = mapper.GetField(field, null, null) as Link;

            //Assert
            Assert.AreEqual("", result.Anchor);
            Assert.AreEqual("testClass", result.Class);
            Assert.AreEqual("", result.Query);
            Assert.AreEqual("_blank", result.Target);
            Assert.AreEqual(Guid.Empty, result.TargetId);
            Assert.AreEqual("Test description", result.Text);
            Assert.AreEqual("test alternative", result.Title);
            Assert.AreEqual(LinkType.External, result.Type);
            Assert.AreEqual("http://www.google.com", result.Url);
        }
Пример #4
0
        public void GetField_FieldContainsMediaLinkMissingItem_ReturnsNotSetLink()
        {
            //Assign
            var mapper     = new SitecoreFieldLinkMapper();
            var fieldValue =
                "<link text=\"Test description\" linktype=\"media\" url=\"/Files/20121222_001405\" title=\"test alternative\" class=\"testClass\" target=\"_blank\" id=\"{11111111-CF15-4067-A3F4-85148606F9CD}\" />";

            var item  = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldLinkMapper/GetField");
            var field = item.Fields[FieldName];

            using (new ItemEditing(item, true))
            {
                field.Value = fieldValue;
            }

            //Act
            var result = mapper.GetField(field, null, null) as Link;

            //Assert
            Assert.AreEqual("", result.Anchor);
            Assert.AreEqual("testClass", result.Class);
            Assert.AreEqual("", result.Query);
            Assert.AreEqual("_blank", result.Target);
            Assert.AreEqual(new Guid("{11111111-CF15-4067-A3F4-85148606F9CD}"), result.TargetId);
            Assert.AreEqual("Test description", result.Text);
            Assert.AreEqual("test alternative", result.Title);
            Assert.AreEqual(LinkType.Media, result.Type);
            Assert.AreEqual("", result.Url);
        }
Пример #5
0
        public void GetField_FieldContainsInternalMissingItem_ReturnsNotSetLink()
        {
            //Assign
            var mapper     = new SitecoreFieldLinkMapper();
            var fieldValue =
                "<link text=\"Test description\" linktype=\"internal\" url=\"/Tests/DataMappers/SitecoreFieldLinkMapper/Target.aspx\" anchor=\"testAnchor\" querystring=\"q=s\" title=\"test alternative\" class=\"testClass\" target=\"testTarget\" id=\"{11111111-3B6F-4F5F-A5C2-FD2B9D5A47A0}\" />";

            var item  = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldLinkMapper/GetField");
            var field = item.Fields[FieldName];

            using (new ItemEditing(item, true))
            {
                field.Value = fieldValue;
            }

            //Act
            var result = mapper.GetField(field, new SitecoreFieldConfiguration(), null) as Link;

            //Assert
            Assert.AreEqual("testAnchor", result.Anchor);
            Assert.AreEqual("testClass", result.Class);
            Assert.AreEqual("q=s", result.Query);
            Assert.AreEqual("testTarget", result.Target);
            Assert.AreEqual(new Guid("{11111111-3B6F-4F5F-A5C2-FD2B9D5A47A0}"), result.TargetId);
            Assert.AreEqual("Test description", result.Text);
            Assert.AreEqual("test alternative", result.Title);
            Assert.AreEqual(LinkType.Internal, result.Type);
            Assert.AreEqual("", result.Url);
        }
Пример #6
0
        [Category("Exclude82")] //Requires fake db fix
        public void GetField__InternalLink_FieldContainsInternal_ReturnsInternalLink()
        {
            //Assign
            var templateId = ID.NewID;
            var targetId   = ID.NewID;
            var fieldName  = "Field";

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    new DbField(fieldName)
                    {
                        Type = "internal link"
                    }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var mapper     = new SitecoreFieldLinkMapper(new FakeUrlOptionsResolver());
                var fieldValue = "/sitecore/content/Target";

                Sitecore.Context.Site = null;


                var item  = database.GetItem("/sitecore/content/Target");
                var field = item.Fields[fieldName];

                using (new ItemEditing(item, true))
                {
                    field.Value = fieldValue;
                }

                Sitecore.Links.LinkProvider provider =
                    Substitute.For <Sitecore.Links.LinkProvider>();
                provider
                .GetItemUrl(item, Arg.Any <Sitecore.Links.UrlOptions>())
                .Returns("/target.aspx");


                using (new Sitecore.FakeDb.Links.LinkProviderSwitcher(provider))
                {
                    //Act
                    var result = mapper.GetField(field, new SitecoreFieldConfiguration(), null) as Link;

                    //Assert
                    Assert.AreEqual(null, result.Anchor);
                    Assert.AreEqual(null, result.Class);
                    Assert.AreEqual(null, result.Query);
                    Assert.AreEqual(null, result.Target);
                    Assert.AreEqual(targetId.Guid, result.TargetId);
                    Assert.AreEqual("Target", result.Text);
                    Assert.AreEqual(null, result.Title);
                    Assert.AreEqual(LinkType.Internal, result.Type);
                    Assert.AreEqual("/target.aspx", result.Url);
                }
            }
        }
Пример #7
0
        public void GetField_FieldContainsMediaLink_ReturnsMediaLink()
        {
            //Assign
            var templateId = ID.NewID;
            var targetId   = ID.NewID;
            var fieldName  = "Field";

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { fieldName, "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var mapper     = new SitecoreFieldLinkMapper(new FakeUrlOptionsResolver());
                var fieldValue =
                    "<link text=\"Test description\" linktype=\"media\" url=\"/Files/20121222_001405\" title=\"test alternative\" class=\"testClass\" target=\"_blank\" id=\"{0}\" />"
                    .Formatted(targetId);

                var item  = database.GetItem("/sitecore/content/Target");
                var field = item.Fields[fieldName];

                using (new ItemEditing(item, true))
                {
                    field.Value = fieldValue;
                }
                Sitecore.Resources.Media.MediaProvider mediaProvider =
                    NSubstitute.Substitute.For <Sitecore.Resources.Media.MediaProvider>();

                mediaProvider
                .GetMediaUrl(Arg.Is <Sitecore.Data.Items.MediaItem>(i => i.ID == targetId))
                .Returns("Media.Aspx");

                // substitute the original provider with the mocked one
                using (new Sitecore.FakeDb.Resources.Media.MediaProviderSwitcher(mediaProvider))
                {
                    //Act
                    var result = mapper.GetField(field, null, null) as Link;

                    //Assert
                    Assert.AreEqual("", result.Anchor);
                    Assert.AreEqual("testClass", result.Class);
                    Assert.AreEqual("", result.Query);
                    Assert.AreEqual("_blank", result.Target);
                    Assert.AreEqual(targetId.Guid, result.TargetId);
                    Assert.AreEqual("Test description", result.Text);
                    Assert.AreEqual("test alternative", result.Title);
                    Assert.AreEqual(LinkType.Media, result.Type);
                    Assert.AreEqual("Media.Aspx", result.Url);
                }
            }
        }
        public void GetField_FieldContainsInternalButItemMissing_ReturnsEmptyUrl()
        {
            //Assign
            var templateId = ID.NewID;
            var targetId   = ID.NewID;
            var fieldName  = "Field";

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { fieldName, "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                //Assign
                var mapper     = new SitecoreFieldLinkMapper();
                var fieldValue =
                    "<link text=\"Test description\" linktype=\"internal\" url=\"/Tests/DataMappers/SitecoreFieldLinkMapper/Target.aspx\" anchor=\"testAnchor\" querystring=\"q=s\" title=\"test alternative\" class=\"testClass\" target=\"testTarget\" id=\"{AAAAAAAA-3B6F-4F5F-A5C2-FD2B9D5A47A0}\" />";

                Sitecore.Context.Site = null;


                var item  = database.GetItem("/sitecore/content/Target");
                var field = item.Fields[fieldName];

                using (new ItemEditing(item, true))
                {
                    field.Value = fieldValue;
                }

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


                //Act
                var result = mapper.GetField(field, new SitecoreFieldConfiguration(), context) as Link;

                //Assert
                Assert.AreEqual("testAnchor", result.Anchor);
                Assert.AreEqual("testClass", result.Class);
                Assert.AreEqual("q=s", result.Query);
                Assert.AreEqual("testTarget", result.Target);
                Assert.AreEqual(new Guid("{AAAAAAAA-3B6F-4F5F-A5C2-FD2B9D5A47A0}"), result.TargetId);
                Assert.AreEqual("Test description", result.Text);
                Assert.AreEqual("test alternative", result.Title);
                Assert.AreEqual(LinkType.Internal, result.Type);
                Assert.AreEqual(string.Empty, result.Url);
            }
        }
        public void GetField_FieldContainsAnchor_ReturnsAnchorLink()
        {
            //Assign
            var templateId = ID.NewID;
            var targetId   = ID.NewID;
            var fieldName  = "Field";

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { fieldName, "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var mapper     = new SitecoreFieldLinkMapper();
                var fieldValue =
                    "<link text=\"Test description\" linktype=\"anchor\" url=\"testAnchor\" anchor=\"testAnchor\" title=\"test alternate\" class=\"testClass\" style=\"mystyle\" />";

                var item  = database.GetItem("/sitecore/content/Target");
                var field = item.Fields[fieldName];

                using (new ItemEditing(item, true))
                {
                    field.Value = fieldValue;
                }

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


                //Act
                var result = mapper.GetField(field, null, context) as Link;

                //Assert
                Assert.AreEqual("testAnchor", result.Anchor);
                Assert.AreEqual("testClass", result.Class);
                Assert.AreEqual("", result.Query);
                Assert.AreEqual("", result.Target);
                Assert.AreEqual(Guid.Empty, result.TargetId);
                Assert.AreEqual("Test description", result.Text);
                Assert.AreEqual("test alternate", result.Title);
                Assert.AreEqual(LinkType.Anchor, result.Type);
                Assert.AreEqual("testAnchor", result.Url);
                Assert.AreEqual("mystyle", result.Style);
            }
        }
        public void GetField_FieldContainsMediaLinkMissingItem_ReturnsNotSetLink()
        {
            //Assign
            var templateId = ID.NewID;
            var targetId   = ID.NewID;
            var fieldName  = "Field";

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { fieldName, "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var mapper     = new SitecoreFieldLinkMapper(new FakeUrlOptionsResolver());
                var fieldValue =
                    "<link text=\"Test description\" linktype=\"media\" url=\"/Files/20121222_001405\" title=\"test alternative\" class=\"testClass\" target=\"_blank\" id=\"{11111111-CF15-4067-A3F4-85148606F9CD}\" />";

                var item  = database.GetItem("/sitecore/content/Target");
                var field = item.Fields[fieldName];

                using (new ItemEditing(item, true))
                {
                    field.Value = fieldValue;
                }


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

                //Act
                var result = mapper.GetField(field, null, context) as Link;

                //Assert
                Assert.AreEqual("", result.Anchor);
                Assert.AreEqual("testClass", result.Class);
                Assert.AreEqual("", result.Query);
                Assert.AreEqual("_blank", result.Target);
                Assert.AreEqual(new Guid("{11111111-CF15-4067-A3F4-85148606F9CD}"), result.TargetId);
                Assert.AreEqual("Test description", result.Text);
                Assert.AreEqual("test alternative", result.Title);
                Assert.AreEqual(LinkType.Media, result.Type);
                Assert.AreEqual("", result.Url);
            }
        }
Пример #11
0
        public void GetField_FieldContainsMailto_ReturnsMailtoLink()
        {
            //Assign
            var templateId = ID.NewID;
            var targetId   = ID.NewID;
            var fieldName  = "Field";

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { fieldName, "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var mapper     = new SitecoreFieldLinkMapper();
                var fieldValue =
                    "<link text=\"Test description\" linktype=\"mailto\" url=\"mailto:[email protected]\" anchor=\"\" title=\"test alternate\" class=\"testClass\" />";

                var item  = database.GetItem("/sitecore/content/Target");
                var field = item.Fields[fieldName];

                using (new ItemEditing(item, true))
                {
                    field.Value = fieldValue;
                }

                //Act
                var result = mapper.GetField(field, new SitecoreFieldConfiguration(), null) as Link;

                //Assert
                Assert.AreEqual("", result.Anchor);
                Assert.AreEqual("testClass", result.Class);
                Assert.AreEqual("", result.Query);
                Assert.AreEqual("", result.Target);
                Assert.AreEqual(Guid.Empty, result.TargetId);
                Assert.AreEqual("Test description", result.Text);
                Assert.AreEqual("test alternate", result.Title);
                Assert.AreEqual(LinkType.MailTo, result.Type);
                Assert.AreEqual("mailto:[email protected]", result.Url);
            }
        }
        [Category("Exclude82")] //Requires fake db fix
        public void GetField_FieldContainsInternalWithSpecialCharacters_ReturnsInternalLink()
        {
            //Assign
            var templateId = ID.NewID;
            var targetId   = ID.NewID;
            var fieldName  = "Field";

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { fieldName, "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var mapper     = new SitecoreFieldLinkMapper(new FakeUrlOptionsResolver());
                var fieldValue =
                    "<link text=\"Test description\" linktype=\"internal\" url=\"/Target.aspx\" anchor=\"testAnchor\" querystring=\"q%3ds%253d\" title=\"test alternative\" class=\"testClass\" target=\"testTarget\" id=\"{0}\" />"
                    .Formatted(targetId);

                Sitecore.Context.Site = null;


                var item  = database.GetItem("/sitecore/content/Target");
                var field = item.Fields[fieldName];

                using (new ItemEditing(item, true))
                {
                    field.Value = fieldValue;
                }

#if SC90 || SC91
                var linkProvider = Substitute.For <BaseLinkManager>();
                linkProvider
                .GetItemUrl(item, Arg.Any <Sitecore.Links.UrlOptions>())
                .Returns("/target.aspx");

                SitecoreVersionAbstractions.LinkManager = new LazyResetable <BaseLinkManager>(() => linkProvider);
#else
                Sitecore.Links.LinkProvider provider =
                    Substitute.For <Sitecore.Links.LinkProvider>();
                provider
                .GetItemUrl(item, Arg.Any <Sitecore.Links.UrlOptions>())
                .Returns("/target.aspx");


                new Sitecore.FakeDb.Links.LinkProviderSwitcher(provider);
#endif

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


                //Act
                var result = mapper.GetField(field, new SitecoreFieldConfiguration(), context) as Link;

                //Assert
                Assert.AreEqual("testAnchor", result.Anchor);
                Assert.AreEqual("testClass", result.Class);
                Assert.AreEqual("q=s%3d", result.Query);
                Assert.AreEqual("testTarget", result.Target);
                Assert.AreEqual(targetId.Guid, result.TargetId);
                Assert.AreEqual("Test description", result.Text);
                Assert.AreEqual("test alternative", result.Title);
                Assert.AreEqual(LinkType.Internal, result.Type);
                Assert.AreEqual("/target.aspx", result.Url);
            }
        }
        public void GetField_FieldContainsMediaLink_ReturnsMediaLink()
        {
            //Assign
            var templateId = ID.NewID;
            var targetId   = ID.NewID;
            var fieldName  = "Field";

            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    { fieldName, "" }
                },
                new Sitecore.FakeDb.DbItem("Target", targetId, templateId),
            })
            {
                var mapper     = new SitecoreFieldLinkMapper(new FakeUrlOptionsResolver());
                var fieldValue =
                    "<link text=\"Test description\" linktype=\"media\" url=\"/Files/20121222_001405\" title=\"test alternative\" class=\"testClass\" target=\"_blank\" id=\"{0}\" />"
                    .Formatted(targetId);

                var item  = database.GetItem("/sitecore/content/Target");
                var field = item.Fields[fieldName];

                using (new ItemEditing(item, true))
                {
                    field.Value = fieldValue;
                }


#if SC90 || SC91 || SC92 || SC93 || SC100
                var mediaUrlProvider = Substitute.For <BaseMediaManager>();

                SitecoreVersionAbstractions.MediaManager = new LazyResetable <BaseMediaManager>(() => mediaUrlProvider);

                mediaUrlProvider
                .GetMediaUrl(Arg.Is <Sitecore.Data.Items.MediaItem>(i => i.ID == targetId))
                .Returns("Media.Aspx");
#else
                Sitecore.Resources.Media.MediaProvider mediaProvider =
                    Substitute.For <Sitecore.Resources.Media.MediaProvider>();
                mediaProvider
                .GetMediaUrl(Arg.Is <Sitecore.Data.Items.MediaItem>(i => i.ID == targetId))
                .Returns("Media.Aspx");

                new Sitecore.FakeDb.Resources.Media.MediaProviderSwitcher(mediaProvider);
#endif

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


                //Act
                var result = mapper.GetField(field, null, context) as Link;

                //Assert
                Assert.AreEqual("", result.Anchor);
                Assert.AreEqual("testClass", result.Class);
                Assert.AreEqual("", result.Query);
                Assert.AreEqual("_blank", result.Target);
                Assert.AreEqual(targetId.Guid, result.TargetId);
                Assert.AreEqual("Test description", result.Text);
                Assert.AreEqual("test alternative", result.Title);
                Assert.AreEqual(LinkType.Media, result.Type);
                Assert.AreEqual("Media.Aspx", result.Url);
            }
        }