Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/22/2022 09:45:12 AM (4 years ago)
Author:
imath
Message:

Stop using the post link into the new_blog_post activity action

Now the post link is included into the activity content (see [13305]), displaying it into the activity action is no more needed.
This commit also :

  • introduces a new function to get a site's URL and Name out of BP Blogs meta which avoids some code duplication in new_blog, new_blog_post and new_blog_comment activity action format callbacks.
  • improves the new_blog_post activity content layout when the corresponding post's image is not the featured one.
  • properly deprecates pre-2.0 activity action filters.

Props teeboy4real

Closes https://github.com/buddypress/buddypress/pull/27
Fixes #8052

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/blogs/activity.php

    r12606 r13342  
    7474
    7575                $user_link = bp_core_get_userlink( $u );
    76                 $blog_url = get_home_url();
    77                 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) );
    78                 $post_title = bp_activity_get_meta( $a, 'post_title' );
    79                 $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>';
    80 
    81                 $expected = sprintf( '%s wrote a new post, %s', $user_link, $post_link );
     76                $expected = sprintf( '%s wrote a new post', $user_link );
    8277
    8378                $this->assertSame( $expected, $a_obj->action );
     
    109104                $user_link = bp_core_get_userlink( $u );
    110105                $blog_url = get_home_url();
    111                 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) );
    112                 $post_title = bp_activity_get_meta( $a, 'post_title' );
    113                 $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>';
    114 
    115                 $expected = sprintf( '%s wrote a new post, %s, on the site %s', $user_link, $post_link, '<a href="' . $blog_url . '">' . bp_blogs_get_blogmeta( $a_obj->item_id, 'name' ) . '</a>' );
     106
     107                $expected = sprintf( '%s wrote a new post on the site %s', $user_link, '<a href="' . $blog_url . '">' . bp_blogs_get_blogmeta( $a_obj->item_id, 'name' ) . '</a>' );
    116108
    117109                $this->assertSame( $expected, $a_obj->action );
     
    143135                        'item_id' => $b,
    144136                        'secondary_item_id' => $p,
     137                ) );
     138
     139                $a_obj = new BP_Activity_Activity( $a );
     140
     141                $user_link = bp_core_get_userlink( $u );
     142                $blog_url = get_blog_option( $a_obj->item_id, 'home' );
     143
     144                $expected = sprintf( '%s wrote a new post on the site %s', $user_link, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' );
     145
     146                $this->assertSame( $expected, $a_obj->action );
     147        }
     148
     149        /**
     150         * @group activity_action
     151         * @group bp_blogs_format_activity_action_new_blog_comment
     152         * @group post_type_comment_activities
     153         */
     154        public function test_bp_blogs_format_activity_action_new_blog_comment_ms_nonrootblog() {
     155                if ( ! is_multisite() ) {
     156                        $this->markTestSkipped();
     157                }
     158
     159                $b = self::factory()->blog->create();
     160                $u = self::factory()->user->create();
     161
     162                switch_to_blog( $b );
     163                $p = self::factory()->post->create( array(
     164                        'post_author' => $u,
     165                ) );
     166                $p_obj = get_post( $p );
     167                $c = self::factory()->comment->create( array(
     168                        'comment_post_ID' => $p,
     169                ) );
     170                $c_obj = get_comment( $c );
     171                restore_current_blog();
     172
     173                $a = self::factory()->activity->create( array(
     174                        'component' => buddypress()->blogs->id,
     175                        'type' => 'new_blog_comment',
     176                        'user_id' => $u,
     177                        'item_id' => $b,
     178                        'secondary_item_id' => $c,
    145179                ) );
    146180
     
    153187                $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>';
    154188
    155                 $expected = sprintf( '%s wrote a new post, %s, on the site %s', $user_link, $post_link, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' );
     189                $expected = sprintf( '%s commented on the post, %s, on the site %s', $user_link, $post_link, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' );
    156190
    157191                $this->assertSame( $expected, $a_obj->action );
    158         }
    159 
    160         /**
    161          * @group activity_action
    162          * @group bp_blogs_format_activity_action_new_blog_comment
    163          * @group post_type_comment_activities
    164          */
    165         public function test_bp_blogs_format_activity_action_new_blog_comment_ms_nonrootblog() {
    166                 if ( ! is_multisite() ) {
    167                         $this->markTestSkipped();
    168                 }
    169 
    170                 $b = self::factory()->blog->create();
    171                 $u = self::factory()->user->create();
    172 
    173                 switch_to_blog( $b );
    174                 $p = self::factory()->post->create( array(
    175                         'post_author' => $u,
    176                 ) );
    177                 $p_obj = get_post( $p );
    178                 $c = self::factory()->comment->create( array(
    179                         'comment_post_ID' => $p,
    180                 ) );
    181                 $c_obj = get_comment( $c );
    182                 restore_current_blog();
    183 
    184                 $a = self::factory()->activity->create( array(
    185                         'component' => buddypress()->blogs->id,
    186                         'type' => 'new_blog_comment',
    187                         'user_id' => $u,
    188                         'item_id' => $b,
    189                         'secondary_item_id' => $c,
    190                 ) );
    191 
    192                 $a_obj = new BP_Activity_Activity( $a );
    193 
    194                 $user_link = bp_core_get_userlink( $u );
    195                 $blog_url = get_blog_option( $a_obj->item_id, 'home' );
    196                 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) );
    197                 $post_title = $p_obj->post_title;
    198                 $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>';
    199 
    200                 $expected = sprintf( '%s commented on the post, %s, on the site %s', $user_link, $post_link, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' );
    201 
    202                 $this->assertSame( $expected, $a_obj->action );
    203         }
    204 
    205         /**
    206          * @group bp_blogs_format_activity_action_new_blog
    207          */
    208         public function test_bp_activity_format_activity_action_new_blog_backpat() {
    209                 if ( ! is_multisite() ) {
    210                         $this->markTestSkipped();
    211                 }
    212 
    213                 add_filter( 'bp_blogs_activity_created_blog_action', array( $this, 'created_blog_passthrough' ), 10, 2 );
    214 
    215                 $b = self::factory()->blog->create();
    216                 $u = self::factory()->user->create();
    217 
    218                 $recorded_blog          = new BP_Blogs_Blog;
    219                 $recorded_blog->user_id = $u;
    220                 $recorded_blog->blog_id = $b;
    221                 $recorded_blog_id       = $recorded_blog->save();
    222 
    223                 $a = self::factory()->activity->create( array(
    224                         'component' => buddypress()->blogs->id,
    225                         'type' => 'new_blog',
    226                         'user_id' => $u,
    227                         'item_id' => $b,
    228                 ) );
    229 
    230                 $this->assertEquals( $this->userblog_id, $recorded_blog_id );
    231         }
    232 
    233         /**
    234          * @group bp_blogs_format_activity_action_new_blog_post
    235          */
    236         public function test_bp_activity_format_activity_action_new_blog_post_backpat() {
    237                 if ( ! is_multisite() ) {
    238                         $this->markTestSkipped();
    239                 }
    240 
    241                 add_filter( 'bp_blogs_activity_new_post_action', array( $this, 'new_post_passthrough' ), 10, 2 );
    242 
    243                 $b = self::factory()->blog->create();
    244 
    245                 switch_to_blog( $b );
    246                 $p = self::factory()->post->create();
    247                 restore_current_blog();
    248 
    249                 $u = self::factory()->user->create();
    250                 $a = self::factory()->activity->create( array(
    251                         'component' => buddypress()->blogs->id,
    252                         'type' => 'new_blog_post',
    253                         'user_id' => $u,
    254                         'item_id' => $b,
    255                         'secondary_item_id' => $p,
    256                 ) );
    257 
    258                 $this->assertEquals( $this->post_id, $p );
    259         }
    260 
    261         /**
    262          * @group bp_blogs_format_activity_action_new_blog_comment
    263          */
    264         public function test_bp_activity_format_activity_action_new_blog_comment_backpat() {
    265                 if ( ! is_multisite() ) {
    266                         $this->markTestSkipped();
    267                 }
    268 
    269                 add_filter( 'bp_blogs_activity_new_comment_action', array( $this, 'new_comment_passthrough' ), 10, 2 );
    270 
    271                 $b = self::factory()->blog->create();
    272 
    273                 switch_to_blog( $b );
    274                 $p = self::factory()->post->create();
    275                 $c = self::factory()->comment->create( array(
    276                         'comment_post_ID' => $p,
    277                 ) );
    278                 restore_current_blog();
    279 
    280                 $u = self::factory()->user->create();
    281                 $a = self::factory()->activity->create( array(
    282                         'component' => buddypress()->blogs->id,
    283                         'type' => 'new_blog_comment',
    284                         'user_id' => $u,
    285                         'item_id' => $b,
    286                         'secondary_item_id' => $c,
    287                 ) );
    288 
    289                 $this->assertEquals( $this->comment_post_id, $p );
    290192        }
    291193
     
    389291                $a_obj = new BP_Activity_Activity( $a );
    390292                $this->assertTrue( ! empty( $a_obj->action ) );
    391 
    392         }
    393 
    394         /**
    395          * @group activity_action
    396          * @group bp_blogs_format_activity_action_new_blog_post
    397          */
    398         public function test_bp_blogs_format_activity_action_new_blog_post_no_title() {
    399                 if ( is_multisite() ) {
    400                         $this->markTestSkipped();
    401                 }
    402 
    403                 buddypress()->activity->actions = new stdClass();
    404 
    405                 $u = self::factory()->user->create();
    406                 $p = wp_insert_post( array(
    407                         'post_author' => $u,
    408                         'post_title'  => '', // no title: the object of the test
    409                         'post_status' => 'publish',
    410                         'post_content' => 'foo bar',
    411                 ) );
    412 
    413                 $user_link = bp_core_get_userlink( $u );
    414                 $blog_url = get_home_url();
    415                 $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) );
    416                 $post_link = '<a href="' . $post_url . '">(no title)</a>';
    417 
    418                 // Set activity actions
    419                 bp_activity_get_actions();
    420 
    421                 $a_obj = bp_activity_get( array(
    422                         'item_id'           => 1,
    423                         'secondary_item_id' => $p,
    424                 ) );
    425 
    426                 $expected = sprintf( '%s wrote a new post, %s', $user_link, $post_link );
    427 
    428                 $this->assertSame( $expected, $a_obj['activities'][0]->action );
    429         }
    430 
    431         /**
    432          * @group activity_action
    433          * @group bp_blogs_format_activity_action_new_blog_post
    434          */
    435         public function test_bp_blogs_format_activity_action_new_blog_post_updated_without_title() {
    436                 if ( is_multisite() ) {
    437                         $this->markTestSkipped();
    438                 }
    439 
    440                 buddypress()->activity->actions = new stdClass();
    441 
    442                 $u = self::factory()->user->create();
    443                 $p = wp_insert_post( array(
    444                         'post_author' => $u,
    445                         'post_title'  => 'foo',
    446                         'post_status' => 'publish',
    447                         'post_content' => 'foo bar',
    448                 ) );
    449 
    450                 $user_link  = bp_core_get_userlink( $u );
    451                 $blog_url   = get_home_url();
    452                 $post_url   = add_query_arg( 'p', $p, trailingslashit( $blog_url ) );
    453                 $post_title = get_the_title( $p );
    454                 $post_link  = '<a href="' . $post_url . '">' . $post_title . '</a>';
    455 
    456                 // Set actions
    457                 bp_activity_get_actions();
    458 
    459                 $a_obj = bp_activity_get( array(
    460                         'item_id'           => 1,
    461                         'secondary_item_id' => $p,
    462                 ) );
    463 
    464                 $expected = sprintf( '%s wrote a new post, %s', $user_link, $post_link );
    465 
    466                 $this->assertSame( $expected, $a_obj['activities'][0]->action );
    467 
    468                 // Update the post by removing its title
    469                 wp_update_post( array(
    470                         'ID'         => $p,
    471                         'post_title' => '',
    472                 ) );
    473 
    474                 // we now expect the (no title) post link
    475                 $post_link = '<a href="' . $post_url . '">(no title)</a>';
    476                 $expected = sprintf( '%s wrote a new post, %s', $user_link, $post_link );
    477 
    478                 $a_obj = bp_activity_get( array(
    479                         'item_id'           => 1,
    480                         'secondary_item_id' => $p,
    481                 ) );
    482 
    483                 $this->assertSame( $expected, $a_obj['activities'][0]->action );
    484293        }
    485294
Note: See TracChangeset for help on using the changeset viewer.