Skip to:
Content

bbPress.org

Changeset 7781


Ignore:
Timestamp:
10/04/2026 07:42:50 AM (5 weeks ago)
Author:
johnjamesjacoby
Message:

Tests: Cover topic and reply author templates.

Replace twelve incomplete author-template tests. Verify registered and anonymous names, avatars, links, URLs, email addresses, and displayed roles, including output wrappers.

In trunk, for 2.7.

See #3695.

Location:
trunk/tests/phpunit/testcases
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/replies/template/authors.php

    r7407 r7781  
    1313         * @covers ::bbp_reply_author
    1414         * @covers ::bbp_get_reply_author
    15          * @todo   Implement test_bbp_get_reply_author().
    1615         */
    1716        public function test_bbp_get_reply_author() {
    18                 // Remove the following lines when you implement this test.
    19                 $this->markTestIncomplete(
    20                         'This test has not been implemented yet.'
    21                 );
     17                $user_id  = $this->factory->user->create( array( 'display_name' => 'Reply Author' ) );
     18                $topic_id = $this->factory->topic->create();
     19                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id, 'post_author' => $user_id ) );
     20
     21                $this->assertSame( 'Reply Author', bbp_get_reply_author( $reply_id ) );
     22                $this->expectOutputString( 'Reply Author' );
     23                bbp_reply_author( $reply_id );
     24        }
     25
     26        /**
     27         * @covers ::bbp_get_reply_author
     28         */
     29        public function test_bbp_get_reply_author_uses_anonymous_name() {
     30                $topic_id = $this->factory->topic->create();
     31                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id, 'post_author' => 0 ) );
     32                update_post_meta( $reply_id, '_bbp_anonymous_name', 'Guest Author' );
     33
     34                $this->assertSame( 'Guest Author', bbp_get_reply_author( $reply_id ) );
    2235        }
    2336
    … …  
    6578         * @covers ::bbp_reply_author_avatar
    6679         * @covers ::bbp_get_reply_author_avatar
    67          * @todo   Implement test_bbp_get_reply_author_avatar().
    6880         */
    6981        public function test_bbp_get_reply_author_avatar() {
    70                 // Remove the following lines when you implement this test.
    71                 $this->markTestIncomplete(
    72                         'This test has not been implemented yet.'
    73                 );
     82                $user_id  = $this->factory->user->create();
     83                $topic_id = $this->factory->topic->create();
     84                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id, 'post_author' => $user_id ) );
     85                $avatar   = bbp_get_reply_author_avatar( $reply_id, 64 );
     86
     87                $this->assertSame( get_avatar( $user_id, 64 ), $avatar );
     88                $this->expectOutputString( $avatar );
     89                bbp_reply_author_avatar( $reply_id, 64 );
     90        }
     91
     92        /**
     93         * @covers ::bbp_get_reply_author_avatar
     94         */
     95        public function test_bbp_get_reply_author_avatar_uses_anonymous_email() {
     96                $topic_id = $this->factory->topic->create();
     97                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id, 'post_author' => 0 ) );
     98                update_post_meta( $reply_id, '_bbp_anonymous_email', 'guest@example.org' );
     99
     100                $this->assertSame( get_avatar( 'guest@example.org', 64 ), bbp_get_reply_author_avatar( $reply_id, 64 ) );
    74101        }
    75102
    … …  
    77104         * @covers ::bbp_reply_author_link
    78105         * @covers ::bbp_get_reply_author_link
    79          * @todo   Implement test_bbp_get_reply_author_link().
    80106         */
    81107        public function test_bbp_get_reply_author_link() {
    82                 // Remove the following lines when you implement this test.
    83                 $this->markTestIncomplete(
    84                         'This test has not been implemented yet.'
    85                 );
     108                $user_id  = $this->factory->user->create( array( 'display_name' => 'Reply Author' ) );
     109                $topic_id = $this->factory->topic->create();
     110                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id, 'post_author' => $user_id ) );
     111                $args     = array( 'post_id' => $reply_id, 'type' => 'name' );
     112                $link     = bbp_get_reply_author_link( $args );
     113
     114                $this->assertStringContainsString( 'Reply Author', $link );
     115                $this->assertStringContainsString( 'bbp-author-name', $link );
     116                $this->assertStringContainsString( esc_url( bbp_get_user_profile_url( $user_id ) ), $link );
     117                $this->expectOutputString( $link );
     118                bbp_reply_author_link( $args );
     119        }
     120
     121        /**
     122         * @covers ::bbp_get_reply_author_link
     123         */
     124        public function test_bbp_get_reply_author_link_does_not_link_anonymous_name() {
     125                $topic_id = $this->factory->topic->create();
     126                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id, 'post_author' => 0 ) );
     127                update_post_meta( $reply_id, '_bbp_anonymous_name', 'Guest Author' );
     128                update_post_meta( $reply_id, '_bbp_anonymous_website', 'https://example.org/guest' );
     129                $link     = bbp_get_reply_author_link( array( 'post_id' => $reply_id, 'type' => 'name' ) );
     130
     131                $this->assertStringContainsString( 'Guest Author', $link );
     132                $this->assertStringNotContainsString( '<a ', $link );
    86133        }
    87134
    … …  
    89136         * @covers ::bbp_reply_author_url
    90137         * @covers ::bbp_get_reply_author_url
    91          * @todo   Implement test_bbp_get_reply_author_url().
    92138         */
    93139        public function test_bbp_get_reply_author_url() {
    94                 // Remove the following lines when you implement this test.
    95                 $this->markTestIncomplete(
    96                         'This test has not been implemented yet.'
    97                 );
     140                $user_id  = $this->factory->user->create();
     141                $topic_id = $this->factory->topic->create();
     142                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id, 'post_author' => $user_id ) );
     143
     144                $this->assertSame( bbp_get_user_profile_url( $user_id ), bbp_get_reply_author_url( $reply_id ) );
     145                $this->expectOutputString( esc_url( bbp_get_user_profile_url( $user_id ) ) );
     146                bbp_reply_author_url( $reply_id );
     147        }
     148
     149        /**
     150         * @covers ::bbp_get_reply_author_url
     151         */
     152        public function test_bbp_get_reply_author_url_uses_anonymous_website() {
     153                $topic_id = $this->factory->topic->create();
     154                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id, 'post_author' => 0 ) );
     155
     156                $this->assertSame( '', bbp_get_reply_author_url( $reply_id ) );
     157                update_post_meta( $reply_id, '_bbp_anonymous_website', 'https://example.org/guest' );
     158                $this->assertSame( 'https://example.org/guest', bbp_get_reply_author_url( $reply_id ) );
    98159        }
    99160
    … …  
    101162         * @covers ::bbp_reply_author_email
    102163         * @covers ::bbp_get_reply_author_email
    103          * @todo   Implement test_bbp_get_reply_author_email().
    104164         */
    105165        public function test_bbp_get_reply_author_email() {
    106                 // Remove the following lines when you implement this test.
    107                 $this->markTestIncomplete(
    108                         'This test has not been implemented yet.'
    109                 );
     166                $user_id  = $this->factory->user->create( array( 'user_email' => 'reply-author@example.org' ) );
     167                $topic_id = $this->factory->topic->create();
     168                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id, 'post_author' => $user_id ) );
     169
     170                $this->assertSame( 'reply-author@example.org', bbp_get_reply_author_email( $reply_id ) );
     171                $this->expectOutputString( 'reply-author@example.org' );
     172                bbp_reply_author_email( $reply_id );
     173        }
     174
     175        /**
     176         * @covers ::bbp_get_reply_author_email
     177         */
     178        public function test_bbp_get_reply_author_email_uses_anonymous_meta() {
     179                $topic_id = $this->factory->topic->create();
     180                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id, 'post_author' => 0 ) );
     181
     182                $this->assertSame( '', bbp_get_reply_author_email( $reply_id ) );
     183                update_post_meta( $reply_id, '_bbp_anonymous_email', 'guest@example.org' );
     184                $this->assertSame( 'guest@example.org', bbp_get_reply_author_email( $reply_id ) );
    110185        }
    111186
    … …  
    113188         * @covers ::bbp_reply_author_role
    114189         * @covers ::bbp_get_reply_author_role
    115          * @todo   Implement test_bbp_get_reply_author_role().
    116190         */
    117191        public function test_bbp_get_reply_author_role() {
    118                 // Remove the following lines when you implement this test.
    119                 $this->markTestIncomplete(
    120                         'This test has not been implemented yet.'
    121                 );
     192                $user_id  = $this->factory->user->create();
     193                $topic_id = $this->factory->topic->create();
     194                $reply_id = $this->factory->reply->create( array( 'post_parent' => $topic_id, 'post_author' => $user_id ) );
     195                $args     = array( 'reply_id' => $reply_id );
     196                $role     = bbp_get_user_display_role( $user_id );
     197                $expected = '<div class="bbp-author-role bbp-role-' . sanitize_key( $role ) . '">' . $role . '</div>';
     198
     199                $this->assertSame( $expected, bbp_get_reply_author_role( $args ) );
     200                $this->expectOutputString( $expected );
     201                bbp_reply_author_role( $args );
    122202        }
    123203}
  • trunk/tests/phpunit/testcases/topics/template/authors.php

    r7407 r7781  
    1313         * @covers ::bbp_topic_author
    1414         * @covers ::bbp_get_topic_author
    15          * @todo   Implement test_bbp_get_topic_author().
    1615         */
    1716        public function test_bbp_get_topic_author() {
    18                 // Remove the following lines when you implement this test.
    19                 $this->markTestIncomplete(
    20                         'This test has not been implemented yet.'
    21                 );
     17                $user_id  = $this->factory->user->create( array( 'display_name' => 'Topic Author' ) );
     18                $topic_id = $this->factory->topic->create( array( 'post_author' => $user_id ) );
     19
     20                $this->assertSame( 'Topic Author', bbp_get_topic_author( $topic_id ) );
     21                $this->expectOutputString( 'Topic Author' );
     22                bbp_topic_author( $topic_id );
     23        }
     24
     25        /**
     26         * @covers ::bbp_get_topic_author
     27         */
     28        public function test_bbp_get_topic_author_uses_anonymous_name() {
     29                $topic_id = $this->factory->topic->create( array( 'post_author' => 0 ) );
     30                update_post_meta( $topic_id, '_bbp_anonymous_name', 'Guest Author' );
     31
     32                $this->assertSame( 'Guest Author', bbp_get_topic_author( $topic_id ) );
    2233        }
    2334
    … …  
    5667         * @covers ::bbp_topic_author_avatar
    5768         * @covers ::bbp_get_topic_author_avatar
    58          * @todo   Implement test_bbp_get_topic_author_avatar().
    5969         */
    6070        public function test_bbp_get_topic_author_avatar() {
    61                 // Remove the following lines when you implement this test.
    62                 $this->markTestIncomplete(
    63                         'This test has not been implemented yet.'
    64                 );
     71                $user_id  = $this->factory->user->create();
     72                $topic_id = $this->factory->topic->create( array( 'post_author' => $user_id ) );
     73                $avatar   = bbp_get_topic_author_avatar( $topic_id, 64 );
     74
     75                $this->assertSame( get_avatar( $user_id, 64 ), $avatar );
     76                $this->expectOutputString( $avatar );
     77                bbp_topic_author_avatar( $topic_id, 64 );
     78        }
     79
     80        /**
     81         * @covers ::bbp_get_topic_author_avatar
     82         */
     83        public function test_bbp_get_topic_author_avatar_uses_anonymous_email() {
     84                $topic_id = $this->factory->topic->create( array( 'post_author' => 0 ) );
     85                update_post_meta( $topic_id, '_bbp_anonymous_email', 'guest@example.org' );
     86
     87                $this->assertSame( get_avatar( 'guest@example.org', 64 ), bbp_get_topic_author_avatar( $topic_id, 64 ) );
    6588        }
    6689
    … …  
    6891         * @covers ::bbp_topic_author_link
    6992         * @covers ::bbp_get_topic_author_link
    70          * @todo   Implement test_bbp_get_topic_author_link().
    7193         */
    7294        public function test_bbp_get_topic_author_link() {
    73                 // Remove the following lines when you implement this test.
    74                 $this->markTestIncomplete(
    75                         'This test has not been implemented yet.'
    76                 );
     95                $user_id  = $this->factory->user->create( array( 'display_name' => 'Topic Author' ) );
     96                $topic_id = $this->factory->topic->create( array( 'post_author' => $user_id ) );
     97                $args     = array( 'post_id' => $topic_id, 'type' => 'name' );
     98                $link     = bbp_get_topic_author_link( $args );
     99
     100                $this->assertStringContainsString( 'Topic Author', $link );
     101                $this->assertStringContainsString( 'bbp-author-name', $link );
     102                $this->assertStringContainsString( esc_url( bbp_get_user_profile_url( $user_id ) ), $link );
     103                $this->expectOutputString( $link );
     104                bbp_topic_author_link( $args );
     105        }
     106
     107        /**
     108         * @covers ::bbp_get_topic_author_link
     109         */
     110        public function test_bbp_get_topic_author_link_does_not_link_anonymous_name() {
     111                $topic_id = $this->factory->topic->create( array( 'post_author' => 0 ) );
     112                update_post_meta( $topic_id, '_bbp_anonymous_name', 'Guest Author' );
     113                update_post_meta( $topic_id, '_bbp_anonymous_website', 'https://example.org/guest' );
     114                $link     = bbp_get_topic_author_link( array( 'post_id' => $topic_id, 'type' => 'name' ) );
     115
     116                $this->assertStringContainsString( 'Guest Author', $link );
     117                $this->assertStringNotContainsString( '<a ', $link );
    77118        }
    78119
    … …  
    80121         * @covers ::bbp_topic_author_url
    81122         * @covers ::bbp_get_topic_author_url
    82          * @todo   Implement test_bbp_get_topic_author_url().
    83123         */
    84124        public function test_bbp_get_topic_author_url() {
    85                 // Remove the following lines when you implement this test.
    86                 $this->markTestIncomplete(
    87                         'This test has not been implemented yet.'
    88                 );
     125                $user_id  = $this->factory->user->create();
     126                $topic_id = $this->factory->topic->create( array( 'post_author' => $user_id ) );
     127
     128                $this->assertSame( bbp_get_user_profile_url( $user_id ), bbp_get_topic_author_url( $topic_id ) );
     129                $this->expectOutputString( esc_url( bbp_get_user_profile_url( $user_id ) ) );
     130                bbp_topic_author_url( $topic_id );
     131        }
     132
     133        /**
     134         * @covers ::bbp_get_topic_author_url
     135         */
     136        public function test_bbp_get_topic_author_url_uses_anonymous_website() {
     137                $topic_id = $this->factory->topic->create( array( 'post_author' => 0 ) );
     138
     139                $this->assertSame( '', bbp_get_topic_author_url( $topic_id ) );
     140                update_post_meta( $topic_id, '_bbp_anonymous_website', 'https://example.org/guest' );
     141                $this->assertSame( 'https://example.org/guest', bbp_get_topic_author_url( $topic_id ) );
    89142        }
    90143
    … …  
    92145         * @covers ::bbp_topic_author_email
    93146         * @covers ::bbp_get_topic_author_email
    94          * @todo   Implement test_bbp_get_topic_author_email().
    95147         */
    96148        public function test_bbp_get_topic_author_email() {
    97                 // Remove the following lines when you implement this test.
    98                 $this->markTestIncomplete(
    99                         'This test has not been implemented yet.'
    100                 );
     149                $user_id  = $this->factory->user->create( array( 'user_email' => 'topic-author@example.org' ) );
     150                $topic_id = $this->factory->topic->create( array( 'post_author' => $user_id ) );
     151
     152                $this->assertSame( 'topic-author@example.org', bbp_get_topic_author_email( $topic_id ) );
     153                $this->expectOutputString( 'topic-author@example.org' );
     154                bbp_topic_author_email( $topic_id );
     155        }
     156
     157        /**
     158         * @covers ::bbp_get_topic_author_email
     159         */
     160        public function test_bbp_get_topic_author_email_uses_anonymous_meta() {
     161                $topic_id = $this->factory->topic->create( array( 'post_author' => 0 ) );
     162
     163                $this->assertSame( '', bbp_get_topic_author_email( $topic_id ) );
     164                update_post_meta( $topic_id, '_bbp_anonymous_email', 'guest@example.org' );
     165                $this->assertSame( 'guest@example.org', bbp_get_topic_author_email( $topic_id ) );
    101166        }
    102167
    … …  
    104169         * @covers ::bbp_topic_author_role
    105170         * @covers ::bbp_get_topic_author_role
    106          * @todo   Implement test_bbp_get_topic_author_role().
    107171         */
    108172        public function test_bbp_get_topic_author_role() {
    109                 // Remove the following lines when you implement this test.
    110                 $this->markTestIncomplete(
    111                         'This test has not been implemented yet.'
    112                 );
     173                $user_id  = $this->factory->user->create();
     174                $topic_id = $this->factory->topic->create( array( 'post_author' => $user_id ) );
     175                $args     = array( 'topic_id' => $topic_id );
     176                $role     = bbp_get_user_display_role( $user_id );
     177                $expected = '<div class="bbp-author-role bbp-role-' . sanitize_key( $role ) . '">' . $role . '</div>';
     178
     179                $this->assertSame( $expected, bbp_get_topic_author_role( $args ) );
     180                $this->expectOutputString( $expected );
     181                bbp_topic_author_role( $args );
    113182        }
    114183}
Note: See TracChangeset for help on using the changeset viewer.