public void EventWidget_AllEvents_FilterByCalendar() { var methodName = MethodInfo.GetCurrentMethod().Name; var calendarId = ServerOperations.Events().CreateCalendar(Guid.NewGuid(), "custom_calendar"); ServerOperations.Events().CreateEvent(methodName + "_fromdefault", "some content", false, DateTime.Now, DateTime.Now.AddHours(2), ServerOperations.Events().GetDefaultCalendarId()); ServerOperations.Events().CreateEvent(methodName + "_fromcustom", "some content", false, DateTime.Now, DateTime.Now.AddHours(2), calendarId); try { var mvcProxy = new MvcControllerProxy(); mvcProxy.ControllerName = typeof(EventController).FullName; var eventController = new EventController(); eventController.Model.NarrowSelectionMode = Telerik.Sitefinity.Frontend.Mvc.Models.SelectionMode.FilteredItems; eventController.Model.SerializedNarrowSelectionFilters = this.GetNarrowSelectionSerializedQueryData("Calendars", "Parent.Id.ToString()", "Parent.Id", calendarId, "System.String"); mvcProxy.Settings = new ControllerSettings(eventController); using (var generator = new PageContentGenerator()) { generator.CreatePageWithWidget(mvcProxy, null, methodName, methodName, methodName, 0); var pageContent = WebRequestHelper.GetPageWebContent(RouteHelper.GetAbsoluteUrl("~/" + methodName + "0")); Assert.Contains(pageContent, methodName + "_fromcustom", System.StringComparison.Ordinal); Assert.DoesNotContain(pageContent, methodName + "_fromdefault", System.StringComparison.Ordinal); } } finally { ServerOperations.Events().DeleteAllEvents(); ServerOperations.Events().DeleteCalendar(calendarId); } }
private Guid CreateTemplateWithWidgetAndBasePageOnIt(PageTemplateFramework framework, Controller widgetController, out Guid pageId, out string pageUrl) { var pageManager = PageManager.GetManager(); // Create template var templateId = framework == PageTemplateFramework.Hybrid ? ServerOperations.Templates().CreateHybridMVCPageTemplate(FrontendModuleFilterTests.TemplateTitle + Guid.NewGuid().ToString("N")) : ServerOperations.Templates().CreatePureMVCPageTemplate(FrontendModuleFilterTests.TemplateTitle + Guid.NewGuid().ToString("N")); // Place widget on template var mvcProxy = new MvcControllerProxy(); mvcProxy.ControllerName = widgetController.GetType().FullName; mvcProxy.Settings = new ControllerSettings(widgetController); SampleUtilities.AddControlToTemplate(templateId, mvcProxy, "Body", "FrontendModuleFilterTestsWidgetCaption"); // Create page with template var template = pageManager.GetTemplates().Where(t => t.Id == templateId).SingleOrDefault(); pageId = FeatherServerOperations.Pages().CreatePageWithTemplate(template, "TestPageName", "test-page-url"); var page = pageManager.GetPageNode(pageId); pageUrl = RouteHelper.GetAbsoluteUrl(page.GetFullUrl()); return(templateId); }
public void EventWidget_AllEvents_DisplayAll() { var methodName = MethodInfo.GetCurrentMethod().Name; try { this.BuildEvents(methodName); var eventController = new EventController(); eventController.Model.DisplayMode = ListDisplayMode.Paging; eventController.Model.SelectionMode = SelectionMode.AllItems; var mvcProxy = new MvcControllerProxy() { Settings = new ControllerSettings(eventController), ControllerName = typeof(EventController).FullName }; var containedEvents = new string[] { CurrentEventNameFormat, NextWeekEventNameFormat, NextMonthEventNameFormat, PreviousMonthEventNameFormat, PreviousWeekEventNameFormat }.Select(s => string.Format(CultureInfo.InvariantCulture, s, methodName)); using (var generator = new PageContentGenerator()) { generator.CreatePageWithWidget(mvcProxy, null, methodName, methodName, methodName, 0); var pageContent = WebRequestHelper.GetPageWebContent(RouteHelper.GetAbsoluteUrl("~/" + methodName + "0")); foreach (var title in containedEvents) { Assert.Contains(pageContent, title, StringComparison.Ordinal); } } } finally { ServerOperations.Events().DeleteAllEvents(); } }
public void FoundationResourcePackage_AddNewLayoutFile_VerifyGeneratedTemplateAndCreatedPageContent() { int templatesCount = this.PageManager.GetTemplates().Count(); try { string filePath = FeatherServerOperations.ResourcePackages().GetResourcePackageDestinationFilePath(Constants.PackageName, Constants.LayoutFileName); FeatherServerOperations.ResourcePackages().AddNewResource(Constants.LayoutFileResource, filePath); FeatherServerOperations.ResourcePackages().WaitForTemplatesCountToIncrease(templatesCount, 1); var template = this.PageManager.GetTemplates().Where(t => t.Title == Constants.TemplateTitle).FirstOrDefault(); Assert.IsNotNull(template, "Template was not found"); Guid pageId = FeatherServerOperations.Pages().CreatePageWithTemplate(template, Constants.PageTitle, Constants.PageUrl); var page = this.PageManager.GetPageNode(pageId); var pageUrl = page.GetFullUrl(); pageUrl = RouteHelper.GetAbsoluteUrl(pageUrl); string pageContent = WebRequestHelper.GetPageWebContent(pageUrl); Assert.IsTrue(pageContent.Contains(Constants.LayoutTemplateText), "Layout template text was not found in the page content"); } finally { ServerOperations.Pages().DeletePage(Constants.PageTitle); ServerOperations.Templates().DeletePageTemplate(Constants.TemplateTitle); string filePath = FeatherServerOperations.ResourcePackages().GetResourcePackageDestinationFilePath(Constants.PackageName, Constants.LayoutFileName); File.Delete(filePath); } }
public void TemplateHierarchy_RequestPage_ShouldLogExecutions() { Guid templateId1 = default(Guid); Guid templateId2 = default(Guid); PageNode pageNode = null; try { pageNode = this.CreatePageTemplateHierarchy(ref templateId1, ref templateId2); var fullPageUrl = RouteHelper.GetAbsoluteUrl(pageNode.GetUrl()); // Request page this.ClearData(); this.ExecuteAuthenticatedRequest(fullPageUrl); this.FlushData(); this.AssertWidgetExecutionCount(3); } finally { this.DeletePages(pageNode); Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Templates().DeletePageTemplate(templateId2); Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Templates().DeletePageTemplate(templateId1); } }
public void DynamicWidget_RequestPage_ShouldLogRazorViewCompilation() { var widgetText = "</asp:PlaceHolder>"; var addedText = "Some added text."; var widgetTextEdited = string.Concat(widgetText, addedText); PageNode pageNode = null; try { pageNode = this.CreateBootstrapPageWithDynamicWidget(); this.EditDynamicContentWidgetMasterTemplate(widgetText, widgetTextEdited); var url = RouteHelper.GetAbsoluteUrl(pageNode.GetUrl()); this.ExecuteAuthenticatedRequest(url); this.FlushData(); // Assert widget performance int widgetCount = 1; this.AssertWidgetExecutionCount(widgetCount); this.AssertViewCompilationCount(widgetCount); } finally { this.EditDynamicContentWidgetMasterTemplate(widgetTextEdited, widgetText); this.DeletePages(pageNode); } }
public string GetPageContent(Guid pageId, bool authenticated, string suffixUrl) { PageManager pageManager = PageManager.GetManager(); var page = pageManager.GetPageNode(pageId); var pageUrl = page.GetFullUrl(SystemManager.CurrentContext.AppSettings.DefaultFrontendLanguage, true); pageUrl = RouteHelper.GetAbsoluteUrl(pageUrl); if (!string.IsNullOrWhiteSpace(suffixUrl)) { pageUrl = Sitefinity.Web.Url.Combine(pageUrl, suffixUrl); } pageUrl = UrlTransformations.AppendParam(pageUrl, "t", Guid.NewGuid().ToString()); string pageContent = WebRequestHelper.GetPageWebContent( pageUrl, null, (HttpClient client) => { if (authenticated) { client.DefaultHeaders["Authorization"] = HttpContext.Current.Request.Headers["Authorization"]; client.TransportSettings.Cookies = new System.Net.CookieContainer(); client.TransportSettings.CachePolicy = new System.Net.Cache.HttpRequestCachePolicy(); } }); return(pageContent); }
public void ContentBlockWidget_ValidateOnEditPage() { string testName = "ContentBlockWidgetEditSharedContent"; string pageNamePrefix = testName + "ContentBlockPage"; string pageTitlePrefix = testName + "Content Block"; string urlNamePrefix = testName + "content-block"; int pageIndex = 1; var content = App.WorkWith().ContentItems() .Where(c => c.Title == ContentBlockTitle && c.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master) .Get().Single(); var mvcProxy = new MvcControllerProxy(); mvcProxy.ControllerName = typeof(ContentBlockController).FullName; var contentBlockController = new ContentBlockController(); contentBlockController.SharedContentID = content.Id; mvcProxy.Settings = new ControllerSettings(contentBlockController); var pageId = this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, pageIndex); PageManager manager = PageManager.GetManager(); var page = manager.GetPageNode(pageId); var pageUrl = page.GetFullUrl(); pageUrl = RouteHelper.GetAbsoluteUrl(pageUrl) + "/Action/Edit"; string responseContent = PageInvoker.ExecuteWebRequest(pageUrl); Assert.IsTrue(responseContent.Contains(ContentBlockContent), "The content block with this text was not found!"); }
/// <summary> /// Facebook button. /// </summary> /// <param name="helper">The helper.</param> /// <param name="showCount">if set to <c>true</c> shows count.</param> /// <param name="isLarge">if set to <c>true</c> is large.</param> /// <param name="addText">if set to <c>true</c> [add text].</param> /// <returns>FacebookButton Html</returns> public static System.Web.Mvc.MvcHtmlString FacebookButton(this System.Web.Mvc.HtmlHelper helper, bool showCount, bool isLarge, bool addText) { var currentNode = SiteMapBase.GetCurrentProvider().CurrentNode; var shareUrl = string.Empty; var siteMapNode = SiteMapBase.GetCurrentProvider().CurrentNode; if (currentNode != null && currentNode.Url != null && siteMapNode != null) { shareUrl = RouteHelper.GetAbsoluteUrl(siteMapNode.Url); } string buttonTypeAttribute; if (showCount) { buttonTypeAttribute = "data-type='button_count'"; } else if (isLarge || addText) { buttonTypeAttribute = "data-type='button'"; } else { buttonTypeAttribute = "data-type='icon'"; } var htmlString = string.Format(System.Globalization.CultureInfo.InvariantCulture, @"<div class='fb-share-button' data-href='{0}' {1}></div>", shareUrl, buttonTypeAttribute); var scriptString = @"<div id='fb-root'></div><script>(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = '//connect.facebook.net/en_EN/all.js#xfbml=1'; fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script>"; return(new System.Web.Mvc.MvcHtmlString(htmlString + scriptString)); }
/// <summary> /// Creates the link button. /// </summary> /// <param name="addText">if set to <c>true</c> adds text.</param> /// <param name="baseUrl">The base URL.</param> /// <param name="linkText">The link text.</param> /// <param name="tooltipText">The tooltip text.</param> /// <param name="cssClass">The CSS class.</param> /// <returns> /// CreateLinkButton Html /// </returns> private static string CreateLinkButton(bool addText, string baseUrl, string linkText, string tooltipText, string cssClass) { var shareUrl = string.Empty; var currentNode = SiteMapBase.GetCurrentProvider().CurrentNode; var title = string.Empty; if (currentNode != null && currentNode.Url != null) { shareUrl = RouteHelper.GetAbsoluteUrl(currentNode.Url); title = currentNode.Title; } var url = string.Format(System.Globalization.CultureInfo.InvariantCulture, baseUrl, Uri.EscapeUriString(shareUrl), Uri.EscapeUriString(title)); var clickScript = string.Format(System.Globalization.CultureInfo.InvariantCulture, @"window.open('{0}', '{1}','toolbar=no,width=550,height=550'); return false", url, linkText); var text = string.Empty; if (addText) { text = linkText; } var htmlString = string.Format(System.Globalization.CultureInfo.InvariantCulture, @"<a onclick=""{0}"" title=""{1}""><span class=""{3}""></span>{2}</a>", clickScript, tooltipText, text, cssClass); return(htmlString); }
/// <summary> /// LinkedIn button /// </summary> /// <param name="helper">The helper.</param> /// <param name="showCount">if set to <c>true</c> shows count.</param> /// <returns> /// LinkedInButton Html /// </returns> public static System.Web.Mvc.MvcHtmlString LinkedInButton(this System.Web.Mvc.HtmlHelper helper, bool showCount) { var shareUrl = string.Empty; var currentNode = SiteMapBase.GetCurrentProvider().CurrentNode; if (currentNode != null && currentNode.Url != null) { shareUrl = RouteHelper.GetAbsoluteUrl(currentNode.Url); } var countAttribute = string.Empty; if (showCount) { countAttribute = "data-counter='right'"; } var scriptString = string.Format( System.Globalization.CultureInfo.InvariantCulture, @"<script src='//platform.linkedin.com/in.js' type='text/javascript'>lang: en_US</script><script type='IN/Share' data-url='{0}' {1}></script>", shareUrl, countAttribute); return(new System.Web.Mvc.MvcHtmlString(scriptString)); }
public void CustomWidgetOnTemplate_RequestPage_ShouldLogOnlyWidgetExecution() { PageNode pageNode = null; Guid templateId = Guid.Empty; try { pageNode = this.CreatePageOnTemplateWithCustomWigdet(out templateId); var fullPageUrl = RouteHelper.GetAbsoluteUrl(pageNode.GetFullUrl()); this.ClearData(); this.ExecuteAuthenticatedRequest(fullPageUrl); this.FlushData(); this.AssertWidgetExecutionCount(1); this.AssertViewCompilationCount(0); } finally { this.DeletePages(pageNode); if (templateId != Guid.Empty) { ServerOperations.Templates().DeletePageTemplate(templateId); } } }
public string GetPageContent() { var page = PageManager.GetManager().GetPageNode(this.pageId); var pageUrl = page.GetFullUrl(); pageUrl = RouteHelper.GetAbsoluteUrl(pageUrl); return(WebRequestHelper.GetPageWebContent(pageUrl)); }
public void TemplateHierarchy_EditWidget_ShouldLogCompilation() { Guid templateId1 = default(Guid); Guid templateId2 = default(Guid); var widgetName = "News"; var widgetTemplateName = "List.NewsList.cshtml"; var widgetText = @"<ul class=""list-unstyled"">"; var widgetTextEdited = @"<ul class=""list-unstyled"">edited"; string widgetFilePath = FeatherServerOperations.ResourcePackages().GetResourcePackageMvcViewDestinationFilePath(ResourcePackages.Bootstrap, widgetName, widgetTemplateName); PageNode pageNode = null; try { pageNode = this.CreatePageTemplateHierarchy(ref templateId1, ref templateId2); var fullPageUrl = RouteHelper.GetAbsoluteUrl(pageNode.GetUrl()); var viewPath = "~/Frontend-Assembly/Telerik.Sitefinity.Frontend.News/Mvc/Views/News/List.NewsList.cshtml"; var fullViewPath = string.Concat(viewPath, "#Bootstrap.cshtml"); // Request page this.ClearData(); this.ExecuteAuthenticatedRequest(fullPageUrl); this.FlushData(); this.ClearData(); FeatherServerOperations.ResourcePackages().EditLayoutFile(widgetFilePath, widgetText, widgetTextEdited); this.WaitForAspNetCacheToBeInvalidated(fullViewPath); this.ExecuteAuthenticatedRequest(fullPageUrl); this.FlushData(); this.AssertWidgetExecutionCount(3); this.AssertViewCompilationCount(1); var rootOperationId = this.GetRequestLogRootOperationId(fullPageUrl); var widgetCompilationText = "Compile view \"List.NewsList.cshtml#Bootstrap.cshtml\" of controller \"" + typeof(NewsController).FullName + "\""; this.AssertViewCompilationParams(rootOperationId, viewPath, widgetCompilationText); this.ClearData(); this.ExecuteAuthenticatedRequest(fullPageUrl); this.FlushData(); this.AssertWidgetExecutionCount(3); this.AssertViewCompilationCount(0); } finally { FeatherServerOperations.ResourcePackages().EditLayoutFile(widgetFilePath, widgetTextEdited, widgetText); this.DeletePages(pageNode); Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Templates().DeletePageTemplate(templateId2); Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Templates().DeletePageTemplate(templateId1); } }
public void MixedWidgets_RequestPage_ShouldLogRazorViewCompilation() { var viewRelativePath = "~/Mvc/Views/Test/Index.cshtml"; PageNode pageNode = null; try { var pageTitle = "TestPage1"; ServerOperations.Pages().CreateTestPage(Guid.NewGuid(), pageTitle); var pageManager = PageManager.GetManager(); pageNode = pageManager.GetPageNodes().SingleOrDefault(p => p.Title == pageTitle); var fullPageUrl = RouteHelper.GetAbsoluteUrl(pageNode.GetFullUrl()); this.ClearData(); this.ExecuteAuthenticatedRequest(fullPageUrl); this.FlushData(); this.AssertWidgetExecutionCount(0); this.AssertViewCompilationCount(0); this.AddMixedWidgetsToPage(pageNode); this.ExecuteAuthenticatedRequest(fullPageUrl); this.ClearData(); this.ExecuteAuthenticatedRequest(fullPageUrl); this.FlushData(); var mvcWidgetCount = 1; this.AssertWidgetExecutionCount(mvcWidgetCount); this.AssertViewCompilationCount(0); var viewContent = string.Empty; this.CreateView(viewRelativePath, viewContent); var viewPath = "~/Frontend-Assembly/FeatherWidgets.TestIntegration/Mvc/Views/Test/Index.cshtml"; this.WaitForAspNetCacheToBeInvalidated(viewPath); this.ClearData(); this.ExecuteAuthenticatedRequest(fullPageUrl); this.FlushData(); this.AssertWidgetExecutionCount(mvcWidgetCount); this.AssertViewCompilationCount(mvcWidgetCount); var rootOperationId = this.GetRequestLogRootOperationId(fullPageUrl); var widgetCompilationText = "Compile view \"Index.cshtml\" of controller \"" + typeof(TestController).FullName + "\""; this.AssertViewCompilationParams(rootOperationId, viewPath, widgetCompilationText); } finally { this.DeletePages(pageNode); this.DeleteView(viewRelativePath); } }
private Guid CreatePageWithTemplate(Guid templateId, out string pageUrl) { var pageManager = PageManager.GetManager(); var template = pageManager.GetTemplates().Where(t => t.Id == templateId).FirstOrDefault(); var pageId = Telerik.Sitefinity.Frontend.TestUtilities.CommonOperations.FeatherServerOperations.Pages().CreatePageWithTemplate(template, "TestPageTitle" + Guid.NewGuid().ToString(), "test-page-url" + Guid.NewGuid().ToString()); pageUrl = RouteHelper.GetAbsoluteUrl(pageManager.GetPageNode(pageId).GetFullUrl()); return(pageId); }
public void LayoutTemplates_EditLayoutFile_VerifyGeneratedTemplateAndCreatedPageContent() { PageManager pageManager = PageManager.GetManager(); int templatesCount = pageManager.GetTemplates().Count(); var folderPath = Path.Combine(this.SfPath, "MVC", "Views", "Layouts"); try { if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } string filePath = Path.Combine(folderPath, LayoutFileName); FeatherServerOperations.ResourcePackages().AddNewResource(LayoutFileResource, filePath); FeatherServerOperations.ResourcePackages().WaitForTemplatesCountToIncrease(templatesCount, 1); var template = pageManager.GetTemplates().Where(t => t.Title == TemplateTitle).FirstOrDefault(); Assert.IsNotNull(template, "Template was not found"); Guid pageId = FeatherServerOperations.Pages().CreatePageWithTemplate(template, PageTitle, PageUrl); var page = pageManager.GetPageNode(pageId); var pageUrl = page.GetFullUrl(); pageUrl = RouteHelper.GetAbsoluteUrl(pageUrl); string pageContent = WebRequestHelper.GetPageWebContent(pageUrl); Assert.IsTrue(pageContent.Contains(LayoutTemplateText), "Layout template text was not found in the page content"); string layoutFile = Path.Combine(folderPath, LayoutFileName); FeatherServerOperations.ResourcePackages().EditLayoutFile(layoutFile, TestLayoutTemplateText, TestLayoutTemplateTextEdited); Thread.Sleep(1000); pageContent = WebRequestHelper.GetPageWebContent(pageUrl); Assert.IsFalse(pageContent.Contains(ServerErrorMessage), "Page throws a server error message"); Assert.IsFalse(pageContent.Contains(TestLayoutTemplateText), "Layout template text was found in the page content"); Assert.IsTrue(pageContent.Contains(TestLayoutTemplateTextEdited), "New layout text was not found in the page content"); } finally { ServerOperations.Pages().DeleteAllPages(); ServerOperations.Templates().DeletePageTemplate(TemplateTitle); var filePath = Path.Combine(folderPath, LayoutFileName); File.Delete(filePath); } }
public void ResourcePackageLayoutFiles_DeleteLayoutFile_VerifyTemplateAndPageNotBasedToLayout() { int templatesCount = this.PageManager.GetTemplates().Count(); try { FeatherServerOperations.ResourcePackages().AddNewResourcePackage(Constants.PackageResource); FeatherServerOperations.ResourcePackages().WaitForTemplatesCountToIncrease(templatesCount, 3); var template = this.PageManager.GetTemplates().Where(t => t.Title == Constants.TemplateTestLayout1).FirstOrDefault(); if (template == null) { throw new ArgumentException("template not found"); } Guid pageId = FeatherServerOperations.Pages().CreatePageWithTemplate(template, Constants.PageTitle, Constants.PageUrl); var page = this.PageManager.GetPageNode(pageId); var pageUrl = page.GetFullUrl(); pageUrl = RouteHelper.GetAbsoluteUrl(pageUrl); var pageContent = WebRequestHelper.GetPageWebContent(pageUrl); Assert.IsTrue(pageContent.Contains(Constants.TestLayout1TemplateText), "Layout template text was not found in the page content"); string filePath = FeatherServerOperations.ResourcePackages().GetResourcePackageDestinationFilePath(Constants.TestPackageName, Constants.TestLayoutFileName); File.Delete(filePath); template = this.PageManager.GetTemplates().Where(t => t.Title == Constants.TemplateTestLayout1).FirstOrDefault(); Assert.IsNotNull(template, "Template was not found after layout file was deleted."); this.PublishPage(page); pageContent = WebRequestHelper.GetPageWebContent(pageUrl); Assert.IsFalse(pageContent.Contains(Constants.ServerErrorMessage), "Page throws a server error message"); Assert.IsFalse(pageContent.Contains(Constants.TestLayout1TemplateText), "Layout template text was found in the page content"); } finally { string[] templates = new string[] { Constants.TemplateTestLayout1, Constants.TemplateTestLayout2, Constants.TemplateTestLayout3 }; ServerOperations.Pages().DeletePage(Constants.PageTitle); foreach (var template in templates) { ServerOperations.Templates().DeletePageTemplate(template); } string path = FeatherServerOperations.ResourcePackages().GetResourcePackagesDestination(Constants.TestPackageName); Directory.Delete(path, true); } }
private string GetPageContent(Guid pageId) { PageManager pageManager = PageManager.GetManager(); var page = pageManager.GetPageNode(pageId); var pageUrl = page.GetFullUrl(); pageUrl = RouteHelper.GetAbsoluteUrl(pageUrl); string pageContent = WebRequestHelper.GetPageWebContent(pageUrl); return(pageContent); }
public void ResourcePackageLayoutFiles_RenameTemplateBasedOnLayoutFile_VerifyTemplateAndPage() { int templatesCount = this.PageManager.GetTemplates().Count(); try { FeatherServerOperations.ResourcePackages().AddNewResourcePackage(Constants.PackageResource); FeatherServerOperations.ResourcePackages().WaitForTemplatesCountToIncrease(templatesCount, 3); var template = this.PageManager.GetTemplates().Where(t => t.Title == Constants.TemplateTestLayout1).FirstOrDefault(); if (template == null) { throw new ArgumentException("template not found"); } Guid pageId = FeatherServerOperations.Pages().CreatePageWithTemplate(template, Constants.PageTitle, Constants.PageUrl); var page = this.PageManager.GetPageNode(pageId); var pageUrl = page.GetFullUrl(); pageUrl = RouteHelper.GetAbsoluteUrl(pageUrl); var pageContent = WebRequestHelper.GetPageWebContent(pageUrl); Assert.IsTrue(pageContent.Contains(Constants.TestLayout1TemplateText), "Layout template text was not found in the page content"); template.Title = Constants.TemplateRenamed; template.Name = Constants.TemplateRenamed; this.pageManager.SaveChanges(); Thread.Sleep(1000); pageContent = WebRequestHelper.GetPageWebContent(pageUrl); Assert.IsFalse(pageContent.Contains(Constants.ServerErrorMessage), "Page throws a server error message"); Assert.IsFalse(pageContent.Contains(Constants.TestLayout1TemplateText), "Layout template text was found in the page content"); } finally { string[] templates = new string[] { Constants.TemplateRenamed, Constants.TemplateTestLayout2, Constants.TemplateTestLayout3 }; ServerOperations.Pages().DeleteAllPages(); foreach (var template in templates) { ServerOperations.Templates().DeletePageTemplate(template); } string path = FeatherServerOperations.ResourcePackages().GetResourcePackagesDestination(Constants.TestPackageName); FeatherServerOperations.ResourcePackages().DeleteDirectory(path); } }
/// <summary> /// Gets the public page content. /// </summary> /// <param name="pageId">The id of the page.</param> /// <returns>The page content.</returns> public string GetPageContent(Guid pageId) { PageManager pageManager = PageManager.GetManager(); var page = pageManager.GetPageNode(pageId); var pageUrl = page.GetFullUrl(); pageUrl = RouteHelper.GetAbsoluteUrl(pageUrl); pageUrl = UrlTransformations.AppendParam(pageUrl, "t", Guid.NewGuid().ToString()); string pageContent = WebRequestHelper.GetPageWebContent(pageUrl); return(pageContent); }
/// <summary> /// Gets the public page content. /// </summary> /// <param name="pageId">The id of the page.</param> /// <returns>The page content.</returns> public string GetPageContent(Guid pageId) { PageManager pageManager = PageManager.GetManager(); var page = pageManager.GetPageNode(pageId); var pageUrl = page.GetFullUrl(SystemManager.CurrentContext.AppSettings.DefaultFrontendLanguage, true); pageUrl = RouteHelper.GetAbsoluteUrl(pageUrl); pageUrl = UrlTransformations.AppendParam(pageUrl, "t", Guid.NewGuid().ToString()); string pageContent = WebRequestHelper.GetPageWebContent(pageUrl); return(pageContent); }
//// StoryId: 208381 public void DynamicWidgetMvc_RequestPage_ShouldLogRazorViewCompilation() { var text = "Expected text"; var viewName = "List.Press Article.cshtml"; var basePath = HostingEnvironment.MapPath("~/"); var widgetViewsPath = Path.Combine(basePath, "Mvc\\Views\\PressArticle"); if (!Directory.Exists(widgetViewsPath)) { Directory.CreateDirectory(widgetViewsPath); } var listViewPath = Path.Combine(widgetViewsPath, viewName); PageNode pageNode = null; try { pageNode = this.CreateBootstrapPageWithDynamicWidget(); var url = RouteHelper.GetAbsoluteUrl(pageNode.GetUrl()); this.ExecuteAuthenticatedRequest(url); this.FlushData(); this.ClearData(); File.WriteAllText(listViewPath, text); var content = this.ExecuteAuthenticatedRequest(url); this.FlushData(); // Assert widget performance Assert.Contains(content, text, StringComparison.Ordinal); int widgetCount = 1; this.AssertWidgetExecutionCount(widgetCount); this.AssertViewCompilationCount(widgetCount); } finally { this.DeletePages(pageNode); if (Directory.Exists(widgetViewsPath)) { Directory.Delete(widgetViewsPath, true); } } }
////StoryId: 208384 public void EditLayoutRoot_RequestPageBasedOnTemplate_ShouldLogCompilation() { PageNode pageNode = null; var layoutText = @"@Html.SfPlaceHolder(""TestPlaceHolder"") "; var layoutTextEdited = @"edited @Html.SfPlaceHolder(""TestPlaceHolder"") "; try { this.CreateLayoutFile(TestTemplateFileName); pageNode = this.CreatePageWithMvcWidget(TestTemplateTitle, TestPlaceholder); var fullPageUrl = RouteHelper.GetAbsoluteUrl(pageNode.GetUrl()); this.ExecuteAuthenticatedRequest(fullPageUrl); this.FlushData(); var viewPath = "~/Frontend-Assembly/Telerik.Sitefinity.Frontend/Mvc/Views/Layouts/TestLayout.cshtml"; var layoutFilePath = Path.Combine(HostingEnvironment.MapPath(LayoutsFolderRelativePath), TestTemplateFileName); FeatherServerOperations.ResourcePackages().EditLayoutFile(layoutFilePath, layoutText, layoutTextEdited); this.WaitForAspNetCacheToBeInvalidated(viewPath); this.ClearData(); this.ExecuteAuthenticatedRequest(fullPageUrl); this.FlushData(); // Assert data this.AssertWidgetExecutionCount(1); this.AssertViewCompilationCount(1); var rootOperationId = this.GetRequestLogRootOperationId(fullPageUrl); var widgetCompilationText = "Compile view \"TestLayout.cshtml#Bootstrap.cshtml\" of controller \"" + typeof(GenericController).FullName + "\""; this.AssertViewCompilationParams(rootOperationId, viewPath, widgetCompilationText); this.ClearData(); this.ExecuteAuthenticatedRequest(fullPageUrl); this.FlushData(); this.AssertWidgetExecutionCount(1); this.AssertViewCompilationCount(0); } finally { this.DeletePages(pageNode); ServerOperations.Templates().DeletePageTemplate(TestTemplateTitle); this.DeleteLayoutFile(TestTemplateFileName); } }
public void FormsWidget_SubmitFormWithForumWidgetOnPageBasedOnCustomHybridPage_NoExceptionIsThrown() { var testName = MethodInfo.GetCurrentMethod().Name; var templateName = testName + "template"; var pageName = testName + "page"; var submitButtonControl = new MvcWidgetProxy(); submitButtonControl.ControllerName = typeof(SubmitButtonController).FullName; submitButtonControl.Settings = new ControllerSettings(new SubmitButtonController()); var formId = ServerOperationsFeather.Forms().CreateFormWithWidget(submitButtonControl); var forumControl = new ForumsView(); var pageManager = PageManager.GetManager(); Guid templateId = Guid.Empty; Guid pageId = Guid.Empty; try { templateId = Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Templates().CreateHybridMVCPageTemplate(templateName); pageId = FeatherServerOperations.Pages().CreatePageWithTemplate(pageManager.GetTemplate(templateId), pageName, pageName); ServerOperationsFeather.Forms().AddFormControlToPage(pageId, formId, "TestForm", "Body"); PageContentGenerator.AddControlToPage(pageId, forumControl, "TestForum", "Body"); var page = pageManager.GetPageNode(pageId); var pageUrl = page.GetFullUrl(); pageUrl = RouteHelper.GetAbsoluteUrl(pageUrl); var webRequest = (HttpWebRequest)WebRequest.Create(pageUrl); var dataString = "------WebKitFormBoundaryPIB6p73K1Y0L0ha5--"; var dataBytes = (new ASCIIEncoding()).GetBytes(dataString); webRequest.Method = "POST"; webRequest.ContentLength = dataBytes.Length; webRequest.ContentType = "multipart/form-data"; webRequest.Timeout = 120 * 1000; webRequest.GetRequestStream().Write(dataBytes, 0, dataBytes.Length); Assert.DoesNotThrow(() => webRequest.GetResponse(), "Submitting a form on custom hybrid page with a forum widget on it throws error"); } finally { Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Pages().DeletePage(pageId); Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Templates().DeletePageTemplate(templateId); FormsModuleCodeSnippets.DeleteForm(formId); } }
public void LoginStatus_OnDetailsPage_DoesNotThrowException() { const string LoginStatusCaption = "login status"; Guid newsItemId = Guid.Parse("4785b751-ce3a-4e5e-ba81-138f8f2a8a09"); string testName = System.Reflection.MethodInfo.GetCurrentMethod().Name; var mvcNewsProxy = new MvcControllerProxy(); mvcNewsProxy.ControllerName = typeof(NewsController).FullName; var newsController = new NewsController(); newsController.OpenInSamePage = true; mvcNewsProxy.Settings = new ControllerSettings(newsController); var mvcLoginStatusProxy = new MvcControllerProxy(); mvcLoginStatusProxy.ControllerName = typeof(LoginStatusController).FullName; using (var generator = new PageContentGenerator()) { var pageId = generator.CreatePageWithWidget(mvcNewsProxy, null, testName, testName, testName, 0); PageContentGenerator.AddControlToPage(pageId, mvcLoginStatusProxy, LoginStatusCaption); string pageUrl = UrlPath.ResolveAbsoluteUrl("~/" + testName + "0"); var newsManager = NewsManager.GetManager(); try { var newsItem = newsManager.CreateNewsItem(newsItemId); newsItem.Title = testName; newsItem.UrlName = testName; newsManager.Lifecycle.Publish(newsItem); newsManager.SaveChanges(); string detailNewsUrl = pageUrl + newsItem.ItemDefaultUrl; var pageContent = WebRequestHelper.GetPageWebContent(RouteHelper.GetAbsoluteUrl(detailNewsUrl)); Assert.DoesNotContain(pageContent, "Exception occured while executing the controller. Check error logs for details.", StringComparison.Ordinal); } finally { newsManager.Delete(newsManager.GetNewsItem(newsItemId)); newsManager.SaveChanges(); } } }
public void CustomWidgetOnTemplate_EditView_ShouldLogCompilation() { var viewRelativePath = "~/Mvc/Views/Test/Index.cshtml"; PageNode pageNode = null; Guid templateId = Guid.Empty; try { pageNode = this.CreatePageOnTemplateWithCustomWigdet(out templateId); var fullPageUrl = RouteHelper.GetAbsoluteUrl(pageNode.GetFullUrl()); var viewContent = string.Empty; this.CreateView(viewRelativePath, viewContent); var viewPath = "~/Frontend-Assembly/FeatherWidgets.TestIntegration/Mvc/Views/Test/Index.cshtml"; this.WaitForAspNetCacheToBeInvalidated(viewPath); this.ClearData(); this.ExecuteAuthenticatedRequest(fullPageUrl); this.FlushData(); this.AssertWidgetExecutionCount(1); this.AssertViewCompilationCount(1); var rootOperationId = this.GetRequestLogRootOperationId(fullPageUrl); var widgetCompilationText = "Compile view \"Index.cshtml#Bootstrap.cshtml\" of controller \"" + typeof(TestController).FullName + "\""; this.AssertViewCompilationParams(rootOperationId, viewPath, widgetCompilationText); this.ClearData(); this.ExecuteAuthenticatedRequest(fullPageUrl); this.FlushData(); this.AssertWidgetExecutionCount(1); this.AssertViewCompilationCount(0); } finally { this.DeletePages(pageNode); this.DeleteView(viewRelativePath); if (templateId != Guid.Empty) { ServerOperations.Templates().DeletePageTemplate(templateId); } } }
/// <summary> /// Twitter Button HTML /// </summary> /// <param name="helper">The helper.</param> /// <param name="showCount">if set to <c>true</c> shows count.</param> /// <param name="isLarge">if set to <c>true</c> is large.</param> /// <param name="addText">if set to <c>true</c> adds text.</param> /// <param name="textToShare">The text to share.</param> /// <returns> /// TwitterButton Html /// </returns> public static System.Web.Mvc.MvcHtmlString TwitterButton(this System.Web.Mvc.HtmlHelper helper, bool showCount, bool isLarge, bool addText, string textToShare) { var shareUrl = string.Empty; var currentNode = SiteMapBase.GetCurrentProvider().CurrentNode; if (currentNode != null && currentNode.Url != null) { shareUrl = RouteHelper.GetAbsoluteUrl(currentNode.Url); } var countAttribute = "data-count='horizontal'"; if (!showCount) { countAttribute = "data-count='none'"; } var sizeAttribute = string.Empty; if (isLarge) { sizeAttribute = "data-size='large'"; } var text = string.Empty; if (addText) { text = "Tweet"; } var htmlString = string.Format( System.Globalization.CultureInfo.InvariantCulture, @"<a href='https://twitter.com/share' title='Share on Twitter' class='twitter-share-button' data-url={0} data-text={1} {2} {3}>{4}</a>", shareUrl, textToShare, sizeAttribute, countAttribute, text); var scriptString = @"<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>"; return(new System.Web.Mvc.MvcHtmlString(htmlString + scriptString)); }
////StoryId: 208384 public void TemplateBasedOnNewLayout_RequestPage_ShouldLogRazorViewCompilation() { string childTemplateTitle = "NewTestLayout"; PageNode pageNode = null; try { this.CreateLayoutFile(TestTemplateFileName); this.CreatePureMvcPageTemplate(childTemplateTitle, TestTemplateTitle); pageNode = this.CreatePageWithMvcWidget(childTemplateTitle, TestPlaceholder); var fullPageUrl = RouteHelper.GetAbsoluteUrl(pageNode.GetUrl()); this.ClearData(); this.ExecuteAuthenticatedRequest(fullPageUrl); this.FlushData(); var viewPath = "~/Frontend-Assembly/Telerik.Sitefinity.Frontend/Mvc/Views/Layouts/TestLayout.cshtml"; // Assert data this.AssertWidgetExecutionCount(1); this.AssertViewCompilationCount(1); var rootOperationId = this.GetRequestLogRootOperationId(fullPageUrl); var widgetCompilationText = "Compile view \"TestLayout.cshtml#Bootstrap.cshtml\" of controller \"" + typeof(GenericController).FullName + "\""; this.AssertViewCompilationParams(rootOperationId, viewPath, widgetCompilationText); this.ClearData(); this.ExecuteAuthenticatedRequest(fullPageUrl); this.FlushData(); this.AssertWidgetExecutionCount(1); this.AssertViewCompilationCount(0); } finally { this.DeletePages(pageNode); ServerOperations.Templates().DeletePageTemplate(childTemplateTitle); ServerOperations.Templates().DeletePageTemplate(TestTemplateTitle); this.DeleteLayoutFile(TestTemplateFileName); } }
private Guid CreatePageWithWidget(PageTemplateFramework framework, Controller widgetController, out string pageUrl) { Guid pageId = Guid.Empty; pageUrl = string.Empty; var suffix = Guid.NewGuid().ToString("N"); if (framework == PageTemplateFramework.Hybrid) { var namePrefix = "TestPageName"; var titlePrefix = "TestPageTitle"; var urlPrefix = "test-page-url"; var index = 1; pageId = new PageContentGenerator().CreatePage( string.Format(CultureInfo.InvariantCulture, "{0}{1}", namePrefix + suffix, index.ToString(CultureInfo.InvariantCulture)), string.Format(CultureInfo.InvariantCulture, "{0}{1}", titlePrefix + suffix, index.ToString(CultureInfo.InvariantCulture)), string.Format(CultureInfo.InvariantCulture, "{0}{1}", urlPrefix + suffix, index.ToString(CultureInfo.InvariantCulture))); pageUrl = UrlPath.ResolveAbsoluteUrl("~/" + urlPrefix + suffix + index); } else if (framework == PageTemplateFramework.Mvc) { var pagesOperations = FeatherServerOperations.Pages(); var pageManager = PageManager.GetManager(); var bootstrapTemplate = pageManager.GetTemplates().FirstOrDefault(t => (t.Name == "Bootstrap.default" && t.Title == "default") || t.Title == "Bootstrap.default"); if (bootstrapTemplate == null) { throw new ArgumentException("Bootstrap template not found"); } pageId = pagesOperations.CreatePageWithTemplate(bootstrapTemplate, "FormsPageBootstrap" + suffix, "forms-page-bootstrap" + suffix); pageUrl = RouteHelper.GetAbsoluteUrl(pageManager.GetPageNode(pageId).GetFullUrl()); } var placeholder = framework == PageTemplateFramework.Hybrid ? "Body" : "Contentplaceholder1"; FeatherServerOperations.Pages().AddMvcWidgetToPage(pageId, widgetController.GetType().FullName, "FrontendModuleFilterTestsWidgetCaption", placeholder); return(pageId); }