Build/Test tools: Ensure the `create_and_get()` factory method returns the appropriate WP_Error when creating a term fails.

Fixes: #47952 


git-svn-id: https://develop.svn.wordpress.org/trunk@46262 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2019-09-23 18:54:16 +00:00
parent 2b076b7709
commit f3a268f58c
2 changed files with 10 additions and 0 deletions

View File

@ -85,6 +85,11 @@ class WP_UnitTest_Factory_For_Term extends WP_UnitTest_Factory_For_Thing {
*/
public function create_and_get( $args = array(), $generation_definitions = null ) {
$term_id = $this->create( $args, $generation_definitions );
if ( is_wp_error( $term_id ) ) {
return $term_id;
}
$taxonomy = isset( $args['taxonomy'] ) ? $args['taxonomy'] : $this->taxonomy;
return get_term( $term_id, $taxonomy );
}

View File

@ -79,6 +79,11 @@ abstract class WP_UnitTest_Factory_For_Thing {
*/
public function create_and_get( $args = array(), $generation_definitions = null ) {
$object_id = $this->create( $args, $generation_definitions );
if ( is_wp_error( $object_id ) ) {
return $object_id;
}
return $this->get_object_by_id( $object_id );
}