Make WordPress Core


Ignore:
Timestamp:
05/23/2015 06:28:22 PM (10 years ago)
Author:
boonebgorges
Message:

Introduced $field argument to get_term_link().

This new argument allows developers to specify which term field should be
matched by the value of the $term parameter (in particular, 'name' and
'term_taxonomy_id' are now supported).

Props sudar, mordauk.
Fixes #14156.

File:
1 edited

Legend:

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

    r32552 r32553  
    5555        $term = (string) $t1;
    5656
     57        $actual = get_term_link( $term, 'wptests_tax', 'id' );
     58        $this->assertContains( 'wptests_tax=foo', $actual );
     59    }
     60
     61    /**
     62     * @ticket 14156
     63     */
     64    public function test_should_match_field_by_name() {
     65        $t = $this->factory->term->create( array(
     66            'taxonomy' => 'wptests_tax',
     67            'slug' => 'foo',
     68            'name' => 'Bar Term',
     69        ) );
     70
     71        $actual = get_term_link( 'Bar Term', 'wptests_tax', 'name' );
     72        $this->assertContains( 'wptests_tax=foo', $actual );
     73    }
     74
     75    /**
     76     * @ticket 14156
     77     */
     78    public function test_should_match_field_by_tt_id() {
     79        $t = $this->factory->term->create( array(
     80            'taxonomy' => 'wptests_tax',
     81            'slug' => 'foo',
     82            'name' => 'Bar Term',
     83        ) );
     84
     85        $actual = get_term_link( 'Bar Term', 'wptests_tax', 'name' );
     86        $this->assertContains( 'wptests_tax=foo', $actual );
     87    }
     88
     89    /**
     90     * @ticket 14156
     91     */
     92    public function test_numeric_string_should_be_interpreted_as_term_id_if_id_field_is_specified() {
     93        $t1 = $this->factory->term->create( array(
     94            'taxonomy' => 'wptests_tax',
     95            'name' => 'foo',
     96        ) );
     97        $t2 = $this->factory->term->create( array(
     98            'taxonomy' => 'wptests_tax',
     99            'slug' => $t1,
     100        ) );
     101
     102        $term = (string) $t1;
     103
    57104        $actual = get_term_link( $term, 'wptests_tax' );
    58105        $this->assertContains( 'wptests_tax=' . $term, $actual );
Note: See TracChangeset for help on using the changeset viewer.