Ticket #50781: 50781.3.diff
File 50781.3.diff, 5.3 KB (added by , 4 years ago) |
---|
-
src/wp-includes/class-wp-customize-manager.php
439 439 * 440 440 * @param string|WP_Error $ajax_message Ajax return. 441 441 * @param string $message Optional. UI message. 442 * @param int $response Optional. HTTP response code. 442 443 */ 443 protected function wp_die( $ajax_message, $message = null ) {444 protected function wp_die( $ajax_message, $message = null, $response = 500 ) { 444 445 if ( $this->doing_ajax() ) { 445 446 wp_die( $ajax_message ); 446 447 } … … 472 473 $message .= ob_get_clean(); 473 474 } 474 475 475 wp_die( $message );476 wp_die( $message, $response ); 476 477 } 477 478 478 479 /** … … 521 522 522 523 // If a changeset was provided is invalid. 523 524 if ( isset( $this->_changeset_uuid ) && false !== $this->_changeset_uuid && ! wp_is_uuid( $this->_changeset_uuid ) ) { 524 $this->wp_die( -1, __( 'Invalid changeset UUID ' ));525 $this->wp_die( -1, __( 'Invalid changeset UUID.' ), 404 ); 525 526 } 526 527 527 528 /* … … 548 549 * then send unauthenticated code to prompt re-auth. 549 550 */ 550 551 if ( ! current_user_can( 'customize' ) && ! $this->changeset_post_id() ) { 551 $this->wp_die( $this->messenger_channel ? 0 : -1, __( 'Non-existent changeset UUID.' ) ); 552 $this->wp_die( 553 $this->messenger_channel ? 0 : -1, 554 __( 'Non-existent changeset UUID.' ), 555 404 556 ); 552 557 } 553 558 554 559 if ( ! headers_sent() ) { … … 567 572 // If the requested theme is not the active theme and the user doesn't have 568 573 // the switch_themes cap, bail. 569 574 if ( ! current_user_can( 'switch_themes' ) ) { 570 $this->wp_die( -1, __( 'Sorry, you are not allowed to edit theme options on this site.' ) ); 575 $this->wp_die( 576 -1, 577 __( 'Sorry, you are not allowed to edit theme options on this site.' ), 578 403 579 ); 571 580 } 572 581 573 582 // If the theme has errors while loading, bail. -
tests/phpunit/includes/abstract-testcase.php
443 443 * 444 444 * @throws WPDieException Exception containing the message. 445 445 * 446 * @param string $message The `wp_die()` message. 446 * @param string|WP_Error $message The `wp_die()` message. 447 * @param string|int $title The `wp_die()` title. 448 * @param string|array|int $args The `wp_die()` args. 447 449 */ 448 public function wp_die_handler( $message ) {450 public function wp_die_handler( $message, $title, $args ) { 449 451 if ( is_wp_error( $message ) ) { 450 452 $message = $message->get_error_message(); 451 453 } … … 454 456 $message = '0'; 455 457 } 456 458 457 throw new WPDieException( $message );459 throw new WPDieException( $message, $title, $args ); 458 460 } 459 461 460 462 /** -
tests/phpunit/includes/exceptions.php
6 6 7 7 /** 8 8 * General exception for wp_die(). 9 * 10 * @package WordPress 11 * @subpackage Unit Tests 9 12 */ 10 class WPDieException extends Exception {} 13 class WPDieException extends Exception { 14 /** 15 * Title passed to `wp_die()`. 16 * 17 * @since 5.7.0 18 * 19 * @var string|int 20 */ 21 protected $title; 22 23 /** 24 * Args passed to `wp_die()`. 25 * 26 * @since 5.7.0 27 * 28 * @var string|array|int 29 */ 30 protected $args; 31 32 /** 33 * Constructor. 34 * 35 * @since 5.7.0 36 * 37 * @param string|WP_Error $message The `wp_die()` message. 38 * @param string|int $title The `wp_die()` title. 39 * @param string|array|int $args The `wp_die()` args. 40 */ 41 public function __construct( $message, $title = '', $args = array() ) { 42 parent::__construct( $message ); 43 $this->title = $title; 44 $this->args = $args; 45 } 46 47 /** 48 * Gets the title passed to `wp_die()`. 49 * 50 * @since 5.7.0 51 * 52 * @var string|int 53 */ 54 public function getTitle() { 55 return $this->title; 56 } 57 58 /** 59 * Gets the args passed to `wp_die()`. 60 * 61 * @since 5.7.0 62 * 63 * @var string|array|int 64 */ 65 public function getArgs() { 66 return $this->args; 67 } 68 } 11 69 12 70 /** 13 71 * Exception for cases of wp_die(), for Ajax tests. -
tests/phpunit/tests/customize/manager.php
254 254 $exception = $e; 255 255 } 256 256 $this->assertInstanceOf( 'WPDieException', $exception ); 257 $this->assertContains( 'Invalid changeset UUID', $exception->getMessage() ); 257 $this->assertContains( 'Invalid changeset UUID.', $exception->getMessage() ); 258 $this->assertEquals( 404, $exception->getArgs()['response'] ); 258 259 259 260 update_option( 'fresh_site', '0' ); 260 261 $wp_customize = new WP_Customize_Manager(); … … 312 313 } 313 314 $this->assertInstanceOf( 'WPDieException', $exception ); 314 315 $this->assertContains( 'Non-existent changeset UUID', $exception->getMessage() ); 316 $this->assertEquals( 404, $exception->getArgs()['response'] ); 315 317 316 318 wp_set_current_user( self::$admin_user_id ); 317 319 $wp_customize = new WP_Customize_Manager( array( 'messenger_channel' => 'preview-1' ) );