Changeset 55019
- Timestamp:
- 12/28/2022 02:07:16 PM (22 months ago)
- Location:
- trunk/tests/phpunit
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/abstract-testcase.php
r55016 r55019 1523 1523 * 1524 1524 * @since 4.4.0 1525 * @since 6.2.0 Returns a WP_Error object on failure. 1525 1526 * 1526 1527 * @param array $upload Array of information about the uploaded file, provided by wp_upload_bits(). 1527 1528 * @param int $parent_post_id Optional. Parent post ID. 1528 * @return int|WP_Error The attachment ID on success . The value 0 or WP_Erroron failure.1529 * @return int|WP_Error The attachment ID on success, WP_Error object on failure. 1529 1530 */ 1530 1531 public function _make_attachment( $upload, $parent_post_id = 0 ) { … … 1548 1549 ); 1549 1550 1550 $id = wp_insert_attachment( $attachment, $upload['file'], $parent_post_id ); 1551 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); 1552 return $id; 1551 $attachment_id = wp_insert_attachment( $attachment, $upload['file'], $parent_post_id, true ); 1552 1553 if ( is_wp_error( $attachment_id ) ) { 1554 return $attachment_id; 1555 } 1556 1557 wp_update_attachment_metadata( 1558 $attachment_id, 1559 wp_generate_attachment_metadata( $attachment_id, $upload['file'] ) 1560 ); 1561 1562 return $attachment_id; 1553 1563 } 1554 1564 -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-callback-after-create.php
r46986 r55019 11 11 * WP_UnitTest_Factory_Callback_After_Create constructor. 12 12 * 13 * @since UT (3.7.0) 14 * 13 15 * @param callable $callback A callback function. 14 16 */ … … 20 22 * Calls the set callback on a given object. 21 23 * 22 * @ param mixed $object The object to apply the callback on.24 * @since UT (3.7.0) 23 25 * 24 * @return mixed The possibly altered object. 26 * @param int $object_id ID of the object to apply the callback on. 27 * 28 * @return mixed Updated object field. 25 29 */ 26 public function call( $object ) {27 return call_user_func( $this->callback, $object );30 public function call( $object_id ) { 31 return call_user_func( $this->callback, $object_id ); 28 32 } 29 33 } -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php
r47122 r55019 1 1 <?php 2 2 3 /** 4 * Unit test factory for attachments. 5 * 6 * Note: The below @method notations are defined solely for the benefit of IDEs, 7 * as a way to indicate expected return values from the given factory methods. 8 * 9 * @method int|WP_Error create( $args = array(), $generation_definitions = null ) 10 * @method WP_Post|WP_Error create_and_get( $args = array(), $generation_definitions = null ) 11 * @method (int|WP_Error)[] create_many( $count, $args = array(), $generation_definitions = null ) 12 */ 3 13 class WP_UnitTest_Factory_For_Attachment extends WP_UnitTest_Factory_For_Post { 4 14 5 15 /** 6 16 * Create an attachment fixture. 17 * 18 * @since UT (3.7.0) 19 * @since 6.2.0 Returns a WP_Error object on failure. 7 20 * 8 21 * @param array $args { … … 15 28 * @param array $legacy_args Deprecated. 16 29 * 17 * @return int|WP_Error The attachment ID on success . The value 0 or WP_Erroron failure.30 * @return int|WP_Error The attachment ID on success, WP_Error object on failure. 18 31 */ 19 32 public function create_object( $args, $legacy_parent = 0, $legacy_args = array() ) { … … 34 47 ); 35 48 36 return wp_insert_attachment( $r, $r['file'], $r['post_parent'] );49 return wp_insert_attachment( $r, $r['file'], $r['post_parent'], true ); 37 50 } 38 51 … … 40 53 * Saves an attachment. 41 54 * 55 * @since 4.4.0 56 * @since 6.2.0 Returns a WP_Error object on failure. 57 * 42 58 * @param string $file The file name to create attachment object for. 43 59 * @param int $parent ID of the post to attach the file to. 44 60 * 45 * @return int|WP_Error The attachment ID on success . The value 0 or WP_Erroron failure.61 * @return int|WP_Error The attachment ID on success, WP_Error object on failure. 46 62 */ 47 63 public function create_upload_object( $file, $parent = 0 ) { … … 69 85 70 86 // Save the data. 71 $id = wp_insert_attachment( $attachment, $upload['file'], $parent ); 72 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); 87 $attachment_id = wp_insert_attachment( $attachment, $upload['file'], $parent, true ); 73 88 74 return $id; 89 if ( is_wp_error( $attachment_id ) ) { 90 return $attachment_id; 91 } 92 93 wp_update_attachment_metadata( 94 $attachment_id, 95 wp_generate_attachment_metadata( $attachment_id, $upload['file'] ) 96 ); 97 98 return $attachment_id; 75 99 } 76 100 } -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php
r48121 r55019 7 7 * as a way to indicate expected return values from the given factory methods. 8 8 * 9 * @method int create( $args = array(), $generation_definitions = null )10 * @method WP_Site create_and_get( $args = array(), $generation_definitions = null )11 * @method int[] create_many( $count, $args = array(), $generation_definitions = null )9 * @method int|WP_Error create( $args = array(), $generation_definitions = null ) 10 * @method WP_Site|WP_Error create_and_get( $args = array(), $generation_definitions = null ) 11 * @method (int|WP_Error)[] create_many( $count, $args = array(), $generation_definitions = null ) 12 12 */ 13 13 class WP_UnitTest_Factory_For_Blog extends WP_UnitTest_Factory_For_Thing { -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-bookmark.php
r46586 r55019 9 9 * @since 4.6.0 10 10 * 11 * @method int create( $args = array(), $generation_definitions = null )12 * @method object create_and_get( $args = array(), $generation_definitions = null )13 * @method int[] create_many( $count, $args = array(), $generation_definitions = null )11 * @method int|WP_Error create( $args = array(), $generation_definitions = null ) 12 * @method object|WP_Error create_and_get( $args = array(), $generation_definitions = null ) 13 * @method (int|WP_Error)[] create_many( $count, $args = array(), $generation_definitions = null ) 14 14 */ 15 15 class WP_UnitTest_Factory_For_Bookmark extends WP_UnitTest_Factory_For_Thing { … … 23 23 } 24 24 25 /** 26 * Creates a link object. 27 * 28 * @since 4.6.0 29 * @since 6.2.0 Returns a WP_Error object on failure. 30 * 31 * @param array $args Arguments for the link object. 32 * 33 * @return int|WP_Error The link ID on success, WP_Error object on failure. 34 */ 25 35 public function create_object( $args ) { 26 return wp_insert_link( $args );36 return wp_insert_link( $args, true ); 27 37 } 28 38 39 /** 40 * Updates a link object. 41 * 42 * @since 4.6.0 43 * @since 6.2.0 Returns a WP_Error object on failure. 44 * 45 * @param int $link_id ID of the link to update. 46 * @param array $fields The fields to update. 47 * 48 * @return int|WP_Error The link ID on success, WP_Error object on failure. 49 */ 29 50 public function update_object( $link_id, $fields ) { 30 51 $fields['link_id'] = $link_id; 31 return wp_update_link( $fields ); 52 53 $result = wp_update_link( $fields ); 54 55 if ( 0 === $result ) { 56 return new WP_Error( 'link_update_error', __( 'Could not update link.' ) ); 57 } 58 59 return $result; 32 60 } 33 61 62 /** 63 * Retrieves a link by a given ID. 64 * 65 * @since 4.6.0 66 * 67 * @param int $link_id ID of the link to retrieve. 68 * 69 * @return object|null The link object on success, null on failure. 70 */ 34 71 public function get_object_by_id( $link_id ) { 35 72 return get_bookmark( $link_id ); -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-comment.php
r47017 r55019 7 7 * as a way to indicate expected return values from the given factory methods. 8 8 * 9 * @method int create( $args = array(), $generation_definitions = null )10 * @method WP_Comment create_and_get( $args = array(), $generation_definitions = null )11 * @method int[]create_many( $count, $args = array(), $generation_definitions = null )9 * @method int|WP_Error create( $args = array(), $generation_definitions = null ) 10 * @method WP_Comment|WP_Error create_and_get( $args = array(), $generation_definitions = null ) 11 * @method (int|WP_Error)[] create_many( $count, $args = array(), $generation_definitions = null ) 12 12 */ 13 13 class WP_UnitTest_Factory_For_Comment extends WP_UnitTest_Factory_For_Thing { … … 26 26 * Inserts a comment. 27 27 * 28 * @since UT (3.7.0) 29 * @since 6.2.0 Returns a WP_Error object on failure. 30 * 31 * @global wpdb $wpdb WordPress database abstraction object. 32 * 28 33 * @param array $args The comment details. 29 34 * 30 * @return int| false The comment's ID on success, falseon failure.35 * @return int|WP_Error The comment ID on success, WP_Error object on failure. 31 36 */ 32 37 public function create_object( $args ) { 33 return wp_insert_comment( $this->addslashes_deep( $args ) ); 38 global $wpdb; 39 40 $comment_id = wp_insert_comment( $this->addslashes_deep( $args ) ); 41 42 if ( false === $comment_id ) { 43 return new WP_Error( 44 'db_insert_error', 45 __( 'Could not insert comment into the database.' ), 46 $wpdb->last_error 47 ); 48 } 49 50 return $comment_id; 34 51 } 35 52 … … 37 54 * Updates a comment. 38 55 * 56 * @since UT (3.7.0) 57 * @since 6.2.0 Returns a WP_Error object on failure. 58 * 39 59 * @param int $comment_id The comment ID. 40 60 * @param array $fields The comment details. 41 61 * 42 * @return int The value 1 if the comment was updated, 0 if not updated. 62 * @return int|WP_Error The value 1 if the comment was updated, 0 if not updated. 63 * WP_Error object on failure. 43 64 */ 44 65 public function update_object( $comment_id, $fields ) { 45 66 $fields['comment_ID'] = $comment_id; 46 return wp_update_comment( $this->addslashes_deep( $fields ) );67 return wp_update_comment( $this->addslashes_deep( $fields ), true ); 47 68 } 48 69 49 70 /** 50 71 * Creates multiple comments on a given post. 72 * 73 * @since UT (3.7.0) 51 74 * 52 75 * @param int $post_id ID of the post to create comments for. … … 65 88 * Retrieves a comment by a given ID. 66 89 * 90 * @since UT (3.7.0) 91 * 67 92 * @param int $comment_id ID of the comment to retrieve. 68 93 * -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-network.php
r46831 r55019 7 7 * as a way to indicate expected return values from the given factory methods. 8 8 * 9 * @method int create( $args = array(), $generation_definitions = null )10 * @method WP_Network create_and_get( $args = array(), $generation_definitions = null )11 * @method int[]create_many( $count, $args = array(), $generation_definitions = null )9 * @method int|WP_Error create( $args = array(), $generation_definitions = null ) 10 * @method WP_Network|WP_Error create_and_get( $args = array(), $generation_definitions = null ) 11 * @method (int|WP_Error)[] create_many( $count, $args = array(), $generation_definitions = null ) 12 12 */ 13 13 class WP_UnitTest_Factory_For_Network extends WP_UnitTest_Factory_For_Thing { … … 24 24 } 25 25 26 /** 27 * Creates a network object. 28 * 29 * @since 3.9.0 30 * @since 6.2.0 Returns a WP_Error object on failure. 31 * 32 * @param array $args Arguments for the network object. 33 * 34 * @return int|WP_Error The network ID on success, WP_Error object on failure. 35 */ 26 36 public function create_object( $args ) { 27 37 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; … … 33 43 } 34 44 35 populate_network( $args['network_id'], $args['domain'], $email, $args['title'], $args['path'], $args['subdomain_install'] ); 45 $result = populate_network( 46 $args['network_id'], 47 $args['domain'], 48 $email, 49 $args['title'], 50 $args['path'], 51 $args['subdomain_install'] 52 ); 53 54 if ( is_wp_error( $result ) ) { 55 return $result; 56 } 57 36 58 return (int) $args['network_id']; 37 59 } 38 60 61 /** 62 * Updates a network object. Not implemented. 63 * 64 * @since 3.9.0 65 * 66 * @param int $network_id ID of the network to update. 67 * @param array $fields The fields to update. 68 * 69 * @return void 70 */ 39 71 public function update_object( $network_id, $fields ) {} 40 72 73 /** 74 * Retrieves a network by a given ID. 75 * 76 * @since 3.9.0 77 * 78 * @param int $network_id ID of the network to retrieve. 79 * 80 * @return WP_Network|null The network object on success, null on failure. 81 */ 41 82 public function get_object_by_id( $network_id ) { 42 83 return get_network( $network_id ); -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-post.php
r49789 r55019 7 7 * as a way to indicate expected return values from the given factory methods. 8 8 * 9 * @method int create( $args = array(), $generation_definitions = null )10 * @method WP_Post create_and_get( $args = array(), $generation_definitions = null )11 * @method int[] create_many( $count, $args = array(), $generation_definitions = null )9 * @method int|WP_Error create( $args = array(), $generation_definitions = null ) 10 * @method WP_Post|WP_Error create_and_get( $args = array(), $generation_definitions = null ) 11 * @method (int|WP_Error)[] create_many( $count, $args = array(), $generation_definitions = null ) 12 12 */ 13 13 class WP_UnitTest_Factory_For_Post extends WP_UnitTest_Factory_For_Thing { … … 27 27 * Creates a post object. 28 28 * 29 * @since UT (3.7.0) 30 * @since 6.2.0 Returns a WP_Error object on failure. 31 * 29 32 * @param array $args Array with elements for the post. 30 33 * 31 * @return int The post ID on success. The value 0on failure.34 * @return int|WP_Error The post ID on success, WP_Error object on failure. 32 35 */ 33 36 public function create_object( $args ) { 34 return wp_insert_post( $args );37 return wp_insert_post( $args, true ); 35 38 } 36 39 … … 38 41 * Updates an existing post object. 39 42 * 43 * @since UT (3.7.0) 44 * @since 6.2.0 Returns a WP_Error object on failure. 45 * 40 46 * @param int $post_id ID of the post to update. 41 47 * @param array $fields Post data. 42 48 * 43 * @return int The post ID on success. The value 0on failure.49 * @return int|WP_Error The post ID on success, WP_Error object on failure. 44 50 */ 45 51 public function update_object( $post_id, $fields ) { 46 52 $fields['ID'] = $post_id; 47 return wp_update_post( $fields );53 return wp_update_post( $fields, true ); 48 54 } 49 55 50 56 /** 51 57 * Retrieves a post by a given ID. 58 * 59 * @since UT (3.7.0) 52 60 * 53 61 * @param int $post_id ID of the post to retrieve. -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php
r51298 r55019 7 7 * as a way to indicate expected return values from the given factory methods. 8 8 * 9 * @method int create( $args = array(), $generation_definitions = null )10 * @method WP_Term create_and_get( $args = array(), $generation_definitions = null )11 * @method int[]create_many( $count, $args = array(), $generation_definitions = null )9 * @method int|WP_Error create( $args = array(), $generation_definitions = null ) 10 * @method WP_Term|WP_Error|null create_and_get( $args = array(), $generation_definitions = null ) 11 * @method (int|WP_Error)[] create_many( $count, $args = array(), $generation_definitions = null ) 12 12 */ 13 13 class WP_UnitTest_Factory_For_Term extends WP_UnitTest_Factory_For_Thing { … … 29 29 * Creates a term object. 30 30 * 31 * @ param array $args Array or string of arguments for inserting a term.31 * @since UT (3.7.0) 32 32 * 33 * @return array|WP_Error 33 * @param array $args Array of arguments for inserting a term. 34 * 35 * @return int|WP_Error The term ID on success, WP_Error object on failure. 34 36 */ 35 37 public function create_object( $args ) { 36 38 $args = array_merge( array( 'taxonomy' => $this->taxonomy ), $args ); 37 39 $term_id_pair = wp_insert_term( $args['name'], $args['taxonomy'], $args ); 40 38 41 if ( is_wp_error( $term_id_pair ) ) { 39 42 return $term_id_pair; 40 43 } 44 41 45 return $term_id_pair['term_id']; 42 46 } … … 45 49 * Updates the term. 46 50 * 47 * @ param int|object $term The term to update.48 * @ param array|string $fields The context in which to relate the term to the object.51 * @since UT (3.7.0) 52 * @since 6.2.0 Returns a WP_Error object on failure. 49 53 * 50 * @return int The term ID. 54 * @param int|object $term The term to update. 55 * @param array $fields Array of arguments for updating a term. 56 * 57 * @return int|WP_Error The term ID on success, WP_Error object on failure. 51 58 */ 52 59 public function update_object( $term, $fields ) { 53 60 $fields = array_merge( array( 'taxonomy' => $this->taxonomy ), $fields ); 61 54 62 if ( is_object( $term ) ) { 55 63 $taxonomy = $term->taxonomy; 56 64 } 65 57 66 $term_id_pair = wp_update_term( $term, $taxonomy, $fields ); 67 68 if ( is_wp_error( $term_id_pair ) ) { 69 return $term_id_pair; 70 } 71 58 72 return $term_id_pair['term_id']; 59 73 } … … 61 75 /** 62 76 * Attach terms to the given post. 77 * 78 * @since UT (3.7.0) 63 79 * 64 80 * @param int $post_id The post ID. … … 80 96 * Create a term and returns it as an object. 81 97 * 98 * @since 4.3.0 99 * 82 100 * @param array $args Array or string of arguments for inserting a term. 83 101 * @param null $generation_definitions The default values. … … 93 111 94 112 $taxonomy = isset( $args['taxonomy'] ) ? $args['taxonomy'] : $this->taxonomy; 113 95 114 return get_term( $term_id, $taxonomy ); 96 115 } … … 98 117 /** 99 118 * Retrieves the term by a given ID. 119 * 120 * @since UT (3.7.0) 100 121 * 101 122 * @param int $term_id ID of the term to retrieve. -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php
r46985 r55019 10 10 11 11 /** 12 * Creates a new factory, which will create objects of a specific Thing 13 * 14 * @param object $factory Global factory that can be used to create other objects on the system 15 * @param array $default_generation_definitions Defines what default values should the properties of the object have. The default values 16 * can be generators -- an object with next() method. There are some default generators: {@link WP_UnitTest_Generator_Sequence}, 17 * {@link WP_UnitTest_Generator_Locale_Name}, {@link WP_UnitTest_Factory_Callback_After_Create}. 12 * Creates a new factory, which will create objects of a specific Thing. 13 * 14 * @since UT (3.7.0) 15 * 16 * @param object $factory Global factory that can be used to create other objects 17 * on the system. 18 * @param array $default_generation_definitions Defines what default values should the properties 19 * of the object have. The default values can be generators -- 20 * an object with the next() method. 21 * There are some default generators: 22 * - {@link WP_UnitTest_Generator_Sequence} 23 * - {@link WP_UnitTest_Generator_Locale_Name} 24 * - {@link WP_UnitTest_Factory_Callback_After_Create} 18 25 */ 19 26 public function __construct( $factory, $default_generation_definitions = array() ) { … … 23 30 24 31 /** 25 * Creates an object. 32 * Creates an object and returns its ID. 33 * 34 * @since UT (3.7.0) 26 35 * 27 36 * @param array $args The arguments. 28 37 * 29 * @return mixed The result. Can be anything.38 * @return int|WP_Error The object ID on success, WP_Error object on failure. 30 39 */ 31 40 abstract public function create_object( $args ); … … 34 43 * Updates an existing object. 35 44 * 36 * @param int $object The object ID. 37 * @param array $fields The values to update. 38 * 39 * @return mixed The result. Can be anything. 40 */ 41 abstract public function update_object( $object, $fields ); 42 43 /** 44 * Creates an object. 45 * 46 * @param array $args Optional. The arguments for the object to create. Default is empty array. 47 * @param null $generation_definitions Optional. The default values for the object. Default is null. 48 * 49 * @return mixed The result. Can be anything. 45 * @since UT (3.7.0) 46 * 47 * @param int $object_id The object ID. 48 * @param array $fields The values to update. 49 * 50 * @return int|WP_Error The object ID on success, WP_Error object on failure. 51 */ 52 abstract public function update_object( $object_id, $fields ); 53 54 /** 55 * Creates an object and returns its ID. 56 * 57 * @since UT (3.7.0) 58 * 59 * @param array $args Optional. The arguments for the object to create. 60 * Default empty array. 61 * @param null $generation_definitions Optional. The default values for the object. 62 * Default null. 63 * 64 * @return int|WP_Error The object ID on success, WP_Error object on failure. 50 65 */ 51 66 public function create( $args = array(), $generation_definitions = null ) { … … 55 70 56 71 $generated_args = $this->generate_args( $args, $generation_definitions, $callbacks ); 57 $created = $this->create_object( $generated_args ); 58 if ( ! $created || is_wp_error( $created ) ) { 59 return $created; 72 $object_id = $this->create_object( $generated_args ); 73 74 if ( ! $object_id || is_wp_error( $object_id ) ) { 75 return $object_id; 60 76 } 61 77 62 78 if ( $callbacks ) { 63 $updated_fields = $this->apply_callbacks( $callbacks, $created ); 64 $save_result = $this->update_object( $created, $updated_fields ); 79 $updated_fields = $this->apply_callbacks( $callbacks, $object_id ); 80 $save_result = $this->update_object( $object_id, $updated_fields ); 81 65 82 if ( ! $save_result || is_wp_error( $save_result ) ) { 66 83 return $save_result; 67 84 } 68 85 } 69 return $created; 70 } 71 72 /** 73 * Creates an object and returns its object. 74 * 75 * @param array $args Optional. The arguments for the object to create. Default is empty array. 76 * @param null $generation_definitions Optional. The default values for the object. Default is null. 77 * 78 * @return mixed The created object. Can be anything. 86 87 return $object_id; 88 } 89 90 /** 91 * Creates and returns an object. 92 * 93 * @since UT (3.7.0) 94 * 95 * @param array $args Optional. The arguments for the object to create. 96 * Default empty array. 97 * @param null $generation_definitions Optional. The default values for the object. 98 * Default null. 99 * 100 * @return mixed The created object. Can be anything. WP_Error object on failure. 79 101 */ 80 102 public function create_and_get( $args = array(), $generation_definitions = null ) { … … 91 113 * Retrieves an object by ID. 92 114 * 115 * @since UT (3.7.0) 116 * 93 117 * @param int $object_id The object ID. 94 118 * … … 100 124 * Creates multiple objects. 101 125 * 126 * @since UT (3.7.0) 127 * 102 128 * @param int $count Amount of objects to create. 103 * @param array $args Optional. The arguments for the object to create. Default is empty array. 104 * @param null $generation_definitions Optional. The default values for the object. Default is null. 129 * @param array $args Optional. The arguments for the object to create. 130 * Default empty array. 131 * @param null $generation_definitions Optional. The default values for the object. 132 * Default null. 105 133 * 106 134 * @return array … … 108 136 public function create_many( $count, $args = array(), $generation_definitions = null ) { 109 137 $results = array(); 138 110 139 for ( $i = 0; $i < $count; $i++ ) { 111 140 $results[] = $this->create( $args, $generation_definitions ); 112 141 } 142 113 143 return $results; 114 144 } … … 118 148 * possibly set callbacks on it. 119 149 * 120 * @param array $args Optional. The arguments to combine with defaults. Default is empty array. 121 * @param array|null $generation_definitions Optional. The defaults. Default is null. 122 * @param array|null $callbacks Optional. Array with callbacks to apply on the fields. Default is null. 150 * @since UT (3.7.0) 151 * 152 * @param array $args Optional. The arguments to combine with defaults. 153 * Default empty array. 154 * @param array|null $generation_definitions Optional. The defaults. Default null. 155 * @param array|null $callbacks Optional. Array with callbacks to apply on the fields. 156 * Default null. 123 157 * 124 158 * @return array|WP_Error Combined array on success. WP_Error when default value is incorrent. … … 145 179 $args[ $field_name ] = sprintf( $generator->get_template_string(), $incr ); 146 180 } else { 147 return new WP_Error( 'invalid_argument', 'Factory default value should be either a scalar or an generator object.' ); 181 return new WP_Error( 182 'invalid_argument', 183 'Factory default value should be either a scalar or an generator object.' 184 ); 148 185 } 149 186 } … … 157 194 * Applies the callbacks on the created object. 158 195 * 196 * @since UT (3.7.0) 197 * 159 198 * @param WP_UnitTest_Factory_Callback_After_Create[] $callbacks Array with callback functions. 160 * @param mixed $created The object to apply callbacks for.199 * @param int $object_id ID of the object to apply callbacks for. 161 200 * 162 201 * @return array The altered fields. 163 202 */ 164 public function apply_callbacks( $callbacks, $ created ) {203 public function apply_callbacks( $callbacks, $object_id ) { 165 204 $updated_fields = array(); 166 205 167 206 foreach ( $callbacks as $field_name => $generator ) { 168 $updated_fields[ $field_name ] = $generator->call( $created ); 169 } 207 $updated_fields[ $field_name ] = $generator->call( $object_id ); 208 } 209 170 210 return $updated_fields; 171 211 } … … 173 213 /** 174 214 * Instantiates a callback objects for the given function name. 215 * 216 * @since UT (3.7.0) 175 217 * 176 218 * @param string $function The callback function. … … 184 226 /** 185 227 * Adds slashes to the given value. 228 * 229 * @since UT (3.7.0) 186 230 * 187 231 * @param array|object|string|mixed $value The value to add slashes to. -
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-user.php
r46985 r55019 7 7 * as a way to indicate expected return values from the given factory methods. 8 8 * 9 * @method int create( $args = array(), $generation_definitions = null )10 * @method WP_User create_and_get( $args = array(), $generation_definitions = null )11 * @method int[] create_many( $count, $args = array(), $generation_definitions = null )9 * @method int|WP_Error create( $args = array(), $generation_definitions = null ) 10 * @method WP_User|WP_Error create_and_get( $args = array(), $generation_definitions = null ) 11 * @method (int|WP_Error)[] create_many( $count, $args = array(), $generation_definitions = null ) 12 12 */ 13 13 class WP_UnitTest_Factory_For_User extends WP_UnitTest_Factory_For_Thing { … … 25 25 * Inserts an user. 26 26 * 27 * @since UT (3.7.0) 28 * 27 29 * @param array $args The user data to insert. 28 30 * … … 35 37 /** 36 38 * Updates the user data. 39 * 40 * @since UT (3.7.0) 37 41 * 38 42 * @param int $user_id ID of the user to update. … … 49 53 * Retrieves the user for a given ID. 50 54 * 55 * @since UT (3.7.0) 56 * 51 57 * @param int $user_id ID of the user ID to retrieve. 52 58 * -
trunk/tests/phpunit/tests/post/wpInsertPost.php
r54889 r55019 1193 1193 ) 1194 1194 ); 1195 $this->assert Same( 0,$post_id );1195 $this->assertWPError( $post_id ); 1196 1196 1197 1197 $post_id = self::factory()->post->create( … … 1202 1202 ) 1203 1203 ); 1204 $this->assert Same( 0,$post_id );1204 $this->assertWPError( $post_id ); 1205 1205 1206 1206 // Empty post_date_gmt without floating status … … 1211 1211 ) 1212 1212 ); 1213 $this->assert Same( 0,$post_id );1213 $this->assertWPError( $post_id ); 1214 1214 1215 1215 $post_id = self::factory()->post->create( … … 1220 1220 ) 1221 1221 ); 1222 $this->assert Same( 0,$post_id );1222 $this->assertWPError( $post_id ); 1223 1223 1224 1224 // Valid post_date_gmt … … 1229 1229 ) 1230 1230 ); 1231 $this->assert Same( 0,$post_id );1231 $this->assertWPError( $post_id ); 1232 1232 1233 1233 // Invalid post_date_gmt … … 1238 1238 ) 1239 1239 ); 1240 $this->assert Same( 0,$post_id );1240 $this->assertWPError( $post_id ); 1241 1241 } 1242 1242
Note: See TracChangeset
for help on using the changeset viewer.