Make WordPress Core

Ticket #40027: 40027.2.diff

File 40027.2.diff, 3.1 KB (added by curdin, 10 years ago)

Updated functionality, Unit tests added

  • src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

    diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
    index 9d33eaa475..e3614d878d 100644
    class WP_REST_Terms_Controller extends WP_REST_Controller {  
    182182                        'per_page'   => 'number',
    183183                        'search'     => 'search',
    184184                        'slug'       => 'slug',
     185                        'slugs'       => 'slug',
    185186                );
    186187
    187188                $prepared_args = array();
    … … class WP_REST_Terms_Controller extends WP_REST_Controller {  
    981982                        'type'              => 'string',
    982983                );
    983984
     985                $query_params['slugs'] = array(
     986                        'description'       => __( 'Limit result set to terms with a specific slug.' ),
     987                        'type'              => 'array',
     988                        'items'             => array(
     989                                'type'              => 'string'
     990                        ),
     991                );
     992
    984993                /**
    985994                 * Filter collection parameters for the terms controller.
    986995                 *
  • tests/phpunit/tests/rest-api/rest-categories-controller.php

    diff --git tests/phpunit/tests/rest-api/rest-categories-controller.php tests/phpunit/tests/rest-api/rest-categories-controller.php
    index fbf7d06018..931d7cfefe 100644
    class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas  
    6969                        'post',
    7070                        'search',
    7171                        'slug',
     72                        'slugs',
    7273                        ), $keys );
    7374        }
    7475
    … … class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas  
    417418                $this->assertEquals( 'Apple', $data[0]['name'] );
    418419        }
    419420
     421        public function test_get_items_slugs_arg() {
     422                $this->factory->category->create( array( 'name' => 'Taco' ) );
     423                $this->factory->category->create( array( 'name' => 'Burrito' ) );
     424                $this->factory->category->create( array( 'name' => 'Enchilada' ) );
     425                $this->factory->category->create( array( 'name' => 'Pizza' ) );
     426                $this->factory->category->create( array( 'name' => 'Curry' ) );
     427                $request = new WP_REST_Request( 'GET', '/wp/v2/categories' );
     428                $request->set_param( 'slugs', array(
     429                        'taco',
     430                        'burrito',
     431                        'enchilada',
     432                ) );
     433                $response = $this->server->dispatch( $request );
     434                $this->assertEquals( 200, $response->get_status() );
     435                $data = $response->get_data();
     436                $this->assertEquals( 3, count( $data ) );
     437                $this->assertEquals( 'Burrito', $data[0]['name'] );
     438                $this->assertEquals( 'Enchilada', $data[1]['name'] );
     439                $this->assertEquals( 'Taco', $data[2]['name'] );
     440        }
     441
    420442        public function test_get_terms_parent_arg() {
    421443                $category1 = $this->factory->category->create( array( 'name' => 'Parent' ) );
    422444                $this->factory->category->create( array( 'name' => 'Child', 'parent' => $category1 ) );
  • tests/phpunit/tests/rest-api/rest-tags-controller.php

    diff --git tests/phpunit/tests/rest-api/rest-tags-controller.php tests/phpunit/tests/rest-api/rest-tags-controller.php
    index cb81b17159..b07e73ea92 100644
    class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {  
    8282                        'post',
    8383                        'search',
    8484                        'slug',
     85                        'slugs',
    8586                        ), $keys );
    8687        }
    8788