func TestHiddenPosts(t *testing.T) { var positiveTests = []struct { url, content string }{ {"hello1001", "Body"}, {"", "hello1001"}, {"archive", "hello1001"}, } var negativeTests = []struct { url, content string }{ {"", "hello1001"}, {"archive", "hello1001"}, } ensureLogin() for _, i := range positiveTests { html := htmltest.Curl(i.url) mustContain(t, html, i.content) } doLogout() for _, i := range negativeTests { html := htmltest.Curl(i.url) mustNotContain(t, html, i.content) } }
func TestHiddenPostAccess(t *testing.T) { ensureLogin() html := htmltest.Curl("hello1001") mustContain(t, html, "Body") doLogout() html = htmltest.Curl("hello1001") mustContain(t, html, "Page Not Found") }
func TestRssFeed(t *testing.T) { xml := htmltest.Curl("feeds/rss.xml") url := htmltest.PathToURL("") mustContain(t, xml, fmt.Sprintf("<link>%s</link>", url)) mustContain(t, xml, "<title>Hi3</title>") mustContain(t, xml, fmt.Sprintf("<link>%s/%s</link>", url, "hello3")) }
func TestEditPost(t *testing.T) { ensureLogin() // test with non-hidden post html := htmltest.Curl("edit_post?post=hello3") mustContain(t, html, "Body3") mustContain(t, html, "Hi3") mustContain(t, html, "u3") mustContain(t, html, "Delete!") mustNotContain(t, html, "checked") // now test with hidden post html = htmltest.Curl("edit_post?post=hello1002") mustContain(t, html, "Body1002") mustContain(t, html, "Hi1002") mustContain(t, html, "u1002") mustContain(t, html, "Delete!") mustContain(t, html, "checked") }
func TestTitleByTagGetsCalled(t *testing.T) { defer testData.reset() tag := "taaag" html := htmltest.Curl("/tag/" + tag) testData.expect(t, (*TestData).titlesByTag, tag) mustContain(t, html, "Posts tagged ") mustContain(t, html, tag) }
func TestMainPageShowsCreateAuthorPage(t *testing.T) { tmp := testAuthor testAuthor = nil html := htmltest.Curl("/") mustContain(t, html, "New Password") mustContain(t, html, "Confirm Password") mustNotContain(t, html, "Old Password") testAuthor = tmp }
func TestEmptyDatasetGeneratesFriendlyError(t *testing.T) { tmpPosts := testPosts testPosts = nil defer func() { testPosts = tmpPosts }() html := htmltest.Curl("") mustContain(t, html, "No entries") }
func TestShowCaptcha(t *testing.T) { url := mkQueryURL("comment_submit", map[string]string{ "name": "joe", "captcha": "", "email": "snailmail", "text": "cmmnt%20txt", }) resp := mustUnmarshal(t, htmltest.Curl(url)) T{t}.failIf(resp["status"] != "showcaptcha", "No captcha box") }
func TestReturningCommenterSkipsCaptcha(t *testing.T) { url := mkQueryURL("comment_submit", map[string]string{ "name": "N", "captcha": "", "email": "@", "website": "w", "text": "cmmnt%20txt", }) resp := mustUnmarshal(t, htmltest.Curl(url)) T{t}.failIf(resp["status"] != "accepted", "Comment by returning commenter not accepted") }
func TestHiddenPostDoesNotAppearInRss(t *testing.T) { bak := testPosts testPosts = make([]*Entry, 0) testPosts = append(testPosts, mkTestEntry(1, false)) testPosts = append(testPosts, mkTestEntry(1000, true)) testPosts = append(testPosts, mkTestEntry(2, false)) ensureLogin() xml := htmltest.Curl("feeds/rss.xml") mustNotContain(t, xml, "hello1000") testPosts = bak }
func TestPagination(t *testing.T) { nodes := htmltest.Query(t, "page/2", "*", ".post-title") T{t}.failIf(len(nodes) != PostsPerPage, "Not all posts have been rendered!") if nodes[0].Attr[1].Val != "/hello6" { t.Fatalf("Wrong post!") } if nodes[4].Attr[1].Val != "/hello10" { t.Fatalf("Wrong post!") } html := htmltest.Curl("page/2") mustContain(t, html, "<a href=\"/page/1\">1</a>\n2\n<a href=\"/page/3\">3</a>\n") }
func TestUndetectedLanguageCommentDismiss(t *testing.T) { defer testData.reset() url := mkQueryURL("comment_submit", map[string]string{ "name": "UnknownCommenter", "captcha": "", "email": "@", "website": "w", "text": "cmmnt%20txt", "captcha-id": "666", }) resp := mustUnmarshal(t, htmltest.Curl(url)) T{t}.failIf(resp["status"] != "rejected", "Comment with undetected language not rejected") testData.expect(t, (*TestData).postID, "") }
func TestCorrectCaptchaReply(t *testing.T) { defer testData.reset() deck := NewDeck() deck.SetNextTask(0) task := deck.NextTask() url := mkQueryURL("comment_submit", map[string]string{ "name": "UnknownCommenter", "captcha": task.Answer, "email": "@", "website": "w", "text": "cmmnt%20txt", "captcha-id": task.ID, }) resp := mustUnmarshal(t, htmltest.Curl(url)) T{t}.failIf(resp["status"] != "accepted", "Comment with correct captcha reply not accepted") testData.expectChain(t, []CallSpec{{(*TestData).postID, ""}, {(*TestData).insertCommenter, "UnknownCommenter"}}) }
func TestMainPage(t *testing.T) { var simpleTests = []struct { url string out string }{ {"", "container"}, {"", "header"}, {"", "subheader"}, {"", "content"}, {"", "sidebar"}, {"", "footer"}, {"", "Ribs"}, {"", "utf-8"}, {"", "gopher.png"}, {"", "vim_created.png"}, } for _, test := range simpleTests { mustContain(t, htmltest.Curl(test.url), test.out) } }
func TestDetectedLtLanguageCommentApprove(t *testing.T) { defer testData.reset() temp := langDetector defer func() { langDetector = temp }() langDetector = LTLangDetector{} url := mkQueryURL("comment_submit", map[string]string{ "name": "UnknownCommenter", "captcha": "", "email": "@", "website": "w", "text": "cmmnt%20txt", }) resp := mustUnmarshal(t, htmltest.Curl(url)) T{t}.failIf(resp["status"] != "accepted", "Comment w/ detected language 'lt' not accepted") testData.expectChain(t, []CallSpec{{(*TestData).postID, ""}, {(*TestData).postID, ""}, {(*TestData).postID, ""}, {(*TestData).insertCommenter, "UnknownCommenter"}}) }
func TestNonAdminCantAccessAdminPages(t *testing.T) { doLogout() urls := []string{ "all_comments", "admin", "edit_post", "load_comments", "delete_comment", "delete_post", } for _, u := range urls { html := htmltest.Curl(u) mustContain(t, html, "Verboten") } postUrls := []string{ "moderate_comment", "submit_post", "upload_images", } for _, u := range postUrls { html := htmltest.CurlPost(u) mustContain(t, html, "Verboten") } }
func TestInvalidPageDefaultsToPageOne(t *testing.T) { page1 := htmltest.Curl("/page/1") pageFoo := htmltest.Curl("/page/foo") T{t}.failIf(page1 != pageFoo, "Invalid page did not produce /page/1") }
func TestAdminPageHasEditAuthorButton(t *testing.T) { mustContain(t, htmltest.Curl("/admin"), "Edit Author Profile") }
func TestLoadComments(t *testing.T) { ensureLogin() json := htmltest.Curl("/load_comments?post=hello1") mustContain(t, json, `"Comments":[{"Name":"N","Email":"@"`) }
func TestRobotsTxtGetsServed(t *testing.T) { robots := htmltest.Curl("robots.txt") mustContain(t, robots, "Disallow") }
func TestLogin(t *testing.T) { ensureLogin() html := htmltest.Curl(testPosts[0].URL) mustContain(t, html, "Logout") }
func TestPostPager(t *testing.T) { mustContain(t, htmltest.Curl(""), "/page/2") }
func TestEveryEntryHasAuthor(t *testing.T) { for _, e := range testPosts { mustContain(t, htmltest.Curl(e.URL), "captcha-id") } }
func TestNonEmptyDatasetHasEntries(t *testing.T) { mustNotContain(t, htmltest.Curl(""), "No entries") }
func TestDeleteCommentCallsDbFunc(t *testing.T) { defer testData.reset() htmltest.Curl("delete_comment?id=1&action=delete") testData.expect(t, (*TestData).deleteComment, "1") }
func TestEditAuthor(t *testing.T) { html := htmltest.Curl("/edit_author") mustContain(t, html, "New Password") mustContain(t, html, "Confirm Password") mustContain(t, html, "Old Password") }
func doLogout() { htmltest.Curl("logout") }
func TestDeletePostCallsDbFunc(t *testing.T) { defer testData.reset() htmltest.Curl("delete_post?id=hello1001") testData.expect(t, (*TestData).deletePost, "hello1001") }