mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-23 19:11:58 +01:00
a4b242ae7a
After many refactoring PRs for the "locale" and "template context function", now the ".locale" is not needed for web templates any more. This PR does a clean up for: 1. Remove `ctx.Data["locale"]` for web context. 2. Use `ctx.Locale` in `500.tmpl`, for consistency. 3. Add a test check for `500 page` locale usage. 4. Remove the `Str2html` and `DotEscape` from mail template context data, they are copy&paste errors introduced by #19169 and #16200 . These functions are template functions (provided by the common renderer), but not template data variables. 5. Make email `SendAsync` function mockable (I was planning to add more tests but it would make this PR much too complex, so the tests could be done in another PR)
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package common
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models/unittest"
|
|
"code.gitea.io/gitea/modules/test"
|
|
"code.gitea.io/gitea/modules/web/middleware"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRenderPanicErrorPage(t *testing.T) {
|
|
w := httptest.NewRecorder()
|
|
req := &http.Request{URL: &url.URL{}}
|
|
req = req.WithContext(middleware.WithContextData(context.Background()))
|
|
RenderPanicErrorPage(w, req, errors.New("fake panic error (for test only)"))
|
|
respContent := w.Body.String()
|
|
assert.Contains(t, respContent, `class="page-content status-page-500"`)
|
|
assert.Contains(t, respContent, `</html>`)
|
|
assert.Contains(t, respContent, `lang="en-US"`) // make sure the locale work
|
|
|
|
// the 500 page doesn't have normal pages footer, it makes it easier to distinguish a normal page and a failed page.
|
|
// especially when a sub-template causes page error, the HTTP response code is still 200,
|
|
// the different "footer" is the only way to know whether a page is fully rendered without error.
|
|
assert.False(t, test.IsNormalPageCompleted(respContent))
|
|
}
|
|
|
|
func TestMain(m *testing.M) {
|
|
unittest.MainTest(m)
|
|
}
|