hugolib: More test helper cleanup

This commit is contained in:
Bjørn Erik Pedersen
2017-02-17 21:14:52 +01:00
parent ed847ed93d
commit 07ab7ae3d2
14 changed files with 171 additions and 162 deletions

View File

@@ -74,77 +74,67 @@ func doTestMultiSitesMainLangInRoot(t *testing.T, defaultInSubDir bool) {
frPerm := doc1fr.Permalink()
frRelPerm := doc1fr.RelPermalink()
// Main language in root
require.Equal(t, th.replaceDefaultContentLanguageValue("http://example.com/blog/fr/sect/doc1/", defaultInSubDir), frPerm)
require.Equal(t, th.replaceDefaultContentLanguageValue("/blog/fr/sect/doc1/", defaultInSubDir), frRelPerm)
require.Equal(t, th.replaceDefaultContentLanguageValue("http://example.com/blog/fr/sect/doc1/"), frPerm)
require.Equal(t, th.replaceDefaultContentLanguageValue("/blog/fr/sect/doc1/"), frRelPerm)
th.assertFileContent("public/fr/sect/doc1/index.html", defaultInSubDir, "Single", "Bonjour")
th.assertFileContent("public/en/sect/doc1-slug/index.html", defaultInSubDir, "Single", "Hello")
th.assertFileContent("public/fr/sect/doc1/index.html", "Single", "Bonjour")
th.assertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Hello")
// Check home
if defaultInSubDir {
// should have a redirect on top level.
th.assertFileContent("public/index.html", true, `<meta http-equiv="refresh" content="0; url=http://example.com/blog/fr" />`)
th.assertFileContentStraight("public/index.html", `<meta http-equiv="refresh" content="0; url=http://example.com/blog/fr" />`)
} else {
// should have redirect back to root
th.assertFileContent("public/fr/index.html", true, `<meta http-equiv="refresh" content="0; url=http://example.com/blog" />`)
th.assertFileContentStraight("public/fr/index.html", `<meta http-equiv="refresh" content="0; url=http://example.com/blog" />`)
}
th.assertFileContent("public/fr/index.html", defaultInSubDir, "Home", "Bonjour")
th.assertFileContent("public/en/index.html", defaultInSubDir, "Home", "Hello")
th.assertFileContent("public/fr/index.html", "Home", "Bonjour")
th.assertFileContent("public/en/index.html", "Home", "Hello")
// Check list pages
th.assertFileContent("public/fr/sect/index.html", defaultInSubDir, "List", "Bonjour")
th.assertFileContent("public/en/sect/index.html", defaultInSubDir, "List", "Hello")
th.assertFileContent("public/fr/plaques/frtag1/index.html", defaultInSubDir, "List", "Bonjour")
th.assertFileContent("public/en/tags/tag1/index.html", defaultInSubDir, "List", "Hello")
th.assertFileContent("public/fr/sect/index.html", "List", "Bonjour")
th.assertFileContent("public/en/sect/index.html", "List", "Hello")
th.assertFileContent("public/fr/plaques/frtag1/index.html", "List", "Bonjour")
th.assertFileContent("public/en/tags/tag1/index.html", "List", "Hello")
// Check sitemaps
// Sitemaps behaves different: In a multilanguage setup there will always be a index file and
// one sitemap in each lang folder.
th.assertFileContent("public/sitemap.xml", true,
th.assertFileContentStraight("public/sitemap.xml",
"<loc>http://example.com/blog/en/sitemap.xml</loc>",
"<loc>http://example.com/blog/fr/sitemap.xml</loc>")
if defaultInSubDir {
th.assertFileContent("public/fr/sitemap.xml", true, "<loc>http://example.com/blog/fr/</loc>")
th.assertFileContentStraight("public/fr/sitemap.xml", "<loc>http://example.com/blog/fr/</loc>")
} else {
th.assertFileContent("public/fr/sitemap.xml", true, "<loc>http://example.com/blog/</loc>")
th.assertFileContentStraight("public/fr/sitemap.xml", "<loc>http://example.com/blog/</loc>")
}
th.assertFileContent("public/en/sitemap.xml", true, "<loc>http://example.com/blog/en/</loc>")
th.assertFileContent("public/en/sitemap.xml", "<loc>http://example.com/blog/en/</loc>")
// Check rss
th.assertFileContent("public/fr/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/fr/index.xml"`)
th.assertFileContent("public/en/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/en/index.xml"`)
th.assertFileContent("public/fr/sect/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/fr/sect/index.xml"`)
th.assertFileContent("public/en/sect/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/en/sect/index.xml"`)
th.assertFileContent("public/fr/plaques/frtag1/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/fr/plaques/frtag1/index.xml"`)
th.assertFileContent("public/en/tags/tag1/index.xml", defaultInSubDir, `<atom:link href="http://example.com/blog/en/tags/tag1/index.xml"`)
th.assertFileContent("public/fr/index.xml", `<atom:link href="http://example.com/blog/fr/index.xml"`)
th.assertFileContent("public/en/index.xml", `<atom:link href="http://example.com/blog/en/index.xml"`)
th.assertFileContent("public/fr/sect/index.xml", `<atom:link href="http://example.com/blog/fr/sect/index.xml"`)
th.assertFileContent("public/en/sect/index.xml", `<atom:link href="http://example.com/blog/en/sect/index.xml"`)
th.assertFileContent("public/fr/plaques/frtag1/index.xml", `<atom:link href="http://example.com/blog/fr/plaques/frtag1/index.xml"`)
th.assertFileContent("public/en/tags/tag1/index.xml", `<atom:link href="http://example.com/blog/en/tags/tag1/index.xml"`)
// Check paginators
th.assertFileContent("public/fr/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/fr/"`)
th.assertFileContent("public/en/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/en/"`)
th.assertFileContent("public/fr/page/2/index.html", defaultInSubDir, "Home Page 2", "Bonjour", "http://example.com/blog/fr/")
th.assertFileContent("public/en/page/2/index.html", defaultInSubDir, "Home Page 2", "Hello", "http://example.com/blog/en/")
th.assertFileContent("public/fr/sect/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/fr/sect/"`)
th.assertFileContent("public/en/sect/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/en/sect/"`)
th.assertFileContent("public/fr/sect/page/2/index.html", defaultInSubDir, "List Page 2", "Bonjour", "http://example.com/blog/fr/sect/")
th.assertFileContent("public/en/sect/page/2/index.html", defaultInSubDir, "List Page 2", "Hello", "http://example.com/blog/en/sect/")
th.assertFileContent("public/fr/plaques/frtag1/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/fr/plaques/frtag1/"`)
th.assertFileContent("public/en/tags/tag1/page/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/en/tags/tag1/"`)
th.assertFileContent("public/fr/plaques/frtag1/page/2/index.html", defaultInSubDir, "List Page 2", "Bonjour", "http://example.com/blog/fr/plaques/frtag1/")
th.assertFileContent("public/en/tags/tag1/page/2/index.html", defaultInSubDir, "List Page 2", "Hello", "http://example.com/blog/en/tags/tag1/")
th.assertFileContent("public/fr/page/1/index.html", `refresh" content="0; url=http://example.com/blog/fr/"`)
th.assertFileContent("public/en/page/1/index.html", `refresh" content="0; url=http://example.com/blog/en/"`)
th.assertFileContent("public/fr/page/2/index.html", "Home Page 2", "Bonjour", "http://example.com/blog/fr/")
th.assertFileContent("public/en/page/2/index.html", "Home Page 2", "Hello", "http://example.com/blog/en/")
th.assertFileContent("public/fr/sect/page/1/index.html", `refresh" content="0; url=http://example.com/blog/fr/sect/"`)
th.assertFileContent("public/en/sect/page/1/index.html", `refresh" content="0; url=http://example.com/blog/en/sect/"`)
th.assertFileContent("public/fr/sect/page/2/index.html", "List Page 2", "Bonjour", "http://example.com/blog/fr/sect/")
th.assertFileContent("public/en/sect/page/2/index.html", "List Page 2", "Hello", "http://example.com/blog/en/sect/")
th.assertFileContent("public/fr/plaques/frtag1/page/1/index.html", `refresh" content="0; url=http://example.com/blog/fr/plaques/frtag1/"`)
th.assertFileContent("public/en/tags/tag1/page/1/index.html", `refresh" content="0; url=http://example.com/blog/en/tags/tag1/"`)
th.assertFileContent("public/fr/plaques/frtag1/page/2/index.html", "List Page 2", "Bonjour", "http://example.com/blog/fr/plaques/frtag1/")
th.assertFileContent("public/en/tags/tag1/page/2/index.html", "List Page 2", "Hello", "http://example.com/blog/en/tags/tag1/")
// nn (Nynorsk) and nb (Bokmål) have custom pagePath: side ("page" in Norwegian)
th.assertFileContent("public/nn/side/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/nn/"`)
th.assertFileContent("public/nb/side/1/index.html", defaultInSubDir, `refresh" content="0; url=http://example.com/blog/nb/"`)
}
func (th testHelper) replaceDefaultContentLanguageValue(value string, defaultInSubDir bool) string {
replace := th.Cfg.GetString("defaultContentLanguage") + "/"
if !defaultInSubDir {
value = strings.Replace(value, replace, "", 1)
}
return value
th.assertFileContent("public/nn/side/1/index.html", `refresh" content="0; url=http://example.com/blog/nn/"`)
th.assertFileContent("public/nb/side/1/index.html", `refresh" content="0; url=http://example.com/blog/nb/"`)
}
func TestMultiSitesWithTwoLanguages(t *testing.T) {
@@ -262,7 +252,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
require.Equal(t, "http://example.com/blog/superbob", permalink, "invalid doc3 permalink")
require.Equal(t, "/superbob", doc3.URL(), "invalid url, was specified on doc3")
th.assertFileContent("public/superbob/index.html", true, "doc3|Hello|en")
th.assertFileContent("public/superbob/index.html", "doc3|Hello|en")
require.Equal(t, doc2.Next, doc3, "doc3 should follow doc2, in .Next")
doc1fr := doc1en.Translations()[0]
@@ -306,12 +296,12 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
require.True(t, strings.Contains(languageRedirect, "0; url=http://example.com/blog/fr"), languageRedirect)
// check home page content (including data files rendering)
th.assertFileContent("public/en/index.html", true, "Home Page 1", "Hello", "Hugo Rocks!")
th.assertFileContent("public/fr/index.html", true, "Home Page 1", "Bonjour", "Hugo Rocks!")
th.assertFileContent("public/en/index.html", "Home Page 1", "Hello", "Hugo Rocks!")
th.assertFileContent("public/fr/index.html", "Home Page 1", "Bonjour", "Hugo Rocks!")
// check single page content
th.assertFileContent("public/fr/sect/doc1/index.html", true, "Single", "Shortcode: Bonjour")
th.assertFileContent("public/en/sect/doc1-slug/index.html", true, "Single", "Shortcode: Hello")
th.assertFileContent("public/fr/sect/doc1/index.html", "Single", "Shortcode: Bonjour")
th.assertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Shortcode: Hello")
// Check node translations
homeEn := enSite.getPage(KindHome)
@@ -410,12 +400,12 @@ func TestMultiSitesRebuild(t *testing.T) {
require.Len(t, frSite.RegularPages, 3)
// Verify translations
th.assertFileContent("public/en/sect/doc1-slug/index.html", true, "Hello")
th.assertFileContent("public/fr/sect/doc1/index.html", true, "Bonjour")
th.assertFileContent("public/en/sect/doc1-slug/index.html", "Hello")
th.assertFileContent("public/fr/sect/doc1/index.html", "Bonjour")
// check single page content
th.assertFileContent("public/fr/sect/doc1/index.html", true, "Single", "Shortcode: Bonjour")
th.assertFileContent("public/en/sect/doc1-slug/index.html", true, "Single", "Shortcode: Hello")
th.assertFileContent("public/fr/sect/doc1/index.html", "Single", "Shortcode: Bonjour")
th.assertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Shortcode: Hello")
for i, this := range []struct {
preFunc func(t *testing.T)
@@ -553,8 +543,8 @@ func TestMultiSitesRebuild(t *testing.T) {
require.Len(t, enSite.RegularPages, 5)
require.Len(t, enSite.AllPages, 30)
require.Len(t, frSite.RegularPages, 4)
th.assertFileContent("public/fr/sect/doc1/index.html", true, "Single", "Modified Shortcode: Salut")
th.assertFileContent("public/en/sect/doc1-slug/index.html", true, "Single", "Modified Shortcode: Hello")
th.assertFileContent("public/fr/sect/doc1/index.html", "Single", "Modified Shortcode: Salut")
th.assertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Modified Shortcode: Hello")
},
},
} {
@@ -684,8 +674,8 @@ func TestChangeDefaultLanguage(t *testing.T) {
t.Fatalf("Failed to build sites: %s", err)
}
th.assertFileContent("public/sect/doc1/index.html", false, "Single", "Bonjour")
th.assertFileContent("public/en/sect/doc2/index.html", false, "Single", "Hello")
th.assertFileContent("public/sect/doc1/index.html", "Single", "Bonjour")
th.assertFileContent("public/en/sect/doc2/index.html", "Single", "Hello")
newConfig := createConfig(t, testSiteConfig{Fs: mf, DefaultContentLanguage: "en", DefaultContentLanguageInSubdir: false}, multiSiteTOMLConfigTemplate)
@@ -702,8 +692,8 @@ func TestChangeDefaultLanguage(t *testing.T) {
}
// Default language is now en, so that should now be the "root" language
th.assertFileContent("public/fr/sect/doc1/index.html", false, "Single", "Bonjour")
th.assertFileContent("public/sect/doc2/index.html", false, "Single", "Hello")
th.assertFileContent("public/fr/sect/doc1/index.html", "Single", "Bonjour")
th.assertFileContent("public/sect/doc2/index.html", "Single", "Hello")
}
func TestTableOfContentsInShortcodes(t *testing.T) {
@@ -727,8 +717,8 @@ func TestTableOfContentsInShortcodes(t *testing.T) {
fs := sites.Fs
th := testHelper{sites.Cfg, fs, t}
th.assertFileContent("public/en/post/simple/index.html", true, tocPageSimpleExpected)
th.assertFileContent("public/en/post/withSCInHeading/index.html", true, tocPageWithShortcodesInHeadingsExpected)
th.assertFileContent("public/en/post/simple/index.html", tocPageSimpleExpected)
th.assertFileContent("public/en/post/withSCInHeading/index.html", tocPageWithShortcodesInHeadingsExpected)
}
var tocShortcode = `