public void WikiPages_IsWikiPageTitleValid_Quotes() { string titleQuote, container; titleQuote = "This is really only 1/2 a \"title\"."; Assert.IsFalse(WikiPages.IsWikiPageTitleValid(titleQuote, out container)); }
private bool ValidateTitle() { if (textPageTitle.Text == "") { MsgBox.Show(this, "Page title cannot be empty."); return(false); } if (textPageTitle.Text == PageTitle) { //"rename" to the same thing. DialogResult = DialogResult.Cancel; return(false); } string errorMsg = ""; if (!WikiPages.IsWikiPageTitleValid(textPageTitle.Text, out errorMsg)) { MessageBox.Show(errorMsg); //errorMsg was already translated. return(false); } if (PageTitle != null && textPageTitle.Text.ToLower() == PageTitle.ToLower()) { //the user is just trying to change the capitalization, which is allowed return(true); } WikiPage wp = WikiPages.GetByTitle(textPageTitle.Text); //this is case insensitive, so it won't let you name it the same as another page even if capitalization is different. if (wp != null) { MsgBox.Show(this, "Page title already exists."); return(false); } return(true); }
public void WikiPages_IsWikiPageTitleValid_Underline() { string titleUnderline, container; titleUnderline = "_Title that contains an underline"; Assert.IsFalse(WikiPages.IsWikiPageTitleValid(titleUnderline, out container)); }
public void WikiPages_IsWikiPageTitleValid() { string titleValid, container; titleValid = "This is a valid title"; container = ""; Assert.IsTrue(WikiPages.IsWikiPageTitleValid(titleValid, out container)); }
public void WikiPages_IsWikiPageTitleValid_MultipleLines() { string titleNewLine, container; titleNewLine = "Two line \r\n title"; container = ""; Assert.IsFalse(WikiPages.IsWikiPageTitleValid(titleNewLine, out container)); }
public void WikiPages_IsWikiPageTitleValid_HashMark() { string titleHash, container; titleHash = "Title with an # mark"; container = ""; Assert.IsFalse(WikiPages.IsWikiPageTitleValid(titleHash, out container)); }
///<summary>Before calling this, make sure to increment/decrement the historyNavBack index to keep track of the position in history. If loading a new page, decrement historyNavBack before calling this function. </summary> private void LoadWikiPage(string pageTitle) { //This is called from 11 different places, any time the program needs to refresh a page from the db. //It's also called from the browser_Navigating event when a "wiki:" link is clicked. WikiPage wpage = WikiPages.GetByTitle(pageTitle); if (wpage == null) { string errorMsg = ""; if (!WikiPages.IsWikiPageTitleValid(pageTitle, out errorMsg)) { MsgBox.Show(this, "That page does not exist and cannot be made because the page title contains invalid characters."); return; } if (!MsgBox.Show(this, MsgBoxButtons.YesNo, "That page does not exist. Would you like to create it?")) { return; } Action <string> onWikiSaved = new Action <string>((pageTitleNew) => { //Insert the pageTitleNew where the pageTitle exists in the existing WikiPageCur //(guaranteed to be unique because all INVALID WIKIPAGE LINK's have an ID at the end) string pageContent = WikiPages.GetWikiPageContentWithWikiPageTitles(WikiPageCur.PageContent); WikiPageCur.PageContent = pageContent.Replace(pageTitle, pageTitleNew); WikiPageCur.PageContent = WikiPages.ConvertTitlesToPageNums(WikiPageCur.PageContent); WikiPages.Update(WikiPageCur); }); AddWikiPage(onWikiSaved); return; } WikiPageCur = wpage; try { webBrowserWiki.DocumentText = WikiPages.TranslateToXhtml(WikiPageCur.PageContent, false); } catch (Exception ex) { webBrowserWiki.DocumentText = ""; MessageBox.Show(this, Lan.g(this, "This page is broken and cannot be viewed. Error message:") + " " + ex.Message); } Text = "Wiki - " + WikiPageCur.PageTitle; #region historyMaint //This region is duplicated in webBrowserWiki_Navigating() for external links. Modifications here will need to be reflected there. int indexInHistory = historyNav.Count - (1 + historyNavBack); //historyNavBack number of pages before the last page in history. This is the index of the page we are loading. if (historyNav.Count == 0) //empty history { historyNavBack = 0; historyNav.Add("wiki:" + pageTitle); } else if (historyNavBack < 0) //historyNavBack could be negative here. This means before the action that caused this load, we were not navigating through history, simply set back to 0 and add to historyNav[] if necessary. { historyNavBack = 0; if (historyNav[historyNav.Count - 1] != "wiki:" + pageTitle) { historyNav.Add("wiki:" + pageTitle); } } else if (historyNavBack >= 0 && historyNav[indexInHistory] != "wiki:" + pageTitle) //branching from page in history { historyNav.RemoveRange(indexInHistory, historyNavBack + 1); //remove "forward" history. branching off in a new direction historyNavBack = 0; historyNav.Add("wiki:" + pageTitle); } #endregion }