From a3af4fe46e1e1d184538a83bc8375154a9669316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 20 Feb 2017 09:33:35 +0100 Subject: hugolib: Finish menu vs section content pages This commit also fixes the default menu sort when the weight is 0. Closes #2974 --- hugolib/testhelpers_test.go | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'hugolib/testhelpers_test.go') diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go index 668b46b1d..92af07a46 100644 --- a/hugolib/testhelpers_test.go +++ b/hugolib/testhelpers_test.go @@ -6,12 +6,13 @@ import ( "regexp" - "github.com/spf13/hugo/config" - "github.com/spf13/hugo/deps" - "fmt" "strings" + "github.com/spf13/afero" + "github.com/spf13/hugo/config" + "github.com/spf13/hugo/deps" + "github.com/spf13/hugo/helpers" "github.com/spf13/hugo/source" "github.com/spf13/hugo/tpl" @@ -113,6 +114,39 @@ func newTestSite(t testing.TB, configKeyValues ...interface{}) *Site { return s } +func newTestSitesFromConfig(t testing.TB, tomlConfig string, layoutPathContentPairs ...string) (testHelper, *HugoSites) { + if len(layoutPathContentPairs)%2 != 0 { + t.Fatalf("Layouts must be provided in pairs") + } + mf := afero.NewMemMapFs() + + writeToFs(t, mf, "config.toml", tomlConfig) + + cfg, err := LoadConfig(mf, "", "config.toml") + require.NoError(t, err) + + fs := hugofs.NewFrom(mf, cfg) + th := testHelper{cfg, fs, t} + + for i := 0; i < len(layoutPathContentPairs); i += 2 { + writeSource(t, fs, layoutPathContentPairs[i], layoutPathContentPairs[i+1]) + } + + h, err := NewHugoSites(deps.DepsCfg{Fs: fs, Cfg: cfg}) + + require.NoError(t, err) + + return th, h +} + +func newTestSitesFromConfigWithDefaultTemplates(t testing.TB, tomlConfig string) (testHelper, *HugoSites) { + return newTestSitesFromConfig(t, tomlConfig, + "layouts/_default/single.html", "Single|{{ .Title }}|{{ .Content }}", + "layouts/_default/list.html", "List|{{ .Title }}|{{ .Content }}", + "layouts/_default/terms.html", "Terms List|{{ .Title }}|{{ .Content }}", + ) +} + func newDebugLogger() *jww.Notepad { return jww.NewNotepad(jww.LevelDebug, jww.LevelError, os.Stdout, ioutil.Discard, "", log.Ldate|log.Ltime) } -- cgit v1.2.3