Make WordPress Core

Changeset 51608


Ignore:
Timestamp:
08/13/2021 02:00:05 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Add unit tests for the wp_nonce_ays() function.

Update the wp_die_handler() method to pass the response into WPDieException so that expectExceptionCode() calls work as expected.

Follow-up to [1221/tests], [3934], [4009], [12309].

Props pbearne, jrf, mukesh27.
Fixes #53882.

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

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/abstract-testcase.php

    r51605 r51608  
    453453     * Throws an exception when called.
    454454     *
    455      * @throws WPDieException Exception containing the message.
    456      *
    457      * @param string $message The `wp_die()` message.
    458      */
    459     public function wp_die_handler( $message ) {
     455     * @since UT (3.7.0)
     456     * @since 5.9.0 Added the `$title` and `$args` parameters.
     457     *
     458     * @throws WPDieException Exception containing the message and the response code.
     459     *
     460     * @param string|WP_Error $message The `wp_die()` message or WP_Error object.
     461     * @param string          $title   The `wp_die()` title.
     462     * @param string|array    $args    The `wp_die()` arguments.
     463     */
     464    public function wp_die_handler( $message, $title, $args ) {
    460465        if ( is_wp_error( $message ) ) {
    461466            $message = $message->get_error_message();
     
    466471        }
    467472
    468         throw new WPDieException( $message );
     473        $code = 0;
     474        if ( isset( $args['response'] ) ) {
     475            $code = $args['response'];
     476        }
     477
     478        throw new WPDieException( $message, $code );
    469479    }
    470480
Note: See TracChangeset for help on using the changeset viewer.