Ticket #6119: 6119.patch
File 6119.patch, 2.8 KB (added by , 9 years ago) |
---|
-
src/bp-blogs/bp-blogs-activity.php
diff --git src/bp-blogs/bp-blogs-activity.php src/bp-blogs/bp-blogs-activity.php index c52287c..c2122bc 100644
function bp_blogs_format_activity_action_new_blog_post( $action, $activity ) { 123 123 $post_url = $activity->post_url; 124 124 } 125 125 126 if ( empty( $activity->post_title ) ) { 127 $post_title = bp_activity_get_meta( $activity->id, 'post_title' ); 128 } else { 126 if ( ! empty( $activity->post_title ) ) { 129 127 $post_title = $activity->post_title; 128 129 // If activity already exists try to get the post title from activity meta 130 } else if ( ! empty( $activity->id ) ) { 131 $post_title = bp_activity_get_meta( $activity->id, 'post_title' ); 130 132 } 131 133 132 134 // Should only be empty at the time of post creation 133 135 if ( empty( $post_title ) ) { 136 // Defaults to no title 137 $post_title = esc_html__( '(no title)', 'buddypress' ); 138 134 139 switch_to_blog( $activity->item_id ); 135 140 136 141 $post = get_post( $activity->secondary_item_id ); 137 142 if ( is_a( $post, 'WP_Post' ) ) { 138 $post_title = $post->post_title; 139 bp_activity_update_meta( $activity->id, 'post_title', $post_title ); 143 // Does the post have a title ? 144 if ( ! empty( $post->post_title ) ) { 145 $post_title = $post->post_title; 146 } 147 148 // Make sure the activity id exists 149 if ( ! empty( $activity->id ) ) { 150 bp_activity_update_meta( $activity->id, 'post_title', $post_title ); 151 } 140 152 } 141 153 142 154 restore_current_blog(); -
tests/phpunit/testcases/blogs/activity.php
diff --git tests/phpunit/testcases/blogs/activity.php tests/phpunit/testcases/blogs/activity.php index e67adab..a5d548d 100644
class BP_Tests_Blogs_Activity extends BP_UnitTestCase { 283 283 284 284 $this->assertEquals( $this->comment_post_id, $p ); 285 285 } 286 287 /** 288 * @group activity_action 289 * @group bp_blogs_format_activity_action_new_blog_post 290 */ 291 public function test_bp_blogs_format_activity_action_new_blog_post_no_title() { 292 if ( is_multisite() ) { 293 return; 294 } 295 296 $u = $this->factory->user->create(); 297 $p = wp_insert_post( array( 298 'post_author' => $u, 299 'post_title' => '', // no title: the object of the test 300 'post_status' => 'publish', 301 'post_content' => 'foo bar', 302 ) ); 303 304 $user_link = bp_core_get_userlink( $u ); 305 $blog_url = get_home_url(); 306 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) ); 307 $post_title = '(no title)'; 308 $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>'; 309 310 $a_obj = bp_activity_get( array( 311 'item_id' => 1, 312 'secondary_item_id' => $p, 313 ) ); 314 315 $expected = sprintf( '%s wrote a new post, %s', $user_link, $post_link ); 316 317 $this->assertSame( $expected, $a_obj['activities'][0]->action ); 318 } 319 286 320 /** 287 321 * Dopey passthrough method so we can check that the correct values 288 322 * are being passed to the filter