| | 397 | /** |
| | 398 | * @group bp_blogs_catch_transition_post_status |
| | 399 | */ |
| | 400 | public function test_update_blog_post_and_activity_meta() { |
| | 401 | $post_id = $this->factory->post->create( array( |
| | 402 | 'post_status' => 'publish', |
| | 403 | 'post_type' => 'post', |
| | 404 | 'post_title' => 'First title', |
| | 405 | ) ); |
| | 406 | |
| | 407 | wp_update_post( array( |
| | 408 | 'ID' => $post_id, |
| | 409 | 'post_title' => 'Second title', |
| | 410 | ) ); |
| | 411 | |
| | 412 | $activity_id = bp_activity_get_activity_id( array( |
| | 413 | 'component' => buddypress()->blogs->id, |
| | 414 | 'type' => 'new_blog_post', |
| | 415 | 'item_id' => get_current_blog_id(), |
| | 416 | 'secondary_item_id' => $post_id, |
| | 417 | ) ); |
| | 418 | |
| | 419 | $this->assertEquals( 'Second title', bp_activity_get_meta( $activity_id, 'post_title' ) ); |
| | 420 | } |
| | 421 | |
| | 422 | /** |
| | 423 | * @group bp_blogs_catch_transition_post_status |
| | 424 | */ |
| | 425 | public function test_update_blog_post_and_new_blog_comment_activity_meta() { |
| | 426 | // save the current user and override logged-in user |
| | 427 | $old_user = get_current_user_id(); |
| | 428 | $u = $this->create_user(); |
| | 429 | $this->set_current_user( $u ); |
| | 430 | $userdata = get_userdata( $u ); |
| | 431 | |
| | 432 | // create the blog post |
| | 433 | $post_id = $this->factory->post->create( array( |
| | 434 | 'post_status' => 'publish', |
| | 435 | 'post_type' => 'post', |
| | 436 | 'post_title' => 'First title', |
| | 437 | ) ); |
| | 438 | |
| | 439 | // create the blog comment |
| | 440 | $comment_id = wp_new_comment( array( |
| | 441 | 'comment_post_ID' => $post_id, |
| | 442 | 'comment_author' => $userdata->user_nicename, |
| | 443 | 'comment_author_url' => 'http://buddypress.org', |
| | 444 | 'comment_author_email' => $userdata->user_email, |
| | 445 | 'comment_content' => 'this is a blog comment', |
| | 446 | 'comment_type' => '', |
| | 447 | 'comment_parent' => 0, |
| | 448 | 'user_id' => $u, |
| | 449 | ) ); |
| | 450 | |
| | 451 | // update the initial blog post |
| | 452 | wp_update_post( array( |
| | 453 | 'ID' => $post_id, |
| | 454 | 'post_title' => 'Second title', |
| | 455 | ) ); |
| | 456 | |
| | 457 | // grab the activity ID for the blog comment |
| | 458 | $activity_id = bp_activity_get_activity_id( array( |
| | 459 | 'component' => buddypress()->blogs->id, |
| | 460 | 'type' => 'new_blog_comment', |
| | 461 | 'secondary_item_id' => $comment_id, |
| | 462 | ) ); |
| | 463 | |
| | 464 | // see if blog comment activity meta matches the post items |
| | 465 | $this->assertEquals( 'Second title', bp_activity_get_meta( $activity_id, 'post_title' ) ); |
| | 466 | $this->assertEquals( add_query_arg( 'p', $post_id, home_url( '/' ) ), bp_activity_get_meta( $activity_id, 'post_url' ) ); |
| | 467 | |
| | 468 | // reset |
| | 469 | $this->set_current_user( $old_user ); |
| | 470 | } |
| | 471 | |
| | 472 | /** |
| | 473 | * @group bp_blogs_catch_transition_post_status |
| | 474 | */ |
| | 475 | public function test_update_blog_post_and_activity_comment_meta() { |
| | 476 | // save the current user and override logged-in user |
| | 477 | $old_user = get_current_user_id(); |
| | 478 | $u = $this->create_user(); |
| | 479 | $this->set_current_user( $u ); |
| | 480 | $userdata = get_userdata( $u ); |
| | 481 | |
| | 482 | // create the blog post |
| | 483 | $post_id = $this->factory->post->create( array( |
| | 484 | 'post_status' => 'publish', |
| | 485 | 'post_type' => 'post', |
| | 486 | 'post_title' => 'First title', |
| | 487 | ) ); |
| | 488 | |
| | 489 | // let's use activity comments instead of single "new_blog_comment" activity items |
| | 490 | add_filter( 'bp_disable_blogforum_comments', '__return_false' ); |
| | 491 | |
| | 492 | // create the blog comment |
| | 493 | $comment_id = wp_new_comment( array( |
| | 494 | 'comment_post_ID' => $post_id, |
| | 495 | 'comment_author' => $userdata->user_nicename, |
| | 496 | 'comment_author_url' => 'http://buddypress.org', |
| | 497 | 'comment_author_email' => $userdata->user_email, |
| | 498 | 'comment_content' => 'this is a blog comment', |
| | 499 | 'comment_type' => '', |
| | 500 | 'comment_parent' => 0, |
| | 501 | 'user_id' => $u, |
| | 502 | ) ); |
| | 503 | |
| | 504 | // update the initial blog post |
| | 505 | wp_update_post( array( |
| | 506 | 'ID' => $post_id, |
| | 507 | 'post_title' => 'Second title', |
| | 508 | ) ); |
| | 509 | |
| | 510 | // grab the activity ID for the blog comment |
| | 511 | $activity_id = bp_activity_get_activity_id( array( |
| | 512 | 'type' => 'activity_comment', |
| | 513 | 'display_comments' => 'stream', |
| | 514 | 'meta_query' => array( array( |
| | 515 | 'key' => 'bp_blogs_post_comment_id', |
| | 516 | 'value' => $comment_id, |
| | 517 | ) ) |
| | 518 | ) ); |
| | 519 | |
| | 520 | // see if blog comment activity meta matches the post items |
| | 521 | $this->assertEquals( 'Second title', bp_activity_get_meta( $activity_id, 'post_title' ) ); |
| | 522 | $this->assertEquals( add_query_arg( 'p', $post_id, home_url( '/' ) ), bp_activity_get_meta( $activity_id, 'post_url' ) ); |
| | 523 | |
| | 524 | // reset |
| | 525 | $this->set_current_user( $old_user ); |
| | 526 | remove_filter( 'bp_disable_blogforum_comments', '__return_false' ); |
| | 527 | } |
| | 528 | |