Changeset 55924 for trunk/tests/phpunit/tests/term/getTermField.php
- Timestamp:
- 06/15/2023 03:23:25 AM (2 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/term/getTermField.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term/getTermField.php
r52389 r55924 3 3 /** 4 4 * @group taxonomy 5 * 6 * @covers ::get_term_field 5 7 */ 6 8 class Tests_Term_getTermField extends WP_UnitTestCase { 7 9 8 public $taxonomy = 'wptests_tax'; 10 public static $taxonomy = 'wptests_tax'; 11 12 public static $term; 13 14 /** 15 * Set up shared fixtures. 16 * 17 * @param WP_UnitTest_Factory $factory 18 */ 19 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 20 register_taxonomy( self::$taxonomy, 'post' ); 21 self::$term = $factory->term->create_and_get( 22 array( 23 'taxonomy' => self::$taxonomy, 24 'description' => wpautop( 'Test term description' ), 25 ) 26 ); 27 } 9 28 10 29 public function set_up() { 11 30 parent::set_up(); 12 13 register_taxonomy( $this->taxonomy, 'post' );31 // Required as taxonomies are reset between tests. 32 register_taxonomy( self::$taxonomy, 'post' ); 14 33 } 15 34 … … 18 37 */ 19 38 public function test_get_term_field_should_not_return_error_for_empty_taxonomy() { 20 $term = self:: factory()->term->create_and_get( array( 'taxonomy' => $this->taxonomy ) );39 $term = self::$term; 21 40 22 41 $found = get_term_field( 'taxonomy', $term->term_id, '' ); 23 42 $this->assertNotWPError( $found ); 24 $this->assertSame( $this->taxonomy, $found );43 $this->assertSame( self::$taxonomy, $found ); 25 44 } 26 45 … … 29 48 */ 30 49 public function test_get_term_field_supplying_a_taxonomy() { 31 $term = self:: factory()->term->create_and_get( array( 'taxonomy' => $this->taxonomy ) );50 $term = self::$term; 32 51 33 52 $found = get_term_field( 'taxonomy', $term->term_id, $term->taxonomy ); 34 $this->assertSame( $this->taxonomy, $found );53 $this->assertSame( self::$taxonomy, $found ); 35 54 } 36 55 … … 39 58 */ 40 59 public function test_get_term_field_supplying_no_taxonomy() { 41 $term = self:: factory()->term->create_and_get( array( 'taxonomy' => $this->taxonomy ) );60 $term = self::$term; 42 61 43 62 $found = get_term_field( 'taxonomy', $term->term_id ); 44 $this->assertSame( $this->taxonomy, $found );63 $this->assertSame( self::$taxonomy, $found ); 45 64 } 46 65 … … 49 68 */ 50 69 public function test_get_term_field_should_accept_a_WP_Term_id_or_object() { 51 $term = self:: factory()->term->create_and_get( array( 'taxonomy' => $this->taxonomy ) );70 $term = self::$term; 52 71 53 72 $this->assertInstanceOf( 'WP_Term', $term ); … … 61 80 */ 62 81 public function test_get_term_field_invalid_taxonomy_should_return_WP_Error() { 63 $term = self:: factory()->term->create_and_get( array( 'taxonomy' => $this->taxonomy ) );82 $term = self::$term; 64 83 65 84 $found = get_term_field( 'taxonomy', $term, 'foo-taxonomy' ); … … 72 91 */ 73 92 public function test_get_term_field_invalid_term_should_return_WP_Error() { 74 $found = get_term_field( 'taxonomy', 0, $this->taxonomy );93 $found = get_term_field( 'taxonomy', 0, self::$taxonomy ); 75 94 76 95 $this->assertWPError( $found ); … … 84 103 85 104 public function test_get_term_field_term_id() { 86 $term = self:: factory()->term->create_and_get( array( 'taxonomy' => $this->taxonomy ) );105 $term = self::$term; 87 106 88 107 $this->assertSame( $term->term_id, get_term_field( 'term_id', $term ) ); … … 97 116 array( 98 117 'name' => $name, 99 'taxonomy' => $this->taxonomy,118 'taxonomy' => self::$taxonomy, 100 119 ) 101 120 ); … … 111 130 $term = self::factory()->term->create_and_get( 112 131 array( 113 'taxonomy' => $this->taxonomy,132 'taxonomy' => self::$taxonomy, 114 133 'slug' => $slug, 115 134 ) … … 126 145 $term = self::factory()->term->create_and_get( 127 146 array( 128 'taxonomy' => $this->taxonomy,147 'taxonomy' => self::$taxonomy, 129 148 'name' => $name, 130 149 ) … … 139 158 $term = self::factory()->term->create_and_get( 140 159 array( 141 'taxonomy' => $this->taxonomy,160 'taxonomy' => self::$taxonomy, 142 161 ) 143 162 ); … … 149 168 150 169 public function test_get_term_field_taxonomy() { 151 $term = self:: factory()->term->create_and_get( array( 'taxonomy' => $this->taxonomy ) );152 153 $this->assertSame( $this->taxonomy, get_term_field( 'taxonomy', $term ) );154 $this->assertSame( $this->taxonomy, get_term_field( 'taxonomy', $term->data ) );155 $this->assertSame( $this->taxonomy, get_term_field( 'taxonomy', $term->term_id ) );170 $term = self::$term; 171 172 $this->assertSame( self::$taxonomy, get_term_field( 'taxonomy', $term ) ); 173 $this->assertSame( self::$taxonomy, get_term_field( 'taxonomy', $term->data ) ); 174 $this->assertSame( self::$taxonomy, get_term_field( 'taxonomy', $term->term_id ) ); 156 175 } 157 176 158 177 public function test_get_term_field_description() { 159 $desc = wpautop( 'baz' ); 160 161 $term = self::factory()->term->create_and_get( 162 array( 163 'taxonomy' => $this->taxonomy, 164 'description' => $desc, 165 ) 166 ); 167 168 $this->assertSame( $desc, get_term_field( 'description', $term ) ); 169 $this->assertSame( $desc, get_term_field( 'description', $term->data ) ); 170 $this->assertSame( $desc, get_term_field( 'description', $term->term_id ) ); 178 $description = wpautop( 'Test term description' ); 179 180 $term = self::$term; 181 182 $this->assertSame( $description, get_term_field( 'description', $term ) ); 183 $this->assertSame( $description, get_term_field( 'description', $term->data ) ); 184 $this->assertSame( $description, get_term_field( 'description', $term->term_id ) ); 171 185 } 172 186 173 187 public function test_get_term_field_parent() { 174 $parent = self:: factory()->term->create_and_get( array( 'taxonomy' => $this->taxonomy ) );188 $parent = self::$term; 175 189 $term = self::factory()->term->create_and_get( 176 190 array( 177 'taxonomy' => $this->taxonomy,191 'taxonomy' => self::$taxonomy, 178 192 'parent' => $parent->term_id, 179 193 )
Note: See TracChangeset
for help on using the changeset viewer.