[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @group activity 4 */ 5 class BP_Tests_Activity_Actions extends BP_UnitTestCase { 6 7 /** 8 * @group bp_activity_catch_transition_post_type_status 9 * @group activity_tracking 10 */ 11 public function test_bp_activity_catch_transition_post_type_status_publish() { 12 register_post_type( 'foo', array( 13 'label' => 'foo', 14 'public' => true, 15 'supports' => array( 'buddypress-activity' ), 16 ) ); 17 18 $post_id = self::factory()->post->create( array( 19 'post_status' => 'publish', 20 'post_type' => 'foo', 21 ) ); 22 23 $post = get_post( $post_id ); 24 25 // 'new' => 'publish' 26 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 27 28 _unregister_post_type( 'foo' ); 29 } 30 31 /** 32 * @group bp_activity_catch_transition_post_type_status 33 * @group activity_tracking 34 */ 35 public function test_bp_activity_catch_transition_post_type_status_publish_to_publish() { 36 register_post_type( 'foo', array( 37 'label' => 'foo', 38 'public' => true, 39 'supports' => array( 'buddypress-activity' ), 40 ) ); 41 42 $post_id = self::factory()->post->create( array( 43 'post_status' => 'publish', 44 'post_type' => 'foo', 45 ) ); 46 47 $post = get_post( $post_id ); 48 49 // 'new' => 'publish' 50 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 51 52 _unregister_post_type( 'foo' ); 53 } 54 55 /** 56 * @group bp_activity_catch_transition_post_type_status 57 * @group activity_tracking 58 */ 59 public function test_bp_activity_catch_transition_post_type_status_publish_existing_post() { 60 $u = self::factory()->user->create(); 61 62 $labels = array( 63 'bp_activity_admin_filter' => 'New Foo', 64 'bp_activity_front_filter' => 'Foos', 65 'bp_activity_new_post' => '%1$s posted a new <a href="%2$s">foo</a>', 66 'bp_activity_new_post_ms' => '%1$s posted a new <a href="%2$s">foo</a>, on the site %3$s', 67 ); 68 69 /** 70 * 'public' must be set to true, otherwise bp_activity_get_post_types_tracking_args() fails. 71 */ 72 register_post_type( 'foo', array( 73 'labels' => $labels, 74 'public' => true, 75 'supports' => array( 'buddypress-activity' ), 76 'bp_activity' => array( 77 'action_id' => 'new_foo', 78 'contexts' => array( 'activity' ), 79 'position' => 40, 80 ) 81 ) ); 82 83 // Temporarily remove post type activity hook so activity item isn't created. 84 remove_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10 ); 85 86 // Create the initial post. 87 $p = self::factory()->post->create( array( 88 'post_author' => $u, 89 'post_type' => 'foo', 90 ) ); 91 92 $this->assertEmpty( bp_activity_get_activity_id( array( 'type' => 'new_foo' ) ) ); 93 94 // Add the post type activity hook back. 95 add_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 ); 96 97 // Emulate updating a post; this should create an activity item. 98 wp_update_post( array( 99 'ID' => $p, 100 'post_title' => 'This is an edit', 101 ) ); 102 103 // Assert! 104 $this->assertNotEmpty( bp_activity_get_activity_id( array( 'type' => 'new_foo' ) ), 'Activity item was not created during an edit of an existing WordPress post.' ); 105 106 // Clean up. 107 _unregister_post_type( 'foo' ); 108 } 109 110 /** 111 * @group bp_activity_catch_transition_post_type_status 112 * @group activity_tracking 113 */ 114 public function test_bp_activity_catch_transition_post_type_status_publish_password() { 115 register_post_type( 'foo', array( 116 'label' => 'foo', 117 'public' => true, 118 'supports' => array( 'buddypress-activity' ), 119 ) ); 120 121 $post_id = self::factory()->post->create( array( 122 'post_status' => 'publish', 123 'post_type' => 'foo', 124 ) ); 125 126 $post = get_post( $post_id ); 127 128 // 'new' => 'publish' 129 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 130 131 $post->post_status = 'publish'; 132 $post->post_password = 'foo'; 133 134 wp_update_post( $post ); 135 136 // 'publish' => 'publish' (password protected) 137 $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Password protected post type should not have activity' ); 138 139 _unregister_post_type( 'foo' ); 140 } 141 142 /** 143 * @group bp_activity_catch_transition_post_type_status 144 * @group activity_tracking 145 */ 146 public function test_bp_activity_catch_transition_post_type_status_publish_trash() { 147 register_post_type( 'foo', array( 148 'label' => 'foo', 149 'public' => true, 150 'supports' => array( 'buddypress-activity' ), 151 ) ); 152 153 $post_id = self::factory()->post->create( array( 154 'post_status' => 'publish', 155 'post_type' => 'foo', 156 ) ); 157 158 $post = get_post( $post_id ); 159 160 // 'new' => 'publish' 161 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); 162 163 wp_trash_post( $post->ID ); 164 165 // 'publish' => 'publish' (password protected) 166 $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Unpublished post type should not have activity' ); 167 168 _unregister_post_type( 'foo' ); 169 } 170 171 /** 172 * @ticket BP8579 173 * @group bp_activity_catch_transition_post_type_status 174 * @group activity_tracking 175 */ 176 public function test_bp_activity_catch_transition_post_type_status_publish_publish_author_changed() { 177 $u1 = self::factory()->user->create( 178 array( 179 'role' => 'auhor', 180 ) 181 ); 182 183 $u2 = self::factory()->user->create( 184 array( 185 'role' => 'auhor', 186 ) 187 ); 188 189 $post_id = self::factory()->post->create( array( 190 'post_status' => 'publish', 191 'post_author' => $u1, 192 'post_type' => 'post', 193 ) ); 194 195 $post = get_post( $post_id ); 196 197 // 'new' => 'publish' 198 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_post' ), 'Published post type should have activity' ); 199 200 $post->post_author = $u2; 201 202 wp_update_post( $post ); 203 204 $a = $this->activity_exists_for_post( $post_id, 'new_post', true ); 205 206 $this->assertSame( $u2, $a->user_id, 'The Activity about a published post type should be updated when the post author has changed.' ); 207 } 208 209 /** 210 * @ticket BP8579 211 * @group bp_activity_catch_transition_post_type_status 212 * @group activity_tracking 213 */ 214 public function test_bp_activity_catch_transition_post_type_status_publish_publish_content_changed() { 215 $u1 = self::factory()->user->create( 216 array( 217 'role' => 'auhor', 218 ) 219 ); 220 221 $u2 = self::factory()->user->create( 222 array( 223 'role' => 'auhor', 224 ) 225 ); 226 227 $post_id = self::factory()->post->create( array( 228 'post_status' => 'publish', 229 'post_author' => $u1, 230 'post_type' => 'post', 231 ) ); 232 233 $post = get_post( $post_id ); 234 235 // 'new' => 'publish' 236 $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_post' ), 'Published post type should have activity' ); 237 238 $post->post_content = "This time {$u2} has not edited the post"; 239 240 wp_update_post( $post ); 241 242 $a = $this->activity_exists_for_post( $post_id, 'new_post', true ); 243 244 $this->assertSame( $post->post_content, $a->content, 'The Activity about a published post type should be updated when the post content has changed.' ); 245 } 246 247 protected function activity_exists_for_post( $post_id, $action, $get_object = false ) { 248 $a = bp_activity_get( array( 249 'action' => $action, 250 'item_id' => get_current_blog_id(), 251 'secondary_item_id' => $post_id, 252 ) ); 253 254 if ( $get_object ) { 255 return reset( $a['activities'] ); 256 } 257 258 return ! empty( $a['activities'] ); 259 } 260 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |