private Guid CreateTemplateWithControl(PageTemplateFramework framework) { Guid pageTemplateId = Guid.Empty; var templatesOperations = Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Templates(); if (framework == PageTemplateFramework.Hybrid) { pageTemplateId = templatesOperations.CreateHybridMVCPageTemplate(ModuleUnloadTests.PageTemplateTitle + Guid.NewGuid().ToString()); } else if (framework == PageTemplateFramework.Mvc) { pageTemplateId = templatesOperations.CreatePureMVCPageTemplate(ModuleUnloadTests.PageTemplateTitle + Guid.NewGuid().ToString()); } var mvcProxy = new MvcControllerProxy(); mvcProxy.ControllerName = typeof(ContentBlockController).FullName; var contentBlockController = new ContentBlockController(); contentBlockController.Content = ModuleUnloadTests.PageControlContent; mvcProxy.Settings = new ControllerSettings(contentBlockController); templatesOperations.AddControlToTemplate(pageTemplateId, mvcProxy, "Body", "ContentBlockCaption"); return(pageTemplateId); }
public void ContentBlockWidget_EditSharedContent() { string testName = "ContentBlockWidgetEditSharedContent"; string pageNamePrefix = testName + "ContentBlockPage"; string pageTitlePrefix = testName + "Content Block"; string urlNamePrefix = testName + "content-block"; int pageIndex = 1; string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + pageIndex); 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); this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, pageIndex); App.WorkWith().ContentItem(content.Id).CheckOut().Do(cI => { cI.Content = ContentBlockContentEdited; cI.LastModified = DateTime.UtcNow; }) .CheckIn().Publish().SaveChanges(); string responseContent = PageInvoker.ExecuteWebRequest(url); Assert.IsTrue(responseContent.Contains(ContentBlockContentEdited), "The content block with this title was not found!"); }
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!"); }
public void ContentBlockWidget_AdvancedSettings() { string testName = "ContentBlockWidgetAdvancedSettings"; string pageNamePrefix = testName + "ContentBlockPage"; string pageTitlePrefix = testName + "Content Block"; string urlNamePrefix = testName + "content-block"; int pageIndex = 1; string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + pageIndex); var content = App.WorkWith().ContentItems() .Published() .Where(c => c.Title == ContentBlockTitle) .Get().Single(); var mvcProxy = new MvcControllerProxy(); mvcProxy.ControllerName = typeof(ContentBlockController).FullName; var contentBlockController = new ContentBlockController(); contentBlockController.SharedContentID = content.Id; mvcProxy.Settings = new ControllerSettings(contentBlockController); this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, pageIndex); string responseContent = PageInvoker.ExecuteWebRequest(url); Assert.IsTrue(responseContent.Contains(ContentBlockContent), "The content block with this title was not found!"); }
public void PostForm_LoginRedirectPageId() { string loginFormPageUrl = UrlPath.ResolveAbsoluteUrl("~/" + this.urlNamePrefix + this.pageIndex); this.pageOperations = new PagesOperations(); var userId = ClaimsManager.GetCurrentUserId(); var user = UserManager.GetManager().GetUser(userId); try { ////Create simple page with a content block to redirect on it var mvcProxyContentBlock = new MvcControllerProxy(); mvcProxyContentBlock.ControllerName = typeof(ContentBlockController).FullName; var contentBlockController = new ContentBlockController(); contentBlockController.Content = this.searchValueFirst; mvcProxyContentBlock.Settings = new ControllerSettings(contentBlockController); Guid contentBlockPageID = this.pageOperations.CreatePageWithControl( mvcProxyContentBlock, this.pageNamePrefixContentBlockPage, this.pageTitlePrefixContentBlockPage, this.urlNamePrefixContentBlockPage, this.pageIndexContentBlockFirstPage); ////Create page with login form and set LoginRedirectPageId to the newly created page above var mvcProxy = new MvcControllerProxy(); mvcProxy.ControllerName = typeof(LoginFormController).FullName; var loginFormController = new LoginFormController(); loginFormController.Model.LoginRedirectPageId = contentBlockPageID; mvcProxy.Settings = new ControllerSettings(loginFormController); this.pageOperations.CreatePageWithControl(mvcProxy, this.pageNamePrefix, this.pageTitlePrefix, this.urlNamePrefix, this.pageIndex); SecurityManager.Logout(); ////create new user to Authenticate against newly created login form SitefinityTestUtilities.ServerOperations.Users().CreateUser(this.userName, this.password, "*****@*****.**", "test", "test", true, "AuthenticateUser", "IdentityHasClaimTypes", SecurityConstants.AppRoles.FrontendUsers); string postString = "UserName="******"&Password="******"The request was not redirected to the proper page set in LoginRedirectPageId!"); } finally { using (new AuthenticateUserRegion(user)) { this.pageOperations.DeletePages(); } SecurityManager.Logout(); SitefinityTestUtilities.ServerOperations.Users().DeleteUsers(new[] { this.userName }); } }
private Guid CreatePageWithControl(PageTemplateFramework framework, out string pageUrl) { var pageId = this.CreatePage(framework, out pageUrl); var mvcProxy = new MvcControllerProxy(); mvcProxy.ControllerName = typeof(ContentBlockController).FullName; var contentBlockController = new ContentBlockController(); contentBlockController.Content = ModuleUnloadTests.PageControlContent; mvcProxy.Settings = new ControllerSettings(contentBlockController); PageContentGenerator.AddControlsToPage(pageId, new Control[] { mvcProxy }, framework == PageTemplateFramework.Mvc ? "Contentplaceholder1" : "Body"); return(pageId); }
public void ContentBlockWidget_FormatContentViaBoldFunctionalityToContentBlock() { string pageNamePrefix = "ContentBlockPage"; string pageTitlePrefix = "Content Block"; string urlNamePrefix = "content-block"; int pageIndex = 1; string contentBlockContent = "<div><strong>Bold text</strong></div>"; string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + pageIndex); var mvcProxy = new MvcControllerProxy(); mvcProxy.ControllerName = typeof(ContentBlockController).FullName; var contentBlockController = new ContentBlockController(); contentBlockController.Content = contentBlockContent; mvcProxy.Settings = new ControllerSettings(contentBlockController); this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, pageIndex); string responseContent = PageInvoker.ExecuteWebRequest(url); Assert.IsTrue(responseContent.Contains(contentBlockContent), "Content was not bold!"); }
public void ContentBlockWidget_InsertHyperlinkToContentBlock() { string pageNamePrefix = "ContentBlockPage"; string pageTitlePrefix = "Content Block"; string urlNamePrefix = "content-block"; int pageIndex = 1; string contentBlockContent = "<a href=\"http://wheather.com\" title=\"wheather\">Wheather site</a>"; string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + pageIndex); var mvcProxy = new MvcControllerProxy(); mvcProxy.ControllerName = typeof(ContentBlockController).FullName; var contentBlockController = new ContentBlockController(); contentBlockController.Content = contentBlockContent; mvcProxy.Settings = new ControllerSettings(contentBlockController); this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, pageIndex); string responseContent = PageInvoker.ExecuteWebRequest(url); Assert.IsTrue(responseContent.Contains(contentBlockContent), "Hyperlink was not found!"); }
public void ContentBlockWidget_AddTableToContentBlock() { string pageNamePrefix = "ContentBlockPage"; string pageTitlePrefix = "Content Block"; string urlNamePrefix = "content-block"; int pageIndex = 1; string contentBlockContent = "<table><tbody><tr><td>a</td><td>b</td></tr><tr><td>c</td><td>d</td></tr></tbody></table>"; string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + pageIndex); var mvcProxy = new MvcControllerProxy(); mvcProxy.ControllerName = typeof(ContentBlockController).FullName; var contentBlockController = new ContentBlockController(); contentBlockController.Content = contentBlockContent; mvcProxy.Settings = new ControllerSettings(contentBlockController); this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, pageIndex); string responseContent = PageInvoker.ExecuteWebRequest(url); Assert.IsTrue(responseContent.Contains(contentBlockContent), "Table was not found!"); }
public void ContentBlockWidget_SocialShareButtonsFunctionality() { string pageNamePrefix = "ContentBlockPage"; string pageTitlePrefix = "Content Block"; string urlNamePrefix = "content-block"; int pageIndex = 1; string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + pageIndex); string socialShare = "list-inline sf-social-share"; var mvcProxy = new MvcControllerProxy(); mvcProxy.ControllerName = typeof(ContentBlockController).FullName; var contentBlockController = new ContentBlockController(); contentBlockController.Content = ContentBlockContent; contentBlockController.EnableSocialSharing = true; mvcProxy.Settings = new ControllerSettings(contentBlockController); this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, pageIndex); string responseContent = PageInvoker.ExecuteWebRequest(url); Assert.IsTrue(responseContent.Contains(socialShare), "Social share button was not found!"); }
public void ContentBlockWidget_UnshareFunctionality() { string pageNamePrefix = "ContentBlockPage"; string pageTitlePrefix = "Content Block"; string urlNamePrefix = "content-block"; int pageIndex = 1; var contentManager = ContentManager.GetManager(); var contentItem = contentManager.GetContent() .Single(c => c.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && c.Title == ContentBlockTitle); var mvcProxy = new MvcControllerProxy(); mvcProxy.ControllerName = typeof(ContentBlockController).FullName; var contentBlockController = new ContentBlockController(); contentBlockController.Content = ContentBlockContent; contentBlockController.SharedContentID = contentItem.Id; mvcProxy.Settings = new ControllerSettings(contentBlockController); var pageId = this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, pageIndex); PageContentGenerator.ModifyPageControl( pageId, c => c.ObjectType == mvcProxy.GetType().FullName, (c) => { var manager = PageManager.GetManager(); mvcProxy = manager.LoadControl(c) as MvcControllerProxy; contentBlockController = (ContentBlockController)mvcProxy.Controller; contentBlockController.SharedContentID = Guid.Empty; mvcProxy.Settings = new ControllerSettings(contentBlockController); manager.ReadProperties(mvcProxy, c); }); Assert.AreEqual(0, contentManager.GetCountOfPagesThatUseContent(contentItem.Id)); }
public void ContentBlockWidget_ShareFunctionality() { string pageNamePrefix = "ContentBlockPage"; string pageTitlePrefix = "Content Block"; string urlNamePrefix = "content-block"; int pageIndex = 1; var contentManager = ContentManager.GetManager(); var contentItem = contentManager.GetContent() .Single(c => c.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && c.Title == ContentBlockTitle); var mvcProxy = new MvcControllerProxy(); mvcProxy.ControllerName = typeof(ContentBlockController).FullName; var contentBlockController = new ContentBlockController(); contentBlockController.Content = ContentBlockContent; contentBlockController.SharedContentID = contentItem.Id; mvcProxy.Settings = new ControllerSettings(contentBlockController); this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, pageIndex); Assert.AreEqual(1, contentManager.GetCountOfPagesThatUseContent(contentItem.Id)); }
public void ContentBlockWidget_InsertImageToContentBlock() { string pageNamePrefix = "ContentBlockPage"; string pageTitlePrefix = "Content Block"; string urlNamePrefix = "content-block"; int pageIndex = 1; string imageTitle = "One"; string imageExtension = ".jpg"; string imageName = "Telerik.Sitefinity.TestUtilities.Data.Images.1.jpg"; string contentBlockContentPart1 = "<img alt=\"\" src=\""; string contentBlockContentPart2 = "\" />"; string url = UrlPath.ResolveAbsoluteUrl("~/" + urlNamePrefix + pageIndex); try { var imageId = Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Images().Upload(MediaOperationsBase.DefaultLibrary, imageTitle, imageName, imageExtension); var imageUrl = Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Images().GetImageUrl(imageId); string contentBlockContent = string.Concat(contentBlockContentPart1, imageUrl, contentBlockContentPart2); var mvcProxy = new MvcControllerProxy(); mvcProxy.ControllerName = typeof(ContentBlockController).FullName; var contentBlockController = new ContentBlockController(); contentBlockController.Content = contentBlockContent; mvcProxy.Settings = new ControllerSettings(contentBlockController); this.pageOperations.CreatePageWithControl(mvcProxy, pageNamePrefix, pageTitlePrefix, urlNamePrefix, pageIndex); string responseContent = PageInvoker.ExecuteWebRequest(url); Assert.IsTrue(responseContent.Contains(contentBlockContent), "Image was not found!"); } finally { Telerik.Sitefinity.TestUtilities.CommonOperations.ServerOperations.Images().DeleteAllImages(); } }
public void SubscribeForm_CheckForParamInjections() { this.pageOperations = new PagesOperations(); this.newslettersManager = NewslettersManager.GetManager(); Guid mailingListId = Guid.NewGuid(); var subscribers = this.newslettersManager.GetSubscribers().Where(s => s.Email == this.testEmail).ToList(); bool deleteSubsciber = (subscribers.Count > 0) ? false : true; try { ////Create a new mailing list string mailingListName = this.mailingListBaseName + this.mailingListIndex; SitefinityTestUtilities.ServerOperations.NewsLetter().CreateMailingList(mailingListId, mailingListName, string.Empty, string.Empty, string.Empty); ////Check if the mailing list was created successfully MailingList mailingList = this.newslettersManager.GetMailingLists().Where(l => l.Id == mailingListId).SingleOrDefault(); Assert.IsNotNull(mailingList, "New mailing list was not created successfully!"); ////Create simple page with a SubscribeForm widget that has SelectedMailingListId with the newly created mailing list var mvcControllerProxy = new MvcControllerProxy(); mvcControllerProxy.ControllerName = typeof(SubscribeFormController).FullName; var subscribeFormController = new SubscribeFormController(); subscribeFormController.Model.SelectedMailingListId = mailingListId; subscribeFormController.Model.SuccessfullySubmittedForm = SuccessfullySubmittedForm.OpenSpecificPage; mvcControllerProxy.Settings = new ControllerSettings(subscribeFormController); this.pageOperations.CreatePageWithControl( mvcControllerProxy, this.pageNamePrefix, this.pageTitlePrefix, this.urlNamePrefix, this.pageIndex); ////Create simple page with a content block to redirect on it mvcControllerProxy.ControllerName = typeof(ContentBlockController).FullName; var contentBlockController = new ContentBlockController(); contentBlockController.Content = this.searchValueText; mvcControllerProxy.Settings = new ControllerSettings(contentBlockController); this.pageOperations.CreatePageWithControl( mvcControllerProxy, this.pageNamePrefixContentBlockPage, this.pageTitlePrefixContentBlockPage, this.urlNamePrefixContentBlockPage, this.pageIndexContentBlockPage); string subscribeFormPageUrl = UrlPath.ResolveAbsoluteUrl("~/" + this.urlNamePrefix + this.pageIndex); string redirectUrl = UrlPath.ResolveAbsoluteUrl("~/" + this.urlNamePrefixContentBlockPage + this.pageIndexContentBlockPage); string postString = "Email=" + this.testEmail; ////Make an initial request to register the subscriber var responseContent = PageInvoker.PostWebRequest(subscribeFormPageUrl, postString, false); Assert.IsTrue(responseContent.Contains(this.subscribeValueText), "User was not successfully subscribed!"); ////Make a secondary request to inject the RedirectPageUrl value postString += "&RedirectPageUrl=" + redirectUrl; responseContent = PageInvoker.PostWebRequest(subscribeFormPageUrl, postString, false); Assert.IsFalse(responseContent.Contains(this.searchValueText), "RedirectPageUrl parameter was injected into the model!"); } finally { ////Delete created pages this.pageOperations.DeletePages(); ////Delete the created subsciber if he was created by the test if (deleteSubsciber) { Subscriber subscriber = this.newslettersManager.GetSubscribers().Where(s => s.Email == this.testEmail).FirstOrDefault(); if (subscriber != null) { this.newslettersManager.DeleteSubscriber(subscriber.Id); } } ////Delete created mailing list this.newslettersManager.DeleteMailingList(mailingListId); this.newslettersManager.SaveChanges(); } }
public void PostForm_LoginRedirectFromQueryString() { string loginFormPageUrl = UrlPath.ResolveAbsoluteUrl("~/" + this.urlNamePrefix + this.pageIndex); this.pageOperations = new PagesOperations(); var userId = ClaimsManager.GetCurrentUserId(); var user = UserManager.GetManager().GetUser(userId); try { var mvcProxyContentBlock = new MvcControllerProxy(); mvcProxyContentBlock.ControllerName = typeof(ContentBlockController).FullName; ////Create first simple page with a content block to redirect on it var contentBlockController = new ContentBlockController(); contentBlockController.Content = this.searchValueFirst; mvcProxyContentBlock.Settings = new ControllerSettings(contentBlockController); this.pageOperations.CreatePageWithControl( mvcProxyContentBlock, this.pageNamePrefixContentBlockPage, this.pageTitlePrefixContentBlockPage, this.urlNamePrefixContentBlockPage, this.pageIndexContentBlockFirstPage); ////Create second simple page with a content block to redirect on it var contentBlockControllerSecond = new ContentBlockController(); contentBlockControllerSecond.Content = this.searchValueSecond; mvcProxyContentBlock.Settings = new ControllerSettings(contentBlockControllerSecond); this.pageOperations.CreatePageWithControl( mvcProxyContentBlock, this.pageNamePrefixContentBlockPage, this.pageTitlePrefixContentBlockPage, this.urlNamePrefixContentBlockPage, this.pageIndexContentBlockSecondPage); ////Create page with login form var mvcProxy = new MvcControllerProxy(); mvcProxy.ControllerName = typeof(LoginFormController).FullName; var loginFormController = new LoginFormController(); mvcProxy.Settings = new ControllerSettings(loginFormController); this.pageOperations.CreatePageWithControl(mvcProxy, this.pageNamePrefix, this.pageTitlePrefix, this.urlNamePrefix, this.pageIndex); SecurityManager.Logout(); ////create new user to Authenticate against newly created login form SitefinityTestUtilities.ServerOperations.Users().CreateUser(this.userName, this.password, "*****@*****.**", "test", "test", true, "AuthenticateUser", "IdentityHasClaimTypes", SecurityConstants.AppRoles.FrontendUsers); ////There is few ways to redirect to another page ////First method is to combine realm param with redirect_uri param to get the full redirect url ////Example: ?realm=http://localhost:8086/&redirect_uri=/Sitefinity/Dashboard ////Second method is to use only realm or redirect_uri param to get the full redirect url ////Example: ?redirect_uri=http://localhost:8086/Sitefinity/Dashboard ////Third method is to get ReturnUrl param ////Example: ?ReturnUrl=http://localhost:8086/Sitefinity/Dashboard string postString = "UserName="******"&Password="******"?redirect_uri=" + this.urlNamePrefixContentBlockPage + this.pageIndexContentBlockFirstPage + "&realm=http://localhost/" + "&ReturnUrl=http://localhost/" + this.urlNamePrefixContentBlockPage + this.pageIndexContentBlockSecondPage; responseContent = PageInvoker.ExecuteWebRequest(testURL1, false); responseContent = PageInvoker.PostWebRequest(testURL1, postString, false); Assert.IsTrue(responseContent.Contains(this.searchValueFirst), "The request was not redirected to the proper page set in request url!"); } using (PageInvokerRegion region = new PageInvokerRegion()) { string testURL2 = loginFormPageUrl + "?realm=http://localhost/" + this.urlNamePrefixContentBlockPage + this.pageIndexContentBlockFirstPage; responseContent = PageInvoker.ExecuteWebRequest(testURL2, false); responseContent = PageInvoker.PostWebRequest(testURL2, postString, false); Assert.IsTrue(responseContent.Contains(this.searchValueFirst), "The request was not redirected to the proper page set in request url!"); } using (PageInvokerRegion region = new PageInvokerRegion()) { string testURL3 = loginFormPageUrl + "?redirect_uri=http://localhost/" + this.urlNamePrefixContentBlockPage + this.pageIndexContentBlockFirstPage; responseContent = PageInvoker.ExecuteWebRequest(testURL3, false); responseContent = PageInvoker.PostWebRequest(testURL3, postString, false); Assert.IsTrue(responseContent.Contains(this.searchValueFirst), "The request was not redirected to the proper page set in request url!"); } using (PageInvokerRegion region = new PageInvokerRegion()) { string testURL4 = loginFormPageUrl + "?ReturnUrl=http://localhost/" + this.urlNamePrefixContentBlockPage + this.pageIndexContentBlockSecondPage; responseContent = PageInvoker.ExecuteWebRequest(testURL4, false); responseContent = PageInvoker.PostWebRequest(testURL4, postString, false); Assert.IsTrue(responseContent.Contains(this.searchValueSecond), "The request was not redirected to the proper page set in request url!"); } } finally { using (new AuthenticateUserRegion(user)) { this.pageOperations.DeletePages(); } SecurityManager.Logout(); SitefinityTestUtilities.ServerOperations.Users().DeleteUsers(new[] { this.userName }); } }