Changeset 43510 for branches/4.9/tests/phpunit/tests/post/meta.php
- Timestamp:
- 07/19/2018 06:48:52 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.9/tests/phpunit/tests/post/meta.php
r35244 r43510 6 6 */ 7 7 class Tests_Post_Meta extends WP_UnitTestCase { 8 9 private $last_register_meta_call = array( 10 'object_type' => '', 11 'meta_key' => '', 12 'args' => array(), 13 ); 14 8 15 function setUp() { 9 16 parent::setUp(); … … 238 245 239 246 } 247 248 /** 249 * @ticket 38323 250 * @dataProvider data_register_post_meta 251 */ 252 public function test_register_post_meta( $post_type, $meta_key, $args ) { 253 add_filter( 'register_meta_args', array( $this, 'filter_register_meta_args_set_last_register_meta_call' ), 10, 4 ); 254 255 register_post_meta( $post_type, $meta_key, $args ); 256 257 $args['object_subtype'] = $post_type; 258 259 // Reset global so subsequent data tests do not get polluted. 260 $GLOBALS['wp_meta_keys'] = array(); 261 262 $this->assertEquals( 'post', $this->last_register_meta_call['object_type'] ); 263 $this->assertEquals( $meta_key, $this->last_register_meta_call['meta_key'] ); 264 $this->assertEquals( $args, $this->last_register_meta_call['args'] ); 265 } 266 267 public function data_register_post_meta() { 268 return array( 269 array( 'post', 'registered_key1', array( 'single' => true ) ), 270 array( 'page', 'registered_key2', array() ), 271 array( '', 'registered_key3', array( 'sanitize_callback' => 'absint' ) ), 272 ); 273 } 274 275 public function filter_register_meta_args_set_last_register_meta_call( $args, $defaults, $object_type, $meta_key ) { 276 $this->last_register_meta_call['object_type'] = $object_type; 277 $this->last_register_meta_call['meta_key'] = $meta_key; 278 $this->last_register_meta_call['args'] = $args; 279 280 return $args; 281 } 282 283 /** 284 * @ticket 38323 285 * @dataProvider data_unregister_post_meta 286 */ 287 public function test_unregister_post_meta( $post_type, $meta_key ) { 288 global $wp_meta_keys; 289 290 register_post_meta( $post_type, $meta_key, array() ); 291 unregister_post_meta( $post_type, $meta_key ); 292 293 $actual = $wp_meta_keys; 294 295 // Reset global so subsequent data tests do not get polluted. 296 $wp_meta_keys = array(); 297 298 $this->assertEmpty( $actual ); 299 } 300 301 public function data_unregister_post_meta() { 302 return array( 303 array( 'post', 'registered_key1' ), 304 array( 'page', 'registered_key2' ), 305 array( '', 'registered_key3' ), 306 ); 307 } 240 308 }
Note: See TracChangeset
for help on using the changeset viewer.