Skip to:
Content

BuddyPress.org

Ticket #5942: bp-friends-functions-tests-5942.diff

File bp-friends-functions-tests-5942.diff, 1.9 KB (added by tw2113, 11 years ago)
  • tests/phpunit/testcases/friends/functions.php

     
    66 */
    77class BP_Tests_Friends_Functions extends BP_UnitTestCase {
    88
     9        protected $filter_fired;
     10
     11        public function setUp() {
     12                parent::setUp();
     13
     14                $this->filter_fired = '';
     15        }
     16
     17        public function tearDown() {
     18                parent::tearDown();
     19        }
     20
    921        /**
    1022         * @group friends_get_friendship_request_user_ids
    1123         * @group friends_add_friend
     
    227239
    228240                $this->assertSame( $expected, $found );
    229241        }
     242
     243        /**
     244         * @group friends_add_friend
     245         */
     246        public function test_friends_add_friend_friends_friendship_requested() {
     247                $u1 = $this->factory->user->create();
     248                $u2 = $this->factory->user->create();
     249
     250                add_filter( 'friends_friendship_requested', array( $this, 'friends_friendship_filter_callback' ) );
     251                $n = friends_add_friend( $u1, $u2, false );
     252                remove_filter( 'friends_friendship_requested', array( $this, 'friends_friendship_filter_callback' ) );
     253
     254                $this->assertSame( 'friends_friendship_requested', $this->filter_fired );
     255        }
     256
     257        /**
     258         * @group friends_add_friend
     259         */
     260        public function test_friends_add_friend_friends_friendship_accepted() {
     261                $u1 = $this->factory->user->create();
     262                $u2 = $this->factory->user->create();
     263
     264                add_filter( 'friends_friendship_accepted', array( $this, 'friends_friendship_filter_callback' ) );
     265                $n = friends_add_friend( $u1, $u2, true );
     266                remove_filter( 'friends_friendship_accepted', array( $this, 'friends_friendship_filter_callback' ) );
     267
     268                $this->assertSame( 'friends_friendship_accepted', $this->filter_fired );
     269        }
     270
     271        public function friends_friendship_filter_callback( $value ) {
     272                $this->filter_fired = current_filter();
     273
     274                return $value;
     275        }
     276
    230277}