1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-12-02 18:17:46 +01:00
gojekyll/plugins/avatar_test.go

47 lines
1.4 KiB
Go
Raw Normal View History

2017-07-04 14:06:34 +02:00
package plugins
import (
"regexp"
"testing"
2017-07-09 04:47:50 +02:00
"github.com/osteele/gojekyll/config"
"github.com/osteele/gojekyll/pages"
2017-07-04 14:06:34 +02:00
"github.com/osteele/liquid"
"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-07-09 04:47:50 +02:00
func (s siteFake) AddDocument(pages.Document, bool) {}
func (s siteFake) Config() *config.Config { return &s.c }
func (s siteFake) Pages() (ps []pages.Page) { return }
2017-07-12 13:10:52 +02:00
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"}
Install(plugins, siteFake{config.Default(), engine})
require.NoError(t, directory[plugins[0]].ConfigureTemplateEngine(engine))
2017-08-27 19:56:01 +02:00
bindings := liquid.Bindings{"user": "osteele"}
2017-07-04 14:06:34 +02:00
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")
}