Make WordPress Core


Ignore:
Timestamp:
12/01/2013 11:59:13 PM (13 years ago)
Author:
wonderboymusic
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term.php

    r26187 r26510  
    99        function setUp() {
    1010                parent::setUp();
    11                
     11
    1212                _clean_term_filters();
    1313                // insert one term into every post taxonomy
    … …  
    8686                // clean up
    8787                $this->assertTrue( wp_delete_term($t['term_id'], $this->taxonomy) );
     88        }
     89
     90        function test_get_object_terms() {
     91                $post_id = $this->factory->post->create();
     92                $terms_1 = array('foo', 'bar', 'baz');
     93
     94                wp_set_object_terms( $post_id, $terms_1, $this->taxonomy );
     95                add_filter( 'wp_get_object_terms', array( $this, 'filter_get_object_terms' ) );
     96                $terms = wp_get_object_terms( $post_id, $this->taxonomy );
     97                remove_filter( 'wp_get_object_terms', array( $this, 'filter_get_object_terms' ) );
     98                foreach ( $terms as $term ) {
     99                        $this->assertInternalType( 'object', $term );
     100                }
     101        }
     102
     103        function filter_get_object_terms( $terms ) {
     104                // var_dump reveals an array of objects
     105                $term_ids = wp_list_pluck( $terms, 'term_id' );
     106                // last term is now an integer
     107                return $terms;
    88108        }
    89109
Note: See TracChangeset for help on using the changeset viewer.