Changeset 54061
- Timestamp:
- 09/02/2022 01:14:29 AM (2 years ago)
- Location:
- trunk/tests/phpunit/tests
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/link/editTermLink.php
r53836 r54061 43 43 * 44 44 * @param string $taxonomy Taxonomy being tested (used for index of term keys). 45 * @param bool $use_id Whe n true, pass term ID. Else, passterm object.46 * @return WP_Term|int If $use_id is true, term ID is returned; else instance of WP_Term.45 * @param bool $use_id Whether to return term ID or term object. 46 * @return WP_Term|int Term ID if `$use_id` is true, WP_Term instance otherwise. 47 47 */ 48 48 private function get_term( $taxonomy, $use_id ) { … … 60 60 * @ticket 50225 61 61 * 62 * @param string $taxonomy Taxonomy being tested (used for index of term keys).63 * @param bool $use_id Whe n true, pass term ID. Else, pass term object.64 * @param string $expected Expected URL within admin ofedit link.62 * @param string $taxonomy Taxonomy being tested. 63 * @param bool $use_id Whether to pass term ID or term object to `edit_term_link()`. 64 * @param string $expected Expected part of admin URL for the edit link. 65 65 */ 66 public function test_edit_term_link_ for_permitted_user( $taxonomy, $use_id, $expected ) {66 public function test_edit_term_link_should_return_the_link_for_permitted_user( $taxonomy, $use_id, $expected ) { 67 67 $term = $this->get_term( $taxonomy, $use_id ); 68 68 … … 72 72 73 73 $this->assertStringContainsString( $expected, edit_term_link( '', '', '', $term, false ) ); 74 $this->assertStringContainsString( $expected, edit_term_link( '', '', '', get_term( $term, $taxonomy ), false ) );75 74 } 76 75 … … 80 79 * @ticket 50225 81 80 * 82 * @param string $taxonomy Taxonomy being tested (used for index of term keys).83 * @param bool $use_id Whe n true, pass term ID. Else, pass term object.81 * @param string $taxonomy Taxonomy being tested. 82 * @param bool $use_id Whether to pass term ID or term object to `edit_term_link()`. 84 83 */ 85 public function test_edit_term_link_ for_denied_user( $taxonomy, $use_id ) {84 public function test_edit_term_link_should_return_null_for_denied_user( $taxonomy, $use_id ) { 86 85 wp_set_current_user( self::$user_ids['subscriber'] ); 87 86 $term = $this->get_term( $taxonomy, $use_id ); 88 87 89 88 $this->assertNull( edit_term_link( '', '', '', $term, false ) ); 90 $this->assertNull( edit_term_link( '', '', '', get_term( $term, $taxonomy ), false ) );91 89 } 92 90 … … 96 94 * @ticket 50225 97 95 * 98 * @param string $taxonomy Taxonomy being tested (used for index of term keys).99 * @param bool $use_id Whe n true, pass term ID. Else, pass term object.96 * @param string $taxonomy Taxonomy being tested. 97 * @param bool $use_id Whether to pass term ID or term object to `edit_term_link()`. 100 98 */ 101 public function test_edit_term_link_filter_ is_int_by_term_id( $taxonomy, $use_id ) {99 public function test_edit_term_link_filter_should_receive_term_id( $taxonomy, $use_id ) { 102 100 $term = $this->get_term( $taxonomy, $use_id ); 103 101 … … 112 110 113 111 edit_term_link( '', '', '', $term, false ); 114 }115 116 /**117 * @dataProvider data_edit_term_link118 *119 * @ticket 50225120 *121 * @param string $taxonomy Taxonomy being tested (used for index of term keys).122 * @param bool $use_id When true, pass term ID. Else, pass term object.123 */124 public function test_edit_term_link_filter_is_int_by_term_object( $taxonomy, $use_id ) {125 $term = $this->get_term( $taxonomy, $use_id );126 127 add_filter(128 'edit_term_link',129 function( $location, $term ) {130 $this->assertIsInt( $term );131 },132 10,133 2134 );135 136 edit_term_link( '', '', '', get_term( $term, $taxonomy ), false );137 112 } 138 113 -
trunk/tests/phpunit/tests/link/getEditTermLink.php
r53836 r54061 43 43 * 44 44 * @param string $taxonomy Taxonomy being tested (used for index of term keys). 45 * @param bool $use_id Whe n true, pass term ID. Else, passterm object.46 * @return WP_Term|int If $use_id is true, term ID is returned; else instance of WP_Term.45 * @param bool $use_id Whether to return term ID or term object. 46 * @return WP_Term|int Term ID if `$use_id` is true, WP_Term instance otherwise. 47 47 */ 48 48 private function get_term( $taxonomy, $use_id ) { … … 146 146 * @ticket 50225 147 147 * 148 * @param string $taxonomy Taxonomy being tested (used for index of term keys).149 * @param bool $use_id Whe n true, pass term ID. Else, pass term object.150 * @param string $expected Expected URL within admin ofedit link.151 */ 152 public function test_get_edit_term_link_ for_permitted_user( $taxonomy, $use_id, $expected ) {148 * @param string $taxonomy Taxonomy being tested. 149 * @param bool $use_id Whether to pass term ID or term object to `get_edit_term_link()`. 150 * @param string $expected Expected part of admin URL for the edit link. 151 */ 152 public function test_get_edit_term_link_should_return_the_link_for_permitted_user( $taxonomy, $use_id, $expected ) { 153 153 $term = $this->get_term( $taxonomy, $use_id ); 154 154 … … 158 158 159 159 $this->assertSame( $expected, get_edit_term_link( $term, $taxonomy ) ); 160 $this->assertSame( $expected, get_edit_term_link( get_term( $term, $taxonomy ), $taxonomy ) );161 160 } 162 161 … … 166 165 * @ticket 50225 167 166 * 168 * @param string $taxonomy Taxonomy being tested (used for index of term keys).169 * @param bool $use_id Whe n true, pass term ID. Else, pass term object.170 */ 171 public function test_get_edit_term_link_ for_denied_user( $taxonomy, $use_id ) {167 * @param string $taxonomy Taxonomy being tested. 168 * @param bool $use_id Whether to pass term ID or term object to `get_edit_term_link()`. 169 */ 170 public function test_get_edit_term_link_should_return_null_for_denied_user( $taxonomy, $use_id ) { 172 171 wp_set_current_user( self::$user_ids['subscriber'] ); 173 172 $term = $this->get_term( $taxonomy, $use_id ); 174 173 175 174 $this->assertNull( get_edit_term_link( $term, $taxonomy ) ); 176 $this->assertNull( get_edit_term_link( get_term( $term, $taxonomy ), $taxonomy ) );177 175 } 178 176 … … 182 180 * @ticket 50225 183 181 * 184 * @param string $taxonomy Taxonomy being tested (used for index of term keys).185 * @param bool $use_id Whe n true, pass term ID. Else, pass term object.186 */ 187 public function test_get_edit_term_link_filter_ is_int_by_term_id( $taxonomy, $use_id ) {182 * @param string $taxonomy Taxonomy being tested. 183 * @param bool $use_id Whether to pass term ID or term object to `get_edit_term_link()`. 184 */ 185 public function test_get_edit_term_link_filter_should_receive_term_id( $taxonomy, $use_id ) { 188 186 $term = $this->get_term( $taxonomy, $use_id ); 189 187 … … 201 199 202 200 /** 203 * @dataProvider data_get_edit_term_link204 *205 * @ticket 50225206 *207 * @param string $taxonomy Taxonomy being tested (used for index of term keys).208 * @param bool $use_id When true, pass term ID. Else, pass term object.209 */210 public function test_get_edit_term_link_filter_is_int_by_term_object( $taxonomy, $use_id ) {211 $term = $this->get_term( $taxonomy, $use_id );212 213 add_filter(214 'get_edit_term_link',215 function( $location, $term ) {216 $this->assertIsInt( $term );217 },218 10,219 2220 );221 222 get_edit_term_link( get_term( $term, $taxonomy ), $taxonomy );223 }224 225 /**226 201 * Data provider. 227 202 * -
trunk/tests/phpunit/tests/term/getTermLink.php
r53836 r54061 38 38 * 39 39 * @param string $taxonomy Taxonomy being tested (used for index of term keys). 40 * @param bool $use_id Whe n true, pass term ID. Else, passterm object.41 * @return WP_Term|int If $use_id is true, term ID is returned; else instance of WP_Term.40 * @param bool $use_id Whether to return term ID or term object. 41 * @return WP_Term|int Term ID if `$use_id` is true, WP_Term instance otherwise. 42 42 */ 43 43 private function get_term( $taxonomy, $use_id ) { … … 248 248 249 249 /** 250 * @dataProvider data_ get_term_link250 * @dataProvider data_term_link_filter_should_receive_term_object 251 251 * 252 252 * @ticket 50225 253 253 * 254 * @param string $taxonomy Taxonomy being tested (used for index of term keys).255 * @param bool $use_id Whe n true, pass term ID. Else, pass term object.256 */ 257 public function test_ get_term_link_filter_is_object_by_term_id( $taxonomy, $use_id ) {254 * @param string $taxonomy Taxonomy being tested. 255 * @param bool $use_id Whether to pass term ID or term object to `get_term_link()`. 256 */ 257 public function test_term_link_filter_should_receive_term_object( $taxonomy, $use_id ) { 258 258 $term = $this->get_term( $taxonomy, $use_id ); 259 259 … … 271 271 272 272 /** 273 * @dataProvider data_get_term_link274 *275 * @ticket 50225276 *277 * @param string $taxonomy Taxonomy being tested (used for index of term keys).278 * @param bool $use_id When true, pass term ID. Else, pass term object.279 */280 public function test_get_term_link_filter_is_object_by_term_object( $taxonomy, $use_id ) {281 $term = $this->get_term( $taxonomy, $use_id );282 283 add_filter(284 'term_link',285 function( $location, $term ) {286 $this->assertInstanceOf( 'WP_Term', $term );287 },288 10,289 2290 );291 292 get_term_link( get_term( $term, $taxonomy ), $taxonomy );293 }294 295 /**296 * @dataProvider data_get_term_link297 *298 * @ticket 50225299 *300 * @param string $taxonomy Taxonomy being tested (used for index of term keys).301 * @param bool $use_id When true, pass term ID. Else, skip the test.302 */303 public function test_get_term_feed_link_backward_compatibility( $taxonomy, $use_id ) {304 if ( $use_id ) {305 $term = $this->get_term( $taxonomy, $use_id );306 307 $term_feed_link = get_term_feed_link( $term, $taxonomy );308 $this->assertIsString( $term_feed_link );309 310 $term_feed_link = get_term_feed_link( $term, '' );311 $this->assertIsString( $term_feed_link );312 } else {313 $this->markTestSkipped( 'This test requires to pass an ID to get_term_feed_link()' );314 }315 }316 317 /**318 273 * Data provider. 319 274 * 320 275 * @return array 321 276 */ 322 public function data_ get_term_link() {277 public function data_term_link_filter_should_receive_term_object() { 323 278 return array( 324 279 'category passing term_id' => array( … … 348 303 ); 349 304 } 305 306 /** 307 * @dataProvider data_get_term_feed_link_should_use_term_taxonomy_when_term_id_is_passed 308 * 309 * @ticket 50225 310 * 311 * @param string $taxonomy Taxonomy being tested. 312 */ 313 public function test_get_term_feed_link_should_use_term_taxonomy_when_term_id_is_passed( $taxonomy ) { 314 $term = $this->get_term( $taxonomy, true ); 315 316 $term_feed_link = get_term_feed_link( $term, $taxonomy ); 317 $this->assertIsString( $term_feed_link ); 318 319 $term_feed_link = get_term_feed_link( $term, '' ); 320 $this->assertIsString( $term_feed_link ); 321 } 322 323 /** 324 * Data provider. 325 * 326 * @return array 327 */ 328 public function data_get_term_feed_link_should_use_term_taxonomy_when_term_id_is_passed() { 329 $taxonomies = array( 'category', 'post_tag', 'wptests_tax' ); 330 331 return $this->text_array_to_dataprovider( $taxonomies ); 332 } 350 333 }
Note: See TracChangeset
for help on using the changeset viewer.