2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2020-03-21 19:31:58 +08:00
|
|
|
//
|
|
|
|
|
// 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 (
|
2021-05-13 00:16:45 +08:00
|
|
|
"context"
|
2021-11-15 20:49:02 +08:00
|
|
|
"testing"
|
|
|
|
|
|
2021-10-11 21:41:56 +08:00
|
|
|
"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"
|
2020-03-21 19:31:58 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Test_Encode_Parse(t *testing.T) {
|
|
|
|
|
gtest.C(t, func(t *gtest.T) {
|
|
|
|
|
v := gview.New()
|
2022-03-17 16:58:04 +08:00
|
|
|
v.SetPath(gtest.DataPath("tpl"))
|
2020-03-21 19:31:58 +08:00
|
|
|
v.SetAutoEncode(true)
|
2021-05-13 00:16:45 +08:00
|
|
|
result, err := v.Parse(context.TODO(), "encode.tpl", g.Map{
|
2020-03-21 19:31:58 +08:00
|
|
|
"title": "<b>my title</b>",
|
|
|
|
|
})
|
2022-03-10 11:36:40 +08:00
|
|
|
t.AssertNil(err)
|
2020-03-21 19:31:58 +08:00
|
|
|
t.Assert(result, "<div><b>my title</b></div>")
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_Encode_ParseContent(t *testing.T) {
|
|
|
|
|
gtest.C(t, func(t *gtest.T) {
|
|
|
|
|
v := gview.New()
|
2022-03-17 16:58:04 +08:00
|
|
|
tplContent := gfile.GetContents(gtest.DataPath("tpl", "encode.tpl"))
|
2020-03-21 19:31:58 +08:00
|
|
|
v.SetAutoEncode(true)
|
2021-05-13 00:16:45 +08:00
|
|
|
result, err := v.ParseContent(context.TODO(), tplContent, g.Map{
|
2020-03-21 19:31:58 +08:00
|
|
|
"title": "<b>my title</b>",
|
|
|
|
|
})
|
2022-03-10 11:36:40 +08:00
|
|
|
t.AssertNil(err)
|
2020-03-21 19:31:58 +08:00
|
|
|
t.Assert(result, "<div><b>my title</b></div>")
|
|
|
|
|
})
|
|
|
|
|
}
|