diff --git tests/phpunit/includes/testcase.php tests/phpunit/includes/testcase.php
index 4734179..1355ebe 100644
|
|
|
class BP_UnitTestCase extends WP_UnitTestCase { |
| 40 | 40 | |
| 41 | 41 | // Fixes warnings in multisite functions |
| 42 | 42 | $_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(); |
| 43 | 49 | } |
| 44 | 50 | |
| 45 | 51 | function clean_up_global_scope() { |
| … |
… |
class BP_UnitTestCase extends WP_UnitTestCase { |
| 74 | 80 | } |
| 75 | 81 | } |
| 76 | 82 | |
| | 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 | |
| 77 | 110 | function assertPreConditions() { |
| 78 | 111 | parent::assertPreConditions(); |
| 79 | 112 | |
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 { |
| 22 | 22 | * @group activity_tracking |
| 23 | 23 | */ |
| 24 | 24 | public function test_bp_activity_catch_transition_post_type_status_publish() { |
| 25 | | $bp = buddypress(); |
| 26 | | |
| 27 | 25 | register_post_type( 'foo', array( |
| 28 | 26 | 'label' => 'foo', |
| 29 | 27 | 'public' => true, |
| … |
… |
class BP_Tests_Activity_Actions extends BP_UnitTestCase { |
| 41 | 39 | $this->assertTrue( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Published post type should have activity' ); |
| 42 | 40 | |
| 43 | 41 | _unregister_post_type( 'foo' ); |
| 44 | | |
| 45 | | // Reset globals |
| 46 | | unset( $bp->activity->actions->activity->new_foo ); |
| 47 | | $bp->activity->track = array(); |
| 48 | 42 | } |
| 49 | 43 | |
| 50 | 44 | /** |
| … |
… |
class BP_Tests_Activity_Actions extends BP_UnitTestCase { |
| 52 | 46 | * @group activity_tracking |
| 53 | 47 | */ |
| 54 | 48 | public function test_bp_activity_catch_transition_post_type_status_publish_to_publish() { |
| 55 | | $bp = buddypress(); |
| 56 | | |
| 57 | 49 | register_post_type( 'foo', array( |
| 58 | 50 | 'label' => 'foo', |
| 59 | 51 | 'public' => true, |
| … |
… |
class BP_Tests_Activity_Actions extends BP_UnitTestCase { |
| 81 | 73 | $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Updating a post type should not create a new activity' ); |
| 82 | 74 | |
| 83 | 75 | _unregister_post_type( 'foo' ); |
| 84 | | |
| 85 | | // Reset globals |
| 86 | | unset( $bp->activity->actions->activity->new_foo ); |
| 87 | | $bp->activity->track = array(); |
| 88 | 76 | } |
| 89 | 77 | |
| 90 | 78 | /** |
| … |
… |
class BP_Tests_Activity_Actions extends BP_UnitTestCase { |
| 92 | 80 | * @group activity_tracking |
| 93 | 81 | */ |
| 94 | 82 | public function test_bp_activity_catch_transition_post_type_status_publish_password() { |
| 95 | | $bp = buddypress(); |
| 96 | | |
| 97 | 83 | register_post_type( 'foo', array( |
| 98 | 84 | 'label' => 'foo', |
| 99 | 85 | 'public' => true, |
| … |
… |
class BP_Tests_Activity_Actions extends BP_UnitTestCase { |
| 119 | 105 | $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Password protected post type should not have activity' ); |
| 120 | 106 | |
| 121 | 107 | _unregister_post_type( 'foo' ); |
| 122 | | |
| 123 | | // Reset globals |
| 124 | | unset( $bp->activity->actions->activity->new_foo ); |
| 125 | | $bp->activity->track = array(); |
| 126 | 108 | } |
| 127 | 109 | |
| 128 | 110 | /** |
| … |
… |
class BP_Tests_Activity_Actions extends BP_UnitTestCase { |
| 130 | 112 | * @group activity_tracking |
| 131 | 113 | */ |
| 132 | 114 | public function test_bp_activity_catch_transition_post_type_status_publish_trash() { |
| 133 | | $bp = buddypress(); |
| 134 | | |
| 135 | 115 | register_post_type( 'foo', array( |
| 136 | 116 | 'label' => 'foo', |
| 137 | 117 | 'public' => true, |
| … |
… |
class BP_Tests_Activity_Actions extends BP_UnitTestCase { |
| 154 | 134 | $this->assertFalse( $this->activity_exists_for_post( $post_id, 'new_foo' ), 'Unpublished post type should not have activity' ); |
| 155 | 135 | |
| 156 | 136 | _unregister_post_type( 'foo' ); |
| 157 | | |
| 158 | | // Reset globals |
| 159 | | unset( $bp->activity->actions->activity->new_foo ); |
| 160 | | $bp->activity->track = array(); |
| 161 | 137 | } |
| 162 | 138 | |
| 163 | 139 | protected function activity_exists_for_post( $post_id, $action ) { |
diff --git tests/phpunit/testcases/activity/functions.php tests/phpunit/testcases/activity/functions.php
index 4f8cad6..b6425d9 100644
|
|
|
Bar!'; |
| 585 | 585 | return; |
| 586 | 586 | } |
| 587 | 587 | |
| 588 | | $bp = buddypress(); |
| 589 | | |
| 590 | 588 | register_post_type( 'foo', array( |
| 591 | 589 | 'label' => 'foo', |
| 592 | 590 | 'public' => true, |
| 593 | 591 | 'supports' => array( 'buddypress-activity' ), |
| 594 | 592 | ) ); |
| 595 | 593 | |
| 596 | | // Build the actions to fetch the tracking args |
| 597 | | bp_activity_get_actions(); |
| 598 | | |
| 599 | 594 | $u = $this->factory->user->create(); |
| 600 | 595 | $p = $this->factory->post->create( array( |
| 601 | 596 | 'post_author' => $u, |
| … |
… |
Bar!'; |
| 622 | 617 | $this->assertSame( $expected, $a_obj->action ); |
| 623 | 618 | |
| 624 | 619 | _unregister_post_type( 'foo' ); |
| 625 | | |
| 626 | | // Reset globals |
| 627 | | unset( $bp->activity->actions->activity->new_foo ); |
| 628 | | $bp->activity->track = array(); |
| 629 | 620 | } |
| 630 | 621 | |
| 631 | 622 | /** |
| … |
… |
Bar!'; |
| 638 | 629 | return; |
| 639 | 630 | } |
| 640 | 631 | |
| 641 | | $bp = buddypress(); |
| 642 | | |
| 643 | 632 | $b = $this->factory->blog->create(); |
| 644 | 633 | $u = $this->factory->user->create(); |
| 645 | 634 | |
| … |
… |
Bar!'; |
| 668 | 657 | ); |
| 669 | 658 | |
| 670 | 659 | _unregister_post_type( 'foo' ); |
| 671 | | bp_activity_get_actions(); |
| 672 | 660 | |
| 673 | 661 | restore_current_blog(); |
| 674 | 662 | |
| … |
… |
Bar!'; |
| 685 | 673 | $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>' ); |
| 686 | 674 | |
| 687 | 675 | $this->assertSame( $expected, $a_obj->action ); |
| 688 | | |
| 689 | | // Reset globals |
| 690 | | unset( $bp->activity->actions->activity->new_foo ); |
| 691 | | $bp->activity->track = array(); |
| 692 | 676 | } |
| 693 | 677 | |
| 694 | 678 | /** |
| … |
… |
Bar!'; |
| 696 | 680 | * @group bp_activity_get_actions |
| 697 | 681 | */ |
| 698 | 682 | public function test_bp_activity_get_actions_should_sort_by_position() { |
| 699 | | $old_actions = bp_activity_get_actions(); |
| 700 | | buddypress()->activity->actions = new stdClass; |
| 701 | 683 | |
| 702 | 684 | register_post_type( 'foo5', array( |
| 703 | 685 | 'public' => true, |
| … |
… |
Bar!'; |
| 738 | 720 | ); |
| 739 | 721 | $foo_actions = (array) $actions->foo; |
| 740 | 722 | $this->assertEquals( $expected, array_values( wp_list_pluck( $foo_actions, 'key' ) ) ); |
| 741 | | |
| 742 | | buddypress()->activity->actions = $old_actions; |
| 743 | 723 | } |
| 744 | 724 | |
| 745 | 725 | /** |
| … |
… |
Bar!'; |
| 751 | 731 | return; |
| 752 | 732 | } |
| 753 | 733 | |
| 754 | | $bp = buddypress(); |
| 755 | | |
| 756 | 734 | $labels = array( |
| 757 | 735 | 'name' => 'bars', |
| 758 | 736 | 'singular_name' => 'bar', |
| … |
… |
Bar!'; |
| 768 | 746 | ), |
| 769 | 747 | ) ); |
| 770 | 748 | |
| 771 | | // Build the actions to fetch the tracking args |
| 772 | | bp_activity_get_actions(); |
| 773 | | |
| 774 | 749 | $u = $this->factory->user->create(); |
| 775 | 750 | $p = $this->factory->post->create( array( |
| 776 | 751 | 'post_author' => $u, |
| … |
… |
Bar!'; |
| 796 | 771 | $this->assertSame( $expected, $a_obj->action ); |
| 797 | 772 | |
| 798 | 773 | _unregister_post_type( 'foo' ); |
| 799 | | |
| 800 | | // Reset globals |
| 801 | | unset( $bp->activity->actions->activity->foo_bar ); |
| 802 | | $bp->activity->track = array(); |
| 803 | 774 | } |
| 804 | 775 | |
| 805 | 776 | /** |
| … |
… |
Bar!'; |
| 812 | 783 | return; |
| 813 | 784 | } |
| 814 | 785 | |
| 815 | | $bp = buddypress(); |
| 816 | | $reset = $bp->activity->actions; |
| 817 | | |
| 818 | 786 | $b = $this->factory->blog->create(); |
| 819 | 787 | $u = $this->factory->user->create(); |
| 820 | 788 | |
| … |
… |
Bar!'; |
| 863 | 831 | $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>' ); |
| 864 | 832 | |
| 865 | 833 | $this->assertSame( $expected, $a_obj->action ); |
| 866 | | |
| 867 | | // Reset globals |
| 868 | | unset( $bp->activity->actions->activity->new_foo ); |
| 869 | | $bp->activity->track = array(); |
| 870 | 834 | } |
| 871 | 835 | |
| 872 | 836 | /** |
| … |
… |
Bar!'; |
| 883 | 847 | 'dummy' => 'dummy value', |
| 884 | 848 | ) ); |
| 885 | 849 | |
| 886 | | // Build the actions to fetch the tracking args |
| 887 | | bp_activity_get_actions(); |
| 888 | | |
| 889 | 850 | $u = $this->factory->user->create(); |
| 890 | 851 | |
| 891 | 852 | $post_id = $this->factory->post->create( array( |
| … |
… |
Bar!'; |
| 903 | 864 | $this->assertSame( $bp->blogs->id, $a['activities'][0]->component ); |
| 904 | 865 | |
| 905 | 866 | remove_post_type_support( 'page', 'buddypress-activity' ); |
| 906 | | |
| 907 | | // Reset globals |
| 908 | | unset( $bp->activity->actions->blogs->new_page ); |
| 909 | | $bp->activity->track = array(); |
| 910 | 867 | } |
| 911 | 868 | |
| 912 | 869 | /** |
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 { |
| 6 | 6 | * @group activity_tracking |
| 7 | 7 | */ |
| 8 | 8 | public function test_bp_blogs_loader_post_tracking_args_filter() { |
| 9 | | $bp = buddypress(); |
| 10 | 9 | |
| 11 | 10 | $expected = array( 'new_blog_post', 'new_blog_comment' ); |
| 12 | 11 | |
| … |
… |
class BP_Tests_Blogs_Activity extends BP_UnitTestCase { |
| 233 | 232 | return; |
| 234 | 233 | } |
| 235 | 234 | |
| | 235 | // Make sure the filter will be fired |
| | 236 | bp_activity_get_actions(); |
| | 237 | |
| 236 | 238 | add_filter( 'bp_blogs_activity_new_post_action', array( $this, 'new_post_passthrough' ), 10, 2 ); |
| 237 | 239 | |
| 238 | 240 | $b = $this->factory->blog->create(); |