2019-07-09 11:30:15 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-07-09 11:30:15 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-06-23 15:16:47 +00:00
|
|
|
defmodule Pleroma.Web.Plugs.SetLocalePlugTest do
|
2019-07-09 11:30:15 +00:00
|
|
|
use ExUnit.Case, async: true
|
|
|
|
use Plug.Test
|
|
|
|
|
2020-06-24 06:24:29 +00:00
|
|
|
alias Pleroma.Web.Plugs.SetLocalePlug
|
2019-07-10 09:28:24 +00:00
|
|
|
alias Plug.Conn
|
2019-07-09 11:30:15 +00:00
|
|
|
|
|
|
|
test "default locale is `en`" do
|
|
|
|
conn =
|
|
|
|
:get
|
|
|
|
|> conn("/cofe")
|
|
|
|
|> SetLocalePlug.call([])
|
|
|
|
|
|
|
|
assert "en" == Gettext.get_locale()
|
|
|
|
assert %{locale: "en"} == conn.assigns
|
|
|
|
end
|
|
|
|
|
|
|
|
test "use supported locale from `accept-language`" do
|
|
|
|
conn =
|
|
|
|
:get
|
|
|
|
|> conn("/cofe")
|
|
|
|
|> Conn.put_req_header(
|
|
|
|
"accept-language",
|
|
|
|
"ru, fr-CH, fr;q=0.9, en;q=0.8, *;q=0.5"
|
|
|
|
)
|
|
|
|
|> SetLocalePlug.call([])
|
|
|
|
|
|
|
|
assert "ru" == Gettext.get_locale()
|
|
|
|
assert %{locale: "ru"} == conn.assigns
|
|
|
|
end
|
|
|
|
|
|
|
|
test "use default locale if locale from `accept-language` is not supported" do
|
|
|
|
conn =
|
|
|
|
:get
|
|
|
|
|> conn("/cofe")
|
|
|
|
|> Conn.put_req_header("accept-language", "tlh")
|
|
|
|
|> SetLocalePlug.call([])
|
|
|
|
|
|
|
|
assert "en" == Gettext.get_locale()
|
|
|
|
assert %{locale: "en"} == conn.assigns
|
|
|
|
end
|
|
|
|
end
|