1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-30 05:58:59 +01:00
gojekyll/plugins/avatar_test.go

49 lines
1.6 KiB
Go
Raw Permalink Normal View History

2017-07-04 14:06:34 +02:00
package plugins
import (
"regexp"
"testing"
"github.com/danog/gojekyll/config"
"github.com/danog/gojekyll/pages"
"github.com/danog/liquid"
2017-07-04 14:06:34 +02:00
"github.com/stretchr/testify/require"
)
2017-07-09 04:47:50 +02:00
type siteFake struct {
c config.Config
e *liquid.Engine
2017-07-09 04:47:50 +02:00
}
2017-07-04 14:06:34 +02:00
2017-09-03 18:21:55 +02:00
func (s siteFake) AddHTMLPage(string, string, pages.FrontMatter) {}
func (s siteFake) Config() *config.Config { return &s.c }
func (s siteFake) HasLayout(string) bool { return true }
func (s siteFake) Pages() []Page { return nil }
func (s siteFake) Posts() []Page { return nil }
func (s siteFake) TemplateEngine() *liquid.Engine { return s.e }
2017-07-04 14:06:34 +02:00
func TestAvatarTag(t *testing.T) {
engine := liquid.NewEngine()
2017-07-09 04:47:50 +02:00
plugins := []string{"jekyll-avatar"}
2017-09-02 21:50:47 +02:00
_ = Install(plugins, siteFake{config.Default(), engine})
2017-07-09 04:47:50 +02:00
require.NoError(t, directory[plugins[0]].ConfigureTemplateEngine(engine))
bindings := liquid.Bindings{"user": "danog"}
2017-07-04 14:06:34 +02:00
s, err := engine.ParseAndRenderString(`{% avatar danog %}`, bindings)
2017-07-04 14:06:34 +02:00
require.NoError(t, err)
re := regexp.MustCompile(`<img class="avatar.*avatar.*usercontent\.com/danog\b`)
2017-07-04 14:06:34 +02:00
require.True(t, re.MatchString(s))
s, err = engine.ParseAndRenderString(`{% avatar user='danog' %}`, bindings)
2017-07-04 14:06:34 +02:00
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")
}