[wp-trac] [WordPress Trac] #32536: In unit tests, `$this->factory->term->create_and_get()` returns `null` for non-tags

WordPress Trac noreply at wordpress.org
Sat May 30 04:55:38 UTC 2015


#32536: In unit tests, `$this->factory->term->create_and_get()` returns `null` for
non-tags
------------------------------+-----------------------------
 Reporter:  dlh               |      Owner:
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Build/Test Tools  |    Version:
 Severity:  normal            |   Keywords:
  Focuses:                    |
------------------------------+-----------------------------
 With this code in a unit test:

 {{{
 register_taxonomy( 'wptests_tax', 'post' );
 $term = $this->factory->term->create_and_get( array( 'taxonomy' =>
 'wptests_tax' ) );
 }}}

 `$term` will be `null`.

 If I traced it correctly, this happens in
 `WP_UnitTest_Factory_For_Term::get_object_by_id()`:

 {{{
 return get_term( $term_id, $this->taxonomy );
 }}}

 The `taxonomy` property is not set when `factory->term` is created, so it
 falls back to `'post_tag'`.

 The attached patch would add an overriding `create_and_get()` for
 `WP_UnitTest_Factory_For_Term`.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32536>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list