12
12
13
13
class TestMslsMetaBox extends MslsUnitTestCase {
14
14
15
+
15
16
protected function setUp (): void {
16
17
$ blog = \Mockery::mock ( MslsBlog::class );
17
18
$ blog ->shouldReceive ( 'get_language ' )->andReturn ( 'de_DE ' );
@@ -36,10 +37,8 @@ public function test_suggest(): void {
36
37
Functions \expect ( 'filter_input ' )->once ()->with ( INPUT_GET , MslsFields::FIELD_S , FILTER_SANITIZE_FULL_SPECIAL_CHARS )->andReturn ( 17 );
37
38
Functions \expect ( 'get_post_stati ' )->once ()->andReturn ( array ( 'pending ' , 'draft ' , 'future ' ) );
38
39
Functions \expect ( 'get_the_title ' )->once ()->andReturn ( 'Test ' );
39
-
40
40
Functions \expect ( 'sanitize_text_field ' )->times ( 2 )->andReturnFirstArg ();
41
41
Functions \expect ( 'get_posts ' )->once ()->andReturn ( array ( $ post ) );
42
-
43
42
Functions \expect ( 'switch_to_blog ' )->once ();
44
43
Functions \expect ( 'restore_current_blog ' )->once ();
45
44
Functions \expect ( 'wp_reset_postdata ' )->once ();
@@ -112,7 +111,7 @@ public function test_add( $post_type, $fcount, $ocount, $content_import, $autoco
112
111
$ this ->test ->add ();
113
112
}
114
113
115
- public function test_render_select () {
114
+ public function test_render_select_not_hierarchical () {
116
115
global $ post ;
117
116
118
117
$ post = \Mockery::mock ( 'WP_Post ' );
@@ -142,4 +141,96 @@ public function test_render_select() {
142
141
143
142
$ this ->test ->render_select ();
144
143
}
144
+
145
+ public function test_render_select_hierarchical () {
146
+ global $ post ;
147
+
148
+ $ post = \Mockery::mock ( 'WP_Post ' );
149
+ $ post ->ID = 42 ;
150
+
151
+ $ post_type = \Mockery::mock ( \WP_Post_Type::class );
152
+ $ post_type ->hierarchical = true ;
153
+
154
+ Functions \expect ( 'get_post_type ' )->once ()->andReturn ( 'page ' );
155
+ Functions \expect ( 'get_option ' )->once ()->andReturn ( array ( 'de_DE ' => 42 ) );
156
+ Functions \expect ( 'wp_nonce_field ' )->once ()->andReturn ( 'nonce_field ' );
157
+ Functions \expect ( 'switch_to_blog ' )->once ();
158
+ Functions \expect ( 'restore_current_blog ' )->once ();
159
+ Functions \expect ( 'esc_attr ' )->times ( 4 )->andReturnFirstArg ();
160
+ Functions \expect ( 'esc_url ' )->once ()->andReturnFirstArg ();
161
+ Functions \expect ( 'wp_kses ' )->once ()->andReturnFirstArg ();
162
+ Functions \expect ( '__ ' )->once ()->andReturnFirstArg ();
163
+ Functions \expect ( 'add_query_arg ' )->once ()->andReturn ( 'query_args ' );
164
+ Functions \expect ( 'get_post_type_object ' )->once ()->andReturn ( $ post_type );
165
+ Functions \expect ( 'wp_dropdown_pages ' )->once ()->andReturn ( '<select name="msls_input_region_Code"><option value="0">--some value</option></select> ' );
166
+ Functions \expect ( 'get_edit_post_link ' )->once ()->andReturn ( 'edit-post-link ' );
167
+
168
+ $ expected = '<ul><li><label for="msls_input_de_DE msls-icon-wrapper "><a title="Edit the translation in the de_DE-blog" href="edit-post-link"><span class="language-badge de_DE"><span>de</span><span>DE</span></span></a> </label><select name="msls_input_region_Code"><option value="0">--some value</option></select></li></ul> ' ;
169
+ $ this ->expectOutputString ( $ expected );
170
+
171
+ $ this ->test ->render_select ();
172
+ }
173
+
174
+ public function test_render_input () {
175
+ global $ post ;
176
+
177
+ $ post = \Mockery::mock ( 'WP_Post ' );
178
+ $ post ->ID = 42 ;
179
+
180
+ $ post_type = \Mockery::mock ( \WP_Post_Type::class );
181
+
182
+ Functions \expect ( 'get_post_types ' )->once ()->andReturn ( array ( 'post ' , 'page ' ) );
183
+ Functions \expect ( 'get_post_type ' )->once ()->andReturn ( 'page ' );
184
+ Functions \expect ( 'get_the_title ' )->once ()->andReturn ( 'Test ' );
185
+
186
+ Functions \when ( 'plugin_dir_path ' )->justReturn ( dirname ( __DIR__ , 2 ) . '/ ' );
187
+
188
+ Functions \expect ( 'get_option ' )->once ()->andReturn ( array ( 'de_DE ' => 42 ) );
189
+ Functions \expect ( 'wp_nonce_field ' )->once ()->andReturn ( 'nonce_field ' );
190
+ Functions \expect ( 'switch_to_blog ' )->once ();
191
+ Functions \expect ( 'restore_current_blog ' )->once ();
192
+ Functions \expect ( 'esc_attr ' )->times ( 4 )->andReturnFirstArg ();
193
+ Functions \expect ( 'esc_html ' )->once ()->andReturnFirstArg ();
194
+ Functions \expect ( 'esc_url ' )->once ()->andReturnFirstArg ();
195
+ Functions \expect ( '__ ' )->once ()->andReturnFirstArg ();
196
+ Functions \expect ( 'get_edit_post_link ' )->once ()->andReturn ( 'edit-post-link ' );
197
+
198
+ $ expected = '<ul><li class=""><label for="msls_title_ msls-icon-wrapper "><a title="Edit the translation in the de_DE-blog" href="edit-post-link"><span class="flag-icon flag-icon-de">de_DE</span></a> </label><input type="hidden" id="msls_id_" name="msls_input_de_DE" value="42"/><input class="msls_title" id="msls_title_" name="msls_title_" type="text" value="Test"/></li></ul><input type="hidden" name="msls_post_type" id="msls_post_type" value="page"/><input type="hidden" name="msls_action" id="msls_action" value="suggest_posts"/> ' ;
199
+
200
+ $ this ->expectOutputString ( $ expected );
201
+
202
+ $ this ->test ->render_input ();
203
+ }
204
+
205
+ public function test_render_select_only_one_blog () {
206
+ $ options = \Mockery::mock ( MslsOptions::class );
207
+
208
+ $ collection = \Mockery::mock ( MslsBlogCollection::class );
209
+ $ collection ->shouldReceive ( 'get ' )->andReturn ( array () );
210
+
211
+ Functions \expect ( '__ ' )->once ()->andReturnFirstArg ();
212
+
213
+ $ this ->test = new MslsMetaBox ( $ options , $ collection );
214
+
215
+ $ expected = '<p>You should define at least another blog in a different language in order to have some benefit from this plugin!</p> ' ;
216
+ $ this ->expectOutputString ( $ expected );
217
+
218
+ $ this ->test ->render_select ();
219
+ }
220
+
221
+ public function test_render_input_only_one_blog () {
222
+ $ options = \Mockery::mock ( MslsOptions::class );
223
+
224
+ $ collection = \Mockery::mock ( MslsBlogCollection::class );
225
+ $ collection ->shouldReceive ( 'get ' )->andReturn ( array () );
226
+
227
+ Functions \expect ( '__ ' )->once ()->andReturnFirstArg ();
228
+
229
+ $ this ->test = new MslsMetaBox ( $ options , $ collection );
230
+
231
+ $ expected = '<p>You should define at least another blog in a different language in order to have some benefit from this plugin!</p> ' ;
232
+ $ this ->expectOutputString ( $ expected );
233
+
234
+ $ this ->test ->render_input ();
235
+ }
145
236
}
0 commit comments