- Timestamp:
- 10/21/2019 07:08:34 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-post-meta-fields.php
r46454 r46563 1980 1980 /** 1981 1981 * @ticket 43392 1982 */ 1983 public function test_meta_values_are_not_set_to_null_in_response_if_type_safely_serializable() { 1984 register_post_meta( 1985 'post', 1986 'boolean', 1982 * @ticket 48363 1983 * @dataProvider _dp_meta_values_are_not_set_to_null_in_response_if_type_safely_serializable 1984 */ 1985 public function test_meta_values_are_not_set_to_null_in_response_if_type_safely_serializable( $type, $stored, $expected ) { 1986 register_post_meta( 1987 'post', 1988 'safe', 1987 1989 array( 1988 1990 'single' => true, 1989 1991 'show_in_rest' => true, 1990 'type' => 'boolean',1991 ) 1992 ); 1993 1994 update_post_meta( self::$post_id, ' boolean', 'true');1992 'type' => $type, 1993 ) 1994 ); 1995 1996 update_post_meta( self::$post_id, 'safe', $stored ); 1995 1997 1996 1998 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 1997 1999 $response = rest_get_server()->dispatch( $request ); 1998 2000 1999 $this->assertTrue( $response->get_data()['meta']['boolean'] ); 2001 $this->assertSame( $expected, $response->get_data()['meta']['safe'] ); 2002 } 2003 2004 public function _dp_meta_values_are_not_set_to_null_in_response_if_type_safely_serializable() { 2005 return array( 2006 array( 'boolean', 'true', true ), 2007 array( 'boolean', 'false', false ), 2008 array( 'boolean', '1', true ), 2009 array( 'boolean', '0', false ), 2010 array( 'boolean', '', false ), 2011 array( 'integer', '', 0 ), 2012 array( 'integer', '1', 1 ), 2013 array( 'integer', '0', 0 ), 2014 array( 'number', '', 0.0 ), 2015 array( 'number', '1.1', 1.1 ), 2016 array( 'number', '0.0', 0.0 ), 2017 array( 'string', '', '' ), 2018 array( 'string', '1', '1' ), 2019 array( 'string', '0', '0' ), 2020 array( 'string', 'str', 'str' ), 2021 ); 2000 2022 } 2001 2023 … … 2600 2622 2601 2623 /** 2624 * @ticket 48363 2625 */ 2626 public function test_boolean_meta_update_to_false_stores_0() { 2627 $this->grant_write_permission(); 2628 2629 register_post_meta( 2630 'post', 2631 'boolean', 2632 array( 2633 'single' => true, 2634 'type' => 'boolean', 2635 'show_in_rest' => true, 2636 'sanitize_callback' => function( $value ) { 2637 return $value ? '1' : '0'; 2638 }, 2639 ) 2640 ); 2641 2642 update_post_meta( self::$post_id, 'boolean', 1 ); 2643 2644 $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); 2645 $request->set_body_params( 2646 array( 2647 'meta' => array( 2648 'boolean' => false, 2649 ), 2650 ) 2651 ); 2652 2653 $response = rest_get_server()->dispatch( $request ); 2654 $this->assertEquals( 200, $response->get_status() ); 2655 $this->assertEquals( '0', get_post_meta( self::$post_id, 'boolean', true ) ); 2656 } 2657 2658 /** 2602 2659 * Internal function used to disable an insert query which 2603 2660 * will trigger a wpdb error for testing purposes.
Note: See TracChangeset
for help on using the changeset viewer.