WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/14/2017 08:53:11 AM (2 years ago)
Author:
swissspidy
Message:

REST API: Allow fetching multiple terms at once via the slug parameter.

This matches a similar change previously made for posts (#38579) and an upcoming change for users (#40213).

Props wonderboymusic, MatheusGimenez, curdin.
Fixes #40027.

Merges [40376] to the 4.7 branch.

Location:
branches/4.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/tests/phpunit/tests/rest-api/rest-tags-controller.php

    r39372 r40427  
    375375        $this->assertEquals( 1, count( $data ) );
    376376        $this->assertEquals( 'Apple', $data[0]['name'] );
     377    }
     378
     379    public function test_get_items_slug_array_arg() {
     380        $id1 = $this->factory->tag->create( array( 'name' => 'Taco' ) );
     381        $id2 = $this->factory->tag->create( array( 'name' => 'Enchilada' ) );
     382        $id3 = $this->factory->tag->create( array( 'name' => 'Burrito' ) );
     383        $this->factory->tag->create( array( 'name' => 'Pizza' ) );
     384        $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
     385        $request->set_param( 'slug', array(
     386            'taco',
     387            'burrito',
     388            'enchilada',
     389        ) );
     390        $response = $this->server->dispatch( $request );
     391        $this->assertEquals( 200, $response->get_status() );
     392        $data = $response->get_data();
     393        $names = wp_list_pluck( $data, 'name' );
     394        sort( $names );
     395        $this->assertEquals( array( 'Burrito', 'Enchilada', 'Taco' ), $names );
     396    }
     397
     398    public function test_get_items_slug_csv_arg() {
     399        $id1 = $this->factory->tag->create( array( 'name' => 'Taco' ) );
     400        $id2 = $this->factory->tag->create( array( 'name' => 'Enchilada' ) );
     401        $id3 = $this->factory->tag->create( array( 'name' => 'Burrito' ) );
     402        $this->factory->tag->create( array( 'name' => 'Pizza' ) );
     403        $request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
     404        $request->set_param( 'slug', 'taco,burrito, enchilada');
     405        $response = $this->server->dispatch( $request );
     406        $this->assertEquals( 200, $response->get_status() );
     407        $data = $response->get_data();
     408        $names = wp_list_pluck( $data, 'name' );
     409        sort( $names );
     410        $this->assertEquals( array( 'Burrito', 'Enchilada', 'Taco' ), $names );
    377411    }
    378412
Note: See TracChangeset for help on using the changeset viewer.