[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @group blogs 4 * @ticket BP6306 5 */ 6 class BP_Tests_Blogs_Filters extends BP_UnitTestCase { 7 protected $activity_actions; 8 protected $custom_post_types; 9 10 public function setUp() { 11 parent::setUp(); 12 13 $this->custom_post_types = array( 'using_old_filter' ); 14 15 register_post_type( 'using_old_filter', array( 16 'label' => 'using_old_filter', 17 'public' => true, 18 'supports' => array( 'comments' ), 19 ) ); 20 21 add_filter( 'bp_blogs_record_post_post_types', array( $this, 'filter_post_types'), 10, 1 ); 22 add_filter( 'bp_blogs_record_comment_post_types', array( $this, 'filter_post_types'), 10, 1 ); 23 } 24 25 function tearDown() { 26 parent::tearDown(); 27 28 $bp = buddypress(); 29 30 _unregister_post_type( 'using_old_filter' ); 31 remove_filter( 'bp_blogs_record_post_post_types', array( $this, 'filter_post_types' ), 10 ); 32 remove_filter( 'bp_blogs_record_comment_post_types', array( $this, 'filter_post_types' ), 10 ); 33 } 34 35 /** 36 * @goup bp_activity_get_actions 37 */ 38 public function test_bp_activity_get_actions() { 39 $activity_actions = bp_activity_get_actions(); 40 41 $this->assertTrue( ! isset( $activity_actions->activity->new_using_old_filter ), 'Post types registering using the bp_blogs_record_post_post_types filter should not have a specific action' ); 42 } 43 44 /** 45 * @goup bp_activity_catch_transition_post_type_status 46 */ 47 public function test_bp_activity_catch_transition_post_type_status() { 48 $post_id = self::factory()->post->create( array( 49 'post_status' => 'publish', 50 'post_type' => 'using_old_filter', 51 ) ); 52 53 $this->assertTrue( $this->activity_exists_for_post_type( get_current_blog_id(), $post_id, 'new_blog_post' ), 'Generated activity for a post type registering using the bp_blogs_record_post_post_types filter should have a new_blog_post action' ); 54 } 55 56 /** 57 * @goup bp_blogs_record_comment 58 * @group post_type_comment_activities 59 */ 60 public function test_bp_blogs_record_comment() { 61 $u = self::factory()->user->create(); 62 $user = self::factory()->user->get_object_by_id( $u ); 63 64 $post_id = self::factory()->post->create( array( 65 'post_status' => 'publish', 66 'post_type' => 'using_old_filter', 67 'post_author' => $u, 68 ) ); 69 70 $comment_id = self::factory()->comment->create( array( 71 'user_id' => $u, 72 'comment_author_email' => $user->user_email, 73 'comment_post_ID' => $post_id, 74 ) ); 75 76 // Approve the comment 77 self::factory()->comment->update_object( $comment_id, array( 'comment_approved' => 1 ) ); 78 79 $this->assertTrue( $this->activity_exists_for_post_type( get_current_blog_id(), $comment_id, 'new_blog_comment' ), 'Generated activity for comments about a post type registering using the bp_blogs_record_post_post_types filter should have a new_blog_comment action' ); 80 } 81 82 /** 83 * @goup bp_blogs_record_comment_sync_activity_comment 84 * @group post_type_comment_activities 85 */ 86 public function test_bp_blogs_record_comment_sync_activity_comment() { 87 $u = self::factory()->user->create(); 88 $user = self::factory()->user->get_object_by_id( $u ); 89 90 add_filter( 'bp_disable_blogforum_comments', '__return_false' ); 91 92 $post_id = self::factory()->post->create( array( 93 'post_status' => 'publish', 94 'post_type' => 'using_old_filter', 95 'post_author' => $u, 96 ) ); 97 98 $parent_activity_id = bp_activity_get_activity_id( array( 99 'component' => 'blogs', 100 'type' => 'new_blog_post', 101 'item_id' => get_current_blog_id(), 102 'secondary_item_id' => $post_id 103 ) ); 104 105 $comment_id = self::factory()->comment->create( array( 106 'user_id' => $u, 107 'comment_author_email' => $user->user_email, 108 'comment_post_ID' => $post_id, 109 ) ); 110 111 // Approve the comment 112 self::factory()->comment->update_object( $comment_id, array( 'comment_approved' => 1 ) ); 113 114 $this->assertTrue( $this->activity_exists_for_post_type( $parent_activity_id, '', 'activity_comment', 'stream' ), 'Generated activity for comments about a post type registering using the bp_blogs_record_post_post_types filter having sync on should have a activity_comment action' ); 115 116 remove_filter( 'bp_disable_blogforum_comments', '__return_false' ); 117 } 118 119 public function filter_post_types( $post_types ) { 120 $post_types = array_merge( $post_types, $this->custom_post_types ); 121 return $post_types; 122 } 123 124 protected function activity_exists_for_post_type( $item_id, $secondary_item_id, $action, $display_comments = false ) { 125 $a = bp_activity_get( array( 126 'display_comments' => $display_comments, 127 'filter' => array( 128 'action' => $action, 129 'primary_id' => $item_id, 130 'secondary_id' => $secondary_item_id, 131 ) ) ); 132 133 return ! empty( $a['activities'] ); 134 } 135 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |