- Timestamp:
- 08/17/2018 01:50:26 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-post-meta-fields.php
r43378 r43571 16 16 17 17 public static function wpSetUpBeforeClass( $factory ) { 18 register_post_type( 'cpt', array( 19 'show_in_rest' => true, 20 'supports' => array( 'custom-fields' ), 21 ) ); 18 register_post_type( 19 'cpt', 20 array( 21 'show_in_rest' => true, 22 'supports' => array( 'custom-fields' ), 23 ) 24 ); 22 25 23 26 self::$wp_meta_keys_saved = isset( $GLOBALS['wp_meta_keys'] ) ? $GLOBALS['wp_meta_keys'] : array(); … … 38 41 39 42 register_meta( 40 'post', 'test_single', array( 43 'post', 44 'test_single', 45 array( 41 46 'show_in_rest' => true, 42 47 'single' => true, … … 45 50 ); 46 51 register_meta( 47 'post', 'test_multi', array( 52 'post', 53 'test_multi', 54 array( 48 55 'show_in_rest' => true, 49 56 'single' => false, … … 52 59 ); 53 60 register_meta( 54 'post', 'test_bad_auth', array( 61 'post', 62 'test_bad_auth', 63 array( 55 64 'show_in_rest' => true, 56 65 'single' => true, … … 60 69 ); 61 70 register_meta( 62 'post', 'test_bad_auth_multi', array( 71 'post', 72 'test_bad_auth_multi', 73 array( 63 74 'show_in_rest' => true, 64 75 'single' => false, … … 69 80 register_meta( 'post', 'test_no_rest', array() ); 70 81 register_meta( 71 'post', 'test_rest_disabled', array( 82 'post', 83 'test_rest_disabled', 84 array( 72 85 'show_in_rest' => false, 73 86 'type' => 'string', … … 75 88 ); 76 89 register_meta( 77 'post', 'test_custom_schema', array( 90 'post', 91 'test_custom_schema', 92 array( 78 93 'single' => true, 79 94 'type' => 'integer', … … 86 101 ); 87 102 register_meta( 88 'post', 'test_custom_schema_multi', array( 103 'post', 104 'test_custom_schema_multi', 105 array( 89 106 'single' => false, 90 107 'type' => 'integer', … … 97 114 ); 98 115 register_meta( 99 'post', 'test_invalid_type', array( 116 'post', 117 'test_invalid_type', 118 array( 100 119 'single' => true, 101 120 'type' => 'lalala', … … 104 123 ); 105 124 register_meta( 106 'post', 'test_no_type', array( 125 'post', 126 'test_no_type', 127 array( 107 128 'single' => true, 108 129 'type' => null, … … 112 133 113 134 register_meta( 114 'post', 'test_custom_name', array( 135 'post', 136 'test_custom_name', 137 array( 115 138 'single' => true, 116 139 'type' => 'string', … … 122 145 123 146 register_meta( 124 'post', 'test_custom_name_multi', array( 147 'post', 148 'test_custom_name_multi', 149 array( 125 150 'single' => false, 126 151 'type' => 'string', … … 131 156 ); 132 157 133 register_post_type( 'cpt', array( 134 'show_in_rest' => true, 135 'supports' => array( 'custom-fields' ), 136 ) ); 137 138 register_post_meta( 'cpt', 'test_cpt_single', array( 139 'show_in_rest' => true, 140 'single' => true, 141 ) ); 142 143 register_post_meta( 'cpt', 'test_cpt_multi', array( 144 'show_in_rest' => true, 145 'single' => false, 146 ) ); 158 register_post_type( 159 'cpt', 160 array( 161 'show_in_rest' => true, 162 'supports' => array( 'custom-fields' ), 163 ) 164 ); 165 166 register_post_meta( 167 'cpt', 168 'test_cpt_single', 169 array( 170 'show_in_rest' => true, 171 'single' => true, 172 ) 173 ); 174 175 register_post_meta( 176 'cpt', 177 'test_cpt_multi', 178 array( 179 'show_in_rest' => true, 180 'single' => false, 181 ) 182 ); 147 183 148 184 // Register 'test_single' on subtype to override for bad auth. 149 register_post_meta( 'cpt', 'test_single', array( 150 'show_in_rest' => true, 151 'single' => true, 152 'auth_callback' => '__return_false', 153 ) ); 185 register_post_meta( 186 'cpt', 187 'test_single', 188 array( 189 'show_in_rest' => true, 190 'single' => true, 191 'auth_callback' => '__return_false', 192 ) 193 ); 154 194 155 195 /** @var WP_REST_Server $wp_rest_server */ … … 259 299 public function test_get_value_types() { 260 300 register_meta( 261 'post', 'test_string', array( 301 'post', 302 'test_string', 303 array( 262 304 'show_in_rest' => true, 263 305 'single' => true, … … 266 308 ); 267 309 register_meta( 268 'post', 'test_number', array( 310 'post', 311 'test_number', 312 array( 269 313 'show_in_rest' => true, 270 314 'single' => true, … … 273 317 ); 274 318 register_meta( 275 'post', 'test_bool', array( 319 'post', 320 'test_bool', 321 array( 276 322 'show_in_rest' => true, 277 323 'single' => true, … … 574 620 public function test_set_value_invalid_value() { 575 621 register_meta( 576 'post', 'my_meta_key', array( 622 'post', 623 'my_meta_key', 624 array( 577 625 'show_in_rest' => true, 578 626 'single' => true, … … 597 645 public function test_set_value_invalid_value_multiple() { 598 646 register_meta( 599 'post', 'my_meta_key', array( 647 'post', 648 'my_meta_key', 649 array( 600 650 'show_in_rest' => true, 601 651 'single' => false, … … 620 670 public function test_set_value_sanitized() { 621 671 register_meta( 622 'post', 'my_meta_key', array( 672 'post', 673 'my_meta_key', 674 array( 623 675 'show_in_rest' => true, 624 676 'single' => true, … … 644 696 public function test_set_value_csv() { 645 697 register_meta( 646 'post', 'my_meta_key', array( 698 'post', 699 'my_meta_key', 700 array( 647 701 'show_in_rest' => true, 648 702 'single' => false, … … 1096 1150 add_post_meta( $post_id, $meta_key, $meta_value ); 1097 1151 1098 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/%s/%d', $endpoint, $post_id ) );1152 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/%s/%d', $endpoint, $post_id ) ); 1099 1153 $response = rest_get_server()->dispatch( $request ); 1100 1154 … … 1149 1203 1150 1204 $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/%s/%d', $endpoint, $post_id ) ); 1151 $request->set_body_params( array( 1152 'meta' => array( 1153 $meta_key => $meta_value, 1154 ), 1155 ) ); 1205 $request->set_body_params( 1206 array( 1207 'meta' => array( 1208 $meta_key => $meta_value, 1209 ), 1210 ) 1211 ); 1156 1212 1157 1213 $response = rest_get_server()->dispatch( $request );
Note: See TracChangeset
for help on using the changeset viewer.