Make WordPress Core


Ignore:
Timestamp:
11/03/2014 06:48:42 PM (10 years ago)
Author:
boonebgorges
Message:

Introduce term_template param to get_the_taxonomies().

This parameter allows theme and plugin authors to specify the formatting they
would like on the term links as they are parsed into the taxonomy list.

Props hereswhatidid, dlh, davidjlaietta.
See #27238.

File:
1 edited

Legend:

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

    r30141 r30209  
    5050    }
    5151
     52    /**
     53     * @group 27238
     54     */
     55    public function test_get_the_taxonomies_term_template() {
     56        $post_id = $this->factory->post->create();
     57
     58        $taxes = get_the_taxonomies( $post_id, array( 'term_template' => '%2$s' ) );
     59        $this->assertEquals( 'Categories: Uncategorized.', $taxes['category'] );
     60
     61        $taxes = get_the_taxonomies( $post_id, array( 'term_template' => '<span class="foo"><a href="%1$s">%2$s</a></span>' ) );
     62        $link = get_category_link( 1 );
     63        $this->assertEquals( 'Categories: <span class="foo"><a href="' . $link . '">Uncategorized</a></span>.', $taxes['category'] );
     64    }
     65
    5266    function test_the_taxonomies() {
    5367        $post_id = $this->factory->post->create();
     
    5872
    5973        $link = get_category_link( 1 );
    60         $expected = "Categories: <a href='$link'>Uncategorized</a>.";
     74        $expected = 'Categories: <a href="' . $link . '">Uncategorized</a>.';
    6175        $this->assertEquals( $expected, $output );
     76    }
     77
     78    /**
     79     * @group 27238
     80     */
     81    function test_the_taxonomies_term_template() {
     82        $post_id = $this->factory->post->create();
     83
     84        $output = get_echo( 'the_taxonomies', array( array( 'post' => $post_id, 'term_template' => '%2$s' ) ) );
     85        $this->assertEquals( 'Categories: Uncategorized.', $output );
     86
     87        $output = get_echo( 'the_taxonomies', array( array( 'post' => $post_id, 'term_template' => '<span class="foo"><a href="%1$s">%2$s</a></span>' ) ) );
     88        $link = get_category_link( 1 );
     89        $this->assertEquals( 'Categories: <span class="foo"><a href="' . $link . '">Uncategorized</a></span>.', $output );
    6290    }
    6391
Note: See TracChangeset for help on using the changeset viewer.