Make WordPress Core


Ignore:
Timestamp:
02/21/2024 07:24:14 PM (9 months ago)
Author:
swissspidy
Message:

Editor: Ensure font collection metadata can be properly localized.

Updates wp_register_font_collection() and WP_Font_Collection so that only font families can be loaded from a file or URL.
All metadata, such as name, description, and list of font categories, needs to be passed directly in PHP so that it can be properly localized.

Props swissspidy, mmaattiiaass, grantmkin, youknowriad.
Fixes #60509.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/fonts/font-library/wpRestFontCollectionsController.php

    r57548 r57686  
    3939        file_put_contents( $mock_file, '{"name": "Mock Collection", "font_families": [ "mock" ], "categories": [ "mock" ] }' );
    4040
    41         wp_register_font_collection( 'mock-col-slug', $mock_file );
     41        wp_register_font_collection(
     42            'mock-col-slug',
     43            array(
     44                'name'          => 'My collection',
     45                'font_families' => $mock_file,
     46            )
     47        );
    4248    }
    4349
     
    7985
    8086        wp_set_current_user( self::$admin_id );
    81         wp_register_font_collection( 'invalid-collection', 'invalid-collection-file' );
     87        wp_register_font_collection(
     88            'invalid-collection',
     89            array(
     90                'name'          => 'My collection',
     91                'font_families' => 'invalid-collection-file',
     92            )
     93        );
    8294
    8395        $request  = new WP_REST_Request( 'GET', '/wp/v2/font-collections' );
     
    133145        wp_set_current_user( self::$admin_id );
    134146        $slug = 'invalid-collection';
    135         wp_register_font_collection( $slug, 'invalid-collection-file' );
     147        wp_register_font_collection(
     148            $slug,
     149            array(
     150                'name'          => 'My collection',
     151                'font_families' => 'invalid-collection-file',
     152            )
     153        );
    136154
    137155        $request  = new WP_REST_Request( 'GET', '/wp/v2/font-collections/' . $slug );
     
    140158        wp_unregister_font_collection( $slug );
    141159
    142         $this->assertErrorResponse( 'font_collection_json_missing', $response, 500, 'When the collection json file is invalid, the response should return an error for "font_collection_json_missing" with 500 status.' );
     160        $this->assertErrorResponse( 'font_collection_json_missing', $response, 500 );
    143161    }
    144162
     
    151169        wp_set_current_user( 0 );
    152170        $response = rest_get_server()->dispatch( $request );
    153         $this->assertErrorResponse( 'rest_cannot_read', $response, 401, 'The response status should be 401 for non-authenticated users.' );
     171        $this->assertErrorResponse( 'rest_cannot_read', $response, 401 );
    154172
    155173        wp_set_current_user( self::$editor_id );
    156174        $response = rest_get_server()->dispatch( $request );
    157         $this->assertErrorResponse( 'rest_cannot_read', $response, 403, 'The response status should be 403 for users without the right permissions.' );
     175        $this->assertErrorResponse( 'rest_cannot_read', $response, 403 );
    158176    }
    159177
Note: See TracChangeset for help on using the changeset viewer.