| | 1 | <?php |
| | 2 | |
| | 3 | /** |
| | 4 | * @group taxonomy |
| | 5 | */ |
| | 6 | class Tests_Term_getTermField extends WP_UnitTestCase { |
| | 7 | |
| | 8 | public $taxonomy = 'wptests_tax'; |
| | 9 | |
| | 10 | function setUp() { |
| | 11 | parent::setUp(); |
| | 12 | |
| | 13 | register_taxonomy( $this->taxonomy, 'post' ); |
| | 14 | } |
| | 15 | |
| | 16 | /** |
| | 17 | * @ticket 34245 |
| | 18 | */ |
| | 19 | public function test_get_term_field_should_return_error_for_empty_term() { |
| | 20 | $found = get_term_field( 'term_id', 0, $this->taxonomy ); |
| | 21 | $this->assertWPError( $found ); |
| | 22 | $this->assertSame( 'invalid_term', $found->get_error_code() ); |
| | 23 | } |
| | 24 | |
| | 25 | /** |
| | 26 | * @ticket 34245 |
| | 27 | */ |
| | 28 | public function test_get_term_field_should_not_return_error_for_empty_taxonomy() { |
| | 29 | $term = $this->factory->term->create_and_get( array( 'taxonomy' => $this->taxonomy ) ); |
| | 30 | |
| | 31 | $found = get_term_field( 'taxonomy', $term->term_id, '' ); |
| | 32 | $this->assertNotWPError( $found ); |
| | 33 | } |
| | 34 | |
| | 35 | /** |
| | 36 | * @ticket 34245 |
| | 37 | */ |
| | 38 | public function test_get_term_field_supplying_a_taxonomy() { |
| | 39 | $term = $this->factory->term->create_and_get( array( 'taxonomy' => $this->taxonomy ) ); |
| | 40 | |
| | 41 | $this->assertSame( $this->taxonomy, get_term_field( 'taxonomy', $term->term_id, $term->taxonomy ) ); |
| | 42 | } |
| | 43 | |
| | 44 | /** |
| | 45 | * @ticket 34245 |
| | 46 | */ |
| | 47 | public function test_get_term_field_supplying_no_taxonomy() { |
| | 48 | $term = $this->factory->term->create_and_get( array( 'taxonomy' => $this->taxonomy ) ); |
| | 49 | |
| | 50 | $this->assertSame( $this->taxonomy, get_term_field( 'taxonomy', $term->term_id ) ); |
| | 51 | } |
| | 52 | |
| | 53 | /** |
| | 54 | * @ticket 34245 |
| | 55 | */ |
| | 56 | public function test_get_term_field_should_accept_a_WP_Term_object_or_a_term_id() { |
| | 57 | $term = $this->factory->term->create_and_get( array( 'taxonomy' => $this->taxonomy ) ); |
| | 58 | |
| | 59 | $this->assertInstanceOf( 'WP_Term', $term ); |
| | 60 | $this->assertSame( $term->term_id, get_term_field( 'term_id', $term ) ); |
| | 61 | $this->assertSame( $term->term_id, get_term_field( 'term_id', $term->term_id ) ); |
| | 62 | } |
| | 63 | } |