Fix lingering reference problem in wp_get_object_terms() by not setting the foreach'd vars to a reference. Adds unit test.

Props stephenharris.
Fixes #26339.



git-svn-id: https://develop.svn.wordpress.org/trunk@26510 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2013-12-01 23:59:13 +00:00
parent 71bc2a38fa
commit b595282dff
2 changed files with 30 additions and 7 deletions

View File

@@ -8,7 +8,7 @@ class Tests_Term extends WP_UnitTestCase {
function setUp() {
parent::setUp();
_clean_term_filters();
// insert one term into every post taxonomy
// otherwise term_ids and term_taxonomy_ids might be identical, which could mask bugs
@@ -87,6 +87,26 @@ class Tests_Term extends WP_UnitTestCase {
$this->assertTrue( wp_delete_term($t['term_id'], $this->taxonomy) );
}
function test_get_object_terms() {
$post_id = $this->factory->post->create();
$terms_1 = array('foo', 'bar', 'baz');
wp_set_object_terms( $post_id, $terms_1, $this->taxonomy );
add_filter( 'wp_get_object_terms', array( $this, 'filter_get_object_terms' ) );
$terms = wp_get_object_terms( $post_id, $this->taxonomy );
remove_filter( 'wp_get_object_terms', array( $this, 'filter_get_object_terms' ) );
foreach ( $terms as $term ) {
$this->assertInternalType( 'object', $term );
}
}
function filter_get_object_terms( $terms ) {
// var_dump reveals an array of objects
$term_ids = wp_list_pluck( $terms, 'term_id' );
// last term is now an integer
return $terms;
}
function test_set_object_terms_by_id() {
$ids = $this->factory->post->create_many(5);