Skip to:
Content

BuddyPress.org

Changeset 9651


Ignore:
Timestamp:
03/26/2015 10:05:12 PM (11 years ago)
Author:
johnjamesjacoby
Message:

Activity: Increase test coverage for delete group.

Includes tests for:

  • Delete by id
  • Delete by type
  • Delete by component
  • Delete by user_id
  • Delete item & comments
  • Delete item, comments, & meta
  • Delete item meta
  • Delete all item meta (legacy)

See #6323.

File:
1 edited

Legend:

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

    r9561 r9651  
    2525         * @group delete
    2626         */
    27         public function test_delete_activity_and_meta() {
     27        public function test_delete_activity_by_id() {
     28
     29                // create an activity update
     30                $activity = $this->factory->activity->create( array(
     31                        'type' => 'activity_update'
     32                ) );
     33
     34                // now delete the activity item
     35                bp_activity_delete( array(
     36                        'id' => $activity
     37                ) );
     38
     39                // now fetch the deleted activity entries
     40                $get = bp_activity_get( array(
     41                        'id' => $activity
     42                ) );
     43
     44                // activities should equal zero
     45                $this->assertEquals( 0, $get['total'] );
     46        }
     47
     48        /**
     49         * @group delete
     50         */
     51        public function test_delete_activity_by_type() {
     52
     53                // Setup criteria
     54                $criteria = array(
     55                        'type' => 'activity_update'
     56                );
     57
     58                // create an activity update
     59                $this->factory->activity->create( $criteria );
     60                $this->factory->activity->create( $criteria );
     61                $this->factory->activity->create( $criteria );
     62                $this->factory->activity->create( $criteria );
     63
     64                // now delete the activity items
     65                bp_activity_delete( $criteria );
     66
     67                // now fetch the deleted activity entries
     68                $get = bp_activity_get( $criteria );
     69
     70                // activities should equal zero
     71                $this->assertEquals( 0, $get['total'] );
     72        }
     73
     74        /**
     75         * @group delete
     76         */
     77        public function test_delete_activity_by_component() {
     78
     79                // Setup criteria
     80                $criteria = array(
     81                        'component' => 'xprofile'
     82                );
     83
     84                // create an activity update
     85                $this->factory->activity->create( $criteria );
     86                $this->factory->activity->create( $criteria );
     87                $this->factory->activity->create( $criteria );
     88                $this->factory->activity->create( $criteria );
     89
     90                // now delete the activity items
     91                bp_activity_delete( $criteria );
     92
     93                // now fetch the deleted activity entries
     94                $get = bp_activity_get( $criteria );
     95
     96                // activities should equal zero
     97                $this->assertEquals( 0, $get['total'] );
     98        }
     99
     100        /**
     101         * @group delete
     102         */
     103        public function test_delete_activity_by_user_id() {
     104
     105                // Setup criteria
     106                $criteria = array(
     107                        'user_id' => '1'
     108                );
     109
     110                // create an activity update
     111                $this->factory->activity->create( $criteria );
     112                $this->factory->activity->create( $criteria );
     113                $this->factory->activity->create( $criteria );
     114                $this->factory->activity->create( $criteria );
     115
     116                // now delete the activity items
     117                bp_activity_delete( $criteria );
     118
     119                // now fetch the deleted activity entries
     120                $get = bp_activity_get( $criteria );
     121
     122                // activities should equal zero
     123                $this->assertEquals( 0, $get['total'] );
     124        }
     125
     126        /**
     127         * @group delete
     128         */
     129        public function test_delete_activity_meta() {
     130
     131                // create an activity update
     132                $activity = $this->factory->activity->create( array(
     133                        'type' => 'activity_update'
     134                ) );
     135
     136                // add some meta to the activity items
     137                bp_activity_update_meta( $activity, 'foo', 'bar' );
     138
     139                // now delete the parent activity item meta entry
     140                bp_activity_delete_meta(  $activity, 'foo', 'bar' );
     141
     142                // now fetch activity meta for the deleted activity entries
     143                $m1 = bp_activity_get_meta( $activity );
     144
     145                // test if activity meta entries still exist
     146                $this->assertEmpty( $m1 );
     147        }
     148
     149        /**
     150         * @group delete
     151         */
     152        public function test_delete_activity_all_meta() {
     153
     154                // create an activity update
     155                $activity = $this->factory->activity->create( array(
     156                        'type' => 'activity_update'
     157                ) );
     158
     159                // add some meta to the activity items
     160                bp_activity_update_meta( $activity, 'foo1', 'bar' );
     161                bp_activity_update_meta( $activity, 'foo2', 'bar' );
     162                bp_activity_update_meta( $activity, 'foo3', 'bar' );
     163                bp_activity_update_meta( $activity, 'foo4', 'bar' );
     164                bp_activity_update_meta( $activity, 'foo5', 'bar' );
     165
     166                // now delete the parent activity item meta entry
     167                bp_activity_delete_meta( $activity );
     168
     169                // now fetch activity meta for the deleted activity entries
     170                $m1 = bp_activity_get_meta( $activity );
     171                $m2 = bp_activity_get_meta( $activity );
     172                $m3 = bp_activity_get_meta( $activity );
     173                $m4 = bp_activity_get_meta( $activity );
     174                $m5 = bp_activity_get_meta( $activity );
     175
     176                // test if activity meta entries still exist
     177                $this->assertEmpty( $m1 );
     178                $this->assertEmpty( $m2 );
     179                $this->assertEmpty( $m3 );
     180                $this->assertEmpty( $m4 );
     181                $this->assertEmpty( $m5 );
     182        }
     183
     184        /**
     185         * @group delete
     186         */
     187        public function test_delete_activity_and_comments() {
     188
    28189                // create an activity update
    29190                $parent_activity = $this->factory->activity->create( array(
     
    44205                ) );
    45206
     207                // now delete the parent activity item
     208                // this should hopefully delete the associated comments and meta entries
     209                bp_activity_delete( array(
     210                        'id' => $parent_activity
     211                ) );
     212
     213                // now fetch the deleted activity entries
     214                $get = bp_activity_get( array(
     215                        'in'               => array( $parent_activity, $comment_one, $comment_two ),
     216                        'display_comments' => 'stream'
     217                ) );
     218
     219                // activities should equal zero
     220                $this->assertEquals( 0, $get['total'] );
     221        }
     222
     223        /**
     224         * @group delete
     225         */
     226        public function test_delete_activity_meta_for_comments() {
     227
     228                // create an activity update
     229                $parent_activity = $this->factory->activity->create( array(
     230                        'type' => 'activity_update',
     231                ) );
     232
     233                // create some activity comments
     234                $comment_one = $this->factory->activity->create( array(
     235                        'type'              => 'activity_comment',
     236                        'item_id'           => $parent_activity,
     237                        'secondary_item_id' => $parent_activity,
     238                ) );
     239
     240                $comment_two = $this->factory->activity->create( array(
     241                        'type'              => 'activity_comment',
     242                        'item_id'           => $parent_activity,
     243                        'secondary_item_id' => $parent_activity,
     244                ) );
     245
    46246                // add some meta to the activity items
    47247                bp_activity_update_meta( $parent_activity, 'foo', 'bar' );
     
    54254                        'id' => $parent_activity
    55255                ) );
    56 
    57                 // now fetch the deleted activity entries
    58                 $get = bp_activity_get( array(
    59                         'in'               => array( $parent_activity, $comment_one, $comment_two ),
    60                         'display_comments' => 'stream'
    61                 ) );
    62 
    63                 // activities should equal zero
    64                 $this->assertEquals( 0, $get['total'] );
    65256
    66257                // now fetch activity meta for the deleted activity entries
Note: See TracChangeset for help on using the changeset viewer.