Пример #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
        [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);
                }
            }
        }
        [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);
            }
        }