Changeset 43378 for trunk/tests/phpunit/tests/term/meta.php
- Timestamp:
- 06/21/2018 09:06:50 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term/meta.php
r42343 r43378 7 7 */ 8 8 class Tests_Term_Meta extends WP_UnitTestCase { 9 10 private $last_register_meta_call = array( 11 'object_type' => '', 12 'meta_key' => '', 13 'args' => array(), 14 ); 15 9 16 public function setUp() { 10 17 parent::setUp(); … … 464 471 $q->set( 'cache_results', true ); 465 472 } 473 474 /** 475 * @ticket 38323 476 * @dataProvider data_register_term_meta 477 */ 478 public function test_register_term_meta( $taxonomy, $meta_key, $args ) { 479 add_filter( 'register_meta_args', array( $this, 'filter_register_meta_args_set_last_register_meta_call' ), 10, 4 ); 480 481 register_term_meta( $taxonomy, $meta_key, $args ); 482 483 $args['object_subtype'] = $taxonomy; 484 485 // Reset global so subsequent data tests do not get polluted. 486 $GLOBALS['wp_meta_keys'] = array(); 487 488 $this->assertEquals( 'term', $this->last_register_meta_call['object_type'] ); 489 $this->assertEquals( $meta_key, $this->last_register_meta_call['meta_key'] ); 490 $this->assertEquals( $args, $this->last_register_meta_call['args'] ); 491 } 492 493 public function data_register_term_meta() { 494 return array( 495 array( 'wptests_tax', 'registered_key1', array( 'single' => true ) ), 496 array( 'category', 'registered_key2', array() ), 497 array( '', 'registered_key3', array( 'sanitize_callback' => 'absint' ) ), 498 ); 499 } 500 501 public function filter_register_meta_args_set_last_register_meta_call( $args, $defaults, $object_type, $meta_key ) { 502 $this->last_register_meta_call['object_type'] = $object_type; 503 $this->last_register_meta_call['meta_key'] = $meta_key; 504 $this->last_register_meta_call['args'] = $args; 505 506 return $args; 507 } 508 509 /** 510 * @ticket 38323 511 * @dataProvider data_unregister_term_meta 512 */ 513 public function test_unregister_term_meta( $taxonomy, $meta_key ) { 514 global $wp_meta_keys; 515 516 register_term_meta( $taxonomy, $meta_key, array() ); 517 unregister_term_meta( $taxonomy, $meta_key ); 518 519 $actual = $wp_meta_keys; 520 521 // Reset global so subsequent data tests do not get polluted. 522 $wp_meta_keys = array(); 523 524 $this->assertEmpty( $actual ); 525 } 526 527 public function data_unregister_term_meta() { 528 return array( 529 array( 'wptests_tax', 'registered_key1' ), 530 array( 'category', 'registered_key2' ), 531 array( '', 'registered_key3' ), 532 ); 533 } 466 534 }
Note: See TracChangeset
for help on using the changeset viewer.