Make WordPress Core

Changeset 64392


Ignore:
Timestamp:
10/16/2026 03:46:38 PM (13 hours ago)
Author:
lancewillett
Message:

Tests: Separate theme feature validation tests.

Move test_register_theme_support_validation() and its provider into a separate WP_UnitTestCase class to avoid unnecessary theme-directory and cache setup. Preserve all eight datasets, assertions, and expected errors.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14306

Props sainathpoojary.
See #66074.

Location:
trunk/tests/phpunit/tests
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme.php

    r64111 r64392  
    830830
    831831        /**
    832          * @ticket 49406
    833          *
    834          * @dataProvider data_register_theme_support_validation
    835          *
    836          * @param string $error_code The error code expected.
    837          * @param array  $args       The args to register.
    838          */
    839         public function test_register_theme_support_validation( $error_code, $args ) {
    840                 $registered = register_theme_feature( 'test-feature', $args );
    841 
    842                 $this->assertWPError( $registered );
    843                 $this->assertSame( $error_code, $registered->get_error_code() );
    844         }
    845 
    846         public function data_register_theme_support_validation() {
    847                 return array(
    848                         array(
    849                                 'invalid_type',
    850                                 array(
    851                                         'type' => 'float',
    852                                 ),
    853                         ),
    854                         array(
    855                                 'invalid_type',
    856                                 array(
    857                                         'type' => array( 'string' ),
    858                                 ),
    859                         ),
    860                         array(
    861                                 'variadic_must_be_array',
    862                                 array(
    863                                         'variadic' => true,
    864                                 ),
    865                         ),
    866                         array(
    867                                 'missing_schema',
    868                                 array(
    869                                         'type'         => 'object',
    870                                         'show_in_rest' => true,
    871                                 ),
    872                         ),
    873                         array(
    874                                 'missing_schema',
    875                                 array(
    876                                         'type'         => 'array',
    877                                         'show_in_rest' => true,
    878                                 ),
    879                         ),
    880                         array(
    881                                 'missing_schema_items',
    882                                 array(
    883                                         'type'         => 'array',
    884                                         'show_in_rest' => array(
    885                                                 'schema' => array(
    886                                                         'type' => 'array',
    887                                                 ),
    888                                         ),
    889                                 ),
    890                         ),
    891                         array(
    892                                 'missing_schema_properties',
    893                                 array(
    894                                         'type'         => 'object',
    895                                         'show_in_rest' => array(
    896                                                 'schema' => array(
    897                                                         'type' => 'object',
    898                                                 ),
    899                                         ),
    900                                 ),
    901                         ),
    902                         array(
    903                                 'invalid_rest_prepare_callback',
    904                                 array(
    905                                         'show_in_rest' => array(
    906                                                 'prepare_callback' => 'this is not a valid function',
    907                                         ),
    908                                 ),
    909                         ),
    910                 );
    911         }
    912 
    913 
    914         /**
    915832         * Tests that block themes support a feature by default.
    916833         *
Note: See TracChangeset for help on using the changeset viewer.