Make WordPress Core


Ignore:
Timestamp:
10/31/2016 11:05:37 AM (8 years ago)
Author:
pento
Message:

REST API: Allow a CSV list of term IDs to be passed to /posts.

[39048] added CSV support to array types, this change explicitly parses term lists as IDs, and adds tests.

Props timmydcrawford, pento.
Fixes #38553.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r39047 r39055  
    200200        $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
    201201        $this->assertTrue( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
     202
    202203        $request->set_param( 'exclude', array( $id2 ) );
     204        $response = $this->server->dispatch( $request );
     205        $data = $response->get_data();
     206        $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
     207        $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
     208
     209        $request->set_param( 'exclude', "$id2" );
    203210        $response = $this->server->dispatch( $request );
    204211        $data = $response->get_data();
     
    13031310        $data = $response->get_data();
    13041311        $this->assertEquals( array( $category['term_id'] ), $data['categories'] );
     1312    }
     1313
     1314    public function test_create_post_with_categories_as_csv() {
     1315        wp_set_current_user( self::$editor_id );
     1316        $category = wp_insert_term( 'Chicken', 'category' );
     1317        $category2 = wp_insert_term( 'Ribs', 'category' );
     1318        $request = new WP_REST_Request( 'POST', '/wp/v2/posts' );
     1319        $params = $this->set_post_data( array(
     1320            'categories' => $category['term_id'] . ',' . $category2['term_id'],
     1321        ) );
     1322        $request->set_body_params( $params );
     1323        $response = $this->server->dispatch( $request );
     1324
     1325        $data = $response->get_data();
     1326        $this->assertEquals( array( $category['term_id'], $category2['term_id'] ), $data['categories'] );
    13051327    }
    13061328
Note: See TracChangeset for help on using the changeset viewer.