示例#1
0
        public static string GetFullPageUrl(Guid pageId)
        {
            if (pageId != Guid.Empty)
            {
                var siteMap = SitefinitySiteMap.GetCurrentProvider();

                SiteMapNode node;
                var         sitefinitySiteMap = siteMap as SiteMapBase;
                if (sitefinitySiteMap != null)
                {
                    node = sitefinitySiteMap.FindSiteMapNodeFromKey(pageId.ToString(), false);
                }
                else
                {
                    node = siteMap.FindSiteMapNodeFromKey(pageId.ToString());
                }

                if (node != null)
                {
                    return(UrlPath.ResolveUrl(node.Url, true));
                }
            }

            return(null);
        }
示例#2
0
        public void NavigationWidget_AllSiblingPagesOfCurrentlyOpenedPage()
        {
            string pageNamePrefix1  = "NavigationPage1";
            string pageTitlePrefix1 = "Navigation Page1";
            string urlNamePrefix1   = "navigation-page1";

            string pageNamePrefix2  = "NavigationPage2";
            string pageTitlePrefix2 = "Navigation Page2";
            string urlNamePrefix2   = "navigation-page2";

            var fluent   = App.WorkWith();
            var page1Key = TestUtils.CreateAndPublishPage(fluent, PageLocation.Frontend, pageNamePrefix1, pageTitlePrefix1, urlNamePrefix1, null, false);

            this.createdPageIDs.Add(page1Key);

            var page2Key = TestUtils.CreateAndPublishPage(fluent, PageLocation.Frontend, pageNamePrefix2, pageTitlePrefix2, urlNamePrefix2, null, false);

            this.createdPageIDs.Add(page2Key);

            var page1Node = SitefinitySiteMap.GetCurrentProvider().FindSiteMapNodeFromKey(page1Key.ToString());

            SystemManager.CurrentHttpContext.Items[SiteMapBase.CurrentNodeKey] = page1Node;

            var navModel = new NavigationModel(PageSelectionMode.CurrentPageSiblings, Guid.Empty, null, -1, true, string.Empty, false);

            var expectedCount = 2;
            var actualCount   = navModel.Nodes.Count;

            Assert.AreEqual(expectedCount, actualCount);
            Assert.AreEqual(pageTitlePrefix1, navModel.Nodes[0].Title);
        }
示例#3
0
        private string PageUrl()
        {
            if (this.PageId != Guid.Empty)
            {
                var siteMap = SitefinitySiteMap.GetCurrentProvider();

                SiteMapNode node;
                var         sitefinitySiteMap = siteMap as SiteMapBase;
                if (sitefinitySiteMap != null)
                {
                    node = sitefinitySiteMap.FindSiteMapNodeFromKey(this.PageId.ToString(), false);
                }
                else
                {
                    node = siteMap.FindSiteMapNodeFromKey(this.PageId.ToString());
                }

                if (node != null)
                {
                    return(UrlPath.ResolveUrl(node.Url, true));
                }
            }

            return(string.Empty);
        }
        public static string GetCurrentPageUrl(this IController controller)
        {
            var currentSiteMap = (SiteMapBase)SitefinitySiteMap.GetCurrentProvider();
            var currentNode    = currentSiteMap.CurrentNode;
            var url            = string.Empty;

            if (currentNode != null)
            {
                url = UrlPath.ResolveUrl(currentNode.Url, absolute: false, removeTrailingSlash: true);
            }

            return(url);
        }
示例#5
0
        public void BreadcrumbModel_FromHomeToCurrentPage()
        {
            this.CreateTestPages();

            var model     = new BreadcrumbModel();
            var viewModel = model.CreateViewModel(null);

            for (int i = 0; i < BreadcrumbWidgetTests.TestPagesCount; i++)
            {
                var expected = SitefinitySiteMap.GetCurrentProvider().FindSiteMapNodeFromKey(this.createdPageIDs[i].ToString());
                var actual   = viewModel.SiteMapNodes[i];

                Assert.AreEqual(expected.Title, actual.Title);
            }
        }
