diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-11-14 13:02:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-14 05:02:11 +0000 |
commit | 3f9c3e7bc394c115ccc4818d6505f1f68de350d2 (patch) | |
tree | e07e4a3dc07ce80104f7949af5cb180b7fce449e /tests | |
parent | 985e2a8af3d6468bac3ab178148c38bdbd8414f5 (diff) | |
download | gitea-3f9c3e7bc394c115ccc4818d6505f1f68de350d2.tar.gz gitea-3f9c3e7bc394c115ccc4818d6505f1f68de350d2.zip |
Refactor render system (#32492)
There were too many patches to the Render system, it's really difficult
to make further improvements.
This PR clears the legacy problems and fix TODOs.
1. Rename `RenderContext.Type` to `RenderContext.MarkupType` to clarify
its usage.
2. Use `ContentMode` to replace `meta["mode"]` and `IsWiki`, to clarify
the rendering behaviors.
3. Use "wiki" mode instead of "mode=gfm + wiki=true"
4. Merge `renderByType` and `renderByFile`
5. Add more comments
----
The problem of "mode=document": in many cases it is not set, so many
non-comment places use comment's hard line break incorrectly
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/markup_external_test.go | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/tests/integration/markup_external_test.go b/tests/integration/markup_external_test.go index e50f5c1356..2d713b0eb9 100644 --- a/tests/integration/markup_external_test.go +++ b/tests/integration/markup_external_test.go @@ -10,6 +10,8 @@ import ( "strings" "testing" + "code.gitea.io/gitea/modules/markup" + "code.gitea.io/gitea/modules/markup/external" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/tests" @@ -23,10 +25,9 @@ func TestExternalMarkupRenderer(t *testing.T) { return } - const repoURL = "user30/renderer" - req := NewRequest(t, "GET", repoURL+"/src/branch/master/README.html") + req := NewRequest(t, "GET", "/user30/renderer/src/branch/master/README.html") resp := MakeRequest(t, req, http.StatusOK) - assert.EqualValues(t, "text/html; charset=utf-8", resp.Header()["Content-Type"][0]) + assert.EqualValues(t, "text/html; charset=utf-8", resp.Header().Get("Content-Type")) bs, err := io.ReadAll(resp.Body) assert.NoError(t, err) @@ -36,4 +37,24 @@ func TestExternalMarkupRenderer(t *testing.T) { data, err := div.Html() assert.NoError(t, err) assert.EqualValues(t, "<div>\n\ttest external renderer\n</div>", strings.TrimSpace(data)) + + r := markup.GetRendererByFileName("a.html").(*external.Renderer) + r.RenderContentMode = setting.RenderContentModeIframe + + req = NewRequest(t, "GET", "/user30/renderer/src/branch/master/README.html") + resp = MakeRequest(t, req, http.StatusOK) + assert.EqualValues(t, "text/html; charset=utf-8", resp.Header().Get("Content-Type")) + bs, err = io.ReadAll(resp.Body) + assert.NoError(t, err) + doc = NewHTMLParser(t, bytes.NewBuffer(bs)) + iframe := doc.Find("iframe") + assert.EqualValues(t, "/user30/renderer/render/branch/master/README.html", iframe.AttrOr("src", "")) + + req = NewRequest(t, "GET", "/user30/renderer/render/branch/master/README.html") + resp = MakeRequest(t, req, http.StatusOK) + assert.EqualValues(t, "text/html; charset=utf-8", resp.Header().Get("Content-Type")) + bs, err = io.ReadAll(resp.Body) + assert.NoError(t, err) + assert.EqualValues(t, "frame-src 'self'; sandbox allow-scripts", resp.Header().Get("Content-Security-Policy")) + assert.EqualValues(t, "<div>\n\ttest external renderer\n</div>\n", string(bs)) } |