Completed
Push — master ( 6e2b0e...a988ab )
by Scott Kingsley
02:52
created
tests/test-wp-fields-api.php 1 patch
Spacing   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -18,10 +18,10 @@  discard block
 block discarded – undo
18 18
 		global $wp_fields;
19 19
 
20 20
 		// Reset WP Fields instance for testing purposes
21
-		$wp_fields->remove_form( true, true );
22
-		$wp_fields->remove_section( true, true );
23
-		$wp_fields->remove_field( true, true );
24
-		$wp_fields->remove_control( true, true );
21
+		$wp_fields->remove_form(true, true);
22
+		$wp_fields->remove_section(true, true);
23
+		$wp_fields->remove_field(true, true);
24
+		$wp_fields->remove_control(true, true);
25 25
 
26 26
 	}
27 27
 
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 		 */
38 38
 		global $wp_fields;
39 39
 
40
-		$this->assertTrue( is_a( $wp_fields, 'WP_Fields_API' ) );
40
+		$this->assertTrue(is_a($wp_fields, 'WP_Fields_API'));
41 41
 
42 42
 	}
43 43
 
@@ -47,14 +47,14 @@  discard block
 block discarded – undo
47 47
 	 * @param string $object_type
48 48
 	 * @param string $object_name
49 49
 	 */
50
-	public function test_add_form( $object_type = 'post', $object_name = null ) {
50
+	public function test_add_form($object_type = 'post', $object_name = null) {
51 51
 
52 52
 		/**
53 53
 		 * @var $wp_fields WP_Fields_API
54 54
 		 */
55 55
 		global $wp_fields;
56 56
 
57
-		$wp_fields->add_form( $object_type, 'my_test_form', $object_name );
57
+		$wp_fields->add_form($object_type, 'my_test_form', $object_name);
58 58
 
59 59
 	}
60 60
 
@@ -64,14 +64,14 @@  discard block
 block discarded – undo
64 64
 	 * @param string $object_type
65 65
 	 * @param string $object_name
66 66
 	 */
67
-	public function test_add_form_invalid( $object_type = 'post' ) {
67
+	public function test_add_form_invalid($object_type = 'post') {
68 68
 
69 69
 		/**
70 70
 		 * @var $wp_fields WP_Fields_API
71 71
 		 */
72 72
 		global $wp_fields;
73 73
 
74
-		$wp_fields->add_form( $object_type, null, null, array() );
74
+		$wp_fields->add_form($object_type, null, null, array());
75 75
 
76 76
 	}
77 77
 
@@ -86,37 +86,37 @@  discard block
 block discarded – undo
86 86
 		global $wp_fields;
87 87
 
88 88
 		// Add a form
89
-		$this->test_add_form( 'post', 'my_custom_post_type' );
89
+		$this->test_add_form('post', 'my_custom_post_type');
90 90
 
91 91
 		// Get forms for object type / name
92
-		$forms = $wp_fields->get_forms( 'post', 'my_custom_post_type' );
92
+		$forms = $wp_fields->get_forms('post', 'my_custom_post_type');
93 93
 
94
-		$this->assertEquals( 1, count( $forms ) );
94
+		$this->assertEquals(1, count($forms));
95 95
 
96
-		$this->assertArrayHasKey( 'my_test_form', $forms );
96
+		$this->assertArrayHasKey('my_test_form', $forms);
97 97
 
98 98
 		// Get a form that doesn't exist
99
-		$forms = $wp_fields->get_forms( 'post', 'some_other_post_type' );
99
+		$forms = $wp_fields->get_forms('post', 'some_other_post_type');
100 100
 
101
-		$this->assertEquals( 0, count( $forms ) );
101
+		$this->assertEquals(0, count($forms));
102 102
 
103 103
 		// Get all forms for object type
104
-		$forms = $wp_fields->get_forms( 'post', true );
104
+		$forms = $wp_fields->get_forms('post', true);
105 105
 
106
-		$this->assertEquals( 1, count( $forms ) );
106
+		$this->assertEquals(1, count($forms));
107 107
 
108
-		$form_ids = wp_list_pluck( $forms, 'id' );
108
+		$form_ids = wp_list_pluck($forms, 'id');
109 109
 
110
-		$this->assertContains( 'my_test_form', $form_ids );
110
+		$this->assertContains('my_test_form', $form_ids);
111 111
 
112 112
 		// Get all forms for all object types
113 113
 		$forms = $wp_fields->get_forms();
114 114
 
115 115
 		// Each array item is an object type with an array of object names
116
-		$this->assertEquals( 1, count( $forms ) );
116
+		$this->assertEquals(1, count($forms));
117 117
 
118 118
 		// Array keys are object types
119
-		$this->assertArrayHasKey( 'post', $forms );
119
+		$this->assertArrayHasKey('post', $forms);
120 120
 
121 121
 	}
122 122
 
@@ -131,14 +131,14 @@  discard block
 block discarded – undo
131 131
 		global $wp_fields;
132 132
 
133 133
 		// Add a form
134
-		$this->test_add_form( 'post' );
134
+		$this->test_add_form('post');
135 135
 
136 136
 		// Get forms for object type / name
137
-		$forms = $wp_fields->get_forms( 'post' );
137
+		$forms = $wp_fields->get_forms('post');
138 138
 
139
-		$this->assertEquals( 1, count( $forms ) );
139
+		$this->assertEquals(1, count($forms));
140 140
 
141
-		$this->assertArrayHasKey( 'my_test_form', $forms );
141
+		$this->assertArrayHasKey('my_test_form', $forms);
142 142
 
143 143
 	}
144 144
 
@@ -153,24 +153,24 @@  discard block
 block discarded – undo
153 153
 		global $wp_fields;
154 154
 
155 155
 		// Add a form
156
-		$this->test_add_form( 'post', 'my_custom_post_type' );
156
+		$this->test_add_form('post', 'my_custom_post_type');
157 157
 
