mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-01 06:34:36 -04:00
Refactor locale&string&template related code (#29165)
Clarify when "string" should be used (and be escaped), and when "template.HTML" should be used (no need to escape) And help PRs like #29059 , to render the error messages correctly. (cherry picked from commit f3eb835886031df7a562abc123c3f6011c81eca8) Conflicts: modules/web/middleware/binding.go routers/web/feed/convert.go tests/integration/branches_test.go tests/integration/repo_branch_test.go trivial context conflicts
This commit is contained in:
parent
d565d85160
commit
65248945c9
78 changed files with 359 additions and 286 deletions
|
@ -309,7 +309,7 @@ func TestLDAPUserSyncWithGroupFilter(t *testing.T) {
|
|||
// all groups the user is a member of, the user filter is modified accordingly inside
|
||||
// the addAuthSourceLDAP based on the value of the groupFilter
|
||||
u := otherLDAPUsers[0]
|
||||
testLoginFailed(t, u.UserName, u.Password, translation.NewLocale("en-US").Tr("form.username_password_incorrect"))
|
||||
testLoginFailed(t, u.UserName, u.Password, translation.NewLocale("en-US").TrString("form.username_password_incorrect"))
|
||||
|
||||
auth.SyncExternalUsers(context.Background(), true)
|
||||
|
||||
|
@ -362,7 +362,7 @@ func TestLDAPUserSigninFailed(t *testing.T) {
|
|||
addAuthSourceLDAP(t, "", "")
|
||||
|
||||
u := otherLDAPUsers[0]
|
||||
testLoginFailed(t, u.UserName, u.Password, translation.NewLocale("en-US").Tr("form.username_password_incorrect"))
|
||||
testLoginFailed(t, u.UserName, u.Password, translation.NewLocale("en-US").TrString("form.username_password_incorrect"))
|
||||
}
|
||||
|
||||
func TestLDAPUserSSHKeySync(t *testing.T) {
|
||||
|
|
|
@ -218,7 +218,7 @@ func TestCantMergeWorkInProgress(t *testing.T) {
|
|||
text := strings.TrimSpace(htmlDoc.doc.Find(".merge-section > .item").Last().Text())
|
||||
assert.NotEmpty(t, text, "Can't find WIP text")
|
||||
|
||||
assert.Contains(t, text, translation.NewLocale("en-US").Tr("repo.pulls.cannot_merge_work_in_progress"), "Unable to find WIP text")
|
||||
assert.Contains(t, text, translation.NewLocale("en-US").TrString("repo.pulls.cannot_merge_work_in_progress"), "Unable to find WIP text")
|
||||
assert.Contains(t, text, "[wip]", "Unable to find WIP text")
|
||||
})
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ func TestCreateRelease(t *testing.T) {
|
|||
session := loginUser(t, "user2")
|
||||
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, false)
|
||||
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", translation.NewLocale("en-US").Tr("repo.release.stable"), 4)
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", translation.NewLocale("en-US").TrString("repo.release.stable"), 4)
|
||||
}
|
||||
|
||||
func TestDeleteRelease(t *testing.T) {
|
||||
|
@ -137,7 +137,7 @@ func TestCreateReleasePreRelease(t *testing.T) {
|
|||
session := loginUser(t, "user2")
|
||||
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", true, false)
|
||||
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", translation.NewLocale("en-US").Tr("repo.release.prerelease"), 4)
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", translation.NewLocale("en-US").TrString("repo.release.prerelease"), 4)
|
||||
}
|
||||
|
||||
func TestCreateReleaseDraft(t *testing.T) {
|
||||
|
@ -146,7 +146,7 @@ func TestCreateReleaseDraft(t *testing.T) {
|
|||
session := loginUser(t, "user2")
|
||||
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, true)
|
||||
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", translation.NewLocale("en-US").Tr("repo.release.draft"), 4)
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", translation.NewLocale("en-US").TrString("repo.release.draft"), 4)
|
||||
}
|
||||
|
||||
func TestCreateReleasePaging(t *testing.T) {
|
||||
|
@ -166,11 +166,11 @@ func TestCreateReleasePaging(t *testing.T) {
|
|||
}
|
||||
createNewRelease(t, session, "/user2/repo1", "v0.0.12", "v0.0.12", false, true)
|
||||
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.12", translation.NewLocale("en-US").Tr("repo.release.draft"), 10)
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.12", translation.NewLocale("en-US").TrString("repo.release.draft"), 10)
|
||||
|
||||
// Check that user4 does not see draft and still see 10 latest releases
|
||||
session2 := loginUser(t, "user4")
|
||||
checkLatestReleaseAndCount(t, session2, "/user2/repo1", "v0.0.11", translation.NewLocale("en-US").Tr("repo.release.stable"), 10)
|
||||
checkLatestReleaseAndCount(t, session2, "/user2/repo1", "v0.0.11", translation.NewLocale("en-US").TrString("repo.release.stable"), 10)
|
||||
}
|
||||
|
||||
func TestViewReleaseListNoLogin(t *testing.T) {
|
||||
|
@ -265,7 +265,7 @@ func TestReleaseOnCommit(t *testing.T) {
|
|||
session := loginUser(t, "user2")
|
||||
createNewReleaseTarget(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", "65f1bf27bc3bf70f64657658635e66094edbcb4d", false, false)
|
||||
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", translation.NewLocale("en-US").Tr("repo.release.stable"), 4)
|
||||
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", translation.NewLocale("en-US").TrString("repo.release.stable"), 4)
|
||||
}
|
||||
|
||||
func TestViewTagsList(t *testing.T) {
|
||||
|
|
|
@ -63,39 +63,39 @@ func testCreateBranches(t *testing.T, giteaURL *url.URL) {
|
|||
OldRefSubURL: "branch/master",
|
||||
NewBranch: "feature/test1",
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("repo.branch.create_success", "feature/test1"),
|
||||
FlashMessage: translation.NewLocale("en-US").TrString("repo.branch.create_success", "feature/test1"),
|
||||
CheckBranch: true,
|
||||
},
|
||||
{
|
||||
OldRefSubURL: "branch/master",
|
||||
NewBranch: "",
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("form.NewBranchName") + translation.NewLocale("en-US").Tr("form.require_error"),
|
||||
FlashMessage: translation.NewLocale("en-US").TrString("form.NewBranchName") + translation.NewLocale("en-US").TrString("form.require_error"),
|
||||
},
|
||||
{
|
||||
OldRefSubURL: "branch/master",
|
||||
NewBranch: "feature=test1",
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("repo.branch.create_success", "feature=test1"),
|
||||
FlashMessage: translation.NewLocale("en-US").TrString("repo.branch.create_success", "feature=test1"),
|
||||
CheckBranch: true,
|
||||
},
|
||||
{
|
||||
OldRefSubURL: "branch/master",
|
||||
NewBranch: strings.Repeat("b", 101),
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("form.NewBranchName") + translation.NewLocale("en-US").Tr("form.max_size_error", "100"),
|
||||
FlashMessage: translation.NewLocale("en-US").TrString("form.NewBranchName") + translation.NewLocale("en-US").TrString("form.max_size_error", "100"),
|
||||
},
|
||||
{
|
||||
OldRefSubURL: "branch/master",
|
||||
NewBranch: "master",
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("repo.branch.branch_already_exists", "master"),
|
||||
FlashMessage: translation.NewLocale("en-US").TrString("repo.branch.branch_already_exists", "master"),
|
||||
},
|
||||
{
|
||||
OldRefSubURL: "branch/master",
|
||||
NewBranch: "master/test",
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("repo.branch.branch_name_conflict", "master/test", "master"),
|
||||
FlashMessage: translation.NewLocale("en-US").TrString("repo.branch.branch_name_conflict", "master/test", "master"),
|
||||
},
|
||||
{
|
||||
OldRefSubURL: "commit/acd1d892867872cb47f3993468605b8aa59aa2e0",
|
||||
|
@ -106,7 +106,7 @@ func testCreateBranches(t *testing.T, giteaURL *url.URL) {
|
|||
OldRefSubURL: "commit/65f1bf27bc3bf70f64657658635e66094edbcb4d",
|
||||
NewBranch: "feature/test3",
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("repo.branch.create_success", "feature/test3"),
|
||||
FlashMessage: translation.NewLocale("en-US").TrString("repo.branch.create_success", "feature/test3"),
|
||||
CheckBranch: true,
|
||||
},
|
||||
{
|
||||
|
@ -114,14 +114,14 @@ func testCreateBranches(t *testing.T, giteaURL *url.URL) {
|
|||
NewBranch: "v1.0.0",
|
||||
CreateRelease: "v1.0.0",
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("repo.branch.tag_collision", "v1.0.0"),
|
||||
FlashMessage: translation.NewLocale("en-US").TrString("repo.branch.tag_collision", "v1.0.0"),
|
||||
},
|
||||
{
|
||||
OldRefSubURL: "tag/v1.0.0",
|
||||
NewBranch: "feature/test4",
|
||||
CreateRelease: "v1.0.1",
|
||||
ExpectedStatus: http.StatusSeeOther,
|
||||
FlashMessage: translation.NewLocale("en-US").Tr("repo.branch.create_success", "feature/test4"),
|
||||
FlashMessage: translation.NewLocale("en-US").TrString("repo.branch.create_success", "feature/test4"),
|
||||
CheckBranch: true,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -49,10 +49,10 @@ func TestSignin(t *testing.T) {
|
|||
password string
|
||||
message string
|
||||
}{
|
||||
{username: "wrongUsername", password: "wrongPassword", message: translation.NewLocale("en-US").Tr("form.username_password_incorrect")},
|
||||
{username: "wrongUsername", password: "password", message: translation.NewLocale("en-US").Tr("form.username_password_incorrect")},
|
||||
{username: "user15", password: "wrongPassword", message: translation.NewLocale("en-US").Tr("form.username_password_incorrect")},
|
||||
{username: "user1@example.com", password: "wrongPassword", message: translation.NewLocale("en-US").Tr("form.username_password_incorrect")},
|
||||
{username: "wrongUsername", password: "wrongPassword", message: translation.NewLocale("en-US").TrString("form.username_password_incorrect")},
|
||||
{username: "wrongUsername", password: "password", message: translation.NewLocale("en-US").TrString("form.username_password_incorrect")},
|
||||
{username: "user15", password: "wrongPassword", message: translation.NewLocale("en-US").TrString("form.username_password_incorrect")},
|
||||
{username: "user1@example.com", password: "wrongPassword", message: translation.NewLocale("en-US").TrString("form.username_password_incorrect")},
|
||||
}
|
||||
|
||||
for _, s := range samples {
|
||||
|
|
|
@ -69,9 +69,9 @@ func TestSignupEmail(t *testing.T) {
|
|||
wantStatus int
|
||||
wantMsg string
|
||||
}{
|
||||
{"exampleUser@example.com\r\n", http.StatusOK, translation.NewLocale("en-US").Tr("form.email_invalid")},
|
||||
{"exampleUser@example.com\r", http.StatusOK, translation.NewLocale("en-US").Tr("form.email_invalid")},
|
||||
{"exampleUser@example.com\n", http.StatusOK, translation.NewLocale("en-US").Tr("form.email_invalid")},
|
||||
{"exampleUser@example.com\r\n", http.StatusOK, translation.NewLocale("en-US").TrString("form.email_invalid")},
|
||||
{"exampleUser@example.com\r", http.StatusOK, translation.NewLocale("en-US").TrString("form.email_invalid")},
|
||||
{"exampleUser@example.com\n", http.StatusOK, translation.NewLocale("en-US").TrString("form.email_invalid")},
|
||||
{"exampleUser@example.com", http.StatusSeeOther, ""},
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ func TestRenameInvalidUsername(t *testing.T) {
|
|||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
assert.Contains(t,
|
||||
htmlDoc.doc.Find(".ui.negative.message").Text(),
|
||||
translation.NewLocale("en-US").Tr("form.username_error"),
|
||||
translation.NewLocale("en-US").TrString("form.username_error"),
|
||||
)
|
||||
|
||||
unittest.AssertNotExistsBean(t, &user_model.User{Name: invalidUsername})
|
||||
|
@ -147,7 +147,7 @@ func TestRenameReservedUsername(t *testing.T) {
|
|||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
assert.Contains(t,
|
||||
htmlDoc.doc.Find(".ui.negative.message").Text(),
|
||||
translation.NewLocale("en-US").Tr("user.form.name_reserved", reservedUsername),
|
||||
translation.NewLocale("en-US").TrString("user.form.name_reserved", reservedUsername),
|
||||
)
|
||||
|
||||
unittest.AssertNotExistsBean(t, &user_model.User{Name: reservedUsername})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue