Make WordPress Core


Ignore:
Timestamp:
01/23/2015 02:56:04 PM (12 years ago)
Author:
boonebgorges
Message:

Introduce 'parent' parameter to wp_get_object_terms().

Props mikeschinkel.
Fixes #15675.

File:
1 edited

Legend:

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

    r31236 r31270  
    357357        }
    358358
     359        /**
     360         * @ticket 15675
     361         */
     362        public function test_parent() {
     363                $t1 = $this->factory->term->create( array(
     364                        'taxonomy' => $this->taxonomy,
     365                ) );
     366                $t2 = $this->factory->term->create( array(
     367                        'taxonomy' => $this->taxonomy,
     368                ) );
     369                $t3 = $this->factory->term->create( array(
     370                        'taxonomy' => $this->taxonomy,
     371                        'parent' => $t1,
     372                ) );
     373                $t4 = $this->factory->term->create( array(
     374                        'taxonomy' => $this->taxonomy,
     375                        'parent' => $t2,
     376                ) );
     377
     378                $p = $this->factory->post->create();
     379
     380                wp_set_object_terms( $p, array( $t1, $t2, $t3, $t3 ), $this->taxonomy );
     381
     382                $found = wp_get_object_terms( $p, $this->taxonomy, array(
     383                        'parent' => $t1,
     384                        'fields' => 'ids',
     385                ) );
     386
     387                $this->assertEquals( array( $t3 ), $found );
     388        }
     389
     390        /**
     391         * @ticket 15675
     392         */
     393        public function test_parent_0() {
     394                $t1 = $this->factory->term->create( array(
     395                        'taxonomy' => $this->taxonomy,
     396                ) );
     397                $t2 = $this->factory->term->create( array(
     398                        'taxonomy' => $this->taxonomy,
     399                ) );
     400                $t3 = $this->factory->term->create( array(
     401                        'taxonomy' => $this->taxonomy,
     402                        'parent' => $t1,
     403                ) );
     404                $t4 = $this->factory->term->create( array(
     405                        'taxonomy' => $this->taxonomy,
     406                        'parent' => $t2,
     407                ) );
     408
     409                $p = $this->factory->post->create();
     410
     411                wp_set_object_terms( $p, array( $t1, $t2, $t3, $t3 ), $this->taxonomy );
     412
     413                $found = wp_get_object_terms( $p, $this->taxonomy, array(
     414                        'parent' => 0,
     415                        'fields' => 'ids',
     416                ) );
     417
     418                $this->assertEqualSets( array( $t1, $t2 ), $found );
     419        }
     420
    359421        public function filter_get_object_terms( $terms ) {
    360422                $term_ids = wp_list_pluck( $terms, 'term_id' );
Note: See TracChangeset for help on using the changeset viewer.