mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-30 06:59:04 +01:00
49 lines
1.6 KiB
Go
49 lines
1.6 KiB
Go
package plugins
|
|
|
|
import (
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/danog/gojekyll/config"
|
|
"github.com/danog/gojekyll/pages"
|
|
"github.com/danog/liquid"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type siteFake struct {
|
|
c config.Config
|
|
e *liquid.Engine
|
|
}
|
|
|
|
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 }
|
|
|
|
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": "danog"}
|
|
|
|
s, err := engine.ParseAndRenderString(`{% avatar danog %}`, bindings)
|
|
require.NoError(t, err)
|
|
re := regexp.MustCompile(`<img class="avatar.*avatar.*usercontent\.com/danog\b`)
|
|
require.True(t, re.MatchString(s))
|
|
|
|
s, err = engine.ParseAndRenderString(`{% avatar user='danog' %}`, 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")
|
|
}
|