Changeset 53836
- Timestamp:
- 08/04/2022 06:28:33 PM (2 years ago)
- Location:
- trunk/tests/phpunit/tests
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/link/editTermLink.php
r53833 r53836 13 13 self::register_custom_taxonomy(); 14 14 15 $taxonomies = array( 'category', 'post_tag', ' custom_taxonomy' );15 $taxonomies = array( 'category', 'post_tag', 'wptests_tax' ); 16 16 foreach ( $taxonomies as $taxonomy ) { 17 17 self::$terms[ $taxonomy ] = $factory->term->create_and_get( array( 'taxonomy' => $taxonomy ) ); … … 24 24 public function set_up() { 25 25 parent::set_up(); 26 wp_set_current_user( self::$user_ids['admin'] ); 26 27 self::register_custom_taxonomy(); 28 } 29 30 /** 31 * Helper to register a custom taxonomy for use in tests. 32 * 33 * @since 5.9.0 34 */ 35 private static function register_custom_taxonomy() { 36 register_taxonomy( 'wptests_tax', 'post' ); 37 } 38 39 /** 40 * Helper to get the term for the given taxonomy. 41 * 42 * @since 5.9.0 43 * 44 * @param string $taxonomy Taxonomy being tested (used for index of term keys). 45 * @param bool $use_id When true, pass term ID. Else, pass term object. 46 * @return WP_Term|int If $use_id is true, term ID is returned; else instance of WP_Term. 47 */ 48 private function get_term( $taxonomy, $use_id ) { 49 $term = self::$terms[ $taxonomy ]; 50 if ( $use_id ) { 51 $term = $term->term_id; 52 } 53 54 return $term; 27 55 } 28 56 … … 37 65 */ 38 66 public function test_edit_term_link_for_permitted_user( $taxonomy, $use_id, $expected ) { 39 wp_set_current_user( self::$user_ids['admin'] );40 67 $term = $this->get_term( $taxonomy, $use_id ); 41 68 … … 73 100 */ 74 101 public function test_edit_term_link_filter_is_int_by_term_id( $taxonomy, $use_id ) { 75 wp_set_current_user( self::$user_ids['admin'] );76 102 $term = $this->get_term( $taxonomy, $use_id ); 77 103 … … 97 123 */ 98 124 public function test_edit_term_link_filter_is_int_by_term_object( $taxonomy, $use_id ) { 99 wp_set_current_user( self::$user_ids['admin'] );100 125 $term = $this->get_term( $taxonomy, $use_id ); 101 126 … … 140 165 ), 141 166 'a custom taxonomy passing term_id' => array( 142 'taxonomy' => ' custom_taxonomy',167 'taxonomy' => 'wptests_tax', 143 168 'use_id' => true, 144 'expected' => 'term.php?taxonomy= custom_taxonomy&tag_ID=%ID%&post_type=post',169 'expected' => 'term.php?taxonomy=wptests_tax&tag_ID=%ID%&post_type=post', 145 170 ), 146 171 'a custom taxonomy passing term object' => array( 147 'taxonomy' => ' custom_taxonomy',172 'taxonomy' => 'wptests_tax', 148 173 'use_id' => false, 149 'expected' => 'term.php?taxonomy= custom_taxonomy&tag_ID=%ID%&post_type=post',174 'expected' => 'term.php?taxonomy=wptests_tax&tag_ID=%ID%&post_type=post', 150 175 ), 151 176 ); 152 177 } 153 154 /**155 * Helper to register a custom taxonomy for use in tests.156 *157 * @since 5.9.0158 */159 private static function register_custom_taxonomy() {160 register_taxonomy( 'custom_taxonomy', 'post' );161 }162 163 /**164 * Helper to get the term for the given taxonomy.165 *166 * @since 5.9.0167 *168 * @param string $taxonomy Taxonomy being tested (used for index of term keys).169 * @param bool $use_id When true, pass term ID. Else, pass term object.170 * @return WP_Term|int If $use_id is true, term ID is returned; else instance of WP_Term.171 */172 private function get_term( $taxonomy, $use_id ) {173 $term = self::$terms[ $taxonomy ];174 if ( $use_id ) {175 $term = $term->term_id;176 }177 178 return $term;179 }180 178 } -
trunk/tests/phpunit/tests/link/getEditTermLink.php
r53833 r53836 13 13 self::register_custom_taxonomy(); 14 14 15 $taxonomies = array( 'category', 'post_tag', ' custom_taxonomy' );15 $taxonomies = array( 'category', 'post_tag', 'wptests_tax' ); 16 16 foreach ( $taxonomies as $taxonomy ) { 17 17 self::$terms[ $taxonomy ] = $factory->term->create_and_get( array( 'taxonomy' => $taxonomy ) ); … … 24 24 public function set_up() { 25 25 parent::set_up(); 26 wp_set_current_user( self::$user_ids['admin'] ); 26 27 self::register_custom_taxonomy(); 27 28 } 28 29 29 30 /** 31 * Helper to register a custom taxonomy for use in tests. 32 * 33 * @since 5.9.0 34 */ 35 private static function register_custom_taxonomy() { 36 register_taxonomy( 'wptests_tax', 'post' ); 37 } 38 39 /** 40 * Helper to get the term for the given taxonomy. 41 * 42 * @since 5.9.0 43 * 44 * @param string $taxonomy Taxonomy being tested (used for index of term keys). 45 * @param bool $use_id When true, pass term ID. Else, pass term object. 46 * @return WP_Term|int If $use_id is true, term ID is returned; else instance of WP_Term. 47 */ 48 private function get_term( $taxonomy, $use_id ) { 49 $term = self::$terms[ $taxonomy ]; 50 if ( $use_id ) { 51 $term = $term->term_id; 52 } 53 54 return $term; 55 } 56 57 public function test_get_edit_term_link_default() { 58 $term1 = self::factory()->term->create( 59 array( 60 'taxonomy' => 'wptests_tax', 61 'name' => 'foo', 62 ) 63 ); 64 65 $actual = get_edit_term_link( $term1, 'wptests_tax' ); 66 $expected = 'http://' . WP_TESTS_DOMAIN . '/wp-admin/term.php?taxonomy=wptests_tax&tag_ID=' . $term1 . '&post_type=post'; 67 $this->assertSame( $expected, $actual ); 68 } 69 70 /** 71 * @ticket 32786 72 */ 73 public function test_get_edit_term_link_invalid_id() { 74 $term1 = self::factory()->term->create( 75 array( 76 'taxonomy' => 'wptests_tax', 77 'name' => 'foo', 78 ) 79 ); 80 81 $actual = get_edit_term_link( 12345, 'wptests_tax' ); 82 $this->assertNull( $actual ); 83 } 84 85 /** 86 * @ticket 32786 87 */ 88 public function test_get_edit_term_link_empty_id() { 89 $actual = get_edit_term_link( '', 'wptests_tax' ); 90 $this->assertNull( $actual ); 91 } 92 93 /** 94 * @ticket 32786 95 */ 96 public function test_get_edit_term_link_bad_tax() { 97 $actual = get_edit_term_link( '', 'bad_tax' ); 98 $this->assertNull( $actual ); 99 } 100 101 /** 102 * @ticket 35922 103 */ 104 public function test_taxonomy_should_not_be_required() { 105 $t = self::factory()->term->create( 106 array( 107 'taxonomy' => 'wptests_tax', 108 'name' => 'foo', 109 ) 110 ); 111 112 $actual = get_edit_term_link( $t ); 113 $this->assertNotNull( $actual ); 114 } 115 116 /** 117 * @ticket 35922 118 */ 119 public function test_cap_check_should_use_correct_taxonomy_when_taxonomy_is_not_specified() { 120 register_taxonomy( 121 'wptests_tax_subscriber', 122 'post', 123 array( 124 'capabilities' => array( 125 'edit_terms' => 'read', 126 ), 127 ) 128 ); 129 130 $t = self::factory()->term->create( 131 array( 132 'taxonomy' => 'wptests_tax_subscriber', 133 'name' => 'foo', 134 ) 135 ); 136 137 wp_set_current_user( self::$user_ids['subscriber'] ); 138 139 $actual = get_edit_term_link( $t ); 140 $this->assertNotNull( $actual ); 141 } 142 143 /** 30 144 * @dataProvider data_get_edit_term_link 31 145 * … … 37 151 */ 38 152 public function test_get_edit_term_link_for_permitted_user( $taxonomy, $use_id, $expected ) { 39 wp_set_current_user( self::$user_ids['admin'] );40 153 $term = $this->get_term( $taxonomy, $use_id ); 41 154 … … 73 186 */ 74 187 public function test_get_edit_term_link_filter_is_int_by_term_id( $taxonomy, $use_id ) { 75 wp_set_current_user( self::$user_ids['admin'] );76 188 $term = $this->get_term( $taxonomy, $use_id ); 77 189 … … 97 209 */ 98 210 public function test_get_edit_term_link_filter_is_int_by_term_object( $taxonomy, $use_id ) { 99 wp_set_current_user( self::$user_ids['admin'] );100 211 $term = $this->get_term( $taxonomy, $use_id ); 101 212 … … 140 251 ), 141 252 'a custom taxonomy passing term_id' => array( 142 'taxonomy' => ' custom_taxonomy',253 'taxonomy' => 'wptests_tax', 143 254 'use_id' => true, 144 'expected' => 'term.php?taxonomy= custom_taxonomy&tag_ID=%ID%&post_type=post',255 'expected' => 'term.php?taxonomy=wptests_tax&tag_ID=%ID%&post_type=post', 145 256 ), 146 257 'a custom taxonomy passing term object' => array( 147 'taxonomy' => ' custom_taxonomy',258 'taxonomy' => 'wptests_tax', 148 259 'use_id' => false, 149 'expected' => 'term.php?taxonomy=custom_taxonomy&tag_ID=%ID%&post_type=post', 150 ), 151 ); 152 } 153 154 /** 155 * Helper to register a custom taxonomy for use in tests. 156 * 157 * @since 5.9.0 158 */ 159 private static function register_custom_taxonomy() { 160 register_taxonomy( 'custom_taxonomy', 'post' ); 161 } 162 163 /** 164 * Helper to get the term for the given taxonomy. 165 * 166 * @since 5.9.0 167 * 168 * @param string $taxonomy Taxonomy being tested (used for index of term keys). 169 * @param bool $use_id When true, pass term ID. Else, pass term object. 170 * @return WP_Term|int If $use_id is true, term ID is returned; else instance of WP_Term. 171 */ 172 private function get_term( $taxonomy, $use_id ) { 173 $term = self::$terms[ $taxonomy ]; 174 if ( $use_id ) { 175 $term = $term->term_id; 176 } 177 178 return $term; 260 'expected' => 'term.php?taxonomy=wptests_tax&tag_ID=%ID%&post_type=post', 261 ), 262 ); 179 263 } 180 264 } -
trunk/tests/phpunit/tests/term/getTermLink.php
r53833 r53836 21 21 parent::set_up(); 22 22 self::register_custom_taxonomy(); 23 } 24 25 /** 26 * Helper to register a custom taxonomy for use in tests. 27 * 28 * @since 5.9.0 29 */ 30 private static function register_custom_taxonomy() { 31 register_taxonomy( 'wptests_tax', 'post' ); 32 } 33 34 /** 35 * Helper to get the term for the given taxonomy. 36 * 37 * @since 5.9.0 38 * 39 * @param string $taxonomy Taxonomy being tested (used for index of term keys). 40 * @param bool $use_id When true, pass term ID. Else, pass term object. 41 * @return WP_Term|int If $use_id is true, term ID is returned; else instance of WP_Term. 42 */ 43 private function get_term( $taxonomy, $use_id ) { 44 $term = self::$terms[ $taxonomy ]; 45 if ( $use_id ) { 46 $term = $term->term_id; 47 } 48 49 return $term; 23 50 } 24 51 … … 321 348 ); 322 349 } 323 324 /**325 * Helper to register a custom taxonomy for use in tests.326 *327 * @since 5.9.0328 */329 private static function register_custom_taxonomy() {330 register_taxonomy( 'wptests_tax', 'post' );331 }332 333 /**334 * Helper to get the term for the given taxonomy.335 *336 * @since 5.9.0337 *338 * @param string $taxonomy Taxonomy being tested (used for index of term keys).339 * @param bool $use_id When true, pass term ID. Else, pass term object.340 * @return WP_Term|int If $use_id is true, term ID is returned; else instance of WP_Term.341 */342 private function get_term( $taxonomy, $use_id ) {343 $term = self::$terms[ $taxonomy ];344 if ( $use_id ) {345 $term = $term->term_id;346 }347 348 return $term;349 }350 350 }
Note: See TracChangeset
for help on using the changeset viewer.