Make WordPress Core


Ignore:
Timestamp:
02/11/2020 01:58:08 AM (5 years ago)
Author:
kadamwhite
Message:

REST API: List all core theme feature support details in /themes endpoint response.

Fully list which first-party core theme features are supported in the /themes endpoint response. This brings the REST API themes controller's response more in line with the output of get_theme_support().

Props adamboro, apieschel, koke, spacedmonkey, TimothyBlynJacobs.
See #49037.

File:
1 edited

Legend:

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

    r46586 r47258  
    189189        $this->assertEquals( 1, count( $properties ) );
    190190        $this->assertArrayHasKey( 'theme_supports', $properties );
    191 
    192         $this->assertEquals( 3, count( $properties['theme_supports']['properties'] ) );
    193         $this->assertArrayHasKey( 'formats', $properties['theme_supports']['properties'] );
    194         $this->assertArrayHasKey( 'post-thumbnails', $properties['theme_supports']['properties'] );
    195         $this->assertArrayHasKey( 'responsive-embeds', $properties['theme_supports']['properties'] );
     191        $theme_supports = $properties['theme_supports']['properties'];
     192        $this->assertEquals( 20, count( $theme_supports ) );
     193        $this->assertArrayHasKey( 'align-wide', $theme_supports );
     194        $this->assertArrayHasKey( 'automatic-feed-links', $theme_supports );
     195        $this->assertArrayHasKey( 'custom-header', $theme_supports );
     196        $this->assertArrayHasKey( 'custom-background', $theme_supports );
     197        $this->assertArrayHasKey( 'custom-logo', $theme_supports );
     198        $this->assertArrayHasKey( 'customize-selective-refresh-widgets', $theme_supports );
     199        $this->assertArrayHasKey( 'title-tag', $theme_supports );
     200        $this->assertArrayHasKey( 'dark-editor-style', $theme_supports );
     201        $this->assertArrayHasKey( 'disable-custom-font-sizes', $theme_supports );
     202        $this->assertArrayHasKey( 'disable-custom-gradients', $theme_supports );
     203        $this->assertArrayHasKey( 'editor-color-palette', $theme_supports );
     204        $this->assertArrayHasKey( 'editor-font-sizes', $theme_supports );
     205        $this->assertArrayHasKey( 'editor-gradient-presets', $theme_supports );
     206        $this->assertArrayHasKey( 'editor-styles', $theme_supports );
     207        $this->assertArrayHasKey( 'formats', $theme_supports );
     208        $this->assertArrayHasKey( 'html5', $theme_supports );
     209        $this->assertArrayHasKey( 'post-thumbnails', $theme_supports );
     210        $this->assertArrayHasKey( 'responsive-embeds', $theme_supports );
     211        $this->assertArrayHasKey( 'title-tag', $theme_supports );
     212        $this->assertArrayHasKey( 'wp-block-styles', $theme_supports );
     213    }
     214
     215    /**
     216     * @ticket 49037
     217     */
     218    public function test_theme_supports_disable_custom_colors_false() {
     219        remove_theme_support( 'disable-custom-colors' );
     220        $response = self::perform_active_theme_request();
     221        $result   = $response->get_data();
     222        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     223        $this->assertArrayHasKey( 'disable-custom-colors', $result[0]['theme_supports'] );
     224        $this->assertFalse( $result[0]['theme_supports']['disable-custom-colors'] );
     225    }
     226
     227    /**
     228     * @ticket 49037
     229     */
     230    public function test_theme_supports_disable_custom_colors_true() {
     231        remove_theme_support( 'disable-custom-colors' );
     232        add_theme_support( 'disable-custom-colors' );
     233        $response = self::perform_active_theme_request();
     234        $result   = $response->get_data();
     235        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     236        $this->assertTrue( $result[0]['theme_supports']['disable-custom-colors'] );
     237    }
     238
     239    /**
     240     * @ticket 49037
     241     */
     242    public function test_theme_supports_disable_custom_font_sizes_false() {
     243        remove_theme_support( 'disable-custom-font-sizes' );
     244        $response = self::perform_active_theme_request();
     245        $result   = $response->get_data();
     246        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     247        $this->assertArrayHasKey( 'disable-custom-font-sizes', $result[0]['theme_supports'] );
     248        $this->assertFalse( $result[0]['theme_supports']['disable-custom-font-sizes'] );
     249    }
     250
     251    /**
     252     * @ticket 49037
     253     */
     254    public function test_theme_supports_disable_custom_font_sizes_true() {
     255        remove_theme_support( 'disable-custom-font-sizes' );
     256        add_theme_support( 'disable-custom-font-sizes' );
     257        $response = self::perform_active_theme_request();
     258        $result   = $response->get_data();
     259        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     260        $this->assertTrue( $result[0]['theme_supports']['disable-custom-font-sizes'] );
     261    }
     262
     263    /**
     264     * @ticket 49037
     265     */
     266    public function test_theme_supports_editor_font_sizes_false() {
     267        remove_theme_support( 'editor-font-sizes' );
     268        $response = self::perform_active_theme_request();
     269        $result   = $response->get_data();
     270        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     271        $this->assertArrayHasKey( 'editor-font-sizes', $result[0]['theme_supports'] );
     272        $this->assertFalse( $result[0]['theme_supports']['editor-font-sizes'] );
     273    }
     274
     275    /**
     276     * @ticket 49037
     277     */
     278    public function test_theme_supports_editor_font_sizes_array() {
     279        remove_theme_support( 'editor-font-sizes' );
     280        $tiny = array(
     281            'name' => 'Tiny',
     282            'size' => 8,
     283            'slug' => 'tiny',
     284        );
     285        add_theme_support( 'editor-font-sizes', array( $tiny ) );
     286        $response = self::perform_active_theme_request();
     287        $result   = $response->get_data();
     288        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     289        $this->assertArrayHasKey( 'editor-font-sizes', $result[0]['theme_supports'] );
     290        $this->assertEquals( array( $tiny ), $result[0]['theme_supports']['editor-font-sizes'] );
     291    }
     292
     293    /**
     294     * @ticket 49037
     295     */
     296    public function test_theme_supports_editor_color_palette_false() {
     297        remove_theme_support( 'editor-color-palette' );
     298        $response = self::perform_active_theme_request();
     299        $result   = $response->get_data();
     300        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     301        $this->assertArrayHasKey( 'editor-color-palette', $result[0]['theme_supports'] );
     302        $this->assertFalse( $result[0]['theme_supports']['editor-color-palette'] );
     303    }
     304
     305    /**
     306     * @ticket 49037
     307     */
     308    public function test_theme_supports_editor_color_palette_array() {
     309        remove_theme_support( 'editor-color-palette' );
     310        $wordpress_blue = array(
     311            'name'  => 'WordPress Blue',
     312            'slug'  => 'wordpress-blue',
     313            'color' => '#0073AA',
     314        );
     315        add_theme_support( 'editor-color-palette', array( $wordpress_blue ) );
     316        $response = self::perform_active_theme_request();
     317        $result   = $response->get_data();
     318        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     319        $this->assertEquals( array( $wordpress_blue ), $result[0]['theme_supports']['editor-color-palette'] );
     320    }
     321
     322    /**
     323     * @ticket 49037
     324     */
     325    public function test_theme_supports_enable_automatic_feed_links() {
     326        remove_theme_support( 'automatic-feed-links' );
     327        add_theme_support( 'automatic-feed-links' );
     328        $response = self::perform_active_theme_request();
     329        $result   = $response->get_data();
     330        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     331        $this->assertTrue( $result[0]['theme_supports']['automatic-feed-links'] );
     332    }
     333
     334    /**
     335     * @ticket 49037
     336     */
     337    public function test_theme_supports_does_not_enable_automatic_feed_links() {
     338        remove_theme_support( 'automatic-feed-links' );
     339        $response = self::perform_active_theme_request();
     340        $result   = $response->get_data();
     341        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     342        $this->assertArrayHasKey( 'automatic-feed-links', $result[0]['theme_supports'] );
     343        $this->assertFalse( $result[0]['theme_supports']['automatic-feed-links'] );
     344    }
     345
     346    /**
     347     * @ticket 49037
     348     */
     349    public function test_theme_does_not_support_custom_logo() {
     350        remove_theme_support( 'custom-logo' );
     351        $response = self::perform_active_theme_request();
     352        $result   = $response->get_data();
     353        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     354        $this->assertArrayHasKey( 'custom-logo', $result[0]['theme_supports'] );
     355        $this->assertFalse( $result[0]['theme_supports']['custom-logo'] );
     356    }
     357
     358    /**
     359     * @ticket 49037
     360     */
     361    public function test_theme_supports_custom_logo() {
     362        remove_theme_support( 'custom-logo' );
     363        $wordpress_logo = array(
     364            'height'      => 100,
     365            'width'       => 400,
     366            'flex-height' => true,
     367            'flex-width'  => true,
     368            'header-text' => array( 'site-title', 'site-description' ),
     369        );
     370        add_theme_support( 'custom-logo', $wordpress_logo );
     371        $response = self::perform_active_theme_request();
     372        $result   = $response->get_data();
     373        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     374        $this->assertEquals( $wordpress_logo, $result[0]['theme_supports']['custom-logo'] );
     375    }
     376
     377    /**
     378     * @ticket 49037
     379     */
     380    public function test_theme_does_not_support_custom_header() {
     381        remove_theme_support( 'custom-header' );
     382        $response = self::perform_active_theme_request();
     383        $result   = $response->get_data();
     384        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     385        $this->assertArrayHasKey( 'custom-header', $result[0]['theme_supports'] );
     386        $this->assertFalse( $result[0]['theme_supports']['custom-header'] );
     387    }
     388
     389    /**
     390     * @ticket 49037
     391     */
     392    public function test_theme_supports_custom_header() {
     393        remove_theme_support( 'custom-header' );
     394        $wordpress_header = array(
     395            'default-image'          => '',
     396            'random-default'         => false,
     397            'width'                  => 0,
     398            'height'                 => 0,
     399            'flex-height'            => false,
     400            'flex-width'             => false,
     401            'default-text-color'     => '',
     402            'header-text'            => true,
     403            'uploads'                => true,
     404            'wp-head-callback'       => '',
     405            'admin-head-callback'    => '',
     406            'admin-preview-callback' => '',
     407            'video'                  => false,
     408            'video-active-callback'  => 'is_front_page',
     409        );
     410        $excluded         = array(
     411            'wp-head-callback',
     412            'admin-head-callback',
     413            'admin-preview-callback',
     414            'video-active-callback',
     415        );
     416        add_theme_support( 'custom-header', $wordpress_header );
     417        $response = self::perform_active_theme_request();
     418        $result   = $response->get_data();
     419        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     420
     421        $expected = array_diff_key( $wordpress_header, array_flip( $excluded ) );
     422        $this->assertEquals( $expected, $result[0]['theme_supports']['custom-header'] );
     423    }
     424
     425    /**
     426     * @ticket 49037
     427     */
     428    public function test_theme_does_not_support_custom_background() {
     429        remove_theme_support( 'custom-background' );
     430        $response = self::perform_active_theme_request();
     431        $result   = $response->get_data();
     432        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     433        $this->assertArrayHasKey( 'custom-background', $result[0]['theme_supports'] );
     434        $this->assertFalse( $result[0]['theme_supports']['custom-background'] );
     435    }
     436
     437    /**
     438     * @ticket 49037
     439     */
     440    public function test_theme_supports_custom_background() {
     441        remove_theme_support( 'custom-background' );
     442        $background = array(
     443            'default-image'          => '',
     444            'default-preset'         => 'default',
     445            'default-position-x'     => 'left',
     446            'default-position-y'     => 'top',
     447            'default-size'           => 'auto',
     448            'default-repeat'         => 'repeat',
     449            'default-attachment'     => 'scroll',
     450            'default-color'          => '',
     451            'wp-head-callback'       => '_custom_background_cb',
     452            'admin-head-callback'    => '',
     453            'admin-preview-callback' => '',
     454        );
     455        $excluded   = array(
     456            'wp-head-callback',
     457            'admin-head-callback',
     458            'admin-preview-callback',
     459        );
     460        add_theme_support( 'custom-background', $background );
     461        $response = self::perform_active_theme_request();
     462        $result   = $response->get_data();
     463        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     464
     465        $expected = array_diff_key( $background, array_flip( $excluded ) );
     466        $this->assertEquals( $expected, $result[0]['theme_supports']['custom-background'] );
     467    }
     468
     469    /**
     470     * @ticket 49037
     471     */
     472    public function test_theme_does_not_support_html5() {
     473        remove_theme_support( 'html5' );
     474        $response = self::perform_active_theme_request();
     475        $result   = $response->get_data();
     476        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     477        $this->assertArrayHasKey( 'html5', $result[0]['theme_supports'] );
     478        $this->assertFalse( $result[0]['theme_supports']['html5'] );
     479    }
     480
     481    /**
     482     * @ticket 49037
     483     */
     484    public function test_theme_supports_html5() {
     485        remove_theme_support( 'html5' );
     486        $html5 = array(
     487            'search-form',
     488            'comment-form',
     489            'comment-list',
     490            'gallery',
     491            'caption',
     492            'script',
     493            'style',
     494        );
     495        add_theme_support( 'html5', $html5 );
     496        $response = self::perform_active_theme_request();
     497        $result   = $response->get_data();
     498        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     499        $this->assertEquals( $html5, $result[0]['theme_supports']['html5'] );
     500    }
     501
     502    /**
     503     * @ticket 49037
     504     */
     505    public function test_theme_cannot_manage_title_tag() {
     506        remove_theme_support( 'title-tag' );
     507        $response = self::perform_active_theme_request();
     508        $result   = $response->get_data();
     509        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     510        $this->assertArrayHasKey( 'title-tag', $result[0]['theme_supports'] );
     511        $this->assertFalse( $result[0]['theme_supports']['title-tag'] );
     512    }
     513
     514    /**
     515     * @ticket 49037
     516     */
     517    public function test_theme_can_manage_title_tag() {
     518        global $_wp_theme_features;
     519        $_wp_theme_features['title-tag'] = true;
     520        $response                        = self::perform_active_theme_request();
     521        $result                          = $response->get_data();
     522        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     523        $this->assertTrue( $result[0]['theme_supports']['title-tag'] );
     524    }
     525
     526    /**
     527     * @ticket 49037
     528     */
     529    public function test_theme_cannot_manage_selective_refresh_for_widgets() {
     530        remove_theme_support( 'customize-selective-refresh-widgets' );
     531        $response = self::perform_active_theme_request();
     532        $result   = $response->get_data();
     533        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     534        $this->assertArrayHasKey( 'customize-selective-refresh-widgets', $result[0]['theme_supports'] );
     535        $this->assertFalse( $result[0]['theme_supports']['customize-selective-refresh-widgets'] );
     536    }
     537
     538    /**
     539     * @ticket 49037
     540     */
     541    public function test_theme_can_manage_selective_refresh_for_widgets() {
     542        remove_theme_support( 'customize-selective-refresh-widgets' );
     543        add_theme_support( 'customize-selective-refresh-widgets' );
     544        $response = self::perform_active_theme_request();
     545        $result   = $response->get_data();
     546        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     547        $this->assertTrue( $result[0]['theme_supports']['customize-selective-refresh-widgets'] );
     548    }
     549
     550    /**
     551     * @ticket 49037
     552     */
     553    public function test_theme_no_wp_block_styles() {
     554        remove_theme_support( 'wp-block-styles' );
     555        $response = self::perform_active_theme_request();
     556        $result   = $response->get_data();
     557        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     558        $this->assertArrayHasKey( 'wp-block-styles', $result[0]['theme_supports'] );
     559        $this->assertFalse( $result[0]['theme_supports']['wp-block-styles'] );
     560    }
     561
     562    /**
     563     * @ticket 49037
     564     */
     565    public function test_theme_wp_block_styles_optin() {
     566        remove_theme_support( 'wp-block-styles' );
     567        add_theme_support( 'wp-block-styles' );
     568        $response = self::perform_active_theme_request();
     569        $result   = $response->get_data();
     570        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     571        $this->assertTrue( $result[0]['theme_supports']['wp-block-styles'] );
     572    }
     573
     574    /**
     575     * @ticket 49037
     576     */
     577    public function test_theme_no_align_wide() {
     578        remove_theme_support( 'align-wide' );
     579        $response = self::perform_active_theme_request();
     580        $result   = $response->get_data();
     581        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     582        $this->assertArrayHasKey( 'align-wide', $result[0]['theme_supports'] );
     583        $this->assertFalse( $result[0]['theme_supports']['align-wide'] );
     584    }
     585
     586    /**
     587     * @ticket 49037
     588     */
     589    public function test_theme_align_wide_optin() {
     590        remove_theme_support( 'align-wide' );
     591        add_theme_support( 'align-wide' );
     592        $response = self::perform_active_theme_request();
     593        $result   = $response->get_data();
     594        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     595        $this->assertTrue( $result[0]['theme_supports']['align-wide'] );
     596    }
     597
     598    /**
     599     * @ticket 49037
     600     */
     601    public function test_theme_no_editor_styles() {
     602        remove_theme_support( 'editor-styles' );
     603        $response = self::perform_active_theme_request();
     604        $result   = $response->get_data();
     605        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     606        $this->assertArrayHasKey( 'editor-styles', $result[0]['theme_supports'] );
     607        $this->assertFalse( $result[0]['theme_supports']['editor-styles'] );
     608    }
     609
     610    /**
     611     * @ticket 49037
     612     */
     613    public function test_theme_editor_styles_optin() {
     614        remove_theme_support( 'editor-styles' );
     615        add_theme_support( 'editor-styles' );
     616        $response = self::perform_active_theme_request();
     617        $result   = $response->get_data();
     618        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     619        $this->assertTrue( $result[0]['theme_supports']['editor-styles'] );
     620    }
     621
     622    /**
     623     * @ticket 49037
     624     */
     625    public function test_theme_no_dark_editor_style() {
     626        remove_theme_support( 'dark-editor-style' );
     627        $response = self::perform_active_theme_request();
     628        $result   = $response->get_data();
     629        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     630        $this->assertArrayHasKey( 'dark-editor-style', $result[0]['theme_supports'] );
     631        $this->assertFalse( $result[0]['theme_supports']['dark-editor-style'] );
     632    }
     633
     634    /**
     635     * @ticket 49037
     636     */
     637    public function test_theme_dark_editor_style_optin() {
     638        remove_theme_support( 'dark-editor-style' );
     639        add_theme_support( 'dark-editor-style' );
     640        $response = self::perform_active_theme_request();
     641        $result   = $response->get_data();
     642        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     643        $this->assertTrue( $result[0]['theme_supports']['dark-editor-style'] );
     644    }
     645
     646    /**
     647     * @ticket 49037
     648     */
     649    public function test_theme_no_disable_custom_gradients() {
     650        remove_theme_support( 'disable-custom-gradients' );
     651        $response = self::perform_active_theme_request();
     652        $result   = $response->get_data();
     653        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     654        $this->assertArrayHasKey( 'disable-custom-gradients', $result[0]['theme_supports'] );
     655        $this->assertFalse( $result[0]['theme_supports']['disable-custom-gradients'] );
     656    }
     657
     658    /**
     659     * @ticket 49037
     660     */
     661    public function test_theme_disable_custom_gradients() {
     662        remove_theme_support( 'disable-custom-gradients' );
     663        add_theme_support( 'disable-custom-gradients' );
     664        $response = self::perform_active_theme_request();
     665        $result   = $response->get_data();
     666        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     667        $this->assertTrue( $result[0]['theme_supports']['disable-custom-gradients'] );
     668    }
     669
     670    /**
     671     * @ticket 49037
     672     */
     673    public function test_theme_supports_editor_gradient_presets_array() {
     674        remove_theme_support( 'editor-gradient-presets' );
     675        $gradient = array(
     676            'name'     => __( 'Vivid cyan blue to vivid purple', 'themeLangDomain' ),
     677            'gradient' => 'linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)',
     678            'slug'     => 'vivid-cyan-blue-to-vivid-purple',
     679        );
     680        add_theme_support( 'editor-gradient-presets', array( $gradient ) );
     681        $response = self::perform_active_theme_request();
     682        $result   = $response->get_data();
     683        $this->assertArrayHasKey( 'theme_supports', $result[0] );
     684        $this->assertEquals( array( $gradient ), $result[0]['theme_supports']['editor-gradient-presets'] );
    196685    }
    197686
Note: See TracChangeset for help on using the changeset viewer.