Make WordPress Core


Ignore:
Timestamp:
12/08/2017 09:00:08 PM (6 years ago)
Author:
johnbillion
Message:

Build/Test tools: Add inline documentation to undocumented methods in the WP_UnitTestCase class.

Props Frank Klein

Fixes #42731

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase.php

    r42343 r42379  
    520520    }
    521521
     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     */
    522530    function assertEqualSets( $expected, $actual ) {
    523531        sort( $expected );
     
    526534    }
    527535
     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     */
    528544    function assertEqualSetsWithIndex( $expected, $actual ) {
    529545        ksort( $expected );
     
    535551     * Asserts that the given variable is a multidimensional array, and that all arrays are non-empty.
    536552     *
    537      * @param array $array
     553     * @since 4.8.0
     554     *
     555     * @param array $array Array to check.
    538556     */
    539557    function assertNonEmptyMultidimensionalArray( $array ) {
     
    550568     * Asserts that a condition is not false.
    551569     *
    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.
    554577     *
    555578     * @throws PHPUnit_Framework_AssertionFailedError
     
    560583
    561584    /**
    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
    563594     *
    564595     * @param string $url The URL for the request.
     
    609640    }
    610641
     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     */
    611652    protected function checkRequirements() {
    612653        parent::checkRequirements();
     
    645686
    646687    /**
    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.
    648693     */
    649694    function knownWPBug( $ticket_id ) {
     
    657702
    658703    /**
    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.
    660711     */
    661712    function knownUTBug( $ticket_id ) {
     
    664715
    665716    /**
    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.
    667722     */
    668723    function knownPluginBug( $ticket_id ) {
     
    675730    }
    676731
     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     */
    677739    public static function forceTicket( $ticket ) {
    678740        self::$forced_tickets[] = $ticket;
     
    680742
    681743    /**
    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
    683752     */
    684753    function prepareTemplate( Text_Template $template ) {
     
    689758
    690759    /**
    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.
    692767     */
    693768    function temp_filename() {
     
    708783
    709784    /**
    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.
    711786     *
    712787     * Any properties that are listed by name as parameters will be expected to be true; all others are
    713788     * expected to be false. For example, assertQueryTrue('is_single', 'is_feed') means is_single()
    714789     * 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`.
    715793     *
    716794     * @param string $prop,... Any number of WP_Query properties that are expected to be true for the current request.
     
    776854    }
    777855
     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     */
    778863    function unlink( $file ) {
    779864        $exists = is_file( $file );
     
    786871    }
    787872
     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     */
    788880    function rmdir( $path ) {
    789881        $files = $this->files_in_dir( $path );
     
    795887    }
    796888
     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     */
    797898    function remove_added_uploads() {
    798         // Remove all uploads.
    799899        $uploads = wp_upload_dir();
    800900        $this->rmdir( $uploads['basedir'] );
    801901    }
    802902
     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     */
    803912    function files_in_dir( $dir ) {
    804913        $files = array();
     
    815924    }
    816925
     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     */
    817933    function scan_user_uploads() {
    818934        static $files = array();
     
    826942    }
    827943
     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     */
    828951    function delete_folders( $path ) {
    829952        $this->matched_dirs = array();
     
    839962    }
    840963
     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     */
    841974    function scandir( $dir ) {
    842975        foreach ( scandir( $dir ) as $path ) {
     
    849982
    850983    /**
    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.
    852991     */
    853992    protected function _microtime_to_float( $microtime ) {
     
    857996
    858997    /**
    859      * Multisite-agnostic way to delete a user from the database.
     998     * Deletes a user from the database in a Multisite-agnostic way.
    860999     *
    8611000     * @since 4.3.0
     1001     *
     1002     * @param int $user_id User ID.
     1003     *
     1004     * @return bool True if the user was deleted.
    8621005     */
    8631006    public static function delete_user( $user_id ) {
     
    8701013
    8711014    /**
    872      * Utility method that resets permalinks and flushes rewrites.
     1015     * Resets permalinks and flushes rewrites.
    8731016     *
    8741017     * @since 4.4.0
     
    8861029    }
    8871030
     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     */
    8881041    function _make_attachment( $upload, $parent_post_id = 0 ) {
    8891042        $type = '';
     
    9061059        );
    9071060
    908         // Save the data
    9091061        $id = wp_insert_attachment( $attachment, $upload['file'], $parent_post_id );
    9101062        wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
     
    9131065
    9141066    /**
    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.
    9161077     */
    9171078    protected function update_post_modified( $post_id, $date ) {
Note: See TracChangeset for help on using the changeset viewer.