Make WordPress Core

Ticket #29251: 29251.2.patch

File 29251.2.patch, 2.7 KB (added by boonebgorges, 10 years ago)
  • src/wp-includes/link-template.php

    diff --git src/wp-includes/link-template.php src/wp-includes/link-template.php
    index 58b722c..48793ba 100644
    function get_edit_term_link( $term_id, $taxonomy, $object_type = '' ) { 
    909909
    910910        if ( $object_type ) {
    911911                $args['post_type'] = $object_type;
    912         } else if ( ! empty( $tax->object_type ) ) {
    913                 $args['post_type'] = reset( $tax->object_type );
     912        } elseif ( ! empty( $tax->object_type ) ) {
     913                foreach ( $tax->object_type as $_object_type ) {
     914                        if ( get_post_type_object( $_object_type ) ) {
     915                                $args['post_type'] = $_object_type;
     916                                break;
     917                        }
     918                }
    914919        }
    915920
    916921        $location = add_query_arg( $args, admin_url( 'edit-tags.php' ) );
  • new file tests/phpunit/tests/link/getEditTermLink.php

    diff --git tests/phpunit/tests/link/getEditTermLink.php tests/phpunit/tests/link/getEditTermLink.php
    new file mode 100644
    index 0000000..a6e9632
    - +  
     1<?php
     2
     3/**
     4 * @group link
     5 * @group taxonomy
     6 */
     7class Tests_Link_GetEditTermLink extends WP_UnitTestCase {
     8        private $current_user;
     9
     10        public function setUp() {
     11                parent::setUp();
     12                $this->current_user = get_current_user_id();
     13                wp_set_current_user( $this->factory->user->create( array( 'role' => 'editor' ) ) );
     14        }
     15
     16        public function tearDown() {
     17                wp_set_current_user( $this->current_user );
     18                parent::tearDown();
     19        }
     20
     21        /**
     22         * @ticket 29251
     23         */
     24        public function test_valid_object_type_should_be_inferred_when_none_is_specified_and_taxonomy_is_associated_with_a_post_type() {
     25                register_post_type( 'wptests_pt' );
     26                register_taxonomy( 'wptests_tax', 'wptests_pt' );
     27                $t = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
     28
     29                $found = get_edit_term_link( $t, 'wptests_tax' );
     30
     31                $this->assertContains( 'post_type=wptests_pt', $found );
     32        }
     33
     34        /**
     35         * @ticket 29251
     36         */
     37        public function test_valid_object_type_should_be_inferred_when_none_is_specified_and_taxonomy_is_associated_with_non_post_type_as_well_as_post_type() {
     38                register_post_type( 'wptests_pt' );
     39                register_taxonomy( 'wptests_tax', array( 'foo', 'wptests_pt' ) );
     40                $t = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
     41
     42                $found = get_edit_term_link( $t, 'wptests_tax' );
     43
     44                $this->assertContains( 'post_type=wptests_pt', $found );
     45        }
     46        /**
     47         * @ticket 29251
     48         */
     49        public function test_object_type_should_not_be_inferred_when_taxonomy_is_associated_with_no_post_types() {
     50                register_taxonomy( 'wptests_tax', 'foo' );
     51                $t = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) );
     52
     53                $found = get_edit_term_link( $t, 'wptests_tax' );
     54
     55                $this->assertNotContains( 'post_type', $found );
     56        }
     57}