1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-22 20:37:05 +00:00

fix #2158 and more

This commit is contained in:
Gerasimos (Makis) Maropoulos
2023-07-08 02:08:18 +03:00
parent 757e7fe61b
commit 6add1ba49b
79 changed files with 551 additions and 467 deletions

View File

@@ -40,49 +40,49 @@ func TestI18n(t *testing.T) {
e := httptest.New(t, app)
// default should be en-US.
e.GET("/").Expect().Status(httptest.StatusOK).Body().Equal(tests["en-US"])
e.GET("/").Expect().Status(httptest.StatusOK).Body().IsEqual(tests["en-US"])
for lang, body := range tests {
e.GET("/").WithQueryString("lang=" + lang).Expect().Status(httptest.StatusOK).
Body().Equal(body)
Body().IsEqual(body)
// test lowercase.
e.GET("/").WithQueryString("lang=" + strings.ToLower(lang)).Expect().Status(httptest.StatusOK).
Body().Equal(body)
Body().IsEqual(body)
// test first part (e.g. en instead of en-US).
langFirstPart := strings.Split(lang, "-")[0]
e.GET("/").WithQueryString("lang=" + langFirstPart).Expect().Status(httptest.StatusOK).
Body().Equal(body)
Body().IsEqual(body)
// test accept-language header prefix (i18n wrapper).
e.GET("/"+lang).WithHeader("Accept-Language", lang).Expect().Status(httptest.StatusOK).
Body().Equal(body)
Body().IsEqual(body)
// test path prefix (i18n router wrapper).
e.GET("/" + lang).Expect().Status(httptest.StatusOK).
Body().Equal(body)
Body().IsEqual(body)
// test path prefix with first part.
e.GET("/" + langFirstPart).Expect().Status(httptest.StatusOK).
Body().Equal(body)
Body().IsEqual(body)
}
e.GET("/other").WithQueryString("lang=el-GR").Expect().Status(httptest.StatusOK).
Body().Equal(elgrMulti)
Body().IsEqual(elgrMulti)
e.GET("/other").WithQueryString("lang=en-US").Expect().Status(httptest.StatusOK).
Body().Equal(enusMulti)
Body().IsEqual(enusMulti)
// test path prefix (i18n router wrapper).
e.GET("/el-gr/other").Expect().Status(httptest.StatusOK).
Body().Equal(elgrMulti)
Body().IsEqual(elgrMulti)
e.GET("/en/other").Expect().Status(httptest.StatusOK).
Body().Equal(enusMulti)
Body().IsEqual(enusMulti)
e.GET("/el-GRtemplates").Expect().Status(httptest.StatusNotFound)
e.GET("/el-templates").Expect().Status(httptest.StatusNotFound)
e.GET("/el/templates").Expect().Status(httptest.StatusOK).Body().Contains(elGR).Contains(zhCN)
e.GET("/not-matched").WithQuery("lang", "en-gb").Expect().Status(httptest.StatusOK).Body().Equal("user language input: en-gb: matched as: en-US: not found key: not_found_key: args: [some values 42]")
e.GET("/not-matched").WithQuery("lang", "en-gb").Expect().Status(httptest.StatusOK).Body().IsEqual("user language input: en-gb: matched as: en-US: not found key: not_found_key: args: [some values 42]")
}

View File

@@ -11,11 +11,11 @@ func TestI18nLoaderFuncMap(t *testing.T) {
e := httptest.New(t, app)
e.GET("/").Expect().Status(httptest.StatusOK).
Body().Equal("Become a MEMBER")
Body().IsEqual("Become a MEMBER")
e.GET("/title").Expect().Status(httptest.StatusOK).
Body().Equal("Account Connections")
Body().IsEqual("Account Connections")
e.GET("/").WithHeader("Accept-Language", "el").Expect().Status(httptest.StatusOK).
Body().Equal("Γίνε ΜΈΛΟΣ")
Body().IsEqual("Γίνε ΜΈΛΟΣ")
e.GET("/title").WithHeader("Accept-Language", "el").Expect().Status(httptest.StatusOK).
Body().Equal("Λογαριασμός Συνδέσεις")
Body().IsEqual("Λογαριασμός Συνδέσεις")
}

View File

@@ -11,11 +11,11 @@ func TestI18nLoaderFuncMap(t *testing.T) {
e := httptest.New(t, app)
e.GET("/").Expect().Status(httptest.StatusOK).
Body().Equal("Become a MEMBER")
Body().IsEqual("Become a MEMBER")
e.GET("/title").Expect().Status(httptest.StatusOK).
Body().Equal("Account Connections")
Body().IsEqual("Account Connections")
e.GET("/").WithHeader("Accept-Language", "el").Expect().Status(httptest.StatusOK).
Body().Equal("Γίνε ΜΈΛΟΣ")
Body().IsEqual("Γίνε ΜΈΛΟΣ")
e.GET("/title").WithHeader("Accept-Language", "el").Expect().Status(httptest.StatusOK).
Body().Equal("Λογαριασμός Συνδέσεις")
Body().IsEqual("Λογαριασμός Συνδέσεις")
}