WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/19/2015 03:28:49 AM (5 years ago)
Author:
DrewAPicture
Message:

Tests: Add some more test coverage for get_term_field().

See #33968.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/getTermField.php

    r35242 r35270  
    4848     * @ticket 34245
    4949     */
    50     public function test_get_term_field_should_accept_a_WP_Term_object_or_a_term_id() {
     50    public function test_get_term_field_should_accept_a_WP_Term_object_term_id_or_object() {
    5151        $term = self::factory()->term->create_and_get( array( 'taxonomy' => $this->taxonomy ) );
    5252
    5353        $this->assertInstanceOf( 'WP_Term', $term );
    5454        $this->assertSame( $term->term_id, get_term_field( 'term_id', $term ) );
     55        $this->assertSame( $term->term_id, get_term_Field( 'term_id', $term->data ) );
    5556        $this->assertSame( $term->term_id, get_term_field( 'term_id', $term->term_id ) );
    5657    }
     
    8182        $this->assertSame( 'invalid_term', $_found->get_error_code() );
    8283    }
     84
     85    public function test_get_term_field_term_id() {
     86        $term = self::factory()->term->create_and_get( array( 'taxonomy' => $this->taxonomy ) );
     87
     88        $this->assertSame( $term->term_id, get_term_field( 'term_id', $term ) );
     89        $this->assertSame( $term->term_id, get_term_field( 'term_id', $term->data ) );
     90        $this->assertSame( $term->term_id, get_term_field( 'term_id', $term->term_id ) );
     91    }
     92
     93    public function test_get_term_field_name() {
     94        $name = rand_str( 15 );
     95
     96        $term = self::factory()->term->create_and_get( array(
     97            'name'     => $name,
     98            'taxonomy' => $this->taxonomy
     99        ) );
     100
     101        $this->assertSame( $name, get_term_field( 'name', $term ) );
     102        $this->assertSame( $name, get_term_field( 'name', $term->data ) );
     103        $this->assertSame( $name, get_term_field( 'name', $term->term_id ) );
     104    }
     105
     106    public function test_get_term_field_slug_when_slug_is_set() {
     107        $slug = rand_str( 15 );
     108
     109        $term = self::factory()->term->create_and_get( array(
     110            'taxonomy' => $this->taxonomy,
     111            'slug'     => $slug
     112        ) );
     113
     114        $this->assertSame( $slug, get_term_field( 'slug', $term ) );
     115        $this->assertSame( $slug, get_term_field( 'slug', $term->data ) );
     116        $this->assertSame( $slug, get_term_field( 'slug', $term->term_id ) );
     117    }
     118
     119    public function test_get_term_field_slug_when_slug_falls_back_from_name() {
     120        $name = rand_str( 15 );
     121
     122        $term = self::factory()->term->create_and_get( array(
     123            'taxonomy' => $this->taxonomy,
     124            'name'     => $name
     125        ) );
     126
     127        $this->assertSame( $name, get_term_field( 'slug', $term ) );
     128        $this->assertSame( $name, get_term_field( 'slug', $term->data ) );
     129        $this->assertSame( $name, get_term_field( 'slug', $term->term_id ) );
     130    }
     131
     132    public function test_get_term_field_slug_when_slug_and_name_are_not_set() {
     133        $term = self::factory()->term->create_and_get( array(
     134            'taxonomy' => $this->taxonomy
     135        ) );
     136
     137        $this->assertSame( $term->slug, get_term_field( 'slug', $term ) );
     138        $this->assertSame( $term->slug, get_term_field( 'slug', $term->data ) );
     139        $this->assertSame( $term->slug, get_term_field( 'slug', $term->term_id ) );
     140    }
     141
     142    public function test_get_term_field_taxonomy() {
     143        $term = self::factory()->term->create_and_get( array( 'taxonomy' => $this->taxonomy ) );
     144
     145        $this->assertSame( $this->taxonomy, get_term_field( 'taxonomy', $term ) );
     146        $this->assertSame( $this->taxonomy, get_term_field( 'taxonomy', $term->data ) );
     147        $this->assertSame( $this->taxonomy, get_term_field( 'taxonomy', $term->term_id ) );
     148    }
     149
     150    public function test_get_term_field_description() {
     151        $desc = wpautop( rand_str() );
     152
     153        $term = self::factory()->term->create_and_get( array(
     154            'taxonomy'    => $this->taxonomy,
     155            'description' => $desc
     156        ) );
     157
     158        $this->assertSame( $desc, get_term_field( 'description', $term ) );
     159        $this->assertSame( $desc, get_term_field( 'description', $term->data ) );
     160        $this->assertSame( $desc, get_term_field( 'description', $term->term_id ) );
     161    }
     162
     163    public function test_get_term_field_parent() {
     164        $parent = self::factory()->term->create_and_get( array( 'taxonomy' => $this->taxonomy ) );
     165        $term   = self::factory()->term->create_and_get( array(
     166            'taxonomy' => $this->taxonomy,
     167            'parent'   => $parent->term_id
     168        ) );
     169
     170        $this->assertSame( $parent->term_id, get_term_field( 'parent', $term ) );
     171        $this->assertSame( $parent->term_id, get_term_field( 'parent', $term->data ) );
     172        $this->assertSame( $parent->term_id, get_term_field( 'parent', $term->term_id ) );
     173    }
    83174}
Note: See TracChangeset for help on using the changeset viewer.