Changeset 7781
- Timestamp:
- 10/04/2026 07:42:50 AM (5 weeks ago)
- Location:
- trunk/tests/phpunit/testcases
- Files:
-
- 2 edited
-
replies/template/authors.php (modified) (6 diffs)
-
topics/template/authors.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/replies/template/authors.php
r7407 r7781 13 13 * @covers ::bbp_reply_author 14 14 * @covers ::bbp_get_reply_author 15 * @todo Implement test_bbp_get_reply_author().16 15 */ 17 16 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 ) ); 22 35 } 23 36 … … 65 78 * @covers ::bbp_reply_author_avatar 66 79 * @covers ::bbp_get_reply_author_avatar 67 * @todo Implement test_bbp_get_reply_author_avatar().68 80 */ 69 81 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 ) ); 74 101 } 75 102 … … 77 104 * @covers ::bbp_reply_author_link 78 105 * @covers ::bbp_get_reply_author_link 79 * @todo Implement test_bbp_get_reply_author_link().80 106 */ 81 107 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 ); 86 133 } 87 134 … … 89 136 * @covers ::bbp_reply_author_url 90 137 * @covers ::bbp_get_reply_author_url 91 * @todo Implement test_bbp_get_reply_author_url().92 138 */ 93 139 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 ) ); 98 159 } 99 160 … … 101 162 * @covers ::bbp_reply_author_email 102 163 * @covers ::bbp_get_reply_author_email 103 * @todo Implement test_bbp_get_reply_author_email().104 164 */ 105 165 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 ) ); 110 185 } 111 186 … … 113 188 * @covers ::bbp_reply_author_role 114 189 * @covers ::bbp_get_reply_author_role 115 * @todo Implement test_bbp_get_reply_author_role().116 190 */ 117 191 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 ); 122 202 } 123 203 } -
trunk/tests/phpunit/testcases/topics/template/authors.php
r7407 r7781 13 13 * @covers ::bbp_topic_author 14 14 * @covers ::bbp_get_topic_author 15 * @todo Implement test_bbp_get_topic_author().16 15 */ 17 16 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 ) ); 22 33 } 23 34 … … 56 67 * @covers ::bbp_topic_author_avatar 57 68 * @covers ::bbp_get_topic_author_avatar 58 * @todo Implement test_bbp_get_topic_author_avatar().59 69 */ 60 70 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 ) ); 65 88 } 66 89 … … 68 91 * @covers ::bbp_topic_author_link 69 92 * @covers ::bbp_get_topic_author_link 70 * @todo Implement test_bbp_get_topic_author_link().71 93 */ 72 94 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 ); 77 118 } 78 119 … … 80 121 * @covers ::bbp_topic_author_url 81 122 * @covers ::bbp_get_topic_author_url 82 * @todo Implement test_bbp_get_topic_author_url().83 123 */ 84 124 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 ) ); 89 142 } 90 143 … … 92 145 * @covers ::bbp_topic_author_email 93 146 * @covers ::bbp_get_topic_author_email 94 * @todo Implement test_bbp_get_topic_author_email().95 147 */ 96 148 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 ) ); 101 166 } 102 167 … … 104 169 * @covers ::bbp_topic_author_role 105 170 * @covers ::bbp_get_topic_author_role 106 * @todo Implement test_bbp_get_topic_author_role().107 171 */ 108 172 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 ); 113 182 } 114 183 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)