@@ -17,57 +17,61 @@ class TestMslsBlogCollection extends MslsUnitTestCase {
17
17
protected function setUp (): void {
18
18
parent ::setUp (); // TODO: Change the autogenerated stub
19
19
20
- $ options = \Mockery::mock ( MslsOptions::class );
21
- $ options ->shouldReceive ( 'get_order ' )->andReturn ( 'description ' );
22
- $ options ->shouldReceive ( 'is_excluded ' )->andReturn ( false );
23
- $ options ->shouldReceive ( 'has_value ' )->andReturn ( false );
24
-
25
- Functions \expect ( 'msls_options ' )->atLeast ()->once ()->andReturn ( $ options );
26
-
27
- $ a = \Mockery::mock ( MslsBlog::class );
28
- $ b = \Mockery::mock ( MslsBlog::class );
29
- $ c = \Mockery::mock ( MslsBlog::class );
30
-
31
- $ a ->userblog_id = 1 ;
32
- $ b ->userblog_id = 2 ;
33
- $ c ->userblog_id = 3 ;
34
-
35
- Functions \expect ( 'get_current_blog_id ' )->atLeast ()->once ()->andReturn ( 1 );
36
- Functions \expect ( 'get_users ' )->atLeast ()->once ()->andReturn ( [] );
37
- Functions \expect ( 'get_blogs_of_user ' )->atLeast ()->once ()->andReturn ( [ $ a , $ b , $ c ] );
38
-
39
- Functions \expect ( 'get_blog_option ' )->atLeast ()->once ()->andReturnUsing ( function ( $ blog_id , $ option ) {
40
- $ wplang = [
41
- 1 => 'de_DE ' ,
42
- 2 => 'it_IT ' ,
43
- 3 => 'fr_FR ' ,
44
- ];
45
-
46
- $ msls = [
47
- 1 => [ 'description ' => 'Deutsch ' ],
48
- 2 => [ 'description ' => 'Italiano ' ],
49
- 3 => [ 'description ' => 'Français ' ],
50
- ];
51
-
52
- switch ( $ option ) {
53
- case 'active_plugins ' :
54
- $ value = in_array ( $ blog_id , [ 1 , 2 ]
55
- ) ? [ 'multisite-language-switcher/MultisiteLanguageSwitcher.php ' ] : [];
56
- break ;
57
- case 'WPLANG ' :
58
- $ value = $ wplang [ $ blog_id ] ?? false ;
59
- break ;
60
- case 'msls ' :
61
- $ value = $ msls [ $ blog_id ] ?? false ;
62
- break ;
20
+ $ options = \Mockery::mock ( MslsOptions::class );
21
+ $ options ->shouldReceive ( 'get_order ' )->andReturn ( 'description ' );
22
+ $ options ->shouldReceive ( 'is_excluded ' )->andReturn ( false );
23
+ $ options ->shouldReceive ( 'has_value ' )->andReturn ( false );
24
+
25
+ Functions \expect ( 'msls_options ' )->atLeast ()->once ()->andReturn ( $ options );
26
+
27
+ $ a = \Mockery::mock ( MslsBlog::class );
28
+ $ b = \Mockery::mock ( MslsBlog::class );
29
+ $ c = \Mockery::mock ( MslsBlog::class );
30
+
31
+ $ a ->userblog_id = 1 ;
32
+ $ b ->userblog_id = 2 ;
33
+ $ c ->userblog_id = 3 ;
34
+
35
+ Functions \expect ( 'get_current_blog_id ' )->atLeast ()->once ()->andReturn ( 1 );
36
+ Functions \expect ( 'get_users ' )->atLeast ()->once ()->andReturn ( array () );
37
+ Functions \expect ( 'get_blogs_of_user ' )->atLeast ()->once ()->andReturn ( array ( $ a , $ b , $ c ) );
38
+
39
+ Functions \expect ( 'get_blog_option ' )->atLeast ()->once ()->andReturnUsing (
40
+ function ( $ blog_id , $ option ) {
41
+ $ wplang = array (
42
+ 1 => 'de_DE ' ,
43
+ 2 => 'it_IT ' ,
44
+ 3 => 'fr_FR ' ,
45
+ );
46
+
47
+ $ msls = array (
48
+ 1 => array ( 'description ' => 'Deutsch ' ),
49
+ 2 => array ( 'description ' => 'Italiano ' ),
50
+ 3 => array ( 'description ' => 'Français ' ),
51
+ );
52
+
53
+ switch ( $ option ) {
54
+ case 'active_plugins ' :
55
+ $ value = in_array (
56
+ $ blog_id ,
57
+ array ( 1 , 2 )
58
+ ) ? array ( 'multisite-language-switcher/MultisiteLanguageSwitcher.php ' ) : array ();
59
+ break ;
60
+ case 'WPLANG ' :
61
+ $ value = $ wplang [ $ blog_id ] ?? false ;
62
+ break ;
63
+ case 'msls ' :
64
+ $ value = $ msls [ $ blog_id ] ?? false ;
65
+ break ;
66
+ }
67
+
68
+ return $ value ;
63
69
}
64
-
65
- return $ value ;
66
- } );
70
+ );
67
71
}
68
72
69
73
public function test_get_configured_blog_description_empty (): void {
70
- Functions \expect ( 'get_site_option ' )->once ()->andReturn ( [] );
74
+ Functions \expect ( 'get_site_option ' )->once ()->andReturn ( array () );
71
75
72
76
$ obj = new MslsBlogCollection ();
73
77
@@ -81,7 +85,7 @@ public function test_get_configured_blog_description_empty(): void {
81
85
}
82
86
83
87
public function test_get_blogs_of_reference_user (): void {
84
- Functions \expect ( 'get_site_option ' )->once ()->andReturn ( [] );
88
+ Functions \expect ( 'get_site_option ' )->once ()->andReturn ( array () );
85
89
86
90
$ options = \Mockery::mock ( MslsOptions::class );
87
91
$ options ->shouldReceive ( 'has_value ' )->andReturn ( true );
@@ -92,23 +96,23 @@ public function test_get_blogs_of_reference_user(): void {
92
96
}
93
97
94
98
public function test_get_current_blog_id (): void {
95
- Functions \expect ( 'get_site_option ' )->once ()->andReturn ( [] );
99
+ Functions \expect ( 'get_site_option ' )->once ()->andReturn ( array () );
96
100
97
101
$ obj = new MslsBlogCollection ();
98
102
99
103
$ this ->assertIsInt ( $ obj ->get_current_blog_id () );
100
104
}
101
105
102
106
public function test_has_current_blog (): void {
103
- Functions \expect ( 'get_site_option ' )->once ()->andReturn ( [] );
107
+ Functions \expect ( 'get_site_option ' )->once ()->andReturn ( array () );
104
108
105
109
$ obj = new MslsBlogCollection ();
106
110
107
111
$ this ->assertIsBool ( $ obj ->has_current_blog () );
108
112
}
109
113
110
114
public function test_is_current_blog_true (): void {
111
- Functions \expect ( 'get_site_option ' )->once ()->andReturn ( [] );
115
+ Functions \expect ( 'get_site_option ' )->once ()->andReturn ( array () );
112
116
113
117
$ obj = new MslsBlogCollection ();
114
118
@@ -119,7 +123,7 @@ public function test_is_current_blog_true(): void {
119
123
}
120
124
121
125
public function test_is_current_blog_false (): void {
122
- Functions \expect ( 'get_site_option ' )->once ()->andReturn ( [] );
126
+ Functions \expect ( 'get_site_option ' )->once ()->andReturn ( array () );
123
127
124
128
$ obj = new MslsBlogCollection ();
125
129
@@ -130,16 +134,25 @@ public function test_is_current_blog_false(): void {
130
134
}
131
135
132
136
public function test_get_objects (): void {
133
- Functions \expect ( 'get_site_option ' )->once ()->andReturn ( [] );
137
+ Functions \expect ( 'get_site_option ' )->once ()->andReturn ( array () );
134
138
135
139
$ obj = new MslsBlogCollection ();
136
140
137
141
$ this ->assertIsArray ( $ obj ->get_objects () );
138
142
}
139
143
144
+ public function test_get_object (): void {
145
+ Functions \expect ( 'get_site_option ' )->once ()->andReturn ( array () );
146
+
147
+ $ obj = new MslsBlogCollection ();
148
+
149
+ $ this ->assertInstanceOf ( MslsBlog::class, $ obj ->get_object ( 1 ) );
150
+ $ this ->assertNull ( $ obj ->get_object ( 4 ) );
151
+ }
152
+
140
153
public function test_is_plugin_active_networkwide (): void {
141
154
Functions \expect ( 'get_site_option ' )->once ()->andReturn (
142
- [ 'multisite-language-switcher/MultisiteLanguageSwitcher.php ' => 'Multisite Language Switcher ' ]
155
+ array ( 'multisite-language-switcher/MultisiteLanguageSwitcher.php ' => 'Multisite Language Switcher ' )
143
156
);
144
157
145
158
$ obj = new MslsBlogCollection ();
@@ -148,7 +161,7 @@ public function test_is_plugin_active_networkwide(): void {
148
161
}
149
162
150
163
public function test_is_plugin_active (): void {
151
- Functions \expect ( 'get_site_option ' )->once ()->andReturn ( [] );
164
+ Functions \expect ( 'get_site_option ' )->once ()->andReturn ( array () );
152
165
153
166
$ obj = new MslsBlogCollection ();
154
167
@@ -159,23 +172,23 @@ public function test_is_plugin_active(): void {
159
172
}
160
173
161
174
public function test_get_plugin_active_blogs (): void {
162
- Functions \expect ( 'get_site_option ' )->once ()->andReturn ( [] );
175
+ Functions \expect ( 'get_site_option ' )->once ()->andReturn ( array () );
163
176
164
177
$ obj = new MslsBlogCollection ();
165
178
166
179
$ this ->assertIsArray ( $ obj ->get_plugin_active_blogs () );
167
180
}
168
181
169
182
public function test_get (): void {
170
- Functions \expect ( 'get_site_option ' )->once ()->andReturn ( [] );
183
+ Functions \expect ( 'get_site_option ' )->once ()->andReturn ( array () );
171
184
172
185
$ obj = new MslsBlogCollection ();
173
186
174
187
$ this ->assertIsArray ( $ obj ->get () );
175
188
}
176
189
177
190
public function test_get_filtered (): void {
178
- Functions \expect ( 'get_site_option ' )->once ()->andReturn ( [] );
191
+ Functions \expect ( 'get_site_option ' )->once ()->andReturn ( array () );
179
192
180
193
$ obj = new MslsBlogCollection ();
181
194
@@ -184,23 +197,23 @@ public function test_get_filtered(): void {
184
197
}
185
198
186
199
public function test_get_users (): void {
187
- Functions \expect ( 'get_site_option ' )->once ()->andReturn ( [] );
200
+ Functions \expect ( 'get_site_option ' )->once ()->andReturn ( array () );
188
201
189
202
$ obj = new MslsBlogCollection ();
190
203
191
204
$ this ->assertIsArray ( $ obj ->get_users () );
192
205
}
193
206
194
207
public function test_get_current_blog (): void {
195
- Functions \expect ( 'get_site_option ' )->once ()->andReturn ( [] );
208
+ Functions \expect ( 'get_site_option ' )->once ()->andReturn ( array () );
196
209
197
210
$ obj = new MslsBlogCollection ();
198
211
199
212
$ this ->assertInstanceOf ( MslsBlog::class, $ obj ->get_current_blog () );
200
213
}
201
214
202
215
public function test_get_blog_language (): void {
203
- Functions \expect ( 'get_site_option ' )->once ()->andReturn ( [] );
216
+ Functions \expect ( 'get_site_option ' )->once ()->andReturn ( array () );
204
217
205
218
$ obj = new MslsBlogCollection ();
206
219
@@ -212,7 +225,7 @@ public function test_get_blog_language(): void {
212
225
}
213
226
214
227
public function test_get_blog_id (): void {
215
- Functions \expect ( 'get_site_option ' )->once ()->andReturn ( [] );
228
+ Functions \expect ( 'get_site_option ' )->once ()->andReturn ( array () );
216
229
217
230
$ obj = new MslsBlogCollection ();
218
231
@@ -221,5 +234,4 @@ public function test_get_blog_id(): void {
221
234
222
235
$ this ->assertNull ( $ obj ->get_blog_id ( 'fr_FR ' ) );
223
236
}
224
-
225
237
}
0 commit comments