4
4
5
5
use Brain \Monkey \Functions ;
6
6
7
+ use lloc \Msls \MslsAdminIcon ;
7
8
use lloc \Msls \MslsOptions ;
8
9
9
10
class TestMslsOptions extends MslsUnitTestCase {
10
11
11
12
public function get_test (): MslsOptions {
12
13
Functions \when ( 'home_url ' )->justReturn ( 'https://lloc.de ' );
13
- Functions \when ( 'get_option ' )->justReturn ( [] );
14
+ Functions \when ( 'get_option ' )->justReturn ( array () );
14
15
Functions \when ( 'update_option ' )->justReturn ( true );
15
16
16
17
return new MslsOptions ();
@@ -36,9 +37,9 @@ public function test_is_query_page_method(): void {
36
37
37
38
public function test_create_method (): void {
38
39
Functions \when ( 'is_admin ' )->justReturn ( true );
39
- Functions \when ( 'get_post_types ' )->justReturn ( [] );
40
+ Functions \when ( 'get_post_types ' )->justReturn ( array () );
40
41
Functions \when ( 'get_post_type ' )->justReturn ( 'post ' );
41
- Functions \when ( 'get_option ' )->justReturn ( [] );
42
+ Functions \when ( 'get_option ' )->justReturn ( array () );
42
43
43
44
$ this ->assertInstanceOf ( MslsOptions::class, MslsOptions::create () );
44
45
}
@@ -49,14 +50,23 @@ public function test_get_arg_method(): void {
49
50
$ this ->assertNull ( $ obj ->get_arg ( 0 ) );
50
51
$ this ->assertIsSTring ( $ obj ->get_arg ( 0 , '' ) );
51
52
$ this ->assertIsFloat ( $ obj ->get_arg ( 0 , 1.1 ) );
52
- $ this ->assertIsArray ( $ obj ->get_arg ( 0 , [] ) );
53
+ $ this ->assertIsArray ( $ obj ->get_arg ( 0 , array () ) );
53
54
}
54
55
55
56
function test_set_method (): void {
56
57
$ obj = $ this ->get_test ();
57
58
58
- $ this ->assertTrue ( $ obj ->set ( [] ) );
59
- $ this ->assertTrue ( $ obj ->set ( array ( 'temp ' => 'abc ' ) ) );
59
+ $ this ->assertTrue ( $ obj ->set ( array () ) );
60
+ $ this ->assertTrue (
61
+ $ obj ->set (
62
+ array (
63
+ 'temp ' => 'abc ' ,
64
+ 'en ' => 1 ,
65
+ 'us ' => 2 ,
66
+ )
67
+ )
68
+ );
69
+
60
70
$ this ->assertFalse ( $ obj ->set ( 'Test ' ) );
61
71
$ this ->assertFalse ( $ obj ->set ( 1 ) );
62
72
$ this ->assertFalse ( $ obj ->set ( 1.1 ) );
@@ -120,11 +130,37 @@ function test_get_flag_url_method(): void {
120
130
}
121
131
122
132
function test_get_available_languages_method (): void {
123
- Functions \when ( 'get_available_languages ' )->justReturn ( [] );
133
+ Functions \expect ( 'get_available_languages ' )->once ()->andReturn ( array ( 'de_DE ' , 'it_IT ' ) );
134
+ Functions \expect ( 'format_code_lang ' )->atLeast ()->once ()->andReturnUsing (
135
+ function ( $ code ) {
136
+ $ map = array (
137
+ 'de_DE ' => 'German ' ,
138
+ 'it_IT ' => 'Italian ' ,
139
+ );
140
+ return $ map [ $ code ] ?? 'American English ' ;
141
+ }
142
+ );
143
+
144
+ $ obj = $ this ->get_test ();
145
+
146
+ $ expected = array (
147
+ 'en_US ' => 'American English ' ,
148
+ 'de_DE ' => 'German ' ,
149
+ 'it_IT ' => 'Italian ' ,
150
+ );
151
+ $ this ->assertEquals ( $ expected , $ obj ->get_available_languages () );
152
+ }
124
153
154
+ public function test_get_icon_type_standard (): void {
125
155
$ obj = $ this ->get_test ();
126
156
127
- $ this ->assertIsArray ( $ obj ->get_available_languages () );
157
+ $ this ->assertEquals ( MslsAdminIcon:: TYPE_FLAG , $ obj ->get_icon_type () );
128
158
}
129
159
160
+ public function test_get_icon_type_admin_display (): void {
161
+ $ obj = $ this ->get_test ();
162
+ $ obj ->set ( array ( 'admin_display ' => MslsAdminIcon::TYPE_LABEL ) );
163
+
164
+ $ this ->assertEquals ( MslsAdminIcon::TYPE_LABEL , $ obj ->get_icon_type () );
165
+ }
130
166
}
0 commit comments