public void ContentNewUser_PointsToValidPage_UserPageGetsPageContents() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); DreamMessage msg; // Create page content/new-user points to string content = "test userpage content"; string pageid; string path; PageUtils.SavePage(p, String.Empty, PageUtils.GenerateUniquePageName(), content, out pageid, out path); // Add content/new-user key SiteUtils.AddConfigKey(p, "content/new-user", path); // Create a user string userid; string username; UserUtils.CreateRandomContributor(p, out userid, out username); // Retrieve a page id. This is to render the template using the "pageid" parameter in the page/{pageid}/contents feature. msg = PageUtils.GetPage(p, String.Empty); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Failed to retrieve home page"); uint homepageid = msg.ToDocument()["@id"].AsUInt ?? 0; Assert.IsTrue(homepageid > 0, "Invalid homepage ID"); // Retrieve user page contents and verify it matches content msg = p.At("pages", "=" + XUri.DoubleEncode("User:"******"contents").With("pageid", homepageid).Get(new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Failed to retrieve user page contents"); Assert.AreEqual(content, msg.ToDocument()["body"].AsText ?? String.Empty, "Unexpected contents"); }
public void PageCreate_NameDoesNotEqualTitle_Unlinked() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Create a page where name != title string path = PageUtils.GenerateUniquePageName(); DreamMessage msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents") .With("title", "unique title") .PostAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, "Linked test")).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page creation failed!"); // Retrieve the page msg = p.At("pages", "=" + XUri.DoubleEncode(path)).GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page retrieval failed!"); // Check that the page is unlinked (i.e. path/@type attribute == custom) string type = msg.ToDocument()["path/@type"].AsText; Assert.AreEqual("custom", type, "Page is unlinked!"); // Delete the page PageUtils.DeletePageByName(p, path, true); }
public void Bug0004185_InboundOutboundLinksAreReversed() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Create page1 string id = null; string path = null; DreamMessage msg = PageUtils.CreateRandomPage(p, out id, out path); // Create page2 with contents containg a link to page1 string linkid = null; string linkpath = null; string content = string.Format( "<a href=\"mks://localhost/{0}\" class=\"internal\" title=\"{0}\">asdasdasdasda</a>", path); msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), content, out linkid, out linkpath); // Retrieve outbound links of page2. Verify link points to page1. msg = p.At("pages", linkid, "links").With("dir", "from").Get(); Assert.IsTrue(msg.ToDocument()["page/@id"].AsText == id, "Outbound link of page with link does not exist!"); // Retrieve inbound links to page1. Verify link originates from page2. msg = p.At("pages", id, "links").With("dir", "to").Get(); Assert.IsTrue(msg.ToDocument()["page/@id"].AsText == linkid, "Inbound link of page linked to is not present!"); // Delete the pages PageUtils.DeletePageByID(p, id, true); PageUtils.DeletePageByID(p, linkid, true); }
public void PageWithLineBreakInLink() { // Login as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Creates a page with contents containing a link with a line break string content = "<p>[[http://www.mindtouch.com/|\n<strong>Link Text</strong>\n]] </p>"; string id = null; string path = null; DreamMessage msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), content, out id, out path); // Retrieve page content msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents").With("mode", "view").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page contents retrieval failed"); content = msg.ToDocument()["body"].AsText; // Assert link is rendered correctly XDoc html = XDocFactory.From("<html>" + System.Web.HttpUtility.HtmlDecode(content) + "</html>", MimeType.HTML); Assert.IsTrue(1 == html["//a"].ListLength && "Link Text" == html["//a/strong"].Contents && "http://www.mindtouch.com/" == html["//a/@href"].Contents, "Link did not render correctly"); // Delete the page PageUtils.DeletePageByID(p, id, true); }
public void PageWithMailToLink() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Create a page with contents containing and email address string content = "<p>[email protected]</p>"; string id = null; string path = null; DreamMessage msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), content, out id, out path); // Retrieve page contents msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents").With("mode", "view").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page content retrieval failed"); // Assert email link is rendered correctly XDoc html = XDocFactory.From("<html>" + System.Web.HttpUtility.HtmlDecode(msg.ToDocument()["body"].AsText) + "</html>", MimeType.HTML); Assert.IsTrue("mailto:[email protected]" == html["//a/@href"].AsText, "Link did not render correctly"); // Delete the page PageUtils.DeletePageByID(p, id, true); }
public void PostContentWithH2() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); string titlecontent = "TITLE"; string content = string.Format("<h2>{0}</h2><p>this is content</p>", titlecontent); // Create a page with above contents string id = null; string path = null; DreamMessage msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), content, out id, out path); // Retrieve page contents msg = p.At("pages", id, "contents").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page content retrieval failed"); // Retrieve contents HTML document, isolate <h2> tag (title), and assert it matches the above content XDoc html = XDocFactory.From("<html>" + System.Web.HttpUtility.HtmlDecode(msg.ToDocument().Contents) + "</html>", MimeType.HTML); Assert.IsTrue(html["//h2"].AsText == titlecontent, "Saved and retrieved H2 content do not match!"); // Delete the page PageUtils.DeletePageByID(p, id, true); }
public void AdminExcludeInboundLinksTest() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Create page1 string page1id; string page1path; DreamMessage msg = PageUtils.CreateRandomPage(p, out page1id, out page1path); // Create page2 with contents containing a link to page1 string page2id; string page2path; string content = string.Format("<a href=\"mks://localhost/{0}\" class=\"internal\" title=\"{0}\">a link to page1</a>", page1path); msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), content, out page2id, out page2path); // Retrieve outbound links of page2. Verify link points to page1. msg = p.At("pages", page2id, "links").With("dir", "from").Get(); Assert.IsTrue(msg.ToDocument()["page/@id"].AsText == page1id, "Outbound link of page with link does not exist!"); // Retrieve inbound links to page1. Verify link originates from page2. msg = p.At("pages", page1id, "links").With("dir", "to").Get(); Assert.IsTrue(msg.ToDocument()["page/@id"].AsText == page2id, "Inbound link of page linked to is not present!"); // Do not exclude anything msg = PageUtils.GetPage(p, page1path, new PageContentFilterSettings()); var doc = msg.ToDocument(); Assert.IsTrue(!doc["inbound"].IsEmpty, "[1] Inbound links information was excluded even though it should not have been excluded"); Assert.IsTrue(!doc["outbound"].IsEmpty, "[2] Outbound links information was excluded even though it should not have been excluded"); // Exclude both inbound and outbound msg = PageUtils.GetPage(p, page1path, new PageContentFilterSettings { ExcludeInboundLinks = true, ExcludeOutboundLinks = true }); doc = msg.ToDocument(); Assert.IsTrue(doc["inbound"].IsEmpty, "[3] Inbound links information wasn't excluded"); Assert.IsTrue(doc["outbound"].IsEmpty, "[4] Outbound links information wasn't excluded"); // exclude outbound only msg = PageUtils.GetPage(p, page1path, new PageContentFilterSettings { ExcludeInboundLinks = false, ExcludeOutboundLinks = true }); doc = msg.ToDocument(); Assert.IsTrue(!doc["inbound"].IsEmpty, "[5] Inbound links information was excluded even though it should not be excluded"); Assert.IsTrue(doc["outbound"].IsEmpty, "[6] Outbound links information wasn't excluded"); // Only exclude inbound msg = PageUtils.GetPage(p, page1path, new PageContentFilterSettings { ExcludeInboundLinks = true, ExcludeOutboundLinks = false }); doc = msg.ToDocument(); Assert.IsTrue(doc["inbound"].IsEmpty, "[7] Inbound links information wasn't excluded"); Assert.IsTrue(!doc["outbound"].IsEmpty, "[8] Outbound links information was exclude even though it should not be excluded"); // Delete the pages PageUtils.DeletePageByID(p, page1id, true); PageUtils.DeletePageByID(p, page2id, true); }
public void CreatingPageByUnbanned() { //Assumptions: // //Actions: // Create user as contributor // Ban user // Unban user // Try to create page from user //Expected result: // Ok Plug p = Utils.BuildPlugForAdmin(); string userId = null; string userName = null; DreamMessage msg = UserUtils.CreateRandomContributor(p, out userId, out userName); XDoc ban = new XDoc("bans") .Elem("description", Utils.GetSmallRandomText()) .Elem("date.expires", DateTime.Now.AddDays(10)) .Start("permissions.revoked") .Elem("operations", banRevokemask) .End() .Start("ban.users") .Start("user").Attr("id", userId).End() .End(); msg = p.At("site", "bans").Post(ban); Assert.AreEqual(DreamStatus.Ok, msg.Status); string banid = msg.ToDocument()["@id"].AsText; Assert.IsTrue(!string.IsNullOrEmpty(banid)); msg = p.At("site", "bans", banid).Delete(); Assert.AreEqual(DreamStatus.Ok, msg.Status); p = Utils.BuildPlugForUser(userName, UserUtils.DefaultUserPsw); string pageTitle = "=" + XUri.DoubleEncode(PageUtils.GenerateUniquePageName()); string content = Utils.GetSmallRandomText(); msg = p.At("pages", pageTitle, "contents").With("edittime", Utils.DateToString(DateTime.MinValue)). PostAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, content)).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status); string pageId = msg.ToDocument()["page/@id"].AsText; p = Utils.BuildPlugForAdmin(); PageUtils.DeletePageByID(p, pageId, true); }
public void Contents_PageWithTalkPage_ManyParameterChanges_CorrectContent() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Create a page with some content and save edittime string path = PageUtils.GenerateUniquePageName(); string content = "test content"; string title = "test title"; string comment = "new page!"; MimeType mime = MimeType.TEXT_UTF8; DreamMessage msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents") .With("title", title) .With("comment", comment) .Post(DreamMessage.Ok(mime, content), new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Creating page failed"); msg = PageUtils.GetPage(p, path); string edittime = msg.ToDocument()["date.edited"].AsText; Assert.IsNotNull(edittime, "No date.edited in page document!"); // Create a talk page string talkid; string talkpath; PageUtils.CreateTalkPage(p, path, out talkid, out talkpath); // Now make some changes string lang = "de"; content = "new test content!"; comment = "edit page!"; title = "new title!"; mime = MimeType.TEXT; msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents") .With("title", title) .With("comment", comment) .With("language", lang) .With("edittime", edittime) .Post(DreamMessage.Ok(mime, content), new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Editing page contents failed"); // Verify changes msg = PageUtils.GetPage(p, path); Assert.AreEqual(title, msg.ToDocument()["title"].AsText ?? String.Empty, "Unexpected title"); Assert.AreEqual(content, msg.ToDocument()["summary"].AsText ?? String.Empty, "Unexpected content"); Assert.AreEqual(lang, msg.ToDocument()["properties/language"].AsText ?? String.Empty, "Unexpected language"); Assert.AreEqual(comment + "; " + "2 words added; " + "page display name changed to '" + title + "'; " + "page language changed to Deutsch", msg.ToDocument()["description"].AsText ?? String.Empty, "Unexpected description"); }
public void Contents_BadTitle_Conflict() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Attempt to save a page with a bad title string path = PageUtils.GenerateUniquePageName(); string title = " "; DreamMessage msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents").With("title", title). Post(DreamMessage.Ok(MimeType.TEXT_UTF8, "test content"), new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Conflict, msg.Status, "Saving page with invalid title succeeded?!"); }
public void PostBigContent() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Generate large amount of content and save to a page string content = Utils.GetBigRandomText(); DreamMessage msg = PageUtils.SavePage(p, PageUtils.GenerateUniquePageName(), content); string id = msg.ToDocument()["page/@id"].AsText; Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page retrieval failed"); // Delete the page PageUtils.DeletePageByID(p, id, true); }
public void MultipleRevisionContent() { // Acquire ADMIN permissions Plug p = Utils.BuildPlugForAdmin(); // Create a page string id = null; string path = null; DreamMessage msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), "filerevcontenttest", out id, out path); string filename = "testfile.txt"; string fileid = null; int revisionsToMake = 5; // Upload a file with revisionsToMake revisions for (int r = 1; r <= revisionsToMake; r++) { string content = string.Format("test file rev {0}", r); msg = p.At("pages", id, "files", "=" + filename).PutAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, content)).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Saving revision " + r); fileid = msg.ToDocument()["@id"].AsText; Assert.IsFalse(string.IsNullOrEmpty(fileid)); } // Create a new page and move the revised file there msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), "filerevcontenttest2", out id, out path); Assert.AreEqual(DreamStatus.Ok, p.At("files", fileid, "move").With("to", id).PostAsync().Wait().Status, "move file failed"); // Create new rev msg = p.At("files", fileid).PutAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, string.Format("test file rev {0}", revisionsToMake + 2))).Wait(); // Assert each revision is consistent for (int r = 1; r <= revisionsToMake; r++) { string expected = string.Format("test file rev {0}", r); string actual = p.At("files", fileid).With("revision", r).Get().AsText(); Assert.AreEqual(expected, actual); } // Check contents of rev of move same as the one before Assert.AreEqual(string.Format("test file rev {0}", revisionsToMake), p.At("files", fileid).With("revision", (revisionsToMake + 1).ToString()).Get().AsText(), "unexpected content after move"); // Check contents of new rev after move Assert.AreEqual(string.Format("test file rev {0}", revisionsToMake + 2), p.At("files", fileid).With("revision", (revisionsToMake + 2).ToString()).Get().AsText(), "unexpected content next rev after move"); // Delete the page PageUtils.DeletePageByID(p, id, true); }
public void GetPageDiffWithoutTags() { // 1. Create a page with some content // 2. Retrieve revisions list // (3) Assert revisions list is populated // 4. Save page with some new content // 5. Retrieve revisions list // (6) Assret revisions list is populated // 7. Perform a diff // (8) Assert diff result matches expected diff // 9. Delete the page // GET:pages/{pageid}/revisions // http://developer.mindtouch.com/Deki/API_Reference/GET%3apages%2f%2f%7bpageid%7d%2f%2frevisions Plug p = Utils.BuildPlugForAdmin(); string content = "This is test content"; string id = null; string path = null; DreamMessage msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), content, out id, out path); msg = p.At("pages", "=" + XUri.DoubleEncode(path), "revisions").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page revisions retrieval failed (1)"); Assert.IsFalse(msg.ToDocument()["page"].IsEmpty, "Page revisions list is empty?! (1)"); PageUtils.SavePage(p, path, "New content"); msg = p.At("pages", id, "revisions").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page revisions retrieval failed (2)"); Assert.IsFalse(msg.ToDocument()["page"].IsEmpty, "Page revisions list is empty?! (2)"); // GET:pages/{pageid}/diff // http://developer.mindtouch.com/Deki/API_Reference/GET%3apages%2f%2f%7bpageid%7d%2f%2fdiff msg = p.At("pages", id, "diff").With("revision", "head").With("previous", -1).Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "diff generation failed"); string diff = "<ins>New</ins><del>This is test</del> content"; Assert.AreEqual(diff, msg.ToDocument().Contents, "diff result does not match expected result"); PageUtils.DeletePageByID(p, id, true); }
private void DeleteWithSubPage(Plug p, string suffix) { string path = PageUtils.GenerateUniquePageName() + suffix; DreamMessage msg = PageUtils.CreateRandomPage(p, path); string id = msg.ToDocument()["page/@id"].AsText; msg = PageUtils.CreateRandomPage(p, path + "/" + Utils.GenerateUniqueName()); string subid = msg.ToDocument()["page/@id"].AsText; string subpath = msg.ToDocument()["page/path"].AsText; msg = PageUtils.DeletePageByID(p, id, false); Assert.AreEqual(DreamStatus.Ok, msg.Status); msg = p.At("pages", "=" + XUri.DoubleEncode(subpath)).GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status); //Assert.IsFalse(msg.ToDocument()[string.Format("page/subpages//page/subpages/page[@id=\"{0}\"]", subid)].IsEmpty); }
public void Contents_TestMerge_CorrectContents() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Create some content to test merge string contentA = "<p>This is some wonderful content</p><p>I love writing tests</p>"; string contentB = "<p>bing bong ping pong</p><p>I love writing tests</p>"; string contentC = "<p>This is some wonderful content</p><p>Expect a cool merge right here</p>"; string contentRes = "<p>bing bong ping pong</p><p>Expect a cool merge right here</p>"; // Upload contentA to page and save edittime string path = PageUtils.GenerateUniquePageName(); DreamMessage msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents").Post(DreamMessage.Ok(MimeType.TEXT_UTF8, contentA), new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Setting page contents to contentA failed"); msg = PageUtils.GetPage(p, path); string edittime = msg.ToDocument()["date.edited"].AsText; Assert.IsNotNull(edittime, "No date.edited in page document!"); // Have it wait a second Wait.For(() => { return(false); }, TimeSpan.FromSeconds(1)); // Upload content B as Admin msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents").With("edittime", edittime).Post(DreamMessage.Ok(MimeType.TEXT_UTF8, contentB), new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Setting page contents to contentB failed"); // Create a user and upload content C as user string userid; string username; UserUtils.CreateRandomContributor(p, out userid, out username); // Upload content C as user p = Utils.BuildPlugForUser(username); msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents").With("edittime", edittime).Post(DreamMessage.Ok(MimeType.TEXT_UTF8, contentC), new Result <DreamMessage>()).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Setting page contents to contentB failed"); // Retrieve page contents and verify merge msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents").Get(new Result <DreamMessage>()).Wait(); Assert.AreEqual(contentRes, msg.ToDocument()["body"].AsText ?? String.Empty, "Unexpected contents after merge"); }
public void GetContent() { // Login as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Generate small random content string content = Utils.GetSmallRandomText(); // Create a page with random content string id = null; string path = null; DreamMessage msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), content, out id, out path); // Retrieve page (by name) and compare contents msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents").With("mode", "view").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page retrieval failed (name)"); XDoc html = XDocFactory.From("<html>" + System.Web.HttpUtility.HtmlDecode(msg.ToDocument()["body"].AsText) + "</html>", MimeType.HTML); Assert.AreEqual(html["/html"].AsText, content, "Retrieved and generated contents do not match! (name)"); // Retrieve page (by ID) and compare contents msg = p.At("pages", id, "contents").With("mode", "view").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page retrieval failed (ID)"); html = XDocFactory.From("<html>" + System.Web.HttpUtility.HtmlDecode(msg.ToDocument()["body"].AsText) + "</html>", MimeType.HTML); Assert.AreEqual(html["/html"].AsText, content, "Retrieved and generated contents do not match! (ID)"); // Generate new random contents string newContent = Utils.GetSmallRandomText(); // Replace contents with new content msg = PageUtils.SavePage(p, path, newContent); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Uploading new content failed"); // Retrieve page (by ID) and compare new contents msg = p.At("pages", id, "contents").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page retrieval failed (ID, new content)"); html = XDocFactory.From("<html>" + System.Web.HttpUtility.HtmlDecode(msg.ToDocument()["body"].AsText) + "</html>", MimeType.HTML); Assert.AreEqual(html["/html"].AsText, newContent, "Retrieved and generated contents do not match! (ID, new content)"); // Delete the page PageUtils.DeletePageByID(p, id, true); }
public void GetPageCreatorInfo() { Plug p = Utils.BuildPlugForAdmin(); string content = "This is test content"; string id = null; string path = null; DreamMessage msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), content, out id, out path); msg = p.At("users", "current").Get(); var pageCreatorId = msg.AsDocument()["@id"].AsText; PageUtils.SavePage(p, path, "New content"); var pageDoc = p.At("pages", id).Get().ToDocument(); Assert.AreEqual(pageCreatorId, pageDoc["user.createdby/@id"].AsText); Assert.IsTrue((pageDoc["date.created"].AsDate ?? DateTime.MinValue) > DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5)), "create date missing."); PageUtils.DeletePageByID(p, id, true); }
public void SiteFeed_CreatePage_CorrectFeedData() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Create a page string path = PageUtils.GenerateUniquePageName(); string contents = "Test feed contents"; DreamMessage msg = p.At("pages", "=" + XUri.DoubleEncode(path), "contents") .PostAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, contents)).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page creation failed!"); int pageid = msg.ToDocument()["page/@id"].AsInt ?? 0; // Retrieve most recent created feed entry msg = p.At("site", "feed").With("format", "rawdaily").With("limit", 1).GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Feed retrieval failed!"); // Run checks rc_id_check(msg); rc_comment_check(msg, "page created, 3 words added"); rc_cur_id_check(msg, pageid); rc_last_oldid_check(msg, 0); rc_this_oldid_check(msg, 0); rc_namespace_check(msg, 0); rc_timestamp_check(msg); rc_title_check(msg, path); rc_type_check(msg, 1); // NEW = 1 rc_moved_to_ns_check(msg, 0); rc_moved_to_title_check(msg, String.Empty); rc_user_name_check(msg, USERNAME); rc_full_name_check(msg, String.Empty); rc_page_exists_check(msg, 1); rc_revision_check(msg, 1); cmnt_deleted_check(msg, 0); //edit_count_check(msg, 1); rc_prev_revision_check(msg, 0); rc_summary_check(msg, "Edited once by " + USERNAME); }
public void GetPageDiffWithTags() { // 1. Create a page with some content with tags // 2. Retrieve revisions list // (3) Assert revisions list is populated // 4. Save page with some new content with tags // 5. Retrieve revisions list // (6) Assret revisions list is populated // 7. Perform a diff // (8) Assert diff result matches expected diff // 9. Delete the page Plug p = Utils.BuildPlugForAdmin(); string content = "<p>This is test</p><p>content</p>"; string id = null; string path = null; DreamMessage msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), content, out id, out path); msg = p.At("pages", "=" + XUri.DoubleEncode(path), "revisions").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page revisions retrieval failed (1)"); Assert.IsFalse(msg.ToDocument()["page"].IsEmpty, "Page revisions list is empty?! (1)"); PageUtils.SavePage(p, path, "<p>New</p><p>content</p>"); msg = p.At("pages", id, "revisions").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page revisions retrieval failed (2)"); Assert.IsFalse(msg.ToDocument()["page"].IsEmpty, "Page revisions list is empty?! 2)"); msg = p.At("pages", id, "diff").With("revision", "head").With("previous", -1).Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "diff generation failed"); string diff = "<p><ins>New</ins><del>This is test</del></p><p>...</p>"; Assert.AreEqual(diff, msg.ToDocument().Contents, "diff result does not match expected result"); PageUtils.DeletePageByID(p, id, true); }
public void MT9092_WikiLocalize_respects_page_culture() { // Fixes: http://youtrack.developer.mindtouch.com/issue/MT-9092 var p = Utils.BuildPlugForAdmin(); // Create a page string id = null; var resource = "activation.activated"; var content = string.Format("{{{{wiki.localize(\"{0}\")}}}}", resource); var title = PageUtils.GenerateUniquePageName(); title = "=" + XUri.DoubleEncode(title); var msg = p.At("pages", title, "contents") .With("language", "fr-fr") .PostAsync(DreamMessage.Ok(MimeType.TEXT_UTF8, content)) .Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page creation failed!"); id = msg.ToDocument()["page/@id"].AsText; _log.DebugFormat("page id: {0}", id); // get localized string & make sure we have localization for it msg = p.At("site", "localization").With("resource", resource).Get(); var invariant = msg.ToText(); msg = p.At("site", "localization").With("resource", resource).With("lang", "fr-fr").Get(); var french = msg.ToText(); Assert.AreNotEqual(invariant, french); // get french page msg = p.At("pages", id, "contents").With("format", "html").Get(); Assert.AreEqual(french, msg.ToDocument()["body"].Contents); // Delete the page PageUtils.DeletePageByID(p, id, true); }
public void GetPageByIdIncludingContents() { // Login as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Generate small random content string content = Utils.GetSmallRandomText(); // Create a page with random content string id = null; string path = null; DreamMessage msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), content, out id, out path); // Retrieve page (by ID) and compare contents msg = p.At("pages", id, "contents").With("mode", "view").With("include", "contents").Get(); var msgDoc = msg.ToDocument(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page retrieval by ID failed"); Assert.AreEqual(content, System.Web.HttpUtility.HtmlDecode(msgDoc["body"].AsText), "The content is incorrect"); // Delete the page PageUtils.DeletePageByID(p, id, true); }
public void GetContentByRevision() { // Log in as ADMIN Plug p = Utils.BuildPlugForAdmin(); // Genereate small, random content string content = Utils.GetSmallRandomText(); // Create page with that content string id = null; string path = null; DreamMessage msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), content, out id, out path); // Retrieve page contents msg = p.At("pages", id, "contents").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page content retrieval failed"); content = msg.ToDocument()["body"].AsText; // Save some new, random content to page msg = PageUtils.SavePage(p, path, Utils.GetSmallRandomText()); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Failed to update page content"); // Retrieve new page content and verify it does not match previous content msg = p.At("pages", id, "contents").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Page content retrieval failed (rev 2)"); Assert.IsFalse(msg.ToDocument()["body"].AsText == content, "Current page content matches previous revision!"); // Retrieve old page content (previous revision) and verify it matches previous content msg = p.At("pages", id, "contents").With("revision", "1").Get(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Retrieval of page content of previous revision failed"); Assert.IsTrue(msg.ToDocument()["body"].AsText == content, "Generated content and retrieved content of first revision do not match!"); // Delete the page PageUtils.DeletePageByID(p, id, true); }
public void RevisionHideAndUnhide() { Plug p = Utils.BuildPlugForAdmin(); string id = null; string path = null; string fileid = null; string filename = null; DreamMessage msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), "filerevhidetest", out id, out path); string filepath = FileUtils.CreateRamdomFile(Encoding.UTF8.GetBytes("My contents.")); FileUtils.UploadFile(p, id, "test file rev 1", out fileid, filepath); FileUtils.UploadFile(p, id, "test file rev 2", out fileid, filepath); FileUtils.UploadFile(p, id, "test file rev 3", out fileid, filepath); string userid; string username; UserUtils.CreateRandomUser(p, "Contributor", out userid, out username); //Check that anon can see contents before hiding revs msg = Utils.BuildPlugForUser(username).At("files", fileid, "contents").With("revision", 2).GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "reg user can't see contents even before hiding!"); //Reinit plug to admin Utils.BuildPlugForAdmin(); string comment = "just cuz.."; XDoc hideRequestXml = new XDoc("revisions").Start("file").Attr("id", fileid).Attr("hidden", true).Attr("revision", 2).End(); msg = p.At("files", fileid, "revisions").With("comment", comment).PostAsync(hideRequestXml).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Non 200 status hiding revisions"); //Ensure correct revisions coming back is visible + hidden msg = p.At("files", fileid, "info").With("revision", 1).GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "files/{id}/info?revision=x returned non 200 status"); Assert.IsFalse(msg.ToDocument()["/page[@revision = \"1\"]/@hidden"].AsBool ?? false, "Rev 1 is hidden!"); //validate hidden rev msg = p.At("files", fileid, "info").With("revision", 2).GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "files/{id}/info?revision=x returned non 200 status"); Assert.IsTrue(msg.ToDocument()["/file[@revision = \"2\"]/@hidden"].AsBool ?? false, "Rev 2 is not hidden!"); Assert.AreEqual(comment, msg.ToDocument()["/file[@revision = \"2\"]/description.hidden"].AsText, "hide comment missing or invalid"); Assert.IsTrue(!string.IsNullOrEmpty(msg.ToDocument()["/file[@revision = \"2\"]/date.hidden"].AsText), "date.hidden missing"); Assert.IsNotNull(msg.ToDocument()["/file[@revision = \"2\"]/user.hiddenby/@id"].AsUInt, "user.hiddenby id missing"); msg = p.At("files", fileid, "info").With("revision", 3).GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "files/{id}/info?revision=x returned non 200 status"); Assert.IsFalse(msg.ToDocument()["/file[@revision = \"3\"]/@hidden"].AsBool ?? false, "Rev 3 is hidden!"); //Ensure admin still has rights to see hidden contents msg = p.At("files", fileid).With("revision", 2).GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "admin can't see hidden contents!"); //Ensure non-admin cannot see hidden contents msg = Utils.BuildPlugForUser(username).At("files", fileid).With("revision", 2).GetAsync().Wait(); Assert.IsTrue(msg.Status == DreamStatus.Unauthorized || msg.Status == DreamStatus.Forbidden, "reg user can still see contents!"); //Attempt to unhide a rev by non admin hideRequestXml = new XDoc("revisions").Start("file").Attr("id", fileid).Attr("hidden", false).Attr("revision", 2).End(); msg = p.At("files", fileid, "revisions").With("comment", comment).PostAsync(hideRequestXml).Wait(); Assert.AreEqual(DreamStatus.Forbidden, msg.Status, "non admin able to unhide rev"); //Attempt to hide a rev by non admin hideRequestXml = new XDoc("revisions").Start("file").Attr("id", fileid).Attr("hidden", true).Attr("revision", 1).End(); msg = p.At("files", fileid, "revisions").With("comment", comment).PostAsync(hideRequestXml).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "DELETE holder unable to hide rev"); //Unhide a rev as normal user (fail!) hideRequestXml = new XDoc("revisions").Start("file").Attr("id", fileid).Attr("hidden", false).Attr("revision", 1).End(); msg = p.At("files", fileid, "revisions").With("comment", comment).PostAsync(hideRequestXml).Wait(); Assert.AreEqual(DreamStatus.Forbidden, msg.Status, "normal user able to unhide!"); //Reinit plug to admin Utils.BuildPlugForAdmin(); //Unhide a rev as admin hideRequestXml = new XDoc("revisions").Start("file").Attr("id", fileid).Attr("hidden", false).Attr("revision", 1).End(); msg = p.At("files", fileid, "revisions").With("comment", comment).PostAsync(hideRequestXml).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "admin unable to make rev visible"); //confirm rev 1 is visible now msg = p.At("files", fileid, "info").With("revision", 1).GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "files/{id}/info?revision=x returned non 200 status"); Assert.IsFalse(msg.ToDocument()["/file[@revision = \"1\"]/@hidden"].AsBool ?? false, "Rev 1 is still hidden!"); }
public void RevisionHideAndUnhide() { // 1. Create a page with 3 revisions // 2. Create a user with Contributor role // (3) Assert unhidden contents can be viewed by user // 4. Hide second revision // (5) Assert first revision remains unhidden // (6) Assert second revision is hidden // (7) Assert third revision is unhidden // (8) Assert admin can view hidden revision contents // (9) Assert Unauthorized HTTP response returned to user attempting to view hidden revision contents // (10) Assert Forbidden HTTP response returned to user when attempting to unhide a hidden revision // (11) Assert user is allowed to hide a revision // (12) Assert Conflict HTTP response returned to user when attempting to revert to hidden revision // 13. Delete the page // 14. Restore page as admin // (15) Assert restored page persists hidden state Plug p = Utils.BuildPlugForAdmin(); string id = null; string path = null; DreamMessage msg = PageUtils.SavePage(p, string.Empty, PageUtils.GenerateUniquePageName(), "Rev1", out id, out path); PageUtils.SavePage(p, path, "Rev2"); PageUtils.SavePage(p, path, "Rev3"); string userid; string username; UserUtils.CreateRandomUser(p, "Contributor", out userid, out username); //Check that anon can see contents before hiding revs msg = Utils.BuildPlugForUser(username).At("pages", id, "contents").With("revision", 2).GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "reg user can't see contents even before hiding!"); //Reinit plug to admin Utils.BuildPlugForAdmin(); string comment = "just cuz.."; XDoc hideRequestXml = new XDoc("revisions").Start("page").Attr("id", id).Attr("hidden", true).Attr("revision", 2).End(); msg = p.At("pages", id, "revisions").With("comment", comment).PostAsync(hideRequestXml).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "Non 200 status hiding revisions"); //Ensure correct revisions coming back is visible + hidden msg = p.At("pages", id, "revisions").With("revision", 1).GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "pages/{id}/revisions?revision=x returned non 200 status"); Assert.IsFalse(msg.ToDocument()["/page[@revision = \"1\"]/@hidden"].AsBool ?? false, "Rev 1 is hidden!"); //validate hidden rev msg = p.At("pages", id, "revisions").With("revision", 2).GetAsync().Wait(); Assert.IsTrue(msg.ToDocument()["/page[@revision = \"2\"]/@hidden"].AsBool ?? false, "Rev 2 is not hidden!"); Assert.AreEqual(comment, msg.ToDocument()["/page[@revision = \"2\"]/description.hidden"].AsText, "hide comment missing or invalid"); Assert.IsTrue(!string.IsNullOrEmpty(msg.ToDocument()["/page[@revision = \"2\"]/date.hidden"].AsText), "date.hidden missing"); Assert.IsNotNull(msg.ToDocument()["/page[@revision = \"2\"]/user.hiddenby/@id"].AsUInt, "user.hiddenby id missing"); msg = p.At("pages", id, "revisions").With("revision", 3).GetAsync().Wait(); Assert.IsFalse(msg.ToDocument()["/page[@revision = \"3\"]/@hidden"].AsBool ?? false, "Rev 3 is hidden!"); //Ensure admin still has rights to see hidden page contents msg = p.At("pages", id, "contents").With("revision", 2).GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "admin can't see hidden contents!"); //Ensure non-admin cannot see hidden page contents msg = Utils.BuildPlugForUser(username).At("pages", id, "contents").With("revision", 2).GetAsync().Wait(); Assert.IsTrue(msg.Status == DreamStatus.Unauthorized || msg.Status == DreamStatus.Forbidden, "reg user can still see contents!"); //Attempt to unhide a rev by non admin hideRequestXml = new XDoc("revisions").Start("page").Attr("id", id).Attr("hidden", false).Attr("revision", 2).End(); msg = p.At("pages", id, "revisions").With("comment", comment).PostAsync(hideRequestXml).Wait(); Assert.AreEqual(DreamStatus.Forbidden, msg.Status, "non admin able to unhide rev"); //Attempt to hide a rev by non admin hideRequestXml = new XDoc("revisions").Start("page").Attr("id", id).Attr("hidden", true).Attr("revision", 1).End(); msg = p.At("pages", id, "revisions").With("comment", comment).PostAsync(hideRequestXml).Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "DELETE holder unable to hide rev"); //revert hidden rev msg = p.At("pages", id, "revert").With("fromrevision", 2).PostAsync().Wait(); Assert.AreEqual(DreamStatus.Conflict, msg.Status, "able to revert a hidden rev!"); //delete page msg = p.At("pages", id).DeleteAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "unable to delete page!"); //Reinit plug to admin Utils.BuildPlugForAdmin(); //undelete page msg = p.At("archive", "pages", id, "restore").PostAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "unable to restore page!"); //Ensure correct revisions coming back is visible + hidden msg = p.At("pages", id, "revisions").With("revision", 2).GetAsync().Wait(); Assert.AreEqual(DreamStatus.Ok, msg.Status, "pages/{id}/revisions?revision=x returned non 200 status"); Assert.IsTrue(msg.ToDocument()["/page[@revision = \"2\"]/@hidden"].AsBool ?? false, "Rev 2 is no longer hidden after delete/restore!"); }