44
55use Brain \Monkey \Functions ;
66
7+ use lloc \Msls \MslsAdminIcon ;
78use lloc \Msls \MslsOptions ;
89
910class TestMslsOptions extends MslsUnitTestCase {
1011
1112 public function get_test (): MslsOptions {
1213 Functions \when ( 'home_url ' )->justReturn ( 'https://lloc.de ' );
13- Functions \when ( 'get_option ' )->justReturn ( [] );
14+ Functions \when ( 'get_option ' )->justReturn ( array () );
1415 Functions \when ( 'update_option ' )->justReturn ( true );
1516
1617 return new MslsOptions ();
@@ -36,9 +37,9 @@ public function test_is_query_page_method(): void {
3637
3738 public function test_create_method (): void {
3839 Functions \when ( 'is_admin ' )->justReturn ( true );
39- Functions \when ( 'get_post_types ' )->justReturn ( [] );
40+ Functions \when ( 'get_post_types ' )->justReturn ( array () );
4041 Functions \when ( 'get_post_type ' )->justReturn ( 'post ' );
41- Functions \when ( 'get_option ' )->justReturn ( [] );
42+ Functions \when ( 'get_option ' )->justReturn ( array () );
4243
4344 $ this ->assertInstanceOf ( MslsOptions::class, MslsOptions::create () );
4445 }
@@ -49,14 +50,23 @@ public function test_get_arg_method(): void {
4950 $ this ->assertNull ( $ obj ->get_arg ( 0 ) );
5051 $ this ->assertIsSTring ( $ obj ->get_arg ( 0 , '' ) );
5152 $ this ->assertIsFloat ( $ obj ->get_arg ( 0 , 1.1 ) );
52- $ this ->assertIsArray ( $ obj ->get_arg ( 0 , [] ) );
53+ $ this ->assertIsArray ( $ obj ->get_arg ( 0 , array () ) );
5354 }
5455
5556 function test_set_method (): void {
5657 $ obj = $ this ->get_test ();
5758
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+
6070 $ this ->assertFalse ( $ obj ->set ( 'Test ' ) );
6171 $ this ->assertFalse ( $ obj ->set ( 1 ) );
6272 $ this ->assertFalse ( $ obj ->set ( 1.1 ) );
@@ -120,11 +130,37 @@ function test_get_flag_url_method(): void {
120130 }
121131
122132 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+ }
124153
154+ public function test_get_icon_type_standard (): void {
125155 $ obj = $ this ->get_test ();
126156
127- $ this ->assertIsArray ( $ obj ->get_available_languages () );
157+ $ this ->assertEquals ( MslsAdminIcon:: TYPE_FLAG , $ obj ->get_icon_type () );
128158 }
129159
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+ }
130166}
0 commit comments