Changeset 7793
- Timestamp:
- 10/04/2026 08:54:57 AM (5 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/testcases/replies/template/links.php
r7448 r7793 10 10 class BBP_Tests_Replies_Template_Links extends BBP_UnitTestCase { 11 11 12 private function with_keymaster_reply( $callback ) { 13 $old_user = get_current_user_id(); 14 $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); 15 $forum_id = $this->factory->forum->create(); 16 $topic_id = $this->factory->topic->create( array( 17 'post_parent' => $forum_id, 18 'topic_meta' => array( 'forum_id' => $forum_id ), 19 ) ); 20 $reply_id = $this->factory->reply->create( array( 21 'post_parent' => $topic_id, 22 'reply_meta' => array( 'forum_id' => $forum_id, 'topic_id' => $topic_id ), 23 ) ); 24 bbp_set_user_role( $user_id, bbp_get_keymaster_role() ); 25 $this->set_current_user( $user_id ); 26 27 try { 28 $callback( $reply_id, $topic_id, $forum_id, $user_id ); 29 } finally { 30 $this->set_current_user( $old_user ); 31 } 32 } 33 12 34 /** 13 35 * @covers ::bbp_reply_to_link 14 36 * @covers ::bbp_get_reply_to_link 15 * @todo Implement test_bbp_get_reply_to_link().16 37 */ 17 38 public function test_bbp_get_reply_to_link() { 18 // Remove the following lines when you implement this test. 19 $this->markTestIncomplete( 20 'This test has not been implemented yet.' 21 ); 39 $this->with_keymaster_reply( function ( $reply_id ) { 40 $args = array( 'id' => $reply_id, 'reply_text' => 'Answer', 'link_before' => '<span>', 'link_after' => '</span>' ); 41 $link = bbp_get_reply_to_link( $args ); 42 $this->assertStringStartsWith( '<span><a role="button"', $link ); 43 $this->assertStringContainsString( 'bbp_reply_to=' . $reply_id, $link ); 44 $this->assertStringContainsString( 'class="bbp-reply-to-link"', $link ); 45 $this->assertStringContainsString( '>Answer</a></span>', $link ); 46 $this->expectOutputString( $link ); 47 bbp_reply_to_link( $args ); 48 } ); 22 49 } 23 50 … … 25 52 * @covers ::bbp_cancel_reply_to_link 26 53 * @covers ::bbp_get_cancel_reply_to_link 27 * @todo Implement test_bbp_get_cancel_reply_to_link().28 54 */ 29 55 public function test_bbp_get_cancel_reply_to_link() { 30 // Remove the following lines when you implement this test. 31 $this->markTestIncomplete( 32 'This test has not been implemented yet.' 33 ); 56 $this->assertNull( bbp_get_cancel_reply_to_link() ); 57 $old_reply_to = isset( $_GET['bbp_reply_to'] ) ? $_GET['bbp_reply_to'] : null; 58 add_filter( 'bbp_thread_replies', '__return_true' ); 59 60 try { 61 unset( $_GET['bbp_reply_to'] ); 62 $this->assertStringContainsString( 'style="display:none;"', bbp_get_cancel_reply_to_link() ); 63 $_GET['bbp_reply_to'] = '42'; 64 $link = bbp_get_cancel_reply_to_link( 'Stop' ); 65 $this->assertStringContainsString( '#post-42', $link ); 66 $this->assertStringContainsString( '>Stop</a>', $link ); 67 $this->assertStringNotContainsString( 'display:none', $link ); 68 $this->expectOutputString( $link ); 69 bbp_cancel_reply_to_link( 'Stop' ); 70 } finally { 71 remove_filter( 'bbp_thread_replies', '__return_true' ); 72 if ( null === $old_reply_to ) { 73 unset( $_GET['bbp_reply_to'] ); 74 } else { 75 $_GET['bbp_reply_to'] = $old_reply_to; 76 } 77 } 34 78 } 35 79 … … 58 102 * @covers ::bbp_reply_edit_link 59 103 * @covers ::bbp_get_reply_edit_link 60 * @todo Implement test_bbp_get_reply_edit_link().61 104 */ 62 105 public function test_bbp_get_reply_edit_link() { 63 // Remove the following lines when you implement this test. 64 $this->markTestIncomplete( 65 'This test has not been implemented yet.' 66 ); 106 $this->with_keymaster_reply( function ( $reply_id ) { 107 $args = array( 'id' => $reply_id, 'edit_text' => 'Modify', 'link_before' => '<span>', 'link_after' => '</span>' ); 108 $link = bbp_get_reply_edit_link( $args ); 109 $this->assertStringContainsString( 'class="bbp-reply-edit-link"', $link ); 110 $this->assertStringContainsString( esc_url( bbp_get_reply_edit_url( $reply_id ) ), $link ); 111 $this->assertStringContainsString( '>Modify</a></span>', $link ); 112 $this->expectOutputString( $link ); 113 bbp_reply_edit_link( $args ); 114 } ); 67 115 } 68 116 … … 70 118 * @covers ::bbp_reply_edit_url 71 119 * @covers ::bbp_get_reply_edit_url 72 * @todo Implement test_bbp_get_reply_edit_url().73 120 */ 74 121 public function test_bbp_get_reply_edit_url() { 75 // Remove the following lines when you implement this test. 76 $this->markTestIncomplete( 77 'This test has not been implemented yet.' 78 ); 122 $this->assertNull( bbp_get_reply_edit_url( PHP_INT_MAX ) ); 123 $this->with_keymaster_reply( function ( $reply_id ) { 124 $url = bbp_get_reply_edit_url( $reply_id ); 125 $this->assertNotEmpty( $url ); 126 $this->assertStringContainsString( bbp_get_edit_rewrite_id(), $url ); 127 $this->expectOutputString( esc_url( $url ) ); 128 bbp_reply_edit_url( $reply_id ); 129 } ); 79 130 } 80 131 … … 82 133 * @covers ::bbp_reply_trash_link 83 134 * @covers ::bbp_get_reply_trash_link 84 * @todo Implement test_bbp_get_reply_trash_link().85 135 */ 86 136 public function test_bbp_get_reply_trash_link() { 87 // Remove the following lines when you implement this test. 88 $this->markTestIncomplete( 89 'This test has not been implemented yet.' 90 ); 137 $this->with_keymaster_reply( function ( $reply_id ) { 138 $args = array( 'id' => $reply_id, 'trash_text' => 'Discard', 'restore_text' => 'Recover', 'delete_text' => 'Erase' ); 139 $link = bbp_get_reply_trash_link( $args ); 140 $this->assertStringContainsString( 'bbp-reply-trash-link', $link ); 141 $this->assertStringContainsString( '>Discard</a>', $link ); 142 wp_trash_post( $reply_id ); 143 $link = bbp_get_reply_trash_link( $args ); 144 $this->assertStringContainsString( 'bbp-reply-restore-link', $link ); 145 $this->assertStringContainsString( 'bbp-reply-delete-link', $link ); 146 $this->assertStringContainsString( '>Recover</a>', $link ); 147 $this->assertStringContainsString( '>Erase</a>', $link ); 148 $this->expectOutputString( $link ); 149 bbp_reply_trash_link( $args ); 150 } ); 91 151 } 92 152 … … 94 154 * @covers ::bbp_reply_spam_link 95 155 * @covers ::bbp_get_reply_spam_link 96 * @todo Implement test_bbp_get_reply_spam_link().97 156 */ 98 157 public function test_bbp_get_reply_spam_link() { 99 // Remove the following lines when you implement this test. 100 $this->markTestIncomplete( 101 'This test has not been implemented yet.' 102 ); 158 $this->with_keymaster_reply( function ( $reply_id ) { 159 $args = array( 'id' => $reply_id, 'spam_text' => 'Flag', 'unspam_text' => 'Clear' ); 160 $link = bbp_get_reply_spam_link( $args ); 161 $this->assertStringContainsString( 'bbp-reply-spam-link', $link ); 162 $this->assertStringContainsString( '>Flag</a>', $link ); 163 bbp_spam_reply( $reply_id ); 164 $link = bbp_get_reply_spam_link( $args ); 165 $this->assertStringContainsString( '>Clear</a>', $link ); 166 $this->expectOutputString( $link ); 167 bbp_reply_spam_link( $args ); 168 } ); 103 169 } 104 170 … … 106 172 * @covers ::bbp_reply_move_link 107 173 * @covers ::bbp_get_reply_move_link 108 * @todo Implement test_bbp_get_reply_move_link().109 174 */ 110 175 public function test_bbp_get_reply_move_link() { 111 // Remove the following lines when you implement this test. 112 $this->markTestIncomplete( 113 'This test has not been implemented yet.' 114 ); 176 $this->with_keymaster_reply( function ( $reply_id ) { 177 $args = array( 'id' => $reply_id, 'split_text' => 'Relocate' ); 178 $link = bbp_get_reply_move_link( $args ); 179 $this->assertStringContainsString( 'bbp-reply-move-link', $link ); 180 $this->assertStringContainsString( 'action=move', $link ); 181 $this->assertStringContainsString( '>Relocate</a>', $link ); 182 $this->expectOutputString( $link ); 183 bbp_reply_move_link( $args ); 184 } ); 115 185 } 116 186 … … 118 188 * @covers ::bbp_topic_split_link 119 189 * @covers ::bbp_get_topic_split_link 120 * @todo Implement test_bbp_get_topic_split_link().121 190 */ 122 191 public function test_bbp_get_topic_split_link() { 123 // Remove the following lines when you implement this test. 124 $this->markTestIncomplete( 125 'This test has not been implemented yet.' 126 ); 192 $this->with_keymaster_reply( function ( $reply_id ) { 193 $args = array( 'id' => $reply_id, 'split_text' => 'Divide' ); 194 $link = bbp_get_topic_split_link( $args ); 195 $this->assertStringContainsString( 'bbp-topic-split-link', $link ); 196 $this->assertStringContainsString( 'action=split', $link ); 197 $this->assertStringContainsString( '>Divide</a>', $link ); 198 $this->expectOutputString( $link ); 199 bbp_topic_split_link( $args ); 200 } ); 127 201 } 128 202 … … 130 204 * @covers ::bbp_reply_approve_link 131 205 * @covers ::bbp_get_reply_approve_link 132 * @todo Implement test_bbp_get_reply_approve_link().133 206 */ 134 207 public function test_bbp_get_reply_approve_link() { 135 // Remove the following lines when you implement this test. 136 $this->markTestIncomplete( 137 'This test has not been implemented yet.' 138 ); 208 $this->with_keymaster_reply( function ( $reply_id ) { 209 $args = array( 'id' => $reply_id, 'approve_text' => 'Accept', 'unapprove_text' => 'Hold' ); 210 $link = bbp_get_reply_approve_link( $args ); 211 $this->assertStringContainsString( 'bbp-reply-approve-link', $link ); 212 $this->assertStringContainsString( '>Hold</a>', $link ); 213 bbp_unapprove_reply( $reply_id ); 214 $link = bbp_get_reply_approve_link( $args ); 215 $this->assertStringContainsString( '>Accept</a>', $link ); 216 $this->expectOutputString( $link ); 217 bbp_reply_approve_link( $args ); 218 } ); 139 219 } 140 220 … … 142 222 * @covers ::bbp_topic_pagination_links 143 223 * @covers ::bbp_get_topic_pagination_links 144 * @todo Implement test_bbp_get_topic_pagination_links().145 224 */ 146 225 public function test_bbp_get_topic_pagination_links() { 147 // Remove the following lines when you implement this test. 148 $this->markTestIncomplete( 149 'This test has not been implemented yet.' 150 ); 226 $old_query = bbpress()->reply_query; 227 bbpress()->reply_query = (object) array(); 228 229 try { 230 $this->assertFalse( bbp_get_topic_pagination_links() ); 231 bbpress()->reply_query->pagination_links = '<a href="?paged=2">2</a>'; 232 $this->assertSame( '<a href="?paged=2">2</a>', bbp_get_topic_pagination_links() ); 233 $this->expectOutputString( '<a href="?paged=2">2</a>' ); 234 bbp_topic_pagination_links(); 235 } finally { 236 bbpress()->reply_query = $old_query; 237 } 151 238 } 152 239 }
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)