Ticket #6834: 6834.patch
File 6834.patch, 3.7 KB (added by , 9 years ago) |
---|
-
src/bp-activity/bp-activity-actions.php
diff --git src/bp-activity/bp-activity-actions.php src/bp-activity/bp-activity-actions.php index 7d17133..f9b9e83 100644
function bp_activity_catch_transition_post_type_status( $new_status, $old_status 797 797 if ( $new_status === $old_status ) { 798 798 // An edit of an existing post should update the existing activity item. 799 799 if ( $new_status == 'publish' ) { 800 bp_activity_post_type_update( $post ); 800 $edit = bp_activity_post_type_update( $post ); 801 802 // Post was never recorded into activity stream, so record it now! 803 if ( null === $edit ) { 804 bp_activity_post_type_publish( $post->ID, $post ); 805 } 801 806 } 802 807 803 808 return; -
tests/phpunit/testcases/activity/actions.php
diff --git tests/phpunit/testcases/activity/actions.php tests/phpunit/testcases/activity/actions.php index d1ae6df..7cbd2f3 100644
class BP_Tests_Activity_Actions extends BP_UnitTestCase { 57 57 // 'new' => 'publish' 58 58 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 59 59 60 // Delete the activity61 bp_activity_post_type_unpublish( $post_id, $post );62 63 $post->post_status = 'publish';64 $post->post_content .= ' foo';65 66 wp_update_post( $post );67 68 $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Updating a post type should not create a new activity' );69 70 60 _unregister_post_type( 'foo' ); 71 61 72 62 // Reset globals … … class BP_Tests_Activity_Actions extends BP_UnitTestCase { 78 68 * @group bp_activity_catch_transition_post_type_status 79 69 * @group activity_tracking 80 70 */ 71 public function test_bp_activity_catch_transition_post_type_status_publish_existing_post() { 72 $u = $this->factory->user->create(); 73 74 $labels = array( 75 'bp_activity_admin_filter' => 'New Foo', 76 'bp_activity_front_filter' => 'Foos', 77 'bp_activity_new_post' => '%1$s posted a new <a href="%2$s">foo</a>', 78 'bp_activity_new_post_ms' => '%1$s posted a new <a href="%2$s">foo</a>, on the site %3$s', 79 ); 80 81 /** 82 * 'public' must be set to true, otherwise bp_activity_get_post_types_tracking_args() fails. 83 */ 84 register_post_type( 'foo', array( 85 'labels' => $labels, 86 'public' => true, 87 'supports' => array( 'buddypress-activity' ), 88 'bp_activity' => array( 89 'action_id' => 'new_foo', 90 'contexts' => array( 'activity' ), 91 'position' => 40, 92 ) 93 ) ); 94 95 // Temporarily remove post type activity hook so activity item isn't created. 96 remove_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 ); 97 98 // Create the initial post. 99 $p = $this->factory->post->create( array( 100 'post_author' => $u, 101 'post_type' => 'foo', 102 ) ); 103 104 $this->assertEmpty( bp_activity_get_activity_id( array( 'type' => 'new_foo' ) ) ); 105 106 // Add the post type activity hook back. 107 add_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 ); 108 109 // Emulate updating a post; this should create an activity item. 110 wp_update_post( array( 111 'ID' => $p, 112 'post_title' => 'This is an edit', 113 ) ); 114 115 // Assert! 116 $this->assertNotEmpty( bp_activity_get_activity_id( array( 'type' => 'new_foo' ) ), 'Activity item was not created during an edit of an existing WordPress post.' ); 117 118 // Clean up. 119 _unregister_post_type( 'foo' ); 120 } 121 122 /** 123 * @group bp_activity_catch_transition_post_type_status 124 * @group activity_tracking 125 */ 81 126 public function test_bp_activity_catch_transition_post_type_status_publish_password() { 82 127 $bp = buddypress(); 83 128