Conditions | 1 |
Paths | 1 |
Total Lines | 114 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
197 | public function test_cmb2_field_render() { |
||
198 | |||
199 | $cmb_plugin_instance = CMB2_Bootstrap_260::initiate(); |
||
200 | $cmb_plugin_instance->include_cmb(); |
||
201 | |||
202 | BrightcoveVideoField\add_brightcove_video_field(); |
||
203 | |||
204 | $video_data = [ |
||
205 | 'bc_video_id' => '1236242437001', |
||
206 | 'bc_video_duration' => '2:29', |
||
207 | 'bc_player_id' => '61hrf3oYj', |
||
208 | 'bc_account_id' => '8926567543001', |
||
209 | ]; |
||
210 | |||
211 | $args = [ |
||
212 | 'name' => esc_html__( 'Brightcove Video', 'cmb2-brightcove-video-field' ), |
||
213 | 'id' => 'brightcove_featured_video', |
||
214 | 'type' => 'brightcove_video', |
||
215 | 'default' => $video_data, |
||
216 | ]; |
||
217 | |||
218 | $cmb_field = new CMB2_Field( [ |
||
219 | 'field_args' => $args, |
||
220 | ] ); |
||
221 | |||
222 | $field_type_obj = new CMB2_Types( $cmb_field ); |
||
223 | |||
224 | ob_start(); |
||
225 | $field_type_obj->render(); |
||
226 | $field_render_html = ob_get_contents(); |
||
227 | ob_end_clean(); |
||
228 | |||
229 | $field_render_html = $this->trim_html_markup( $field_render_html ); |
||
230 | |||
231 | $hash_id = $cmb_field->hash_id(); |
||
232 | |||
233 | // Test Brightcove Video Preview. |
||
234 | $this->assertContains( |
||
235 | 'https://players.brightcove.net/8926567543001/61hrf3oYj_default/index.html?videoId=1236242437001', |
||
236 | $field_render_html |
||
237 | ); |
||
238 | |||
239 | $bc_video_id_input_field = sprintf( |
||
240 | '<input |
||
241 | type="hidden" |
||
242 | class="bc_video_id" |
||
243 | name="brightcove_featured_video[bc_video_id]" |
||
244 | id="brightcove_featured_video_bc_video_id" |
||
245 | value="%s" |
||
246 | data-hash=\'%s\' />', |
||
247 | $video_data['bc_video_id'], |
||
248 | $hash_id |
||
249 | ); |
||
250 | |||
251 | // Test Brightcove Video ID Input Hidden Field. |
||
252 | $this->assertContains( |
||
253 | $this->trim_html_markup( $bc_video_id_input_field ), |
||
254 | $field_render_html |
||
255 | ); |
||
256 | |||
257 | $bc_video_duration_input_field = sprintf( |
||
258 | '<input |
||
259 | type="hidden" |
||
260 | class="bc_video_duration" |
||
261 | name="brightcove_featured_video[bc_video_duration]" |
||
262 | id="brightcove_featured_video_bc_video_duration" |
||
263 | value="%s" |
||
264 | data-hash=\'%s\' />', |
||
265 | $video_data['bc_video_duration'], |
||
266 | $hash_id |
||
267 | ); |
||
268 | |||
269 | // Test Brightcove Video Duration Input Hidden Field. |
||
270 | $this->assertContains( |
||
271 | $this->trim_html_markup( $bc_video_duration_input_field ), |
||
272 | $field_render_html |
||
273 | ); |
||
274 | |||
275 | $bc_player_id_input_field = sprintf( |
||
276 | '<input |
||
277 | type="hidden" |
||
278 | class="bc_player_id" |
||
279 | name="brightcove_featured_video[bc_player_id]" |
||
280 | id="brightcove_featured_video_bc_player_id" |
||
281 | value="%s" |
||
282 | data-hash=\'%s\' />', |
||
283 | $video_data['bc_player_id'], |
||
284 | $hash_id |
||
285 | ); |
||
286 | |||
287 | // Test Brightcove Video Player ID Input Hidden Field. |
||
288 | $this->assertContains( |
||
289 | $this->trim_html_markup( $bc_player_id_input_field ), |
||
290 | $field_render_html |
||
291 | ); |
||
292 | |||
293 | $bc_account_id_input_field = sprintf( |
||
294 | '<input |
||
295 | type="hidden" |
||
296 | class="bc_account_id" |
||
297 | name="brightcove_featured_video[bc_account_id]" |
||
298 | id="brightcove_featured_video_bc_account_id" |
||
299 | value="%s" |
||
300 | data-hash=\'%s\' />', |
||
301 | $video_data['bc_account_id'], |
||
302 | $hash_id |
||
303 | ); |
||
304 | |||
305 | // Test Brightcove Account ID Input Hidden Field. |
||
306 | $this->assertContains( |
||
307 | $this->trim_html_markup( $bc_account_id_input_field ), |
||
308 | $field_render_html |
||
309 | ); |
||
310 | } |
||
311 | |||
349 |