Make WordPress Core


Ignore:
Timestamp:
04/11/2022 11:36:56 PM (4 years ago)
Author:
davidbaumwald
Message:

Formatting: Make get_the_author_link pluggable.

Adds a new filter to alter the output of get_the_author_link. This change also adds unit tests for the new filter.

Props dshanske, donmhico, audrasjb, peterwilsoncc, SergeyBiryukov.
Fixes #51859.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/author.php

    r52389 r53147  
    2020                                'display_name' => 'Test Author',
    2121                                'description'  => 'test_author',
     22                                'user_url'     => 'http://example.com',
    2223                        )
    2324                );
    … …  
    145146        }
    146147
     148        /**
     149         * @ticket 51859
     150         *
     151         * @covers ::get_the_author_link
     152         */
     153        public function test_get_the_author_link() {
     154                $author_url          = get_the_author_meta( 'url' );
     155                $author_display_name = get_the_author();
     156
     157                $link = get_the_author_link();
     158
     159                $this->assertStringContainsString( $author_url, $link, 'The link does not contain the author URL' );
     160                $this->assertStringContainsString( $author_display_name, $link, 'The link does not contain the author display name' );
     161        }
     162
     163        /**
     164         * @ticket 51859
     165         *
     166         * @covers ::get_the_author_link
     167         */
     168        public function test_filtered_get_the_author_link() {
     169                $filter = new MockAction();
     170
     171                add_filter( 'the_author_link', array( &$filter, 'filter' ) );
     172
     173                get_the_author_link();
     174
     175                $this->assertSame( 1, $filter->get_call_count() );
     176                $this->assertSame( array( 'the_author_link' ), $filter->get_tags() );
     177        }
    147178}
Note: See TracChangeset for help on using the changeset viewer.