Make WordPress Core


Ignore:
Timestamp:
11/18/2016 06:52:19 PM (8 years ago)
Author:
rachelbaker
Message:

REST API: Remove the karma property and query parameter from the Comments endpoints.

WordPress has not used the karma property internally for the past 8 years. There is no need to expose it in the REST API endpoints. Sites that use karma can include it using the register_rest_field() function.

Props dd32, danielbachhuber.
Fixes #38821.

File:
1 edited

Legend:

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

    r39290 r39292  
    136136            'exclude',
    137137            'include',
    138             'karma',
    139138            'offset',
    140139            'order',
     
    11621161    }
    11631162
    1164     public function test_create_comment_karma_without_permission() {
    1165         wp_set_current_user( self::$subscriber_id );
    1166 
    1167         $params = array(
    1168             'post'         => self::$post_id,
    1169             'author_name'  => 'Homer Jay Simpson',
    1170             'author_email' => 'chunkylover53@aol.com',
    1171             'author_url'   => 'http://compuglobalhypermeganet.com',
    1172             'content'      => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.',
    1173             'author'       => self::$subscriber_id,
    1174             'karma'        => 100,
    1175         );
    1176 
    1177         $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    1178         $request->add_header( 'content-type', 'application/json' );
    1179         $request->set_body( wp_json_encode( $params ) );
    1180         $response = $this->server->dispatch( $request );
    1181 
    1182         $this->assertErrorResponse( 'rest_comment_invalid_karma', $response, 403 );
    1183     }
    1184 
    11851163    public function test_create_comment_invalid_post() {
    11861164        wp_set_current_user( self::$subscriber_id );
     
    11931171            'content'      => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.',
    11941172            'author'       => self::$subscriber_id,
    1195         );
    1196 
    1197         $request = new WP_REST_Request( 'POST', '/wp/v2/comments' );
    1198         $request->add_header( 'content-type', 'application/json' );
    1199         $request->set_body( wp_json_encode( $params ) );
    1200         $response = $this->server->dispatch( $request );
    1201 
    1202         $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    1203     }
    1204 
    1205     public function test_create_comment_karma_invalid_value() {
    1206         wp_set_current_user( self::$subscriber_id );
    1207 
    1208         $params = array(
    1209             'post'       => self::$post_id,
    1210             'author_name'  => 'Homer Jay Simpson',
    1211             'author_email' => 'chunkylover53@aol.com',
    1212             'author_url'   => 'http://compuglobalhypermeganet.com',
    1213             'content'     => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.',
    1214             'author'       => self::$subscriber_id,
    1215             'karma'     => 'themostkarmaever',
    12161173        );
    12171174
     
    16501607            'content'      => 'Testing.',
    16511608            'date'         => '2014-11-07T10:14:25',
    1652             'karma'        => 100,
    16531609            'post'         => $post_id,
    16541610        );
     
    16691625        $this->assertEquals( $params['author_ip'], $comment['author_ip'] );
    16701626        $this->assertEquals( $params['post'], $comment['post'] );
    1671         $this->assertEquals( $params['karma'], $comment['karma'] );
    16721627
    16731628        $this->assertEquals( mysql_to_rfc3339( $updated->comment_date ), $comment['date'] );
     
    22242179        $data = $response->get_data();
    22252180        $properties = $data['schema']['properties'];
    2226         $this->assertEquals( 18, count( $properties ) );
     2181        $this->assertEquals( 17, count( $properties ) );
    22272182        $this->assertArrayHasKey( 'id', $properties );
    22282183        $this->assertArrayHasKey( 'author', $properties );
     
    22362191        $this->assertArrayHasKey( 'date', $properties );
    22372192        $this->assertArrayHasKey( 'date_gmt', $properties );
    2238         $this->assertArrayHasKey( 'karma', $properties );
    22392193        $this->assertArrayHasKey( 'link', $properties );
    22402194        $this->assertArrayHasKey( 'meta', $properties );
     
    23832337            $this->assertEquals( $comment->comment_agent, $data['author_user_agent'] );
    23842338            $this->assertEquals( $comment->comment_content, $data['content']['raw'] );
    2385             $this->assertEquals( $comment->comment_karma, $data['karma'] );
    23862339        }
    23872340
     
    23912344            $this->assertArrayNotHasKey( 'author_user_agent', $data );
    23922345            $this->assertArrayNotHasKey( 'raw', $data['content'] );
    2393             $this->assertArrayNotHasKey( 'karma', $data );
    23942346        }
    23952347    }
Note: See TracChangeset for help on using the changeset viewer.