Ticket #46499: 46499.diff
File 46499.diff, 11.1 KB (added by , 6 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 * 72 * @return void 73 */ 64 74 public static function setUpBeforeClass() { 65 75 global $wpdb; 66 76 … … 82 92 self::commit_transaction(); 83 93 } 84 94 95 /** 96 * Runs the routine after all tests have been ran. 97 * 98 * @return void 99 */ 85 100 public static function tearDownAfterClass() { 86 101 parent::tearDownAfterClass(); 87 102 … … 99 114 self::commit_transaction(); 100 115 } 101 116 117 /** 118 * Runs the routine before each test is executed. 119 * 120 * @return void 121 */ 102 122 public function setUp() { 103 123 set_time_limit( 0 ); 104 124 … … 138 158 139 159 /** 140 160 * After a test method runs, reset any state in WordPress the test method might have changed. 161 * 162 * @return void 141 163 */ 142 164 public function tearDown() { 143 165 global $wpdb, $wp_query, $wp; … … 165 187 wp_set_current_user( 0 ); 166 188 } 167 189 190 /** 191 * Cleans the global scope (e.g the $_GET and $_POST). 192 * 193 * @return void 194 */ 168 195 public function clean_up_global_scope() { 169 196 $_GET = array(); 170 197 $_POST = array(); … … 306 333 } 307 334 } 308 335 336 /** 337 * Flushes the WordPress cache. 338 * 339 * @return void 340 */ 309 341 public static function flush_cache() { 310 342 global $wp_object_cache; 311 343 $wp_object_cache->group_ops = array(); … … 341 373 } 342 374 } 343 375 376 /** 377 * Starts a database transaction. 378 * 379 * @return void 380 */ 344 381 public function start_transaction() { 345 382 global $wpdb; 346 383 $wpdb->query( 'SET autocommit = 0;' ); … … 359 396 $wpdb->query( 'COMMIT;' ); 360 397 } 361 398 399 /** 400 * Replaces the create table statement for a create temporary table statement. 401 * 402 * @param string $query The query to replace the statement for. 403 * 404 * @return string The altered query. 405 */ 362 406 public function _create_temporary_tables( $query ) { 363 407 if ( 'CREATE TABLE' === substr( trim( $query ), 0, 12 ) ) { 364 408 return substr_replace( trim( $query ), 'CREATE TEMPORARY TABLE', 0, 12 ); … … 366 410 return $query; 367 411 } 368 412 413 /** 414 * Replaces the drop table statement for a drop temporary table statement. 415 * 416 * @param string $query The query to replace the statement for. 417 * 418 * @return string The altered query. 419 */ 369 420 public function _drop_temporary_tables( $query ) { 370 421 if ( 'DROP TABLE' === substr( trim( $query ), 0, 10 ) ) { 371 422 return substr_replace( trim( $query ), 'DROP TEMPORARY TABLE', 0, 10 ); … … 373 424 return $query; 374 425 } 375 426 427 /** 428 * Retrieves the die handler. 429 * 430 * @param callable $handler The current die handler. 431 * 432 * @return callable The test die handler. 433 */ 376 434 public function get_wp_die_handler( $handler ) { 377 435 return array( $this, 'wp_die_handler' ); 378 436 } 379 437 438 /** 439 * Throws an exception when called. 440 * 441 * @param string $message The die message. 442 * 443 * @throws WPDieException Exception containing the message. 444 */ 380 445 public function wp_die_handler( $message ) { 381 446 if ( ! is_scalar( $message ) ) { 382 447 $message = '0'; … … 385 450 throw new WPDieException( $message ); 386 451 } 387 452 453 /** 454 * Sets up the expectations for testing a deprecated call. 455 * 456 * @Return void 457 */ 388 458 public function expectDeprecated() { 389 459 $annotations = $this->getAnnotations(); 390 460 foreach ( array( 'class', 'method' ) as $depth ) { … … 405 475 add_action( 'doing_it_wrong_trigger_error', '__return_false' ); 406 476 } 407 477 478 /** 479 * Handles a deprecated expectation. The docbloc should contain `@expectedDeprecated` 480 * to trigger this. 481 * 482 * @return void 483 */ 408 484 public function expectedDeprecated() { 409 485 $errors = array(); 410 486 … … 493 569 } 494 570 } 495 571 572 /** 573 * Adds a deprecated function to the list of caught deprecated calles. 574 * 575 * @param string $function The deprecated function. 576 * 577 * @return void 578 */ 496 579 public function deprecated_function_run( $function ) { 497 580 if ( ! in_array( $function, $this->caught_deprecated ) ) { 498 581 $this->caught_deprecated[] = $function; … … 499 582 } 500 583 } 501 584 585 /** 586 * Adds a function that has been called in a wrong way to the list of 587 * doing it wrong calls. 588 * 589 * @param string $function The function to add. 590 * 591 * @return void 592 */ 502 593 public function doing_it_wrong_run( $function ) { 503 594 if ( ! in_array( $function, $this->caught_doing_it_wrong ) ) { 504 595 $this->caught_doing_it_wrong[] = $function; … … 505 596 } 506 597 } 507 598 599 /** 600 * Checks if the given actual value is an instance of WP_Error. 601 * 602 * @param mixed $actual The actual value to check. 603 * @param string $message The message to show when test fails. 604 * 605 * @return void 606 */ 508 607 public function assertWPError( $actual, $message = '' ) { 509 608 $this->assertInstanceOf( 'WP_Error', $actual, $message ); 510 609 } 511 610 611 /** 612 * Checks if the given value isn't an instance of WP_Error. 613 * 614 * @param mixed $actual The actual value to check. 615 * @param string $message The message to show when test fails. 616 * 617 * @return void 618 */ 512 619 public function assertNotWPError( $actual, $message = '' ) { 513 620 if ( is_wp_error( $actual ) && '' === $message ) { 514 621 $message = $actual->get_error_message(); … … 516 623 $this->assertNotInstanceOf( 'WP_Error', $actual, $message ); 517 624 } 518 625 626 627 /** 628 * Checks if the given actual value is an instance of IXR_Error. 629 * 630 * @param mixed $actual The actual value to check. 631 * @param string $message The message to show when test fails. 632 * 633 * @return void 634 */ 519 635 public function assertIXRError( $actual, $message = '' ) { 520 636 $this->assertInstanceOf( 'IXR_Error', $actual, $message ); 521 637 } 522 638 639 /** 640 * Checks if the given value isn't an instance of IXR_Error. 641 * 642 * @param mixed $actual The actual value to check. 643 * @param string $message The message to show when test fails. 644 * 645 * @return void 646 */ 523 647 public function assertNotIXRError( $actual, $message = '' ) { 524 648 if ( $actual instanceof IXR_Error && '' === $message ) { 525 649 $message = $actual->message; … … 527 651 $this->assertNotInstanceOf( 'IXR_Error', $actual, $message ); 528 652 } 529 653 654 /** 655 * Checks if the given fields are present in the given object. 656 * 657 * @param object $object The actual object. 658 * @param array $fields The fields to check. 659 * 660 * @return void 661 */ 530 662 public function assertEqualFields( $object, $fields ) { 531 663 foreach ( $fields as $field_name => $field_value ) { 532 664 if ( $object->$field_name != $field_value ) { … … 535 667 } 536 668 } 537 669 670 /** 671 * Performs an assertion with whitespace being discarded from the expected and actual values. 672 * 673 * @param string $expected The expected value. 674 * @param string $actual The actual value. 675 * 676 * @return void 677 */ 538 678 public function assertDiscardWhitespace( $expected, $actual ) { 539 679 $this->assertEquals( preg_replace( '/\s*/', '', $expected ), preg_replace( '/\s*/', '', $actual ) ); 540 680 } … … 546 686 * 547 687 * @param array $expected Expected array. 548 688 * @param array $actual Array to check. 689 * 690 * @return void 549 691 */ 550 692 public function assertEqualSets( $expected, $actual ) { 551 693 sort( $expected ); … … 560 702 * 561 703 * @param array $expected Expected array. 562 704 * @param array $actual Array to check. 705 * 706 * @return void 563 707 */ 564 708 public function assertEqualSetsWithIndex( $expected, $actual ) { 565 709 ksort( $expected ); … … 573 717 * @since 4.8.0 574 718 * 575 719 * @param array $array Array to check. 720 * 721 * @return void 576 722 */ 577 723 public function assertNonEmptyMultidimensionalArray( $array ) { 578 724 $this->assertTrue( is_array( $array ) ); … … 596 742 * @since 3.5.0 597 743 * 598 744 * @param string $url The URL for the request. 745 * 746 * @return void 599 747 */ 600 748 public function go_to( $url ) { 601 749 // note: the WP and WP_Query classes like to silently fetch parameters … … 651 799 * support this behaviour. 652 800 * 653 801 * @since 3.5.0 802 * 803 * @return void 654 804 */ 655 805 protected function checkRequirements() { 656 806 parent::checkRequirements(); … … 701 851 * 702 852 * @since 3.5.0 703 853 * 704 * @param int $ticket_id Ticket number. 854 * @param int $ticket_id Ticket number 855 * 856 * @return void 705 857 */ 706 858 public function knownWPBug( $ticket_id ) { 707 859 if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( $ticket_id, self::$forced_tickets ) ) { … … 731 883 * @since 3.5.0 732 884 * 733 885 * @param int $ticket_id Ticket number. 886 * 887 * @return void 734 888 */ 735 889 public function knownPluginBug( $ticket_id ) { 736 890 if ( WP_TESTS_FORCE_KNOWN_BUGS || in_array( 'Plugin' . $ticket_id, self::$forced_tickets ) ) { … … 747 901 * @since 3.5.0 748 902 * 749 903 * @param int $ticket Ticket number. 904 * 905 * @return void 750 906 */ 751 907 public static function forceTicket( $ticket ) { 752 908 self::$forced_tickets[] = $ticket; … … 760 916 * 761 917 * This method defines the constants after including files. 762 918 * 763 * @param Text_Template $template 919 * @param Text_Template $template The template to prepare. 920 * 921 * @return void 764 922 */ 765 923 public function prepareTemplate( Text_Template $template ) { 766 924 $template->setVar( array( 'constants' => '' ) ); … … 804 962 * @since 3.8.0 Moved from `Tests_Query_Conditionals` to `WP_UnitTestCase`. 805 963 * 806 964 * @param string $prop,... Any number of WP_Query properties that are expected to be true for the current request. 965 * 966 * @return void 807 967 */ 808 968 public function assertQueryTrue() { 809 969 global $wp_query; … … 871 1031 * Does not delete a file if its path is set in the `$ignore_files` property. 872 1032 * 873 1033 * @param string $file File path. 1034 * 1035 * @return void 874 1036 */ 875 1037 public function unlink( $file ) { 876 1038 $exists = is_file( $file ); … … 888 1050 * Does not delete files if their paths are set in the `$ignore_files` property. 889 1051 * 890 1052 * @param string $path Directory path. 1053 * 1054 * @return void 891 1055 */ 892 1056 public function rmdir( $path ) { 893 1057 $files = $this->files_in_dir( $path ); … … 906 1070 * `$ignore_files` property. 907 1071 * - `rmdir()` and its helper methods only delete files that are not listed in the `$ignore_files` property. If 908 1072 * called during `tearDown()` in tests, this will only delete files added during the previously run test. 1073 * 1074 * @return void 909 1075 */ 910 1076 public function remove_added_uploads() { 911 1077 $uploads = wp_upload_dir(); … … 959 1125 * @since 4.1.0 960 1126 * 961 1127 * @param string $path Path to the directory to scan. 1128 * 1129 * @return void 962 1130 */ 963 1131 public function delete_folders( $path ) { 964 1132 $this->matched_dirs = array(); … … 982 1150 * @since 4.1.0 983 1151 * 984 1152 * @param string $dir Path to the directory to scan. 1153 * 1154 * @return void 985 1155 */ 986 1156 public function scandir( $dir ) { 987 1157 foreach ( scandir( $dir ) as $path ) { … … 1031 1201 * @global WP_Rewrite $wp_rewrite 1032 1202 * 1033 1203 * @param string $structure Optional. Permalink structure to set. Default empty. 1204 * 1205 * @return void 1034 1206 */ 1035 1207 public function set_permalink_structure( $structure = '' ) { 1036 1208 global $wp_rewrite;