Make WordPress Core


Ignore:
Timestamp:
09/02/2022 01:14:29 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Simplify and correct get_term_link() and get_edit_term_link() tests:

  • Some assertions were unnecessarily duplicated. They aim to test the function behavior both when passing a term ID and term object, however that is already handled via the $use_id parameter of the get_term() helper in the same test class. The data providers already supply test cases both with a term ID and term object, so there is no need for a second assertion or a whole second test method with a term object.
  • One get_term_feed_link() test was unnecessarily skipped half of the time, when term object was passed instead of term ID. Instead, it can use a dedicated data provider and avoid skipping.

Includes:

  • Using more descriptive test method names to clarify the intention of the tests.
  • Some documentation updates for clarity.

Follow-up to [52180], [52255], [52258], [52305], [53833], [53836].

See #55652.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/link/editTermLink.php

    r53836 r54061  
    4343         *
    4444         * @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.
     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.
    4747         */
    4848        private function get_term( $taxonomy, $use_id ) {
     
    6060         * @ticket 50225
    6161         *
    62          * @param string $taxonomy Taxonomy being tested (used for index of term keys).
    63          * @param bool   $use_id   When true, pass term ID. Else, pass term object.
    64          * @param string $expected Expected URL within admin of edit 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.
    6565         */
    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 ) {
    6767                $term = $this->get_term( $taxonomy, $use_id );
    6868
     
    7272
    7373                $this->assertStringContainsString( $expected, edit_term_link( '', '', '', $term, false ) );
    74                 $this->assertStringContainsString( $expected, edit_term_link( '', '', '', get_term( $term, $taxonomy ), false ) );
    7574        }
    7675
     
    8079         * @ticket 50225
    8180         *
    82          * @param string $taxonomy Taxonomy being tested (used for index of term keys).
    83          * @param bool   $use_id   When 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()`.
    8483         */
    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 ) {
    8685                wp_set_current_user( self::$user_ids['subscriber'] );
    8786                $term = $this->get_term( $taxonomy, $use_id );
    8887
    8988                $this->assertNull( edit_term_link( '', '', '', $term, false ) );
    90                 $this->assertNull( edit_term_link( '', '', '', get_term( $term, $taxonomy ), false ) );
    9189        }
    9290
     
    9694         * @ticket 50225
    9795         *
    98          * @param string $taxonomy Taxonomy being tested (used for index of term keys).
    99          * @param bool   $use_id   When 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()`.
    10098         */
    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 ) {
    102100                $term = $this->get_term( $taxonomy, $use_id );
    103101
     
    112110
    113111                edit_term_link( '', '', '', $term, false );
    114         }
    115 
    116         /**
    117          * @dataProvider data_edit_term_link
    118          *
    119          * @ticket 50225
    120          *
    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                         2
    134                 );
    135 
    136                 edit_term_link( '', '', '', get_term( $term, $taxonomy ), false );
    137112        }
    138113
Note: See TracChangeset for help on using the changeset viewer.