Make WordPress Core

Ticket #46504: 46504.diff

File 46504.diff, 17.0 KB (added by andizer, 6 years ago)
  • tests/phpunit/includes/factory/class-wp-unittest-factory-callback-after-create.php

     
    55        /**
    66         * @var callable
    77         */
    8         var $callback;
     8        public $callback;
    99
    1010        /**
    1111         * WP_UnitTest_Factory_Callback_After_Create constructor.
     
    1212         *
    1313         * @param callable $callback A callback function.
    1414         */
    15         function __construct( $callback ) {
     15        public function __construct( $callback ) {
    1616                $this->callback = $callback;
    1717        }
    1818
     
    2323         *
    2424         * @return mixed The possibly altered object.
    2525         */
    26         function call( $object ) {
     26        public function call( $object ) {
    2727                return call_user_func( $this->callback, $object );
    2828        }
    2929}
  • tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php

     
    1616         *
    1717         * @return  int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
    1818         */
    19         function create_object( $args, $legacy_parent = 0, $legacy_args = array() ) {
     19        public function create_object( $args, $legacy_parent = 0, $legacy_args = array() ) {
    2020                // Backward compatibility for legacy argument format.
    2121                if ( is_string( $args ) ) {
    2222                        $file                = $args;
     
    4444         *
    4545         * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
    4646         */
    47         function create_upload_object( $file, $parent = 0 ) {
     47        public function create_upload_object( $file, $parent = 0 ) {
    4848                $contents = file_get_contents( $file );
    4949                $upload   = wp_upload_bits( wp_basename( $file ), null, $contents );
    5050
  • tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php

     
    1212 */
    1313class WP_UnitTest_Factory_For_Blog extends WP_UnitTest_Factory_For_Thing {
    1414
    15         function __construct( $factory = null ) {
     15        public function __construct( $factory = null ) {
    1616                global $current_site, $base;
    1717                parent::__construct( $factory );
    1818                $this->default_generation_definitions = array(
     
    3030         *
    3131         * @return int|WP_Error Returns WP_Error object on failure, the site ID on success.
    3232         */
    33         function create_object( $args ) {
     33        public function create_object( $args ) {
    3434                global $wpdb;
    3535                $meta    = isset( $args['meta'] ) ? $args['meta'] : array( 'public' => 1 );
    3636                $user_id = isset( $args['user_id'] ) ? $args['user_id'] : get_current_user_id();
     
    5353         *
    5454         * @return void
    5555         */
    56         function update_object( $blog_id, $fields ) {}
     56        public function update_object( $blog_id, $fields ) {}
    5757
    5858        /**
    5959         * Retrieves a site by given blog id.
     
    6262         *
    6363         * @return null|WP_Site The site object or null if not found.
    6464         */
    65         function get_object_by_id( $blog_id ) {
     65        public function get_object_by_id( $blog_id ) {
    6666                return get_site( $blog_id );
    6767        }
    6868}
  • tests/phpunit/includes/factory/class-wp-unittest-factory-for-comment.php

     
    1212 */
    1313class WP_UnitTest_Factory_For_Comment extends WP_UnitTest_Factory_For_Thing {
    1414
    15         function __construct( $factory = null ) {
     15        public function __construct( $factory = null ) {
    1616                parent::__construct( $factory );
    1717                $this->default_generation_definitions = array(
    1818                        'comment_author'     => new WP_UnitTest_Generator_Sequence( 'Commenter %s' ),
     
    2929         *
    3030         * @return false|int The comment's ID on success, false on failure.
    3131         */
    32         function create_object( $args ) {
     32        public function create_object( $args ) {
    3333                return wp_insert_comment( $this->addslashes_deep( $args ) );
    3434        }
    3535
     
    4141         *
    4242         * @return int When updated 1, not update 0.
    4343         */
    44         function update_object( $comment_id, $fields ) {
     44        public function update_object( $comment_id, $fields ) {
    4545                $fields['comment_ID'] = $comment_id;
    4646                return wp_update_comment( $this->addslashes_deep( $fields ) );
    4747        }
     
    5656         *
    5757         * @return int[] Array with the comment ids.
    5858         */
    59         function create_post_comments( $post_id, $count = 1, $args = array(), $generation_definitions = null ) {
     59        public function create_post_comments( $post_id, $count = 1, $args = array(), $generation_definitions = null ) {
    6060                $args['comment_post_ID'] = $post_id;
    6161                return $this->create_many( $count, $args, $generation_definitions );
    6262        }
     
    6868         *
    6969         * @return null|WP_Comment WP_Comment when found, null when not found.
    7070         */
    71         function get_object_by_id( $comment_id ) {
     71        public function get_object_by_id( $comment_id ) {
    7272                return get_comment( $comment_id );
    7373        }
    7474}
  • tests/phpunit/includes/factory/class-wp-unittest-factory-for-network.php

     
    1212 */
    1313class WP_UnitTest_Factory_For_Network extends WP_UnitTest_Factory_For_Thing {
    1414
    15         function __construct( $factory = null ) {
     15        public function __construct( $factory = null ) {
    1616                parent::__construct( $factory );
    1717                $this->default_generation_definitions = array(
    1818                        'domain'            => WP_TESTS_DOMAIN,
     
    2323                );
    2424        }
    2525
    26         function create_object( $args ) {
     26        public function create_object( $args ) {
    2727                require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    2828
    2929                if ( ! isset( $args['user'] ) ) {
     
    3636                return $args['network_id'];
    3737        }
    3838
    39         function update_object( $network_id, $fields ) {}
     39        public function update_object( $network_id, $fields ) {}
    4040
    41         function get_object_by_id( $network_id ) {
     41        public function get_object_by_id( $network_id ) {
    4242                return get_network( $network_id );
    4343        }
    4444}
  • tests/phpunit/includes/factory/class-wp-unittest-factory-for-post.php

     
    1212 */
    1313class WP_UnitTest_Factory_For_Post extends WP_UnitTest_Factory_For_Thing {
    1414
    15         function __construct( $factory = null ) {
     15        public function __construct( $factory = null ) {
    1616                parent::__construct( $factory );
    1717                $this->default_generation_definitions = array(
    1818                        'post_status'  => 'publish',
     
    3030         *
    3131         * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure.
    3232         */
    33         function create_object( $args ) {
     33        public function create_object( $args ) {
    3434                return wp_insert_post( $args );
    3535        }
    3636
     
    4242         *
    4343         * @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success.
    4444         */
    45         function update_object( $post_id, $fields ) {
     45        public function update_object( $post_id, $fields ) {
    4646                $fields['ID'] = $post_id;
    4747                return wp_update_post( $fields );
    4848        }
     
    5454         *
    5555         * @return null|WP_Post WP_Post on success or null on failure.
    5656         */
    57         function get_object_by_id( $post_id ) {
     57        public function get_object_by_id( $post_id ) {
    5858                return get_post( $post_id );
    5959        }
    6060}
  • tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php

     
    1414        private $taxonomy;
    1515        const DEFAULT_TAXONOMY = 'post_tag';
    1616
    17         function __construct( $factory = null, $taxonomy = null ) {
     17        public function __construct( $factory = null, $taxonomy = null ) {
    1818                parent::__construct( $factory );
    1919                $this->taxonomy                       = $taxonomy ? $taxonomy : self::DEFAULT_TAXONOMY;
    2020                $this->default_generation_definitions = array(
     
    3131         *
    3232         * @return array|WP_Error
    3333         */
    34         function create_object( $args ) {
     34        public function create_object( $args ) {
    3535                $args         = array_merge( array( 'taxonomy' => $this->taxonomy ), $args );
    3636                $term_id_pair = wp_insert_term( $args['name'], $args['taxonomy'], $args );
    3737                if ( is_wp_error( $term_id_pair ) ) {
     
    4848         *
    4949         * @return int The term id.
    5050         */
    51         function update_object( $term, $fields ) {
     51        public function update_object( $term, $fields ) {
    5252                $fields = array_merge( array( 'taxonomy' => $this->taxonomy ), $fields );
    5353                if ( is_object( $term ) ) {
    5454                        $taxonomy = $term->taxonomy;
     
    7171         *
    7272         * @return array|false|WP_Error Array of term taxonomy IDs of affected terms. WP_Error or false on failure.
    7373         */
    74         function add_post_terms( $post_id, $terms, $taxonomy, $append = true ) {
     74        public function add_post_terms( $post_id, $terms, $taxonomy, $append = true ) {
    7575                return wp_set_post_terms( $post_id, $terms, $taxonomy, $append );
    7676        }
    7777
     
    8383         *
    8484         * @return null|WP_Error|WP_Term WP_Term on success. WP_error if taxonomy does not exist. Null for miscellaneous failure.
    8585         */
    86         function create_and_get( $args = array(), $generation_definitions = null ) {
     86        public function create_and_get( $args = array(), $generation_definitions = null ) {
    8787                $term_id  = $this->create( $args, $generation_definitions );
    8888                $taxonomy = isset( $args['taxonomy'] ) ? $args['taxonomy'] : $this->taxonomy;
    8989                return get_term( $term_id, $taxonomy );
     
    9696         *
    9797         * @return null|WP_Error|WP_Term WP_Term on success. WP_error if taxonomy does not exist. Null for miscellaneous failure.
    9898         */
    99         function get_object_by_id( $term_id ) {
     99        public function get_object_by_id( $term_id ) {
    100100                return get_term( $term_id, $this->taxonomy );
    101101        }
    102102}
  • tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php

     
    55 */
    66abstract class WP_UnitTest_Factory_For_Thing {
    77
    8         var $default_generation_definitions;
    9         var $factory;
     8        public $default_generation_definitions;
     9        public $factory;
    1010
    1111        /**
    1212         * Creates a new factory, which will create objects of a specific Thing
     
    1616         * can be generators -- an object with next() method. There are some default generators: {@link WP_UnitTest_Generator_Sequence},
    1717         * {@link WP_UnitTest_Generator_Locale_Name}, {@link WP_UnitTest_Factory_Callback_After_Create}.
    1818         */
    19         function __construct( $factory, $default_generation_definitions = array() ) {
     19        public function __construct( $factory, $default_generation_definitions = array() ) {
    2020                $this->factory                        = $factory;
    2121                $this->default_generation_definitions = $default_generation_definitions;
    2222        }
     
    2828         *
    2929         * @return mixed The result. Can be anything.
    3030         */
    31         abstract function create_object( $args );
     31        abstract public function create_object( $args );
    3232
    3333        /**
    3434         * Updates an existing object.
     
    3838         *
    3939         * @return mixed The result. Can be anything.
    4040         */
    41         abstract function update_object( $object, $fields );
     41        abstract public function update_object( $object, $fields );
    4242
    4343        /**
    4444         * Creates an object.
     
    4848         *
    4949         * @return mixed The result. Can be anything.
    5050         */
    51         function create( $args = array(), $generation_definitions = null ) {
     51        public function create( $args = array(), $generation_definitions = null ) {
    5252                if ( is_null( $generation_definitions ) ) {
    5353                        $generation_definitions = $this->default_generation_definitions;
    5454                }
     
    7777         *
    7878         * @return mixed The created object. Can be anything.
    7979         */
    80         function create_and_get( $args = array(), $generation_definitions = null ) {
     80        public function create_and_get( $args = array(), $generation_definitions = null ) {
    8181                $object_id = $this->create( $args, $generation_definitions );
    8282                return $this->get_object_by_id( $object_id );
    8383        }
     
    8989         *
    9090         * @return mixed The object. Can be anything.
    9191         */
    92         abstract function get_object_by_id( $object_id );
     92        abstract public function get_object_by_id( $object_id );
    9393
    9494        /**
    9595         * Creates multiple objects.
     
    100100         *
    101101         * @return array
    102102         */
    103         function create_many( $count, $args = array(), $generation_definitions = null ) {
     103        public function create_many( $count, $args = array(), $generation_definitions = null ) {
    104104                $results = array();
    105105                for ( $i = 0; $i < $count; $i++ ) {
    106106                        $results[] = $this->create( $args, $generation_definitions );
     
    118118         *
    119119         * @return array|WP_Error Combined array on success. WP_Error when default value is incorrent.
    120120         */
    121         function generate_args( $args = array(), $generation_definitions = null, &$callbacks = null ) {
     121        public function generate_args( $args = array(), $generation_definitions = null, &$callbacks = null ) {
    122122                $callbacks = array();
    123123                if ( is_null( $generation_definitions ) ) {
    124124                        $generation_definitions = $this->default_generation_definitions;
     
    155155         *
    156156         * @return array The altered fields.
    157157         */
    158         function apply_callbacks( $callbacks, $created ) {
     158        public function apply_callbacks( $callbacks, $created ) {
    159159                $updated_fields = array();
    160160
    161161                foreach ( $callbacks as $field_name => $generator ) {
     
    171171         *
    172172         * @return WP_UnitTest_Factory_Callback_After_Create
    173173         */
    174         function callback( $function ) {
     174        public function callback( $function ) {
    175175                return new WP_UnitTest_Factory_Callback_After_Create( $function );
    176176        }
    177177
     
    182182         *
    183183         * @return array|string The value with the possibly applied slashes.
    184184         */
    185         function addslashes_deep( $value ) {
     185        public function addslashes_deep( $value ) {
    186186                if ( is_array( $value ) ) {
    187187                        $value = array_map( array( $this, 'addslashes_deep' ), $value );
    188188                } elseif ( is_object( $value ) ) {
  • tests/phpunit/includes/factory/class-wp-unittest-factory-for-user.php

     
    1212 */
    1313class WP_UnitTest_Factory_For_User extends WP_UnitTest_Factory_For_Thing {
    1414
    15         function __construct( $factory = null ) {
     15        public function __construct( $factory = null ) {
    1616                parent::__construct( $factory );
    1717                $this->default_generation_definitions = array(
    1818                        'user_login' => new WP_UnitTest_Generator_Sequence( 'User %s' ),
     
    2828         *
    2929         * @return int|WP_Error
    3030         */
    31         function create_object( $args ) {
     31        public function create_object( $args ) {
    3232                return wp_insert_user( $args );
    3333        }
    3434
     
    4040         *
    4141         * @return int|WP_Error User id on success. WP_Error on failure.
    4242         */
    43         function update_object( $user_id, $fields ) {
     43        public function update_object( $user_id, $fields ) {
    4444                $fields['ID'] = $user_id;
    4545                return wp_update_user( $fields );
    4646        }
     
    5252         *
    5353         * @return WP_User The user.
    5454         */
    55         function get_object_by_id( $user_id ) {
     55        public function get_object_by_id( $user_id ) {
    5656                return new WP_User( $user_id );
    5757        }
    5858}
  • tests/phpunit/includes/factory/class-wp-unittest-factory.php

     
    5858         */
    5959        public $network;
    6060
    61         function __construct() {
     61        public function __construct() {
    6262                $this->post       = new WP_UnitTest_Factory_For_Post( $this );
    6363                $this->attachment = new WP_UnitTest_Factory_For_Attachment( $this );
    6464                $this->comment    = new WP_UnitTest_Factory_For_Comment( $this );
  • tests/phpunit/includes/factory/class-wp-unittest-generator-sequence.php

     
    55        public $next;
    66        public $template_string;
    77
    8         function __construct( $template_string = '%s', $start = null ) {
     8        public function __construct( $template_string = '%s', $start = null ) {
    99                if ( $start ) {
    1010                        $this->next = $start;
    1111                } else {
     
    1515                $this->template_string = $template_string;
    1616        }
    1717
    18         function next() {
     18        public function next() {
    1919                $generated = sprintf( $this->template_string, $this->next );
    2020                $this->next++;
    2121                return $generated;