示例#6
0
        public void BreadcrumbModel_FromHomeToCurrentPage_WithRestrictedPages()
        {
            this.CreateTestPages();

            ObjectFactory.RegisterSitemapNodeFilter <DummySitemapFilter>("DummyFilter");
            var restrictedPageIndex = 1;

            DummySitemapFilter.RestrictPageNode(this.createdPageIDs[restrictedPageIndex]);

            //// invalidates sitemap cache
            var inf = typeof(SiteMapBase).GetMethod("Reset", BindingFlags.Static | BindingFlags.NonPublic);

            inf.Invoke(null, null);

            using (var userReg = new CreateUserRegion("Viewer" + Guid.NewGuid().ToString("N") + "@mail.com", false))
            {
                using (var profileReg = new CreateUserProfileRegion(userReg.User, "Viewer"))
                {
                    using (new AuthenticateUserRegion(userReg.User))
                    {
                        var model     = new BreadcrumbModel();
                        var viewModel = model.CreateViewModel(null);
                        var skipStep  = 0;

                        for (int i = 0; i < BreadcrumbWidgetTests.TestPagesCount; i++)
                        {
                            var expected = SitefinitySiteMap.GetCurrentProvider().FindSiteMapNodeFromKey(this.createdPageIDs[i].ToString());
                            if (i == restrictedPageIndex)
                            {
                                Assert.IsNull(expected);
                                skipStep--;
                                continue;
                            }

                            var breadcrumgIndex = i + skipStep;
                            var actual          = viewModel.SiteMapNodes[breadcrumgIndex];
                            Assert.AreEqual(expected.Title, actual.Title);
                        }
                    }
                }
            }

            DummySitemapFilter.Clear();
        }
示例#7
0
        private void CreateTestPages(bool groupPages = false)
        {
            var baseName = "testPage";

            var      fluent     = App.WorkWith();
            PageNode parentPage = null;

            for (int i = 0; i < BreadcrumbWidgetTests.TestPagesCount; i++)
            {
                var isGroupPage = groupPages && i < BreadcrumbWidgetTests.TestPagesCount - 1 && i != 0;
                var name        = baseName + i;
                var pageId      = TestUtils.CreateAndPublishPage(fluent, PageLocation.Frontend, name, name, name, parentPage, isGroupPage);
                this.createdPageIDs.Add(pageId);

                parentPage = fluent.Page(pageId).Get();
            }

            var pageNode = SitefinitySiteMap.GetCurrentProvider().FindSiteMapNodeFromKey(this.createdPageIDs.Last().ToString());

            SystemManager.CurrentHttpContext.Items[SiteMapBase.CurrentNodeKey] = pageNode;
        }
示例#8
0
        // Checks whether we are under a top-level page with a certain title.
        private bool IsPageUnder(IWorkflowResolutionContext context, string topLevelTitle)
        {
            if (typeof(PageNode).IsAssignableFrom(context.ContentType) &&
                context.ContentId != Guid.Empty)
            {
                var          siteMap      = SitefinitySiteMap.GetCurrentProvider() as SiteMapBase;
                PageSiteNode pageSiteNode = (PageSiteNode)siteMap.FindSiteMapNodeFromKey(context.ContentId.ToString());

                while (pageSiteNode != null)
                {
                    if (pageSiteNode.Title == topLevelTitle && pageSiteNode.ParentNode == pageSiteNode.RootNode)
                    {
                        return(true);
                    }

                    pageSiteNode = pageSiteNode.ParentNode as PageSiteNode;
                }
            }

            return(false);
        }
示例#9
0
        public void BreadcrumbModel_BreadcrumbExtender_VirtualNodes()
        {
            this.CreateTestPages();

            var model = new BreadcrumbModel();

            model.AllowVirtualNodes = true;
            var extender  = new DummyBreadcrumbExtender();
            var viewModel = model.CreateViewModel(extender);

            Assert.AreEqual(BreadcrumbWidgetTests.TestPagesCount + 1, viewModel.SiteMapNodes.Count);

            for (int i = 0; i < BreadcrumbWidgetTests.TestPagesCount; i++)
            {
                var expected = SitefinitySiteMap.GetCurrentProvider().FindSiteMapNodeFromKey(this.createdPageIDs[i].ToString());
                var actual   = viewModel.SiteMapNodes[i];

                Assert.AreEqual(expected.Title, actual.Title);
            }

            Assert.AreEqual(DummyBreadcrumbExtender.DummySiteMapNodeTitle, viewModel.SiteMapNodes.Last().Title);
        }