gf/os/gview/gview_z_unit_feature_encode_test.go
2021-11-17 23:20:58 +08:00

45 lines
1.2 KiB
Go

// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gview_test
import (
"context"
"testing"
"github.com/gogf/gf/v2/debug/gdebug"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/os/gview"
"github.com/gogf/gf/v2/test/gtest"
)
func Test_Encode_Parse(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
v := gview.New()
v.SetPath(gdebug.TestDataPath("tpl"))
v.SetAutoEncode(true)
result, err := v.Parse(context.TODO(), "encode.tpl", g.Map{
"title": "<b>my title</b>",
})
t.Assert(err, nil)
t.Assert(result, "<div>&lt;b&gt;my title&lt;/b&gt;</div>")
})
}
func Test_Encode_ParseContent(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
v := gview.New()
tplContent := gfile.GetContents(gdebug.TestDataPath("tpl", "encode.tpl"))
v.SetAutoEncode(true)
result, err := v.ParseContent(context.TODO(), tplContent, g.Map{
"title": "<b>my title</b>",
})
t.Assert(err, nil)
t.Assert(result, "<div>&lt;b&gt;my title&lt;/b&gt;</div>")
})
}