Changeset 42379
- Timestamp:
- 12/08/2017 09:00:08 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/testcase.php
r42343 r42379 520 520 } 521 521 522 /** 523 * Asserts that the contents of two un-keyed, single arrays are equal, without accounting for the order of elements. 524 * 525 * @since 3.5.0 526 * 527 * @param array $expected Expected array. 528 * @param array $actual Array to check. 529 */ 522 530 function assertEqualSets( $expected, $actual ) { 523 531 sort( $expected ); … … 526 534 } 527 535 536 /** 537 * Asserts that the contents of two keyed, single arrays are equal, without accounting for the order of elements. 538 * 539 * @since 4.1.0 540 * 541 * @param array $expected Expected array. 542 * @param array $actual Array to check. 543 */ 528 544 function assertEqualSetsWithIndex( $expected, $actual ) { 529 545 ksort( $expected ); … … 535 551 * Asserts that the given variable is a multidimensional array, and that all arrays are non-empty. 536 552 * 537 * @param array $array 553 * @since 4.8.0 554 * 555 * @param array $array Array to check. 538 556 */ 539 557 function assertNonEmptyMultidimensionalArray( $array ) { … … 550 568 * Asserts that a condition is not false. 551 569 * 552 * @param bool $condition 553 * @param string $message 570 * This method has been backported from a more recent PHPUnit version, as tests running on PHP 5.2 use 571 * PHPUnit 3.6.x. 572 * 573 * @since 4.7.4 574 * 575 * @param bool $condition Condition to check. 576 * @param string $message Optional. Message to display when the assertion fails. 554 577 * 555 578 * @throws PHPUnit_Framework_AssertionFailedError … … 560 583 561 584 /** 562 * Modify WordPress's query internals as if a given URL has been requested. 585 * Sets the global state to as if a given URL has been requested. 586 * 587 * This sets: 588 * - The super globals. 589 * - The globals. 590 * - The query variables. 591 * - The main query. 592 * 593 * @since 3.5.0 563 594 * 564 595 * @param string $url The URL for the request. … … 609 640 } 610 641 642 /** 643 * Allows tests to be skipped on single or multisite installs by using @group annotations. 644 * 645 * This is a custom extension of the PHPUnit requirements handling. 646 * 647 * Contains legacy code for skipping tests that are associated with an open Trac ticket. Core tests no longer 648 * support this behaviour. 649 * 650 * @since 3.5.0 651 */ 611 652 protected function checkRequirements() { 612 653 parent::checkRequirements(); … … 645 686 646 687 /** 647 * Skips the current test if there is an open WordPress ticket with id $ticket_id 688 * Skips the current test if there is an open Trac ticket associated with it. 689 * 690 * @since 3.5.0 691 * 692 * @param int $ticket_id Ticket number. 648 693 */ 649 694 function knownWPBug( $ticket_id ) { … … 657 702 658 703 /** 659 * @deprecated No longer used since the unit test Trac was merged into Core's. 704 * Skips the current test if there is an open Unit Test Trac ticket associated with it. 705 * 706 * @since 3.5.0 707 * 708 * @deprecated No longer used since the Unit Test Trac was merged into the Core Trac. 709 * 710 * @param int $ticket_id Ticket number. 660 711 */ 661 712 function knownUTBug( $ticket_id ) { … … 664 715 665 716 /** 666 * Skips the current test if there is an open plugin ticket with id $ticket_id 717 * Skips the current test if there is an open Plugin Trac ticket associated with it. 718 * 719 * @since 3.5.0 720 * 721 * @param int $ticket_id Ticket number. 667 722 */ 668 723 function knownPluginBug( $ticket_id ) { … … 675 730 } 676 731 732 /** 733 * Adds a Trac ticket number to the `$forced_tickets` property. 734 * 735 * @since 3.5.0 736 * 737 * @param int $ticket Ticket number. 738 */ 677 739 public static function forceTicket( $ticket ) { 678 740 self::$forced_tickets[] = $ticket; … … 680 742 681 743 /** 682 * Define constants after including files. 744 * Custom preparations for the PHPUnit process isolation template. 745 * 746 * When restoring global state between tests, PHPUnit defines all the constants that were already defined, and then 747 * includes included files. This does not work with WordPress, as the included files define the constants. 748 * 749 * This method defines the constants after including files. 750 * 751 * @param Text_Template $template 683 752 */ 684 753 function prepareTemplate( Text_Template $template ) { … … 689 758 690 759 /** 691 * Returns the name of a temporary file 760 * Creates a unique temporary file name. 761 * 762 * The directory in which the file is created depends on the environment configuration. 763 * 764 * @since 3.5.0 765 * 766 * @return string|bool Path on success, else false. 692 767 */ 693 768 function temp_filename() { … … 708 783 709 784 /** 710 * Check each of the WP_Query is_* functions/properties against expected boolean value.785 * Checks each of the WP_Query is_* functions/properties against expected boolean value. 711 786 * 712 787 * Any properties that are listed by name as parameters will be expected to be true; all others are 713 788 * expected to be false. For example, assertQueryTrue('is_single', 'is_feed') means is_single() 714 789 * and is_feed() must be true and everything else must be false to pass. 790 * 791 * @since 2.5.0 792 * @since 3.8.0 Moved from `Tests_Query_Conditionals` to `WP_UnitTestCase`. 715 793 * 716 794 * @param string $prop,... Any number of WP_Query properties that are expected to be true for the current request. … … 776 854 } 777 855 856 /** 857 * Selectively deletes a file. 858 * 859 * Does not delete a file if its path is set in the `$ignore_files` property. 860 * 861 * @param string $file File path. 862 */ 778 863 function unlink( $file ) { 779 864 $exists = is_file( $file ); … … 786 871 } 787 872 873 /** 874 * Selectively deletes files from a directory. 875 * 876 * Does not delete files if their paths are set in the `$ignore_files` property. 877 * 878 * @param string $path Directory path. 879 */ 788 880 function rmdir( $path ) { 789 881 $files = $this->files_in_dir( $path ); … … 795 887 } 796 888 889 /** 890 * Deletes files added to the `uploads` directory during tests. 891 * 892 * This method works in tandem with the `setUp()` and `rmdir()` methods: 893 * - `setUp()` scans the `uploads` directory before every test, and stores its contents inside of the 894 * `$ignore_files` property. 895 * - `rmdir()` and its helper methods only delete files that are not listed in the `$ignore_files` property. If 896 * called during `tearDown()` in tests, this will only delete files added during the previously run test. 897 */ 797 898 function remove_added_uploads() { 798 // Remove all uploads.799 899 $uploads = wp_upload_dir(); 800 900 $this->rmdir( $uploads['basedir'] ); 801 901 } 802 902 903 /** 904 * Returns a list of all files contained inside a directory. 905 * 906 * @since 4.0.0 907 * 908 * @param string $dir Path to the directory to scan. 909 * 910 * @return array List of file paths. 911 */ 803 912 function files_in_dir( $dir ) { 804 913 $files = array(); … … 815 924 } 816 925 926 /** 927 * Returns a list of all files contained inside the `uploads` directory. 928 * 929 * @since 4.0.0 930 * 931 * @return array List of file paths. 932 */ 817 933 function scan_user_uploads() { 818 934 static $files = array(); … … 826 942 } 827 943 944 /** 945 * Deletes all directories contained inside a directory. 946 * 947 * @since 4.1.0 948 * 949 * @param string $path Path to the directory to scan. 950 */ 828 951 function delete_folders( $path ) { 829 952 $this->matched_dirs = array(); … … 839 962 } 840 963 964 /** 965 * Retrieves all directories contained inside a directory and stores them in the `$matched_dirs` property. Hidden 966 * directories are ignored. 967 * 968 * This is a helper for the `delete_folders()` method. 969 * 970 * @since 4.1.0 971 * 972 * @param string $dir Path to the directory to scan. 973 */ 841 974 function scandir( $dir ) { 842 975 foreach ( scandir( $dir ) as $path ) { … … 849 982 850 983 /** 851 * Helper to Convert a microtime string into a float 984 * Converts a microtime string into a float. 985 * 986 * @since 4.1.0 987 * 988 * @param string $microtime Time string generated by `microtime()`. 989 * 990 * @return float `microtime()` output as a float. 852 991 */ 853 992 protected function _microtime_to_float( $microtime ) { … … 857 996 858 997 /** 859 * Multisite-agnostic way to delete a user from the database.998 * Deletes a user from the database in a Multisite-agnostic way. 860 999 * 861 1000 * @since 4.3.0 1001 * 1002 * @param int $user_id User ID. 1003 * 1004 * @return bool True if the user was deleted. 862 1005 */ 863 1006 public static function delete_user( $user_id ) { … … 870 1013 871 1014 /** 872 * Utility method that resets permalinks and flushes rewrites.1015 * Resets permalinks and flushes rewrites. 873 1016 * 874 1017 * @since 4.4.0 … … 886 1029 } 887 1030 1031 /** 1032 * Creates an attachment post from an uploaded file. 1033 * 1034 * @since 4.4.0 1035 * 1036 * @param array $upload Array of information about the uploaded file, provided by wp_upload_bits(). 1037 * @param int $parent_post_id Optional. Parent post ID. 1038 * 1039 * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure. 1040 */ 888 1041 function _make_attachment( $upload, $parent_post_id = 0 ) { 889 1042 $type = ''; … … 906 1059 ); 907 1060 908 // Save the data909 1061 $id = wp_insert_attachment( $attachment, $upload['file'], $parent_post_id ); 910 1062 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); … … 913 1065 914 1066 /** 915 * There's no way to change post_modified through WP functions. 1067 * Updates the modified and modified GMT date of a post in the database. 1068 * 1069 * @since 4.8.0 1070 * 1071 * @global wpdb $wpdb WordPress database abstraction object. 1072 * 1073 * @param int $post_id Post ID. 1074 * @param string $date Post date, in the format YYYY-MM-DD HH:MM:SS. 1075 * 1076 * @return int|false 1 on success, or false on error. 916 1077 */ 917 1078 protected function update_post_modified( $post_id, $date ) {
Note: See TracChangeset
for help on using the changeset viewer.