1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-12-02 16:27:46 +01:00
gojekyll/plugins/avatar_test.go
2017-09-02 15:50:47 -04:00

49 lines
1.5 KiB
Go

package plugins
import (
"regexp"
"testing"
"github.com/osteele/gojekyll/config"
"github.com/osteele/gojekyll/pages"
"github.com/osteele/liquid"
"github.com/stretchr/testify/require"
)
type siteFake struct {
c config.Config
e *liquid.Engine
}
func (s siteFake) AddDocument(pages.Document, bool) {}
func (s siteFake) Config() *config.Config { return &s.c }
func (s siteFake) HasLayout(string) bool { return true }
func (s siteFake) Pages() []pages.Page { return nil }
func (s siteFake) Posts() []pages.Page { return nil }
func (s siteFake) TemplateEngine() *liquid.Engine { return s.e }
func TestAvatarTag(t *testing.T) {
engine := liquid.NewEngine()
plugins := []string{"jekyll-avatar"}
_ = Install(plugins, siteFake{config.Default(), engine})
require.NoError(t, directory[plugins[0]].ConfigureTemplateEngine(engine))
bindings := liquid.Bindings{"user": "osteele"}
s, err := engine.ParseAndRenderString(`{% avatar osteele %}`, bindings)
require.NoError(t, err)
re := regexp.MustCompile(`<img class="avatar.*avatar.*usercontent\.com/osteele\b`)
require.True(t, re.MatchString(s))
s, err = engine.ParseAndRenderString(`{% avatar user='osteele' %}`, bindings)
require.NoError(t, err)
require.True(t, re.MatchString(s))
s, err = engine.ParseAndRenderString(`{% avatar user=user %}`, bindings)
require.NoError(t, err)
require.True(t, re.MatchString(s))
s, err = engine.ParseAndRenderString(`{% avatar user=user size=20 %}`, bindings)
require.NoError(t, err)
require.Contains(t, s, "20")
}