示例#1
0
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)
	}
}
示例#2
0
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")
}
示例#3
0
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"))
}
示例#4
0
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")
}
示例#5
0
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)
}
示例#6
0
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
}
示例#7
0
func TestEmptyDatasetGeneratesFriendlyError(t *testing.T) {
	tmpPosts := testPosts
	testPosts = nil
	defer func() {
		testPosts = tmpPosts
	}()
	html := htmltest.Curl("")
	mustContain(t, html, "No entries")
}
示例#8
0
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")
}
示例#9
0
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")
}
示例#10
0
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
}
示例#11
0
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")
}
示例#12
0
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, "")
}
示例#13
0
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"}})
}
示例#14
0
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)
	}
}
示例#15
0
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"}})
}
示例#16
0
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")
	}
}
示例#17
0
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")
}
示例#18
0
func TestAdminPageHasEditAuthorButton(t *testing.T) {
	mustContain(t, htmltest.Curl("/admin"), "Edit Author Profile")
}
示例#19
0
func TestLoadComments(t *testing.T) {
	ensureLogin()
	json := htmltest.Curl("/load_comments?post=hello1")
	mustContain(t, json, `"Comments":[{"Name":"N","Email":"@"`)
}
示例#20
0
func TestRobotsTxtGetsServed(t *testing.T) {
	robots := htmltest.Curl("robots.txt")
	mustContain(t, robots, "Disallow")
}
示例#21
0
func TestLogin(t *testing.T) {
	ensureLogin()
	html := htmltest.Curl(testPosts[0].URL)
	mustContain(t, html, "Logout")
}
示例#22
0
func TestPostPager(t *testing.T) {
	mustContain(t, htmltest.Curl(""), "/page/2")
}
示例#23
0
func TestEveryEntryHasAuthor(t *testing.T) {
	for _, e := range testPosts {
		mustContain(t, htmltest.Curl(e.URL), "captcha-id")
	}
}
示例#24
0
func TestNonEmptyDatasetHasEntries(t *testing.T) {
	mustNotContain(t, htmltest.Curl(""), "No entries")
}
示例#25
0
func TestDeleteCommentCallsDbFunc(t *testing.T) {
	defer testData.reset()
	htmltest.Curl("delete_comment?id=1&action=delete")
	testData.expect(t, (*TestData).deleteComment, "1")
}
示例#26
0
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")
}
示例#27
0
func doLogout() {
	htmltest.Curl("logout")
}
示例#28
0
func TestDeletePostCallsDbFunc(t *testing.T) {
	defer testData.reset()
	htmltest.Curl("delete_post?id=hello1001")
	testData.expect(t, (*TestData).deletePost, "hello1001")
}