Make WordPress Core


Ignore:
Timestamp:
06/07/2020 06:44:08 AM (6 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Add additional fields to the themes controller.

When the themes controller was introduced it only returned a theme's supported features. This adds the majority of a theme's header information to the response.

Props ockham, spacedmonkey.
Fixes #49906.

File:
1 edited

Legend:

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

    r47361 r47921  
    126126
    127127        wp_set_current_user( self::$contributor_id );
     128        switch_theme( 'rest-api' );
    128129    }
    129130
     
    151152        $this->check_get_theme_response( $response );
    152153        $fields = array(
     154            'author',
     155            'author_uri',
     156            'description',
     157            'name',
     158            'requires_php',
     159            'requires_wp',
     160            'screenshot',
     161            'stylesheet',
     162            'tags',
     163            'template',
     164            'textdomain',
    153165            'theme_supports',
     166            'theme_uri',
     167            'version',
    154168        );
    155169        $this->assertEqualSets( $fields, array_keys( $data[0] ) );
     
    208222        $data       = $response->get_data();
    209223        $properties = $data['schema']['properties'];
    210         $this->assertEquals( 1, count( $properties ) );
     224        $this->assertEquals( 14, count( $properties ) );
     225
     226        $this->assertArrayHasKey( 'author', $properties );
     227        $this->assertArrayHasKey( 'raw', $properties['author']['properties'] );
     228        $this->assertArrayHasKey( 'rendered', $properties['author']['properties'] );
     229
     230        $this->assertArrayHasKey( 'author_uri', $properties );
     231        $this->assertArrayHasKey( 'raw', $properties['author_uri']['properties'] );
     232        $this->assertArrayHasKey( 'rendered', $properties['author_uri']['properties'] );
     233
     234        $this->assertArrayHasKey( 'description', $properties );
     235        $this->assertArrayHasKey( 'raw', $properties['description']['properties'] );
     236        $this->assertArrayHasKey( 'rendered', $properties['description']['properties'] );
     237
     238        $this->assertArrayHasKey( 'name', $properties );
     239        $this->assertArrayHasKey( 'raw', $properties['name']['properties'] );
     240        $this->assertArrayHasKey( 'rendered', $properties['name']['properties'] );
     241
     242        $this->assertArrayHasKey( 'requires_php', $properties );
     243        $this->assertArrayHasKey( 'requires_wp', $properties );
     244        $this->assertArrayHasKey( 'screenshot', $properties );
     245        $this->assertArrayHasKey( 'stylesheet', $properties );
     246
     247        $this->assertArrayHasKey( 'tags', $properties );
     248        $this->assertArrayHasKey( 'raw', $properties['tags']['properties'] );
     249        $this->assertArrayHasKey( 'items', $properties['tags']['properties']['raw'] );
     250        $this->assertArrayHasKey( 'rendered', $properties['tags']['properties'] );
     251
     252        $this->assertArrayHasKey( 'template', $properties );
     253        $this->assertArrayHasKey( 'textdomain', $properties );
    211254        $this->assertArrayHasKey( 'theme_supports', $properties );
     255
     256        $this->assertArrayHasKey( 'theme_uri', $properties );
     257        $this->assertArrayHasKey( 'raw', $properties['theme_uri']['properties'] );
     258        $this->assertArrayHasKey( 'rendered', $properties['theme_uri']['properties'] );
     259
     260        $this->assertArrayHasKey( 'version', $properties );
     261
    212262        $theme_supports = $properties['theme_supports']['properties'];
    213263        $this->assertEquals( 20, count( $theme_supports ) );
     
    235285
    236286    /**
     287     * @ticket 49906
     288     */
     289    public function test_theme_author() {
     290        $response = self::perform_active_theme_request();
     291        $result   = $response->get_data();
     292        $this->assertArrayHasKey( 'author', $result[0] );
     293        $this->assertSame( 'Michael Heilemann', $result[0]['author']['raw'] );
     294        $this->assertSame(
     295            '<a href="http://binarybonsai.com/?search=1&#038;term=2">Michael Heilemann</a>',
     296            $result[0]['author']['rendered']
     297        );
     298    }
     299
     300    /**
     301     * @ticket 49906
     302     */
     303    public function test_theme_author_uri() {
     304        $response = self::perform_active_theme_request();
     305        $result   = $response->get_data();
     306        $this->assertArrayHasKey( 'author_uri', $result[0] );
     307        $this->assertSame( 'http://binarybonsai.com/?search=1&term=2', $result[0]['author_uri']['raw'] );
     308        $this->assertSame( 'http://binarybonsai.com/?search=1&#038;term=2', $result[0]['author_uri']['rendered'] );
     309    }
     310
     311    /**
     312     * @ticket 49906
     313     */
     314    public function test_theme_description() {
     315        $response = self::perform_active_theme_request();
     316        $result   = $response->get_data();
     317        $this->assertArrayHasKey( 'description', $result[0] );
     318        $this->assertSame(
     319            'The 9\' foot tall theme.',
     320            $result[0]['description']['raw']
     321        );
     322        $this->assertSame(
     323            'The 9&#8242; foot tall theme.',
     324            $result[0]['description']['rendered']
     325        );
     326    }
     327
     328    /**
     329     * @ticket 49906
     330     */
     331    public function test_theme_requires_php() {
     332        $response = self::perform_active_theme_request();
     333        $result   = $response->get_data();
     334        $this->assertArrayHasKey( 'requires_php', $result[0] );
     335        $this->assertSame( '5.6', $result[0]['requires_php'] );
     336    }
     337
     338    /**
     339     * @ticket 49906
     340     */
     341    public function test_theme_requires_wp() {
     342        $response = self::perform_active_theme_request();
     343        $result   = $response->get_data();
     344        $this->assertArrayHasKey( 'requires_wp', $result[0] );
     345        $this->assertSame( '5.3', $result[0]['requires_wp'] );
     346    }
     347
     348    /**
     349     * @ticket 49906
     350     */
     351    public function test_theme_name() {
     352        $response = self::perform_active_theme_request();
     353        $result   = $response->get_data();
     354        $this->assertArrayHasKey( 'name', $result[0] );
     355        $this->assertSame( 'REST Theme', $result[0]['name']['raw'] );
     356        $this->assertSame( 'REST Theme', $result[0]['name']['rendered'] );
     357    }
     358
     359    /**
     360     * @ticket 49906
     361     */
     362    public function test_theme_screenshot() {
     363        $response = self::perform_active_theme_request();
     364        $result   = $response->get_data();
     365        $this->assertArrayHasKey( 'screenshot', $result[0] );
     366        $this->assertSame( '', $result[0]['screenshot'] ); // No screenshot for default theme
     367    }
     368
     369    /**
     370     * @ticket 49906
     371     */
     372    public function test_theme_stylesheet() {
     373        $response = self::perform_active_theme_request();
     374        $result   = $response->get_data();
     375        $this->assertArrayHasKey( 'stylesheet', $result[0] );
     376        $this->assertSame( 'rest-api', $result[0]['stylesheet'] );
     377    }
     378
     379    /**
     380     * @ticket 49906
     381     */
     382    public function test_theme_tags() {
     383        $response = self::perform_active_theme_request();
     384        $result   = $response->get_data();
     385        $this->assertArrayHasKey( 'tags', $result[0] );
     386        $this->assertSame( array( 'holiday', 'custom-menu' ), $result[0]['tags']['raw'] );
     387        $this->assertSame( 'holiday, custom-menu', $result[0]['tags']['rendered'] );
     388    }
     389
     390    /**
     391     * @ticket 49906
     392     */
     393    public function test_theme_template() {
     394        $response = self::perform_active_theme_request();
     395        $result   = $response->get_data();
     396        $this->assertArrayHasKey( 'template', $result[0] );
     397        $this->assertSame( 'default', $result[0]['template'] );
     398    }
     399
     400    /**
     401     * @ticket 49906
     402     */
     403    public function test_theme_textdomain() {
     404        $response = self::perform_active_theme_request();
     405        $result   = $response->get_data();
     406        $this->assertArrayHasKey( 'textdomain', $result[0] );
     407        $this->assertSame( 'rest-api', $result[0]['textdomain'] );
     408    }
     409
     410    public function test_theme_theme_uri() {
     411        $response = self::perform_active_theme_request();
     412        $result   = $response->get_data();
     413        $this->assertArrayHasKey( 'theme_uri', $result[0] );
     414        $this->assertSame( 'http://wordpress.org/?search=1&term=2', $result[0]['theme_uri']['raw'] );
     415        $this->assertSame( 'http://wordpress.org/?search=1&#038;term=2', $result[0]['theme_uri']['rendered'] );
     416    }
     417
     418    /**
     419     * @ticket 49906
     420     */
     421    public function test_theme_version() {
     422        $response = self::perform_active_theme_request();
     423        $result   = $response->get_data();
     424        $this->assertArrayHasKey( 'version', $result[0] );
     425        $this->assertSame( '1.6', $result[0]['version'] );
     426    }
     427
     428    /**
    237429     * @ticket 49037
    238430     */
Note: See TracChangeset for help on using the changeset viewer.