Skip to:
Content

BuddyPress.org

Ticket #6128: 6128.setUp.patch

File 6128.setUp.patch, 9.0 KB (added by imath, 10 years ago)
  • tests/phpunit/includes/testcase.php

    diff --git tests/phpunit/includes/testcase.php tests/phpunit/includes/testcase.php
    index 4734179..1355ebe 100644
    class BP_UnitTestCase extends WP_UnitTestCase { 
    4040
    4141                // Fixes warnings in multisite functions
    4242                $_SERVER['REMOTE_ADDR'] = '';
     43
     44                // Make sure Activity actions are reset before each test
     45                $this->reset_bp_activity_actions();
     46
     47                // Make sure all Post types activities globals are reset before each test
     48                $this->reset_bp_activity_post_types_globals();
    4349        }
    4450
    4551        function clean_up_global_scope() {
    class BP_UnitTestCase extends WP_UnitTestCase { 
    7480                }
    7581        }
    7682
     83        protected function reset_bp_activity_actions() {
     84                buddypress()->activity->actions = new stdClass();
     85
     86                /**
     87                 * Populate the global with default activity actions only
     88                 * before each test.
     89                 */
     90                do_action( 'bp_register_activity_actions' );
     91        }
     92
     93        protected function reset_bp_activity_post_types_globals() {
     94                global $wp_post_types;
     95
     96                // Remove all remaining tracking arguments to each post type
     97                foreach ( $wp_post_types as $post_type => $post_type_arg ) {
     98                        if ( post_type_supports( $post_type, 'buddypress-activity' ) ) {
     99                                remove_post_type_support( 'page', 'buddypress-activity' );
     100                        }
     101
     102                        if ( isset( $post_type_arg->bp_activity ) ) {
     103                                unset( $post_type_arg->bp_activity );
     104                        }
     105                }
     106
     107                buddypress()->activity->track = array();
     108        }
     109
    77110        function assertPreConditions() {
    78111                parent::assertPreConditions();
    79112
  • tests/phpunit/testcases/activity/actions.php

    diff --git tests/phpunit/testcases/activity/actions.php tests/phpunit/testcases/activity/actions.php
    index 799a8fe..bccfcd3 100644
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    2222         * @group activity_tracking
    2323         */
    2424        public function test_bp_activity_catch_transition_post_type_status_publish() {
    25                 $bp = buddypress();
    26 
    2725                register_post_type( 'foo', array(
    2826                        'label'   => 'foo',
    2927                        'public'   => true,
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    4139                $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' );
    4240
    4341                _unregister_post_type( 'foo' );
    44 
    45                 // Reset globals
    46                 unset( $bp->activity->actions->activity->new_foo );
    47                 $bp->activity->track = array();
    4842        }
    4943
    5044        /**
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    5246         * @group activity_tracking
    5347         */
    5448        public function test_bp_activity_catch_transition_post_type_status_publish_to_publish() {
    55                 $bp = buddypress();
    56 
    5749                register_post_type( 'foo', array(
    5850                        'label'   => 'foo',
    5951                        'public'   => true,
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    8173                $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Updating a post type should not create a new activity' );
    8274
    8375                _unregister_post_type( 'foo' );
    84 
    85                 // Reset globals
    86                 unset( $bp->activity->actions->activity->new_foo );
    87                 $bp->activity->track = array();
    8876        }
    8977
    9078        /**
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    9280         * @group activity_tracking
    9381         */
    9482        public function test_bp_activity_catch_transition_post_type_status_publish_password() {
    95                 $bp = buddypress();
    96 
    9783                register_post_type( 'foo', array(
    9884                        'label'   => 'foo',
    9985                        'public'   => true,
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    119105                $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Password protected post type should not have activity' );
    120106
    121107                _unregister_post_type( 'foo' );
    122 
    123                 // Reset globals
    124                 unset( $bp->activity->actions->activity->new_foo );
    125                 $bp->activity->track = array();
    126108        }
    127109
    128110        /**
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    130112         * @group activity_tracking
    131113         */
    132114        public function test_bp_activity_catch_transition_post_type_status_publish_trash() {
    133                 $bp = buddypress();
    134 
    135115                register_post_type( 'foo', array(
    136116                        'label'   => 'foo',
    137117                        'public'   => true,
    class BP_Tests_Activity_Actions extends BP_UnitTestCase { 
    154134                $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Unpublished post type should not have activity' );
    155135
    156136                _unregister_post_type( 'foo' );
    157 
    158                 // Reset globals
    159                 unset( $bp->activity->actions->activity->new_foo );
    160                 $bp->activity->track = array();
    161137        }
    162138
    163139        protected function activity_exists_for_post( $post_id, $action ) {
  • tests/phpunit/testcases/activity/functions.php

    diff --git tests/phpunit/testcases/activity/functions.php tests/phpunit/testcases/activity/functions.php
    index 4f8cad6..b6425d9 100644
    Bar!'; 
    585585                        return;
    586586                }
    587587
    588                 $bp = buddypress();
    589 
    590588                register_post_type( 'foo', array(
    591589                        'label'   => 'foo',
    592590                        'public'   => true,
    593591                        'supports' => array( 'buddypress-activity' ),
    594592                ) );
    595593
    596                 // Build the actions to fetch the tracking args
    597                 bp_activity_get_actions();
    598 
    599594                $u = $this->factory->user->create();
    600595                $p = $this->factory->post->create( array(
    601596                        'post_author' => $u,
    Bar!'; 
    622617                $this->assertSame( $expected, $a_obj->action );
    623618
    624619                _unregister_post_type( 'foo' );
    625 
    626                 // Reset globals
    627                 unset( $bp->activity->actions->activity->new_foo );
    628                 $bp->activity->track = array();
    629620        }
    630621
    631622        /**
    Bar!'; 
    638629                        return;
    639630                }
    640631
    641                 $bp = buddypress();
    642 
    643632                $b = $this->factory->blog->create();
    644633                $u = $this->factory->user->create();
    645634
    Bar!'; 
    668657                );
    669658
    670659                _unregister_post_type( 'foo' );
    671                 bp_activity_get_actions();
    672660
    673661                restore_current_blog();
    674662
    Bar!'; 
    685673                $expected = sprintf( '%s wrote a new %s, on the site %s', $user_link, $post_link, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' );
    686674
    687675                $this->assertSame( $expected, $a_obj->action );
    688 
    689                 // Reset globals
    690                 unset( $bp->activity->actions->activity->new_foo );
    691                 $bp->activity->track = array();
    692676        }
    693677
    694678        /**
    Bar!'; 
    696680         * @group bp_activity_get_actions
    697681         */
    698682        public function test_bp_activity_get_actions_should_sort_by_position() {
    699                 $old_actions = bp_activity_get_actions();
    700                 buddypress()->activity->actions = new stdClass;
    701683
    702684                register_post_type( 'foo5', array(
    703685                        'public'      => true,
    Bar!'; 
    738720                );
    739721                $foo_actions = (array) $actions->foo;
    740722                $this->assertEquals( $expected, array_values( wp_list_pluck( $foo_actions, 'key' ) ) );
    741 
    742                 buddypress()->activity->actions = $old_actions;
    743723        }
    744724
    745725        /**
    Bar!'; 
    751731                        return;
    752732                }
    753733
    754                 $bp = buddypress();
    755 
    756734                $labels = array(
    757735                        'name'                 => 'bars',
    758736                        'singular_name'        => 'bar',
    Bar!'; 
    768746                        ),
    769747                ) );
    770748
    771                 // Build the actions to fetch the tracking args
    772                 bp_activity_get_actions();
    773 
    774749                $u = $this->factory->user->create();
    775750                $p = $this->factory->post->create( array(
    776751                        'post_author' => $u,
    Bar!'; 
    796771                $this->assertSame( $expected, $a_obj->action );
    797772
    798773                _unregister_post_type( 'foo' );
    799 
    800                 // Reset globals
    801                 unset( $bp->activity->actions->activity->foo_bar );
    802                 $bp->activity->track = array();
    803774        }
    804775
    805776        /**
    Bar!'; 
    812783                        return;
    813784                }
    814785
    815                 $bp = buddypress();
    816                 $reset = $bp->activity->actions;
    817 
    818786                $b = $this->factory->blog->create();
    819787                $u = $this->factory->user->create();
    820788
    Bar!'; 
    863831                $expected = sprintf( '%1$s shared a new <a href="%2$s">bar</a>, on the site %3$s', $user_link, $post_url, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' );
    864832
    865833                $this->assertSame( $expected, $a_obj->action );
    866 
    867                 // Reset globals
    868                 unset( $bp->activity->actions->activity->new_foo );
    869                 $bp->activity->track = array();
    870834        }
    871835
    872836        /**
    Bar!'; 
    883847                        'dummy'        => 'dummy value',
    884848                ) );
    885849
    886                 // Build the actions to fetch the tracking args
    887                 bp_activity_get_actions();
    888 
    889850                $u = $this->factory->user->create();
    890851
    891852                $post_id = $this->factory->post->create( array(
    Bar!'; 
    903864                $this->assertSame( $bp->blogs->id, $a['activities'][0]->component );
    904865
    905866                remove_post_type_support( 'page', 'buddypress-activity' );
    906 
    907                 // Reset globals
    908                 unset( $bp->activity->actions->blogs->new_page );
    909                 $bp->activity->track = array();
    910867        }
    911868
    912869        /**
  • tests/phpunit/testcases/blogs/activity.php

    diff --git tests/phpunit/testcases/blogs/activity.php tests/phpunit/testcases/blogs/activity.php
    index 96b6ab6..574a937 100644
    class BP_Tests_Blogs_Activity extends BP_UnitTestCase { 
    66         * @group activity_tracking
    77         */
    88        public function test_bp_blogs_loader_post_tracking_args_filter() {
    9                 $bp = buddypress();
    109
    1110                $expected = array( 'new_blog_post', 'new_blog_comment' );
    1211
    class BP_Tests_Blogs_Activity extends BP_UnitTestCase { 
    233232                        return;
    234233                }
    235234
     235                // Make sure the filter will be fired
     236                bp_activity_get_actions();
     237
    236238                add_filter( 'bp_blogs_activity_new_post_action', array( $this, 'new_post_passthrough' ), 10, 2 );
    237239
    238240                $b = $this->factory->blog->create();