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"
|
2017-09-03 18:18:17 +02:00
|
|
|
"github.com/osteele/gojekyll/frontmatter"
|
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
|
2017-07-10 15:17:31 +02:00
|
|
|
e *liquid.Engine
|
2017-07-09 04:47:50 +02:00
|
|
|
}
|
2017-07-04 14:06:34 +02:00
|
|
|
|
2017-09-03 18:18:17 +02:00
|
|
|
func (s siteFake) AddHTMLPage(string, string, frontmatter.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))
|
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")
|
|
|
|
}
|