Ticket #46504: 46504.diff
File 46504.diff, 17.0 KB (added by , 6 years ago) |
---|
-
tests/phpunit/includes/factory/class-wp-unittest-factory-callback-after-create.php
5 5 /** 6 6 * @var callable 7 7 */ 8 var$callback;8 public $callback; 9 9 10 10 /** 11 11 * WP_UnitTest_Factory_Callback_After_Create constructor. … … 12 12 * 13 13 * @param callable $callback A callback function. 14 14 */ 15 function __construct( $callback ) {15 public function __construct( $callback ) { 16 16 $this->callback = $callback; 17 17 } 18 18 … … 23 23 * 24 24 * @return mixed The possibly altered object. 25 25 */ 26 function call( $object ) {26 public function call( $object ) { 27 27 return call_user_func( $this->callback, $object ); 28 28 } 29 29 } -
tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php
16 16 * 17 17 * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure. 18 18 */ 19 function create_object( $args, $legacy_parent = 0, $legacy_args = array() ) {19 public function create_object( $args, $legacy_parent = 0, $legacy_args = array() ) { 20 20 // Backward compatibility for legacy argument format. 21 21 if ( is_string( $args ) ) { 22 22 $file = $args; … … 44 44 * 45 45 * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure. 46 46 */ 47 function create_upload_object( $file, $parent = 0 ) {47 public function create_upload_object( $file, $parent = 0 ) { 48 48 $contents = file_get_contents( $file ); 49 49 $upload = wp_upload_bits( wp_basename( $file ), null, $contents ); 50 50 -
tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php
12 12 */ 13 13 class WP_UnitTest_Factory_For_Blog extends WP_UnitTest_Factory_For_Thing { 14 14 15 function __construct( $factory = null ) {15 public function __construct( $factory = null ) { 16 16 global $current_site, $base; 17 17 parent::__construct( $factory ); 18 18 $this->default_generation_definitions = array( … … 30 30 * 31 31 * @return int|WP_Error Returns WP_Error object on failure, the site ID on success. 32 32 */ 33 function create_object( $args ) {33 public function create_object( $args ) { 34 34 global $wpdb; 35 35 $meta = isset( $args['meta'] ) ? $args['meta'] : array( 'public' => 1 ); 36 36 $user_id = isset( $args['user_id'] ) ? $args['user_id'] : get_current_user_id(); … … 53 53 * 54 54 * @return void 55 55 */ 56 function update_object( $blog_id, $fields ) {}56 public function update_object( $blog_id, $fields ) {} 57 57 58 58 /** 59 59 * Retrieves a site by given blog id. … … 62 62 * 63 63 * @return null|WP_Site The site object or null if not found. 64 64 */ 65 function get_object_by_id( $blog_id ) {65 public function get_object_by_id( $blog_id ) { 66 66 return get_site( $blog_id ); 67 67 } 68 68 } -
tests/phpunit/includes/factory/class-wp-unittest-factory-for-comment.php
12 12 */ 13 13 class WP_UnitTest_Factory_For_Comment extends WP_UnitTest_Factory_For_Thing { 14 14 15 function __construct( $factory = null ) {15 public function __construct( $factory = null ) { 16 16 parent::__construct( $factory ); 17 17 $this->default_generation_definitions = array( 18 18 'comment_author' => new WP_UnitTest_Generator_Sequence( 'Commenter %s' ), … … 29 29 * 30 30 * @return false|int The comment's ID on success, false on failure. 31 31 */ 32 function create_object( $args ) {32 public function create_object( $args ) { 33 33 return wp_insert_comment( $this->addslashes_deep( $args ) ); 34 34 } 35 35 … … 41 41 * 42 42 * @return int When updated 1, not update 0. 43 43 */ 44 function update_object( $comment_id, $fields ) {44 public function update_object( $comment_id, $fields ) { 45 45 $fields['comment_ID'] = $comment_id; 46 46 return wp_update_comment( $this->addslashes_deep( $fields ) ); 47 47 } … … 56 56 * 57 57 * @return int[] Array with the comment ids. 58 58 */ 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 ) { 60 60 $args['comment_post_ID'] = $post_id; 61 61 return $this->create_many( $count, $args, $generation_definitions ); 62 62 } … … 68 68 * 69 69 * @return null|WP_Comment WP_Comment when found, null when not found. 70 70 */ 71 function get_object_by_id( $comment_id ) {71 public function get_object_by_id( $comment_id ) { 72 72 return get_comment( $comment_id ); 73 73 } 74 74 } -
tests/phpunit/includes/factory/class-wp-unittest-factory-for-network.php
12 12 */ 13 13 class WP_UnitTest_Factory_For_Network extends WP_UnitTest_Factory_For_Thing { 14 14 15 function __construct( $factory = null ) {15 public function __construct( $factory = null ) { 16 16 parent::__construct( $factory ); 17 17 $this->default_generation_definitions = array( 18 18 'domain' => WP_TESTS_DOMAIN, … … 23 23 ); 24 24 } 25 25 26 function create_object( $args ) {26 public function create_object( $args ) { 27 27 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 28 28 29 29 if ( ! isset( $args['user'] ) ) { … … 36 36 return $args['network_id']; 37 37 } 38 38 39 function update_object( $network_id, $fields ) {}39 public function update_object( $network_id, $fields ) {} 40 40 41 function get_object_by_id( $network_id ) {41 public function get_object_by_id( $network_id ) { 42 42 return get_network( $network_id ); 43 43 } 44 44 } -
tests/phpunit/includes/factory/class-wp-unittest-factory-for-post.php
12 12 */ 13 13 class WP_UnitTest_Factory_For_Post extends WP_UnitTest_Factory_For_Thing { 14 14 15 function __construct( $factory = null ) {15 public function __construct( $factory = null ) { 16 16 parent::__construct( $factory ); 17 17 $this->default_generation_definitions = array( 18 18 'post_status' => 'publish', … … 30 30 * 31 31 * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure. 32 32 */ 33 function create_object( $args ) {33 public function create_object( $args ) { 34 34 return wp_insert_post( $args ); 35 35 } 36 36 … … 42 42 * 43 43 * @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success. 44 44 */ 45 function update_object( $post_id, $fields ) {45 public function update_object( $post_id, $fields ) { 46 46 $fields['ID'] = $post_id; 47 47 return wp_update_post( $fields ); 48 48 } … … 54 54 * 55 55 * @return null|WP_Post WP_Post on success or null on failure. 56 56 */ 57 function get_object_by_id( $post_id ) {57 public function get_object_by_id( $post_id ) { 58 58 return get_post( $post_id ); 59 59 } 60 60 } -
tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php
14 14 private $taxonomy; 15 15 const DEFAULT_TAXONOMY = 'post_tag'; 16 16 17 function __construct( $factory = null, $taxonomy = null ) {17 public function __construct( $factory = null, $taxonomy = null ) { 18 18 parent::__construct( $factory ); 19 19 $this->taxonomy = $taxonomy ? $taxonomy : self::DEFAULT_TAXONOMY; 20 20 $this->default_generation_definitions = array( … … 31 31 * 32 32 * @return array|WP_Error 33 33 */ 34 function create_object( $args ) {34 public function create_object( $args ) { 35 35 $args = array_merge( array( 'taxonomy' => $this->taxonomy ), $args ); 36 36 $term_id_pair = wp_insert_term( $args['name'], $args['taxonomy'], $args ); 37 37 if ( is_wp_error( $term_id_pair ) ) { … … 48 48 * 49 49 * @return int The term id. 50 50 */ 51 function update_object( $term, $fields ) {51 public function update_object( $term, $fields ) { 52 52 $fields = array_merge( array( 'taxonomy' => $this->taxonomy ), $fields ); 53 53 if ( is_object( $term ) ) { 54 54 $taxonomy = $term->taxonomy; … … 71 71 * 72 72 * @return array|false|WP_Error Array of term taxonomy IDs of affected terms. WP_Error or false on failure. 73 73 */ 74 function add_post_terms( $post_id, $terms, $taxonomy, $append = true ) {74 public function add_post_terms( $post_id, $terms, $taxonomy, $append = true ) { 75 75 return wp_set_post_terms( $post_id, $terms, $taxonomy, $append ); 76 76 } 77 77 … … 83 83 * 84 84 * @return null|WP_Error|WP_Term WP_Term on success. WP_error if taxonomy does not exist. Null for miscellaneous failure. 85 85 */ 86 function create_and_get( $args = array(), $generation_definitions = null ) {86 public function create_and_get( $args = array(), $generation_definitions = null ) { 87 87 $term_id = $this->create( $args, $generation_definitions ); 88 88 $taxonomy = isset( $args['taxonomy'] ) ? $args['taxonomy'] : $this->taxonomy; 89 89 return get_term( $term_id, $taxonomy ); … … 96 96 * 97 97 * @return null|WP_Error|WP_Term WP_Term on success. WP_error if taxonomy does not exist. Null for miscellaneous failure. 98 98 */ 99 function get_object_by_id( $term_id ) {99 public function get_object_by_id( $term_id ) { 100 100 return get_term( $term_id, $this->taxonomy ); 101 101 } 102 102 } -
tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php
5 5 */ 6 6 abstract class WP_UnitTest_Factory_For_Thing { 7 7 8 var$default_generation_definitions;9 var$factory;8 public $default_generation_definitions; 9 public $factory; 10 10 11 11 /** 12 12 * Creates a new factory, which will create objects of a specific Thing … … 16 16 * can be generators -- an object with next() method. There are some default generators: {@link WP_UnitTest_Generator_Sequence}, 17 17 * {@link WP_UnitTest_Generator_Locale_Name}, {@link WP_UnitTest_Factory_Callback_After_Create}. 18 18 */ 19 function __construct( $factory, $default_generation_definitions = array() ) {19 public function __construct( $factory, $default_generation_definitions = array() ) { 20 20 $this->factory = $factory; 21 21 $this->default_generation_definitions = $default_generation_definitions; 22 22 } … … 28 28 * 29 29 * @return mixed The result. Can be anything. 30 30 */ 31 abstract function create_object( $args );31 abstract public function create_object( $args ); 32 32 33 33 /** 34 34 * Updates an existing object. … … 38 38 * 39 39 * @return mixed The result. Can be anything. 40 40 */ 41 abstract function update_object( $object, $fields );41 abstract public function update_object( $object, $fields ); 42 42 43 43 /** 44 44 * Creates an object. … … 48 48 * 49 49 * @return mixed The result. Can be anything. 50 50 */ 51 function create( $args = array(), $generation_definitions = null ) {51 public function create( $args = array(), $generation_definitions = null ) { 52 52 if ( is_null( $generation_definitions ) ) { 53 53 $generation_definitions = $this->default_generation_definitions; 54 54 } … … 77 77 * 78 78 * @return mixed The created object. Can be anything. 79 79 */ 80 function create_and_get( $args = array(), $generation_definitions = null ) {80 public function create_and_get( $args = array(), $generation_definitions = null ) { 81 81 $object_id = $this->create( $args, $generation_definitions ); 82 82 return $this->get_object_by_id( $object_id ); 83 83 } … … 89 89 * 90 90 * @return mixed The object. Can be anything. 91 91 */ 92 abstract function get_object_by_id( $object_id );92 abstract public function get_object_by_id( $object_id ); 93 93 94 94 /** 95 95 * Creates multiple objects. … … 100 100 * 101 101 * @return array 102 102 */ 103 function create_many( $count, $args = array(), $generation_definitions = null ) {103 public function create_many( $count, $args = array(), $generation_definitions = null ) { 104 104 $results = array(); 105 105 for ( $i = 0; $i < $count; $i++ ) { 106 106 $results[] = $this->create( $args, $generation_definitions ); … … 118 118 * 119 119 * @return array|WP_Error Combined array on success. WP_Error when default value is incorrent. 120 120 */ 121 function generate_args( $args = array(), $generation_definitions = null, &$callbacks = null ) {121 public function generate_args( $args = array(), $generation_definitions = null, &$callbacks = null ) { 122 122 $callbacks = array(); 123 123 if ( is_null( $generation_definitions ) ) { 124 124 $generation_definitions = $this->default_generation_definitions; … … 155 155 * 156 156 * @return array The altered fields. 157 157 */ 158 function apply_callbacks( $callbacks, $created ) {158 public function apply_callbacks( $callbacks, $created ) { 159 159 $updated_fields = array(); 160 160 161 161 foreach ( $callbacks as $field_name => $generator ) { … … 171 171 * 172 172 * @return WP_UnitTest_Factory_Callback_After_Create 173 173 */ 174 function callback( $function ) {174 public function callback( $function ) { 175 175 return new WP_UnitTest_Factory_Callback_After_Create( $function ); 176 176 } 177 177 … … 182 182 * 183 183 * @return array|string The value with the possibly applied slashes. 184 184 */ 185 function addslashes_deep( $value ) {185 public function addslashes_deep( $value ) { 186 186 if ( is_array( $value ) ) { 187 187 $value = array_map( array( $this, 'addslashes_deep' ), $value ); 188 188 } elseif ( is_object( $value ) ) { -
tests/phpunit/includes/factory/class-wp-unittest-factory-for-user.php
12 12 */ 13 13 class WP_UnitTest_Factory_For_User extends WP_UnitTest_Factory_For_Thing { 14 14 15 function __construct( $factory = null ) {15 public function __construct( $factory = null ) { 16 16 parent::__construct( $factory ); 17 17 $this->default_generation_definitions = array( 18 18 'user_login' => new WP_UnitTest_Generator_Sequence( 'User %s' ), … … 28 28 * 29 29 * @return int|WP_Error 30 30 */ 31 function create_object( $args ) {31 public function create_object( $args ) { 32 32 return wp_insert_user( $args ); 33 33 } 34 34 … … 40 40 * 41 41 * @return int|WP_Error User id on success. WP_Error on failure. 42 42 */ 43 function update_object( $user_id, $fields ) {43 public function update_object( $user_id, $fields ) { 44 44 $fields['ID'] = $user_id; 45 45 return wp_update_user( $fields ); 46 46 } … … 52 52 * 53 53 * @return WP_User The user. 54 54 */ 55 function get_object_by_id( $user_id ) {55 public function get_object_by_id( $user_id ) { 56 56 return new WP_User( $user_id ); 57 57 } 58 58 } -
tests/phpunit/includes/factory/class-wp-unittest-factory.php
58 58 */ 59 59 public $network; 60 60 61 function __construct() {61 public function __construct() { 62 62 $this->post = new WP_UnitTest_Factory_For_Post( $this ); 63 63 $this->attachment = new WP_UnitTest_Factory_For_Attachment( $this ); 64 64 $this->comment = new WP_UnitTest_Factory_For_Comment( $this ); -
tests/phpunit/includes/factory/class-wp-unittest-generator-sequence.php
5 5 public $next; 6 6 public $template_string; 7 7 8 function __construct( $template_string = '%s', $start = null ) {8 public function __construct( $template_string = '%s', $start = null ) { 9 9 if ( $start ) { 10 10 $this->next = $start; 11 11 } else { … … 15 15 $this->template_string = $template_string; 16 16 } 17 17 18 function next() {18 public function next() { 19 19 $generated = sprintf( $this->template_string, $this->next ); 20 20 $this->next++; 21 21 return $generated;