WordPress.org

Making WordPress.org

Changeset 4900


Ignore:
Timestamp:
02/14/2017 03:54:43 AM (3 years ago)
Author:
dd32
Message:

Plugin Directory: API: Sort the ratings API response from 5..1 for compatibility with WordPress.

Props SergeyBiryukov.
Fixes #2468.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin.php

    r4765 r4900  
    103103        $result['rating'] = ( get_post_meta( $post_id, 'rating', true ) ?: 0 ) * 20; // Stored as 0.0 ~ 5.0, API outputs as 0..100
    104104        $result['ratings'] = array_map( 'intval', (array) get_post_meta( $post_id, 'ratings', true ) );
     105        krsort( $result['ratings'] );
     106
    105107        $result['num_ratings'] = array_sum( $result['ratings'] );
    106108        $result['support_threads'] = intval( get_post_meta( $post_id, 'support_threads', true ) );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tests/phpunit/tests/wporg-plugin-api.php

    r4724 r4900  
    249249        $this->assertObjectHasAttribute( 'ratings', $plugin_info, 'Ratings exists' );
    250250        $this->assertAttributeInternalType( 'array', 'ratings', $plugin_info, 'Ratings should be an array' );
     251        $this->assertEquals( array( 5, 4, 3, 2, 1 ), array_keys( $plugin_info->ratings ), 'Ratings should be ordered from 5 to 1' );
    251252        $this->assertArrayHasKey( '1', $plugin_info->ratings, 'Rating should have an attribute of 1' );
    252253        $this->assertArrayHasKey( '2', $plugin_info->ratings, 'Rating should have an attribute of 2' );
Note: See TracChangeset for help on using the changeset viewer.