158 158
 		// Form exists for this object type / name
159
-		$form = $wp_fields->get_form( 'post', 'my_test_form', 'my_custom_post_type' );
159
+		$form = $wp_fields->get_form('post', 'my_test_form', 'my_custom_post_type');
160 160
 
161
-		$this->assertNotEmpty( $form );
161
+		$this->assertNotEmpty($form);
162 162
 
163
-		$this->assertEquals( 'my_test_form', $form->id );
163
+		$this->assertEquals('my_test_form', $form->id);
164 164
 
165 165
 		// Form doesn't exist for this object type / name
166
-		$form = $wp_fields->get_form( 'post', 'my_test_form1' );
166
+		$form = $wp_fields->get_form('post', 'my_test_form1');
167 167
 
168
-		$this->assertEmpty( $form );
168
+		$this->assertEmpty($form);
169 169
 
170 170
 		// Form doesn't exist for this object type / name
171
-		$form = $wp_fields->get_form( 'post', 'my_test_form2', 'my_custom_post_type' );
171
+		$form = $wp_fields->get_form('post', 'my_test_form2', 'my_custom_post_type');
172 172
 
173
-		$this->assertEmpty( $form );
173
+		$this->assertEmpty($form);
174 174
 
175 175
 	}
176 176
 
@@ -185,22 +185,22 @@  discard block
 block discarded – undo
185 185
 		global $wp_fields;
186 186
 
187 187
 		// Add a form
188
-		$this->test_add_form( 'post', 'my_custom_post_type' );
188
+		$this->test_add_form('post', 'my_custom_post_type');
189 189
 
190 190
 		// Form exists for this object type / name
191
-		$form = $wp_fields->get_form( 'post', 'my_test_form', 'my_custom_post_type' );
191
+		$form = $wp_fields->get_form('post', 'my_test_form', 'my_custom_post_type');
192 192
 
193
-		$this->assertNotEmpty( $form );
193
+		$this->assertNotEmpty($form);
194 194
 
195
-		$this->assertEquals( 'my_test_form', $form->id );
195
+		$this->assertEquals('my_test_form', $form->id);
196 196
 
197 197
 		// Remove form
198
-		$wp_fields->remove_form( 'post', 'my_test_form', 'my_custom_post_type' );
198
+		$wp_fields->remove_form('post', 'my_test_form', 'my_custom_post_type');
199 199
 
200 200
 		// Form no longer exists for this object type / name
201
-		$form = $wp_fields->get_form( 'post', 'my_test_form', 'my_custom_post_type' );
201
+		$form = $wp_fields->get_form('post', 'my_test_form', 'my_custom_post_type');
202 202
 
203
-		$this->assertEmpty( $form );
203
+		$this->assertEmpty($form);
204 204
 
205 205
 	}
206 206
 
@@ -215,15 +215,15 @@  discard block
 block discarded – undo
215 215
 		global $wp_fields;
216 216
 
217 217
 		// Add a form
218
-		$this->test_add_form( 'post', 'my_custom_post_type' );
218
+		$this->test_add_form('post', 'my_custom_post_type');
219 219
 
220 220
 		// Remove form
221
-		$wp_fields->remove_form( 'post', null, true );
221
+		$wp_fields->remove_form('post', null, true);
222 222
 
223 223
 		// Form no longer exists for this object type / name
224
-		$form = $wp_fields->get_form( 'post', 'my_test_form', 'my_custom_post_type' );
224
+		$form = $wp_fields->get_form('post', 'my_test_form', 'my_custom_post_type');
225 225
 
226
-		$this->assertEmpty( $form );
226
+		$this->assertEmpty($form);
227 227
 
228 228
 	}
229 229
 
@@ -238,15 +238,15 @@  discard block
 block discarded – undo
238 238
 		global $wp_fields;
239 239
 
240 240
 		// Add a form
241
-		$this->test_add_form( 'post' );
241
+		$this->test_add_form('post');
242 242
 
243 243
 		// Remove form
244
-		$wp_fields->remove_form( 'post', 'my_test_form' );
244
+		$wp_fields->remove_form('post', 'my_test_form');
245 245
 
246 246
 		// Form no longer exists for this object type / name
247
-		$form = $wp_fields->get_form( 'post', 'my_test_form' );
247
+		$form = $wp_fields->get_form('post', 'my_test_form');
248 248
 
249
-		$this->assertEmpty( $form );
249
+		$this->assertEmpty($form);
250 250
 
251 251
 	}
252 252
 
@@ -261,15 +261,15 @@  discard block
 block discarded – undo
261 261
 		global $wp_fields;
262 262
 
263 263
 		// Add a form
264
-		$this->test_add_form( 'post', 'my_custom_post_type' );
264
+		$this->test_add_form('post', 'my_custom_post_type');
265 265
 
266 266
 		// Remove form
267
-		$wp_fields->remove_form( 'post', true, 'my_custom_post_type' );
267
+		$wp_fields->remove_form('post', true, 'my_custom_post_type');
268 268
 
269 269
 		// Form no longer exists for this object type / name
270
-		$form = $wp_fields->get_form( 'post', 'my_test_form', 'my_custom_post_type' );
270
+		$form = $wp_fields->get_form('post', 'my_test_form', 'my_custom_post_type');
271 271
 
272
-		$this->assertEmpty( $form );
272
+		$this->assertEmpty($form);
273 273
 
274 274
 	}
275 275
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 	 * @param string $object_type
280 280
 	 * @param string $object_name
281 281
 	 */
