Ticket #46499: 46499-2.diff
File 46499-2.diff, 7.2 KB (added by , 5 years ago) |
---|
-
tests/phpunit/includes/abstract-testcase.php
46 46 return $factory; 47 47 } 48 48 49 /** 50 * Retrieves the name of the current called class. 51 * 52 * @return string The class name. 53 */ 49 54 public static function get_called_class() { 50 55 if ( function_exists( 'get_called_class' ) ) { 51 56 return get_called_class(); … … 61 66 return $backtrace[2]['class']; 62 67 } 63 68 69 /** 70 * Runs the routine before setting up all tests. 71 */ 64 72 public static function setUpBeforeClass() { 65 73 global $wpdb; 66 74 … … 82 90 self::commit_transaction(); 83 91 } 84 92 93 /** 94 * Runs the routine after all tests have been ran. 95 */ 85 96 public static function tearDownAfterClass() { 86 97 parent::tearDownAfterClass(); 87 98 … … 99 110 self::commit_transaction(); 100 111 } 101 112 113 /** 114 * Runs the routine before each test is executed. 115 */ 102 116 public function setUp() { 103 117 set_time_limit( 0 ); 104 118 … … 165 179 wp_set_current_user( 0 ); 166 180 } 167 181 182 /** 183 * Cleans the global scope (e.g the $_GET and $_POST). 184 */ 168 185 public function clean_up_global_scope() { 169 186 $_GET = array(); 170 187 $_POST = array(); … … 306 323 } 307 324 } 308 325 326 /** 327 * Flushes the WordPress cache. 328 */ 309 329 public static function flush_cache() { 310 330 global $wp_object_cache; 311 331 $wp_object_cache->group_ops = array(); … … 341 361 } 342 362 } 343 363 364 /** 365 * Starts a database transaction. 366 */ 344 367 public function start_transaction() { 345 368 global $wpdb; 346 369 $wpdb->query( 'SET autocommit = 0;' ); … … 359 382 $wpdb->query( 'COMMIT;' ); 360 383 } 361 384 385 /** 386 * Replaces the create table statement for a create temporary table statement. 387 * 388 * @param string $query The query to replace the statement for. 389 * 390 * @return string The altered query. 391 */ 362 392 public function _create_temporary_tables( $query ) { 363 393 if ( 'CREATE TABLE' === substr( trim( $query ), 0, 12 ) ) { 364 394 return substr_replace( trim( $query ), 'CREATE TEMPORARY TABLE', 0, 12 ); … … 366 396 return $query; 367 397 } 368 398 399 /** 400 * Replaces the drop table statement for a drop temporary table statement. 401 * 402 * @param string $query The query to replace the statement for. 403 * 404 * @return string The altered query. 405 */ 369 406 public function _drop_temporary_tables( $query ) { 370 407 if ( 'DROP TABLE' === substr( trim( $query ), 0, 10 ) ) { 371 408 return substr_replace( trim( $query ), 'DROP TEMPORARY TABLE', 0, 10 ); … … 373 410 return $query; 374 411 } 375 412 413 /** 414 * Retrieves the die handler. 415 * 416 * @param callable $handler The current die handler. 417 * 418 * @return callable The test die handler. 419 */ 376 420 public function get_wp_die_handler( $handler ) { 377 421 return array( $this, 'wp_die_handler' ); 378 422 } 379 423 424 /** 425 * Throws an exception when called. 426 * 427 * @param string $message The die message. 428 * 429 * @throws WPDieException Exception containing the message. 430 */ 380 431 public function wp_die_handler( $message ) { 381 432 if ( ! is_scalar( $message ) ) { 382 433 $message = '0'; … … 385 436 throw new WPDieException( $message ); 386 437 } 387 438 439 /** 440 * Sets up the expectations for testing a deprecated call. 441 */ 388 442 public function expectDeprecated() { 389 443 $annotations = $this->getAnnotations(); 390 444 foreach ( array( 'class', 'method' ) as $depth ) { … … 405 459 add_action( 'doing_it_wrong_trigger_error', '__return_false' ); 406 460 } 407 461 462 /** 463 * Handles a deprecated expectation. The docbloc should contain `@expectedDeprecated` 464 * to trigger this. 465 */ 408 466 public function expectedDeprecated() { 409 467 $errors = array(); 410 468 … … 493 551 } 494 552 } 495 553 554 /** 555 * Adds a deprecated function to the list of caught deprecated calles. 556 * 557 * @param string $function The deprecated function. 558 */ 496 559 public function deprecated_function_run( $function ) { 497 560 if ( ! in_array( $function, $this->caught_deprecated ) ) { 498 561 $this->caught_deprecated[] = $function; … … 499 562 } 500 563 } 501 564 565 /** 566 * Adds a function that has been called in a wrong way to the list of 567 * doing it wrong calls. 568 * 569 * @param string $function The function to add. 570 */ 502 571 public function doing_it_wrong_run( $function ) { 503 572 if ( ! in_array( $function, $this->caught_doing_it_wrong ) ) { 504 573 $this->caught_doing_it_wrong[] = $function; … … 505 574 } 506 575 } 507 576 577 /** 578 * Checks if the given actual value is an instance of WP_Error. 579 * 580 * @param mixed $actual The actual value to check. 581 * @param string $message The message to show when test fails. 582 */ 508 583 public function assertWPError( $actual, $message = '' ) { 509 584 $this->assertInstanceOf( 'WP_Error', $actual, $message ); 510 585 } 511 586 587 /** 588 * Checks if the given value isn't an instance of WP_Error. 589 * 590 * @param mixed $actual The actual value to check. 591 * @param string $message The message to show when test fails. 592 */ 512 593 public function assertNotWPError( $actual, $message = '' ) { 513 594 if ( is_wp_error( $actual ) && '' === $message ) { 514 595 $message = $actual->get_error_message(); … … 516 597 $this->assertNotInstanceOf( 'WP_Error', $actual, $message ); 517 598 } 518 599 600 601 /** 602 * Checks if the given actual value is an instance of IXR_Error. 603 * 604 * @param mixed $actual The actual value to check. 605 * @param string $message The message to show when test fails. 606 */ 519 607 public function assertIXRError( $actual, $message = '' ) { 520 608 $this->assertInstanceOf( 'IXR_Error', $actual, $message ); 521 609 } 522 610 611 /** 612 * Checks if the given value isn't an instance of IXR_Error. 613 * 614 * @param mixed $actual The actual value to check. 615 * @param string $message The message to show when test fails. 616 */ 523 617 public function assertNotIXRError( $actual, $message = '' ) { 524 618 if ( $actual instanceof IXR_Error && '' === $message ) { 525 619 $message = $actual->message; … … 527 621 $this->assertNotInstanceOf( 'IXR_Error', $actual, $message ); 528 622 } 529 623 624 /** 625 * Checks if the given fields are present in the given object. 626 * 627 * @param object $object The actual object. 628 * @param array $fields The fields to check. 629 */ 530 630 public function assertEqualFields( $object, $fields ) { 531 631 foreach ( $fields as $field_name => $field_value ) { 532 632 if ( $object->$field_name != $field_value ) { … … 535 635 } 536 636 } 537 637 638 /** 639 * Performs an assertion with whitespace being discarded from the expected and actual values. 640 * 641 * @param string $expected The expected value. 642 * @param string $actual The actual value. 643 */ 538 644 public function assertDiscardWhitespace( $expected, $actual ) { 539 645 $this->assertEquals( preg_replace( '/\s*/', '', $expected ), preg_replace( '/\s*/', '', $actual ) ); 540 646 } … … 701 807 * 702 808 * @since 3.5.0 703 809 * 704 * @param int $ticket_id Ticket number .810 * @param int $ticket_id Ticket number 705 811 */ 706 812 public function knownWPBug( $ticket_id ) { 707 813 if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( $ticket_id, self::$forced_tickets ) ) { … … 760 866 * 761 867 * This method defines the constants after including files. 762 868 * 763 * @param Text_Template $template 869 * @param Text_Template $template The template to prepare. 764 870 */ 765 871 public function prepareTemplate( Text_Template $template ) { 766 872 $template->setVar( array( 'constants' => '' ) );