Changeset 44903
- Timestamp:
- 03/15/2019 12:15:08 PM (6 years ago)
- Location:
- trunk/tests/phpunit/includes/factory
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-callback-after-create.php
r44497 r44903 6 6 * @var callable 7 7 */ 8 var$callback;8 public $callback; 9 9 10 10 /** … … 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 } … … 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 } -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php
r44785 r44903 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 ) ) { … … 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 ); -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php
r44497 r44903 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 ); … … 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 ); … … 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 /** … … 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 } -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-comment.php
r44497 r44903 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( … … 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 } … … 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 ) ); … … 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 ); … … 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 } -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-network.php
r42343 r44903 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( … … 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 … … 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 } -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-post.php
r44497 r44903 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( … … 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 } … … 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 ); … … 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 } -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php
r44497 r44903 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; … … 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 ); … … 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 ) ) { … … 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 } … … 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; … … 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 } -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php
r44497 r44903 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 /** … … 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; … … 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 /** … … 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 /** … … 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; … … 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 ); … … 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 /** … … 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++ ) { … … 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 ) ) { … … 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 … … 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 } … … 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 ); -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-user.php
r44497 r44903 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( … … 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 } … … 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 ); … … 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 } -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory.php
r42343 r44903 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 ); -
trunk/tests/phpunit/includes/factory/class-wp-unittest-generator-sequence.php
r42343 r44903 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; … … 16 16 } 17 17 18 function next() {18 public function next() { 19 19 $generated = sprintf( $this->template_string, $this->next ); 20 20 $this->next++;
Note: See TracChangeset
for help on using the changeset viewer.