| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @group link |
| 5 | * @group taxonomy |
| 6 | */ |
| 7 | class 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 | } |