WordPress.org

Make WordPress Core

Ticket #41010: 41010.2.patch

File 41010.2.patch, 2.2 KB (added by atanasangelovdev, 2 years ago)

Added a unit test

  • src/wp-includes/taxonomy.php

     
    19171917        $args['taxonomy'] = $taxonomies;
    19181918        $args['object_ids'] = $object_ids;
    19191919
    1920         $terms = array_merge( $terms, get_terms( $args ) );
     1920        // In case not all taxonomies were unset by the processing above, get the terms of the remaining.
     1921        // Otherwise, if we call `get_terms` with `'taxonomy' => array()` it will return all taxonomies.
     1922        if ( ! empty( $args['taxonomy'] ) ) {
     1923                $terms = array_merge( $terms, get_terms( $args ) );
     1924        }
    19211925
    19221926        /**
    19231927         * Filters the terms for a given object or objects.
  • tests/phpunit/tests/term/wpGetObjectTerms.php

     
    760760                $args['orderby'] = 'term_order';
    761761                return $args;
    762762        }
     763
     764        /**
     765         * @ticket 41010
     766         */
     767        public function test_duplicate_terms_should_not_be_returned_when_passed_multiple_taxonomies() {
     768                $taxonomy1 = 'wptests_tax';
     769                $taxonomy2 = 'wptests_tax_2';
     770
     771                // issue is ONLY present if all of the following are true for $taxonomy_arguments:
     772                // - the key is exactly "args" ("arg" and "foobar" do not trigger it)
     773                // - the value is an array
     774                // - the value is NOT an empty array
     775                $taxonomy_arguments = array(
     776                        'args' => [0],
     777                );
     778
     779                register_taxonomy( $taxonomy1, 'post', $taxonomy_arguments );
     780                register_taxonomy( $taxonomy2, 'post', $taxonomy_arguments );
     781
     782                $post_id = self::factory()->post->create();
     783                $created_terms = array_merge(
     784                        wp_set_object_terms( $post_id, array( 'foo' ), $taxonomy1 ),
     785                        wp_set_object_terms( $post_id, array( 'bar' ), $taxonomy2 )
     786                );
     787
     788                $expected_result = array();
     789                foreach ( $created_terms as $term_id ) {
     790                        $expected_result[] = get_term( intval( $term_id ) );
     791                }
     792
     793                $actual_result = wp_get_object_terms( $post_id, array( $taxonomy1, $taxonomy2 ), array( 'orderby' => 'term_id' ) );
     794                $this->assertEquals( $expected_result, $actual_result );
     795        }
    763796}