282
-	public function test_add_section( $object_type = 'post', $object_name = null ) {
282
+	public function test_add_section($object_type = 'post', $object_name = null) {
283 283
 
284 284
 		/**
285 285
 		 * @var $wp_fields WP_Fields_API
@@ -287,11 +287,11 @@  discard block
 block discarded – undo
287 287
 		global $wp_fields;
288 288
 
289 289
 		// Add a form
290
-		$this->test_add_form( $object_type, $object_name );
290
+		$this->test_add_form($object_type, $object_name);
291 291
 
292
-		$wp_fields->add_section( $object_type, 'my_test_section', $object_name, array(
292
+		$wp_fields->add_section($object_type, 'my_test_section', $object_name, array(
293 293
 			'form' => 'my_test_form',
294
-		) );
294
+		));
295 295
 
296 296
 	}
297 297
 
@@ -306,56 +306,56 @@  discard block
 block discarded – undo
306 306
 		global $wp_fields;
307 307
 
308 308
 		// Add a form
309
-		$this->test_add_section( 'post', 'my_custom_post_type' );
309
+		$this->test_add_section('post', 'my_custom_post_type');
310 310
 
311 311
 		// Get sections for object type / name
312
-		$sections = $wp_fields->get_sections( 'post', 'my_custom_post_type' );
312
+		$sections = $wp_fields->get_sections('post', 'my_custom_post_type');
313 313
 
314
-		$this->assertEquals( 1, count( $sections ) );
314
+		$this->assertEquals(1, count($sections));
315 315
 
316
-		$this->assertArrayHasKey( 'my_test_section', $sections );
316
+		$this->assertArrayHasKey('my_test_section', $sections);
317 317
 
318 318
 		// Get a section that doesn't exist
319
-		$sections = $wp_fields->get_sections( 'post', 'some_other_post_type' );
319
+		$sections = $wp_fields->get_sections('post', 'some_other_post_type');
320 320
 
321
-		$this->assertEquals( 0, count( $sections ) );
321
+		$this->assertEquals(0, count($sections));
322 322
 
323 323
 		// Get sections by form
324
-		$sections = $wp_fields->get_sections( 'post', 'my_custom_post_type', 'my_test_form' );
324
+		$sections = $wp_fields->get_sections('post', 'my_custom_post_type', 'my_test_form');
325 325
 
326
-		$this->assertEquals( 1, count( $sections ) );
326
+		$this->assertEquals(1, count($sections));
327 327
 
328
-		$this->assertArrayHasKey( 'my_test_section', $sections );
328
+		$this->assertArrayHasKey('my_test_section', $sections);
329 329
 
330
-		$this->assertEquals( 'my_test_form', $sections['my_test_section']->get_parent()->id );
330
+		$this->assertEquals('my_test_form', $sections['my_test_section']->get_parent()->id);
331 331
 
332 332
 		// Get sections *from* form
333
-		$form = $wp_fields->get_form( 'post', 'my_test_form', 'my_custom_post_type' );
333
+		$form = $wp_fields->get_form('post', 'my_test_form', 'my_custom_post_type');
334 334
 
335
-		$sections = $form->get_children( 'section' );
335
+		$sections = $form->get_children('section');
336 336
 
337
-		$this->assertEquals( 1, count( $sections ) );
337
+		$this->assertEquals(1, count($sections));
338 338
 
339
-		$this->assertArrayHasKey( 'my_test_section', $sections );
339
+		$this->assertArrayHasKey('my_test_section', $sections);
340 340
 
341
-		$this->assertEquals( 'my_test_form', $sections['my_test_section']->get_parent()->id );
341
+		$this->assertEquals('my_test_form', $sections['my_test_section']->get_parent()->id);
342 342
 
343 343
 		// Get all sections for object type
344
-		$sections = $wp_fields->get_sections( 'post', true );
344
+		$sections = $wp_fields->get_sections('post', true);
345 345
 
346
-		$this->assertEquals( 1, count( $sections ) );
346
+		$this->assertEquals(1, count($sections));
347 347
 
348
-		$section_ids = wp_list_pluck( $sections, 'id' );
348
+		$section_ids = wp_list_pluck($sections, 'id');
349 349
 
350
-		$this->assertContains( 'my_test_section', $section_ids );
350
+		$this->assertContains('my_test_section', $section_ids);
351 351
 
352 352
 		// Get all sections for all object types
353 353
 		$sections = $wp_fields->get_sections();
354 354
 
355 355
 		// Each array item is an object type with an array of object names
356
-		$this->assertEquals( 1, count( $sections ) );
356
+		$this->assertEquals(1, count($sections));
357 357
 
358
-		$this->assertArrayHasKey( 'post', $sections );
358
+		$this->assertArrayHasKey('post', $sections);
359 359
 
360 360
 	}
361 361
 
@@ -370,25 +370,25 @@  discard block
 block discarded – undo
370 370
 		global $wp_fields;
371 371
 
372 372
 		// Add a form
373
-		$this->test_add_section( 'post', 'my_custom_post_type' );
373
+		$this->test_add_section('post', 'my_custom_post_type');
374 374
 
375 375
 		// Section exists for this object type / name
376
-		$section = $wp_fields->get_section( 'post', 'my_test_section', 'my_custom_post_type' );
376
+		$section = $wp_fields->get_section('post', 'my_test_section', 'my_custom_post_type');
377 377
 
378
-		$this->assertNotEmpty( $section );
378
+		$this->assertNotEmpty($section);
379 379
 
380
-		$this->assertEquals( 'my_test_section', $section->id );
381
-		$this->assertEquals( 'my_test_form', $section->get_parent()->id );
380
+		$this->assertEquals('my_test_section', $section->id);
381
+		$this->assertEquals('my_test_form', $section->get_parent()->id);
382 382
 
383 383
 		// Section doesn't exist for this object type / name
384
-		$section = $wp_fields->get_section( 'post', 'my_test_section', 'some_other_post_type' );
384
+		$section = $wp_fields->get_section('post', 'my_test_section', 'some_other_post_type');
385 385
 
386
-		$this->assertEmpty( $section );
386
+		$this->assertEmpty($section);
387 387
 
388 388
 		// Section doesn't exist for this object type / name
389
-		$section = $wp_fields->get_section( 'post', 'my_test_section2', 'my_custom_post_type' );
389
+		$section = $wp_fields->get_section('post', 'my_test_section2', 'my_custom_post_type');
390 390
 
391
-		$this->assertEmpty( $section );
391
+		$this->assertEmpty($section);
392 392
 
393 393
 	}
394 394
 
@@ -403,22 +403,22 @@  discard block
 block discarded – undo
403 403
 		global $wp_fields;
404 404
 
405 405
 		// Add a form
406
-		$this->test_add_section( 'post', 'my_custom_post_type' );
406
+		$this->test_add_section('post', 'my_custom_post_type');
407 407
 
408 408
 		// Section exists for this object type / name
409
-		$section = $wp_fields->get_section( 'post', 'my_test_section', 'my_custom_post_type' );
409
+		$section = $wp_fields->get_section('post', 'my_test_section', 'my_custom_post_type');
410 410
 
411
-		$this->assertNotEmpty( $section );
411
+		$this->assertNotEmpty($section);
412 412
 
413
-		$this->assertEquals( 'my_test_section', $section->id );
413
+		$this->assertEquals('my_test_section', $section->id);
414 414
 
415 415
 		// Remove section
416
-		$wp_fields->remove_section( 'post', 'my_test_section', 'my_custom_post_type' );
416
+		$wp_fields->remove_section('post', 'my_test_section', 'my_custom_post_type');
417 417
 
418 418
 		// Section no longer exists for this object type / name
419
-		$section = $wp_fields->get_section( 'post', 'my_test_section', 'my_custom_post_type' );
419
+		$section = $wp_fields->get_section('post', 'my_test_section', 'my_custom_post_type');
420 420
 
421
-		$this->assertEmpty( $section );
421
+		$this->assertEmpty($section);
422 422
 
423 423
 	}
424 424
 
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 	 * @param string $object_type
429 429
 	 * @param string $object_name
430 430
 	 */
431
-	public function test_add_field( $object_type = 'post', $object_name = null ) {
431
+	public function test_add_field($object_type = 'post', $object_name = null) {
432 432
 
433 433
 		/**
434 434
 		 * @var $wp_fields WP_Fields_API
@@ -436,16 +436,16 @@  discard block
 block discarded – undo
436 436
 		global $wp_fields;
437 437
 
438 438
 		// Add a section for the control
439
-		$this->test_add_section( $object_type, $object_name );
439
+		$this->test_add_section($object_type, $object_name);
440 440
 
441
-		$wp_fields->add_field( $object_type, 'my_test_field', $object_name, array(
441
+		$wp_fields->add_field($object_type, 'my_test_field', $object_name, array(
442 442
 			'control' => array(
443 443
 				'id'      => 'my_test_field_control',
444 444
 				'label'   => 'My Test Field',
445 445
 				'type'    => 'text',
446 446
 				'section' => 'my_test_section',
447 447
 			),
448
-		) );
448
+		));
449 449
 
450 450
 	}
451 451
 
@@ -460,19 +460,19 @@  discard block
 block discarded – undo
460 460
 		global $wp_fields;
461 461
 
462 462
 		// Add a field
463
-		$this->test_add_field( 'post', 'my_custom_post_type' );
463
+		$this->test_add_field('post', 'my_custom_post_type');
464 464
 
465 465
 		// Get fields for object type / name
466
-		$fields = $wp_fields->get_fields( 'post', 'my_custom_post_type' );
466
+		$fields = $wp_fields->get_fields('post', 'my_custom_post_type');
467 467
 
468
-		$this->assertEquals( 1, count( $fields ) );
468
+		$this->assertEquals(1, count($fields));
469 469
 
470
-		$this->assertArrayHasKey( 'my_test_field', $fields );
470
+		$this->assertArrayHasKey('my_test_field', $fields);
471 471
 
472 472
 		// Get a field that doesn't exist
473
-		$fields = $wp_fields->get_fields( 'post', 'some_other_post_type' );
473
+		$fields = $wp_fields->get_fields('post', 'some_other_post_type');
474 474
 
475
-		$this->assertEquals( 0, count( $fields ) );
475
+		$this->assertEquals(0, count($fields));
476 476
 
477 477
 	}
478 478
 
@@ -487,24 +487,24 @@  discard block
 block discarded – undo
487 487
 		global $wp_fields;
488 488
 
489 489
 		// Add a field
490
-		$this->test_add_field( 'post', 'my_custom_post_type' );
490
+		$this->test_add_field('post', 'my_custom_post_type');
491 491
 
492 492
 		// Field exists for this object type / name
493
-		$field = $wp_fields->get_field( 'post', 'my_test_field', 'my_custom_post_type' );
493
+		$field = $wp_fields->get_field('post', 'my_test_field', 'my_custom_post_type');
494 494
 
495
-		$this->assertNotEmpty( $field );
495
+		$this->assertNotEmpty($field);
496 496
 
497
-		$this->assertEquals( 'my_test_field', $field->id );
497
+		$this->assertEquals('my_test_field', $field->id);
498 498
 
499 499
 		// Field doesn't exist for this object type / name
500
-		$field = $wp_fields->get_field( 'post', 'my_test_field', 'some_other_post_type' );
500
+		$field = $wp_fields->get_field('post', 'my_test_field', 'some_other_post_type');
501 501
 
502
-		$this->assertEmpty( $field );
502
+		$this->assertEmpty($field);
503 503
 
504 504
 		// Field doesn't exist for this object type / name
505
-		$field = $wp_fields->get_field( 'post', 'my_test_field2', 'my_custom_post_type' );
505
+		$field = $wp_fields->get_field('post', 'my_test_field2', 'my_custom_post_type');
506 506
 
507
-		$this->assertEmpty( $field );
507
+		$this->assertEmpty($field);
508 508
 
509 509
 	}
510 510
 
@@ -519,22 +519,22 @@  discard block
 block discarded – undo
519 519
 		global $wp_fields;
520 520
 
521 521
 		// Add a field
522
-		$this->test_add_field( 'post', 'my_custom_post_type' );
522
+		$this->test_add_field('post', 'my_custom_post_type');
523 523
 
524 524
 		// Field exists for this object type / name
525
-		$field = $wp_fields->get_field( 'post', 'my_test_field', 'my_custom_post_type' );
525
+		$field = $wp_fields->get_field('post', 'my_test_field', 'my_custom_post_type');
526 526
 
527
-		$this->assertNotEmpty( $field );
527
+		$this->assertNotEmpty($field);
528 528
 
529
-		$this->assertEquals( 'my_test_field', $field->id );
529
+		$this->assertEquals('my_test_field', $field->id);
530 530
 
531 531
 		// Remove field
532
-		$wp_fields->remove_field( 'post', 'my_test_field', 'my_custom_post_type' );
532
+		$wp_fields->remove_field('post', 'my_test_field', 'my_custom_post_type');
533 533
 
534 534
 		// Field no longer exists for this object type / name
535
-		$field = $wp_fields->get_field( 'post', 'my_test_field', 'my_custom_post_type' );
535
+		$field = $wp_fields->get_field('post', 'my_test_field', 'my_custom_post_type');
536 536
 
537
-		$this->assertEmpty( $field );
537
+		$this->assertEmpty($field);
538 538
 
539 539
 	}
540 540
 
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
 	 * @param string $object_type
545 545
 	 * @param string $object_name
546 546
 	 */
547
-	public function test_add_control( $object_type = 'post', $object_name = null ) {
547
+	public function test_add_control($object_type = 'post', $object_name = null) {
548 548
 
549 549
 		/**
550 550
 		 * @var $wp_fields WP_Fields_API
@@ -552,14 +552,14 @@  discard block
 block discarded – undo
552 552
 		global $wp_fields;
553 553
 
554 554
 		// Add a field for the control
555
-		$this->test_add_field( $object_type, $object_name );
555
+		$this->test_add_field($object_type, $object_name);
556 556
 
557
-		$wp_fields->add_control( $object_type, 'my_test_control', $object_name, array(
557
+		$wp_fields->add_control($object_type, 'my_test_control', $object_name, array(
558 558
 			'section' => 'my_test_section',
559 559
 			'field'   => 'my_test_field',
560 560
 			'label'   => 'My Test Control Field',
561 561
 			'type'    => 'text',
562
-		) );
562
+		));
563 563
 
564 564
 	}
565 565
 
@@ -574,45 +574,45 @@  discard block
 block discarded – undo
574 574
 		global $wp_fields;
575 575
 
576 576
 		// Add a control / field / section
577
-		$this->test_add_control( 'post', 'my_custom_post_type' );
577
+		$this->test_add_control('post', 'my_custom_post_type');
578 578
 
579 579
 		// Get controls for object type / name
580
-		$controls = $wp_fields->get_controls( 'post', 'my_custom_post_type' );
580
+		$controls = $wp_fields->get_controls('post', 'my_custom_post_type');
581 581
 
582 582
 		// There are two controls, the default one with the main field and this control
583
-		$this->assertEquals( 2, count( $controls ) );
583
+		$this->assertEquals(2, count($controls));
584 584
 
585
-		$this->assertArrayHasKey( 'my_test_control', $controls );
586
-		$this->assertArrayHasKey( 'my_test_field_control', $controls );
585
+		$this->assertArrayHasKey('my_test_control', $controls);
586
+		$this->assertArrayHasKey('my_test_field_control', $controls);
587 587
 
588
-		$this->assertEquals( 'my_test_section', $controls['my_test_control']->get_parent()->id );
588
+		$this->assertEquals('my_test_section', $controls['my_test_control']->get_parent()->id);
589 589
 
590 590
 		// Get a control that doesn't exist
591
-		$controls = $wp_fields->get_controls( 'post', 'some_other_post_type' );
591
+		$controls = $wp_fields->get_controls('post', 'some_other_post_type');
592 592
 
593
-		$this->assertEquals( 0, count( $controls ) );
593
+		$this->assertEquals(0, count($controls));
594 594
 
595 595
 		// Get controls by section
596
-		$controls = $wp_fields->get_controls( 'post', 'my_custom_post_type', 'my_test_section' );
596
+		$controls = $wp_fields->get_controls('post', 'my_custom_post_type', 'my_test_section');
597 597
 
598
-		$this->assertEquals( 2, count( $controls ) );
598
+		$this->assertEquals(2, count($controls));
599 599
 
600
-		$this->assertArrayHasKey( 'my_test_control', $controls );
601
-		$this->assertArrayHasKey( 'my_test_field_control', $controls );
600
+		$this->assertArrayHasKey('my_test_control', $controls);
601
+		$this->assertArrayHasKey('my_test_field_control', $controls);
602 602
 
603
-		$this->assertEquals( 'my_test_section', $controls['my_test_control']->get_parent()->id );
603
+		$this->assertEquals('my_test_section', $controls['my_test_control']->get_parent()->id);
604 604
 
605 605
 		// Get sections *from* form
606
-		$section = $wp_fields->get_section( 'post', 'my_test_section', 'my_custom_post_type' );
606
+		$section = $wp_fields->get_section('post', 'my_test_section', 'my_custom_post_type');
607 607
 
608
-		$controls = $section->get_children( 'control' );
608
+		$controls = $section->get_children('control');
609 609
 
610
-		$this->assertEquals( 2, count( $controls ) );
610
+		$this->assertEquals(2, count($controls));
611 611
 
612
-		$this->assertArrayHasKey( 'my_test_control', $controls );
613
-		$this->assertArrayHasKey( 'my_test_field_control', $controls );
612
+		$this->assertArrayHasKey('my_test_control', $controls);
613
+		$this->assertArrayHasKey('my_test_field_control', $controls);
614 614
 
615
-		$this->assertEquals( 'my_test_section', $controls['my_test_control']->get_parent()->id );
615
+		$this->assertEquals('my_test_section', $controls['my_test_control']->get_parent()->id);
616 616
 
617 617
 	}
618 618
 
@@ -627,37 +627,37 @@  discard block
 block discarded – undo
627 627
 		global $wp_fields;
628 628
 
629 629
 		// Add a control / field / section
630
-		$this->test_add_control( 'post', 'my_custom_post_type' );
630
+		$this->test_add_control('post', 'my_custom_post_type');
631 631
 
632 632
 		// Control exists for this object type / name
633
-		$control = $wp_fields->get_control( 'post', 'my_test_field_control', 'my_custom_post_type' );
633
+		$control = $wp_fields->get_control('post', 'my_test_field_control', 'my_custom_post_type');
634 634
 
635
-		$this->assertNotEmpty( $control );
635
+		$this->assertNotEmpty($control);
636 636
 
637
-		$this->assertEquals( 'my_test_field_control', $control->id );
638
-		$this->assertNotEmpty( $control->get_field() );
639
-		$this->assertEquals( 'my_test_field', $control->get_field()->id );
640
-		$this->assertEquals( 'my_test_section', $control->get_parent()->id );
637
+		$this->assertEquals('my_test_field_control', $control->id);
638
+		$this->assertNotEmpty($control->get_field());
639
+		$this->assertEquals('my_test_field', $control->get_field()->id);
640
+		$this->assertEquals('my_test_section', $control->get_parent()->id);
641 641
 
642 642
 		// Control exists for this object type / name
643
-		$control = $wp_fields->get_control( 'post', 'my_test_control', 'my_custom_post_type' );
643
+		$control = $wp_fields->get_control('post', 'my_test_control', 'my_custom_post_type');
644 644
 
645
-		$this->assertNotEmpty( $control );
645
+		$this->assertNotEmpty($control);
646 646
 
647
-		$this->assertEquals( 'my_test_control', $control->id );
648
-		$this->assertNotEmpty( $control->get_field() );
649
-		$this->assertEquals( 'my_test_field', $control->get_field()->id );
650
-		$this->assertEquals( 'my_test_section', $control->get_parent()->id );
647
+		$this->assertEquals('my_test_control', $control->id);
648
+		$this->assertNotEmpty($control->get_field());
649
+		$this->assertEquals('my_test_field', $control->get_field()->id);
650
+		$this->assertEquals('my_test_section', $control->get_parent()->id);
651 651
 
652 652
 		// Control doesn't exist for this object type / name
653
-		$control = $wp_fields->get_control( 'post', 'my_test_control', 'some_other_post_type' );
653
+		$control = $wp_fields->get_control('post', 'my_test_control', 'some_other_post_type');
654 654
 
655
-		$this->assertEmpty( $control );
655
+		$this->assertEmpty($control);
656 656
 
657 657
 		// Control doesn't exist for this object type / name
658
-		$control = $wp_fields->get_control( 'post', 'my_test_control2', 'my_custom_post_type' );
658
+		$control = $wp_fields->get_control('post', 'my_test_control2', 'my_custom_post_type');
659 659
 
660
-		$this->assertEmpty( $control );
660
+		$this->assertEmpty($control);
661 661
 
662 662
 	}
663 663
 
@@ -672,32 +672,32 @@  discard block
 block discarded – undo
672 672
 		global $wp_fields;
673 673
 
674 674
 		// Add a control / field / section
675
-		$this->test_add_control( 'post', 'my_custom_post_type' );
675
+		$this->test_add_control('post', 'my_custom_post_type');
676 676
 
677 677
 		// Control exists for this object type / name
678
-		$control = $wp_fields->get_control( 'post', 'my_test_control', 'my_custom_post_type' );
678
+		$control = $wp_fields->get_control('post', 'my_test_control', 'my_custom_post_type');
679 679
 
680
-		$this->assertNotEmpty( $control );
680
+		$this->assertNotEmpty($control);
681 681
 
682
-		$this->assertEquals( 'my_test_control', $control->id );
683
-		$this->assertEquals( 'my_test_field', $control->get_field()->id );
684
-		$this->assertEquals( 'my_test_section', $control->get_parent()->id );
682
+		$this->assertEquals('my_test_control', $control->id);
683
+		$this->assertEquals('my_test_field', $control->get_field()->id);
684
+		$this->assertEquals('my_test_section', $control->get_parent()->id);
685 685
 
686 686
 		// Remove control
687
-		$wp_fields->remove_control( 'post', 'my_test_control', 'my_custom_post_type' );
687
+		$wp_fields->remove_control('post', 'my_test_control', 'my_custom_post_type');
688 688
 
689 689
 		// Control no longer exists for this object type / name
690
-		$control = $wp_fields->get_control( 'post', 'my_test_control', 'my_custom_post_type' );
690
+		$control = $wp_fields->get_control('post', 'my_test_control', 'my_custom_post_type');
691 691
 
692
-		$this->assertEmpty( $control );
692
+		$this->assertEmpty($control);
693 693
 
694 694
 		// Remove field's control
695
-		$wp_fields->remove_control( 'post', 'my_test_field_control', 'my_custom_post_type' );
695
+		$wp_fields->remove_control('post', 'my_test_field_control', 'my_custom_post_type');
696 696
 
697 697
 		// Control no longer exists for this object type / name
698
-		$control = $wp_fields->get_control( 'post', 'my_test_field_control', 'my_custom_post_type' );
698
+		$control = $wp_fields->get_control('post', 'my_test_field_control', 'my_custom_post_type');
699 699
 
700
-		$this->assertEmpty( $control );
700
+		$this->assertEmpty($control);
701 701
 
702 702
 	}
703 703
 
Please login to merge, or discard this patch.
wordpress-fields-api.php 1 patch
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  */
14 14
 
15 15
 // @todo Remove this when done testing
16
-if ( defined( 'WP_DEBUG' ) && WP_DEBUG && ! empty( $_GET['no-fields-api'] ) ) {
16
+if (defined('WP_DEBUG') && WP_DEBUG && ! empty($_GET['no-fields-api'])) {
17 17
 	return;
18 18
 }
19 19
 
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 /**
28 28
  * The absolute server path to the fields API directory.
29 29
  */
30
-define( 'WP_FIELDS_API_DIR', plugin_dir_path( __FILE__ ) );
30
+define('WP_FIELDS_API_DIR', plugin_dir_path(__FILE__));
31 31
 
32 32
 /**
33 33
  * On `plugins_loaded`, create an instance of the Fields API manager class.
@@ -35,33 +35,33 @@  discard block
 block discarded – undo
35 35
 function _wp_fields_api_include() {
36 36
 
37 37
 	// Bail if we're already in WP core (depending on the name used)
38
-	if ( class_exists( 'WP_Fields_API' ) || class_exists( 'Fields_API' ) ) {
38
+	if (class_exists('WP_Fields_API') || class_exists('Fields_API')) {
39 39
 		return;
40 40
 	}
41 41
 
42
-	if ( ! defined( 'WP_FIELDS_API_EXAMPLES' ) ) {
43
-		define( 'WP_FIELDS_API_EXAMPLES', false );
42
+	if ( ! defined('WP_FIELDS_API_EXAMPLES')) {
43
+		define('WP_FIELDS_API_EXAMPLES', false);
44 44
 	}
45 45
 
46
-	require_once( WP_FIELDS_API_DIR . 'implementation/wp-includes/fields-api/class-wp-fields-api.php' );
46
+	require_once(WP_FIELDS_API_DIR.'implementation/wp-includes/fields-api/class-wp-fields-api.php');
47 47
 
48 48
 	// Init Fields API class
49 49
 	$GLOBALS['wp_fields'] = WP_Fields_API::get_instance();
50 50
 
51 51
 }
52 52
 
53
-add_action( 'plugins_loaded', '_wp_fields_api_include', 8 );
53
+add_action('plugins_loaded', '_wp_fields_api_include', 8);
54 54
 
55 55
 /**
56 56
  * Implement Fields API Customizer instead of WP Core Customizer.
57 57
  */
58 58
 function _wp_fields_api_customize_include() {
59 59
 
60
-	if ( ! ( ( isset( $_REQUEST['wp_customize'] ) && 'on' == $_REQUEST['wp_customize'] ) || ( is_admin() && 'customize.php' == basename( $_SERVER['PHP_SELF'] ) ) ) ) {
60
+	if ( ! ((isset($_REQUEST['wp_customize']) && 'on' == $_REQUEST['wp_customize']) || (is_admin() && 'customize.php' == basename($_SERVER['PHP_SELF'])))) {
61 61
 		return;
62 62
 	}
63 63
 
64
-	require_once( WP_FIELDS_API_DIR . 'implementation/wp-includes/class-wp-customize-manager.php' );
64
+	require_once(WP_FIELDS_API_DIR.'implementation/wp-includes/class-wp-customize-manager.php');
65 65
 
66 66
 	// Init Customize class
67 67
 	$GLOBALS['wp_customize'] = new WP_Customize_Manager;
@@ -76,63 +76,63 @@  discard block
 block discarded – undo
76 76
  */
77 77
 function _wp_fields_api_implementations() {
78 78
 
79
-	$implementation_dir = WP_FIELDS_API_DIR . 'implementation/wp-includes/fields-api/forms/';
79
+	$implementation_dir = WP_FIELDS_API_DIR.'implementation/wp-includes/fields-api/forms/';
80 80
 
81 81
 	// Meta boxes
82
-	add_action( 'add_meta_boxes', array( 'WP_Fields_API_Meta_Box_Section', 'add_meta_boxes' ), 10, 2 );
82
+	add_action('add_meta_boxes', array('WP_Fields_API_Meta_Box_Section', 'add_meta_boxes'), 10, 2);
83 83
 
84 84
 	// Post
85
-	require_once( $implementation_dir . 'class-wp-fields-api-form-post.php' );
85
+	require_once($implementation_dir.'class-wp-fields-api-form-post.php');
86 86
 
87
-	WP_Fields_API_Form_Post::register( 'post', 'post-edit' );
87
+	WP_Fields_API_Form_Post::register('post', 'post-edit');
88 88
 
89 89
 	// Term
90
-	require_once( $implementation_dir . 'class-wp-fields-api-form-term.php' );
91
-	require_once( $implementation_dir . 'class-wp-fields-api-form-term-add.php' );
90
+	require_once($implementation_dir.'class-wp-fields-api-form-term.php');
91
+	require_once($implementation_dir.'class-wp-fields-api-form-term-add.php');
92 92
 
93
-	WP_Fields_API_Form_Term::register( 'term', 'term-edit' );
94
-	WP_Fields_API_Form_Term_Add::register( 'term', 'term-add' );
93
+	WP_Fields_API_Form_Term::register('term', 'term-edit');
94
+	WP_Fields_API_Form_Term_Add::register('term', 'term-add');
95 95
 
96 96
 	// User
97
-	require_once( $implementation_dir . 'class-wp-fields-api-form-user-edit.php' );
97
+	require_once($implementation_dir.'class-wp-fields-api-form-user-edit.php');
98 98
 
99
-	WP_Fields_API_Form_User_Edit::register( 'user', 'user-edit' );
99
+	WP_Fields_API_Form_User_Edit::register('user', 'user-edit');
100 100
 
101 101
 	// Comment
102
-	require_once( $implementation_dir . 'class-wp-fields-api-form-comment.php' );
102
+	require_once($implementation_dir.'class-wp-fields-api-form-comment.php');
103 103
 
104
-	WP_Fields_API_Form_Comment::register( 'comment', 'comment-edit' );
104
+	WP_Fields_API_Form_Comment::register('comment', 'comment-edit');
105 105
 
106 106
 	// Settings
107
-	require_once( $implementation_dir . 'settings/class-wp-fields-api-form-settings.php' );
108
-	require_once( $implementation_dir . 'settings/class-wp-fields-api-form-settings-general.php' );
107
+	require_once($implementation_dir.'settings/class-wp-fields-api-form-settings.php');
108
+	require_once($implementation_dir.'settings/class-wp-fields-api-form-settings-general.php');
109 109
 
110
-	WP_Fields_API_Form_Settings_General::register( 'settings', 'general' );
110
+	WP_Fields_API_Form_Settings_General::register('settings', 'general');
111 111
 
112 112
 	// Settings API compatibility
113
-	require_once( $implementation_dir . 'settings/class-wp-fields-api-settings-api.php' );
113
+	require_once($implementation_dir.'settings/class-wp-fields-api-settings-api.php');
114 114
 
115 115
 	// Run Settings API compatibility (has it's own hooks)
116 116
 	new WP_Fields_API_Settings_API;
117 117
 
118 118
 }
119
-add_action( 'fields_register', '_wp_fields_api_implementations', 5 );
119
+add_action('fields_register', '_wp_fields_api_implementations', 5);
120 120
 
121 121
 // Post
122
-add_action( 'load-post.php', '_wp_fields_api_load_include', 999 );
122
+add_action('load-post.php', '_wp_fields_api_load_include', 999);
123 123
 
124 124
 // Term
125
-add_action( 'load-edit-tags.php', '_wp_fields_api_load_include', 999 );
125
+add_action('load-edit-tags.php', '_wp_fields_api_load_include', 999);
126 126
 
127 127
 // User
128
-add_action( 'load-user-edit.php', '_wp_fields_api_load_include', 999 );
129
-add_action( 'load-profile.php', '_wp_fields_api_load_include', 999 );
128
+add_action('load-user-edit.php', '_wp_fields_api_load_include', 999);
129
+add_action('load-profile.php', '_wp_fields_api_load_include', 999);
130 130
 
131 131
 // Comment
132
-add_action( 'load-comment.php', '_wp_fields_api_load_include', 999 );
132
+add_action('load-comment.php', '_wp_fields_api_load_include', 999);
133 133
 
134 134
 // Settings
135
-add_action( 'load-options-general.php', '_wp_fields_api_load_include', 999 );
135
+add_action('load-options-general.php', '_wp_fields_api_load_include', 999);
136 136
 
137 137
 function _wp_fields_api_load_include() {
138 138
 
@@ -140,19 +140,19 @@  discard block
 block discarded – undo
140 140
 
141 141
 	static $overridden;
142 142
 
143
-	if ( empty( $overridden ) ) {
143
+	if (empty($overridden)) {
144 144
 		$overridden = array();
145 145
 	}
146 146
 
147
-	$load_path = WP_FIELDS_API_DIR . 'implementation/wp-admin/';
147
+	$load_path = WP_FIELDS_API_DIR.'implementation/wp-admin/';
148 148
 
149
-	if ( file_exists( $load_path . $pagenow ) && ! in_array( $pagenow, $overridden ) ) {
149
+	if (file_exists($load_path.$pagenow) && ! in_array($pagenow, $overridden)) {
150 150
 		$overridden[] = $pagenow;
151 151
 
152 152
 		_wp_fields_api_override_compatibility();
153 153
 
154 154
 		// Load our override
155
-		require_once( $load_path . $pagenow );
155
+		require_once($load_path.$pagenow);
156 156
 
157 157
 		// Bail on original core file, don't run the rest
158 158
 		exit;
@@ -171,19 +171,19 @@  discard block
 block discarded – undo
171 171
 	 * The following hooks are fired to ensure backward compatibility.
172 172
 	 * In all other cases, 'load-' . $pagenow should be used instead.
173 173
 	 */
174
-	if ( $typenow == 'page' ) {
175
-		if ( $pagenow == 'post-new.php' )
176
-			do_action( 'load-page-new.php' );
177
-		elseif ( $pagenow == 'post.php' )
178
-			do_action( 'load-page.php' );
179
-	}  elseif ( $pagenow == 'edit-tags.php' ) {
180
-		if ( $taxnow == 'category' )
181
-			do_action( 'load-categories.php' );
182
-		elseif ( $taxnow == 'link_category' )
183
-			do_action( 'load-edit-link-categories.php' );
174
+	if ($typenow == 'page') {
175
+		if ($pagenow == 'post-new.php')
176
+			do_action('load-page-new.php');
177
+		elseif ($pagenow == 'post.php')
178
+			do_action('load-page.php');
179
+	}  elseif ($pagenow == 'edit-tags.php') {
180
+		if ($taxnow == 'category')
181
+			do_action('load-categories.php');
182
+		elseif ($taxnow == 'link_category')
183
+			do_action('load-edit-link-categories.php');
184 184
 	}
185 185
 
186
-	if ( ! empty( $_REQUEST['action'] ) ) {
186
+	if ( ! empty($_REQUEST['action'])) {
187 187
 		/**
188 188
 		 * Fires when an 'action' request variable is sent.
189 189
 		 *
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 		 *
193 193
 		 * @since 2.6.0
194 194
 		 */
195
-		do_action( 'admin_action_' . $_REQUEST['action'] );
195
+		do_action('admin_action_'.$_REQUEST['action']);
196 196
 	}
197 197
 
198 198
 }
199 199
\ No newline at end of file
Please login to merge, or discard this patch.