| | 2267 | /** |
| | 2268 | * @ticket 48264 |
| | 2269 | */ |
| | 2270 | public function test_update_array_of_ints_meta() { |
| | 2271 | $this->grant_write_permission(); |
| | 2272 | register_post_meta( |
| | 2273 | 'post', |
| | 2274 | 'items', |
| | 2275 | array( |
| | 2276 | 'single' => true, |
| | 2277 | 'type' => 'array', |
| | 2278 | 'show_in_rest' => array( |
| | 2279 | 'schema' => array( |
| | 2280 | 'items' => array( |
| | 2281 | 'type' => 'integer', |
| | 2282 | ), |
| | 2283 | ), |
| | 2284 | ), |
| | 2285 | ) |
| | 2286 | ); |
| | 2287 | |
| | 2288 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); |
| | 2289 | $request->set_body_params( |
| | 2290 | array( |
| | 2291 | 'meta' => array( |
| | 2292 | 'items' => array( 1, 2, 3 ), |
| | 2293 | ), |
| | 2294 | ) |
| | 2295 | ); |
| | 2296 | |
| | 2297 | rest_get_server()->dispatch( $request ); |
| | 2298 | $response = rest_get_server()->dispatch( $request ); |
| | 2299 | $this->assertEquals( 200, $response->get_status() ); |
| | 2300 | } |
| | 2301 | |
| | 2302 | /** |
| | 2303 | * @ticket 48264 |
| | 2304 | */ |
| | 2305 | public function test_update_array_of_ints_meta_stored_strings_are_updated() { |
| | 2306 | $this->grant_write_permission(); |
| | 2307 | register_post_meta( |
| | 2308 | 'post', |
| | 2309 | 'items', |
| | 2310 | array( |
| | 2311 | 'single' => true, |
| | 2312 | 'type' => 'array', |
| | 2313 | 'show_in_rest' => array( |
| | 2314 | 'schema' => array( |
| | 2315 | 'items' => array( |
| | 2316 | 'type' => 'integer', |
| | 2317 | ), |
| | 2318 | ), |
| | 2319 | ), |
| | 2320 | ) |
| | 2321 | ); |
| | 2322 | |
| | 2323 | update_post_meta( self::$post_id, 'items', array( '1', '2', '3' ) ); |
| | 2324 | |
| | 2325 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); |
| | 2326 | $request->set_body_params( |
| | 2327 | array( |
| | 2328 | 'meta' => array( |
| | 2329 | 'items' => array( 1, 2, 3 ), |
| | 2330 | ), |
| | 2331 | ) |
| | 2332 | ); |
| | 2333 | |
| | 2334 | $response = rest_get_server()->dispatch( $request ); |
| | 2335 | $this->assertEquals( 200, $response->get_status() ); |
| | 2336 | $this->assertSame( array( 1, 2, 3 ), get_post_meta( self::$post_id, 'items', true ) ); |
| | 2337 | } |
| | 2338 | |
| | 2339 | /** |
| | 2340 | * @ticket 48264 |
| | 2341 | */ |
| | 2342 | public function test_update_array_of_ints_meta_string_request_data_is_set_as_ints() { |
| | 2343 | $this->grant_write_permission(); |
| | 2344 | register_post_meta( |
| | 2345 | 'post', |
| | 2346 | 'items', |
| | 2347 | array( |
| | 2348 | 'single' => true, |
| | 2349 | 'type' => 'array', |
| | 2350 | 'show_in_rest' => array( |
| | 2351 | 'schema' => array( |
| | 2352 | 'items' => array( |
| | 2353 | 'type' => 'integer', |
| | 2354 | ), |
| | 2355 | ), |
| | 2356 | ), |
| | 2357 | ) |
| | 2358 | ); |
| | 2359 | |
| | 2360 | update_post_meta( self::$post_id, 'items', array( 1, 2, 3 ) ); |
| | 2361 | |
| | 2362 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); |
| | 2363 | $request->set_body_params( |
| | 2364 | array( |
| | 2365 | 'meta' => array( |
| | 2366 | 'items' => array( '1', '2', '3' ), |
| | 2367 | ), |
| | 2368 | ) |
| | 2369 | ); |
| | 2370 | |
| | 2371 | $response = rest_get_server()->dispatch( $request ); |
| | 2372 | $this->assertEquals( 200, $response->get_status() ); |
| | 2373 | $this->assertSame( array( 1, 2, 3 ), get_post_meta( self::$post_id, 'items', true ) ); |
| | 2374 | } |
| | 2375 | |
| | 2376 | /** |
| | 2377 | * @ticket 48264 |
| | 2378 | */ |
| | 2379 | public function test_update_array_of_ints_meta_string_request_data_and_string_stored_data() { |
| | 2380 | $this->grant_write_permission(); |
| | 2381 | register_post_meta( |
| | 2382 | 'post', |
| | 2383 | 'items', |
| | 2384 | array( |
| | 2385 | 'single' => true, |
| | 2386 | 'type' => 'array', |
| | 2387 | 'show_in_rest' => array( |
| | 2388 | 'schema' => array( |
| | 2389 | 'items' => array( |
| | 2390 | 'type' => 'integer', |
| | 2391 | ), |
| | 2392 | ), |
| | 2393 | ), |
| | 2394 | ) |
| | 2395 | ); |
| | 2396 | |
| | 2397 | update_post_meta( self::$post_id, 'items', array( '1', '2', '3' ) ); |
| | 2398 | |
| | 2399 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); |
| | 2400 | $request->set_body_params( |
| | 2401 | array( |
| | 2402 | 'meta' => array( |
| | 2403 | 'items' => array( '1', '2', '3' ), |
| | 2404 | ), |
| | 2405 | ) |
| | 2406 | ); |
| | 2407 | |
| | 2408 | $response = rest_get_server()->dispatch( $request ); |
| | 2409 | $this->assertEquals( 200, $response->get_status() ); |
| | 2410 | $this->assertSame( array( 1, 2, 3 ), get_post_meta( self::$post_id, 'items', true ) ); |
| | 2411 | } |
| | 2412 | |