Make WordPress Core

Ticket #32786: 32786.2.diff

File 32786.2.diff, 2.2 KB (added by MikeHansenMe, 11 years ago)
  • src/wp-includes/link-template.php

     
    907907 */
    908908function get_edit_term_link( $term_id, $taxonomy, $object_type = '' ) {
    909909        $tax = get_taxonomy( $taxonomy );
    910         if ( !current_user_can( $tax->cap->edit_terms ) )
     910
     911        if ( false === $tax ) {
    911912                return;
     913        }
    912914
     915        if ( ! current_user_can( $tax->cap->edit_terms ) ) {
     916                return;
     917        }
     918
    913919        $term = get_term( $term_id, $taxonomy );
    914920
     921        if ( is_wp_error( $term ) || is_null( $term ) ) {
     922                return;
     923        }
     924
    915925        $args = array(
    916926                'action' => 'edit',
    917927                'taxonomy' => $taxonomy,
  • tests/phpunit/tests/term/get-edit-term-link.php

     
     1<?php
     2
     3/**
     4 * @group taxonomy
     5 */
     6class Tests_Term_GetEditTermLink extends WP_UnitTestCase {
     7
     8        public function setUp() {
     9                parent::setUp();
     10                wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
     11                register_taxonomy( 'wptests_tax', 'post' );
     12
     13        }
     14
     15        public function test_get_edit_term_link_default() {
     16
     17                $term1 = $this->factory->term->create( array(
     18                        'taxonomy' => 'wptests_tax',
     19                        'name' => 'foo',
     20                ) );
     21
     22                $actual = get_edit_term_link( $term1, 'wptests_tax' );
     23                $expected = 'http://example.org/wp-admin/edit-tags.php?action=edit&taxonomy=wptests_tax&tag_ID=' . $term1 . '&post_type=post';
     24                $this->assertEquals( $actual, $expected );
     25        }
     26
     27        public function test_get_edit_term_link_invalid_id() {
     28
     29                $term1 = $this->factory->term->create( array(
     30                        'taxonomy' => 'wptests_tax',
     31                        'name' => 'foo',
     32                ) );
     33
     34                $actual = get_edit_term_link( 12345, 'wptests_tax' );
     35                $this->assertNull( $actual );
     36        }
     37
     38        public function test_get_edit_term_link_empty_id() {
     39                $actual = get_edit_term_link( '', 'wptests_tax' );
     40                $this->assertNull( $actual );
     41        }
     42
     43        public function test_get_edit_term_link_bad_tax() {
     44                $actual = get_edit_term_link( '', 'bad_tax' );
     45                $this->assertNull( $actual );
     46        }
     47
     48
     49}