WordPress.org

Make WordPress Core

Ticket #46813: 46813.4.diff

File 46813.4.diff, 1.8 KB (added by tmdesigned, 9 months ago)

Added unit test

  • src/wp-includes/functions.php

     
    29792979                $title = '';
    29802980        }
    29812981
     2982        /* Disable doing_it_wrong checks to prevent additional notices while dying */
     2983        add_filter( 'doing_it_wrong_trigger_error', '__return_false', 10, 1 );
     2984
    29822985        if ( wp_doing_ajax() ) {
    29832986                /**
    29842987                 * Filters the callback for killing WordPress execution for Ajax requests.
  • tests/phpunit/tests/includes/helpers.php

     
    378378        }
    379379
    380380        /**
     381         * This tests that _doing_it_wrong is suppressed in the wp_die() handler
     382         *
     383         * @ticket 46813
     384         */
     385        public function test_wp_die_has_doing_it_wrong_suppressed(){
     386                $expected = "Some Catastrophic Error";
     387
     388                //Unset query to trigger _doing_it_wrong later
     389                unset($GLOBALS['wp_query']);
     390
     391                //Deregister test suite's manipulation of _doing_it_wrong
     392                remove_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ) );
     393                remove_action( 'doing_it_wrong_trigger_error', '__return_false' );
     394
     395                try{
     396                        //remove any other errors
     397                        error_clear_last();
     398                        //trigger our own error, suppressing error handling
     399                        @trigger_error( $expected, E_USER_WARNING );
     400                        //run wp_die to test if _doing_it_wrong runs
     401                        wp_die();
     402                }catch (WPDieException $e){
     403                        //do nothing with exception regardless
     404                }
     405
     406                //test that no additional errors were reported after ours
     407                $last_error_reported = error_get_last();
     408                $this->assertSame( $last_error_reported['message'], $expected );
     409        }
     410       
     411        /**
    381412         * This test is just a setup for the one that follows.
    382413         *
    383414         * @ticket 38196