Make WordPress Core


Ignore:
Timestamp:
08/04/2022 06:28:33 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Combine test classes for get_edit_term_link() tests.

There were two sets of tests for the function:

  • One in the link directory, based on the link-template.php file name.
  • One in the term directory, based on the component name.

To avoid confusion and make it easier to decide where new tests should go in the future, the existing tests are now combined in the former location.

Includes:

  • Setting the current user in ::set_up() instead of each individual test method.
  • Changing the custom taxonomy name to wptests_tax for consistency with other tests.
  • Moving ::register_custom_taxonomy() and ::get_term() helpers to the beginning of the class.

Follow-up to [32954], [36646], [52180], [52255], [53833].

See #55652.

File:
1 edited

Legend:

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

    r53833 r53836  
    2121        parent::set_up();
    2222        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;
    2350    }
    2451
     
    321348        );
    322349    }
    323 
    324     /**
    325      * Helper to register a custom taxonomy for use in tests.
    326      *
    327      * @since 5.9.0
    328      */
    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.0
    337      *
    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     }
    350350}
Note: See TracChangeset for help on using the changeset viewer.