FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
BookStack/tests/LanguageTest.php at development · BookStackApp/BookStack · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
BookStackApp
/
BookStack
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
2.4k
Star
19k
Code
Issues
0
Pull requests
1
Security and quality
8
Insights
Additional navigation options
Code
Issues
Pull requests
Security and quality
Insights
Expand file tree
Breadcrumbs
BookStack
/
tests
/
LanguageTest.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
107 lines (88 loc) · 3.45 KB
Breadcrumbs
BookStack
/
tests
/
LanguageTest.php
Copy path
File metadata and controls
107 lines (88 loc) · 3.45 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace
Tests
;
use
BookStack
\
Activity
\
ActivityType
;
use
BookStack
\
Translation
\
LocaleManager
;
class
LanguageTest
extends
TestCase
{
protected
array
$
langs
;
/**
* LanguageTest constructor.
*/
protected
function
setUp
():
void
{
parent
::
setUp
();
$
this
->
langs
=
array_diff
(
scandir
(
lang_path
(
''
)), [
'
..
'
,
'
.
'
]);
}
public
function
test_locales_list_set_properly
()
{
$
appLocales
=
$
this
->
app
->
make
(LocaleManager::class)->
getAllAppLocales
();
sort
(
$
appLocales
);
sort
(
$
this
->
langs
);
$
this
->
assertEquals
(
implode
(
'
:
'
,
$
this
->
langs
),
implode
(
'
:
'
,
$
appLocales
),
'
app.locales configuration variable does not match those found in lang files
'
);
}
// Not part of standard phpunit test runs since we sometimes expect non-added langs.
public
function
test_locales_all_have_language_dropdown_entry
()
{
$
this
->
markTestSkipped
(
'
Only used when checking language inclusion
'
);
$
dropdownLocales
=
array_keys
(
trans
(
'
settings.language_select
'
, [],
'
en
'
));
sort
(
$
dropdownLocales
);
sort
(
$
this
->
langs
);
$
diffs
=
array_diff
(
$
this
->
langs
,
$
dropdownLocales
);
if
(
count
(
$
diffs
) >
0
) {
$
diffText
=
implode
(
'
,
'
,
$
diffs
);
$
warning
=
"
Languages:
{
$
diffText
}
found in files but not in language select dropdown.
"
;
$
this
->
fail
(
$
warning
);
}
$
this
->
assertTrue
(
true
);
}
public
function
test_correct_language_if_not_logged_in
()
{
$
loginReq
=
$
this
->
get
(
'
/login
'
);
$
loginReq
->
assertSee
(
'
Log In
'
);
$
loginPageFrenchReq
=
$
this
->
get
(
'
/login
'
, [
'
Accept-Language
'
=>
'
fr
'
]);
$
loginPageFrenchReq
->
assertSee
(
'
Se Connecter
'
);
}
public
function
test_public_lang_autodetect_can_be_disabled
()
{
config
()->
set
(
'
app.auto_detect_locale
'
,
false
);
$
loginReq
=
$
this
->
get
(
'
/login
'
);
$
loginReq
->
assertSee
(
'
Log In
'
);
$
loginPageFrenchReq
=
$
this
->
get
(
'
/login
'
, [
'
Accept-Language
'
=>
'
fr
'
]);
$
loginPageFrenchReq
->
assertDontSee
(
'
Se Connecter
'
);
}
public
function
test_all_lang_files_loadable
()
{
$
files
=
array_diff
(
scandir
(
lang_path
(
'
en
'
)), [
'
..
'
,
'
.
'
]);
foreach
(
$
this
->
langs
as
$
lang
) {
foreach
(
$
files
as
$
file
) {
$
loadError
=
false
;
try
{
$
translations
=
trans
(
str_replace
(
'
.php
'
,
''
,
$
file
), [],
$
lang
);
}
catch
(
\
Exception
$
e
) {
$
loadError
=
true
;
}
$
this
->
assertFalse
(
$
loadError
,
"
Translation file
{
$
lang
}
/
{
$
file
}
failed to load
"
);
}
}
}
public
function
test_views_use_rtl_if_rtl_language_is_set
()
{
$
this
->
asEditor
()->
withHtml
(
$
this
->
get
(
'
/
'
))->
assertElementExists
(
'
html[dir="ltr"]
'
);
setting
()->
putUser
(
$
this
->
users
->
editor
(),
'
language
'
,
'
ar
'
);
$
this
->
withHtml
(
$
this
->
get
(
'
/
'
))->
assertElementExists
(
'
html[dir="rtl"]
'
);
}
public
function
test_unknown_lang_does_not_break_app
()
{
config
()->
set
(
'
app.locale
'
,
'
zz
'
);
$
loginReq
=
$
this
->
get
(
'
/login
'
, [
'
Accept-Language
'
=>
'
zz
'
]);
$
loginReq
->
assertOk
();
$
loginReq
->
assertSee
(
'
Log In
'
);
}
public
function
test_all_activity_types_have_activity_text
()
{
foreach
(ActivityType::
all
()
as
$
activityType
) {
$
langKey
=
'
activities.
'
.
$
activityType
;
$
this
->
assertNotEquals
(
$
langKey
,
trans
(
$
langKey
, [],
'
en
'
));
}
}
}
Back
|
FazBrowse Home
|
New Git URL