Skip to:
Content

bbPress.org


Ignore:
Timestamp:
11/01/2016 07:24:50 AM (9 years ago)
Author:
johnjamesjacoby
Message:

Favorites/Subscriptions/Moderators: Introduce metadata API for linking multiple users to multiple forums/topics.

Previous to this, connections were stored in usermeta. We knew this would not scale, but bbPress 1 had a friendlier database schema & we expected WordPress's taxonomy/relationship roadmap would be farther along by now.

By storing user ID's in postmeta instead, we gain an ability to query for connections from both directions without custom MySQL, while also leveraging persistent caching in a more sane way.

This commit includes several new helper functions for low-level relationship management, as well as modifications to existing functions to allow them to continue to work as they always have.

See: #2959.

File:
1 edited

Legend:

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

    r5755 r6109  
    8787
    8888    /**
     89     * @covers ::bbp_add_user_to_object
     90     */
     91    public function test_bbp_add_user_to_object() {
     92        $u = $this->factory->user->create_many( 3 );
     93        $t = $this->factory->topic->create();
     94
     95        // Add object terms.
     96        foreach ( $u as $k => $v ) {
     97            bbp_add_user_to_object( $t, $v, '_bbp_moderator' );
     98        }
     99
     100        $r = get_metadata( 'post', $t, '_bbp_moderator', false );
     101
     102        $this->assertCount( 3, $r );
     103    }
     104
     105    /**
     106     * @covers ::bbp_remove_user_from_object
     107     */
     108    public function test_bbp_remove_user_from_object() {
     109        $u = $this->factory->user->create();
     110        $t = $this->factory->topic->create();
     111
     112        // Add object terms.
     113        add_metadata( 'post', $t, '_bbp_moderator', $u, false );
     114
     115        $r = get_metadata( 'post', $t, '_bbp_moderator', false );
     116
     117        $this->assertCount( 1, $r );
     118
     119        $r = bbp_remove_user_from_object( $t, $u, '_bbp_moderator' );
     120
     121        $this->assertTrue( $r );
     122
     123        $r = get_metadata( 'post', $t, '_bbp_moderator', false );
     124
     125        $this->assertCount( 0, $r );
     126    }
     127
     128    /**
     129     * @covers ::bbp_is_object_of_user
     130     */
     131    public function test_bbp_is_object_of_user() {
     132        $u = $this->factory->user->create();
     133        $t = $this->factory->topic->create();
     134
     135        $r = bbp_is_object_of_user( $t, $u, '_bbp_moderator' );
     136
     137        $this->assertFalse( $r );
     138
     139        // Add user id.
     140        add_metadata( 'post', $t, '_bbp_moderator', $u, false );
     141
     142        $r = bbp_is_object_of_user( $t, $u, '_bbp_moderator' );
     143
     144        $this->assertTrue( $r );
     145    }
     146
     147    /**
    89148     * @covers ::bbp_edit_user_handler
    90149     * @todo   Implement test_bbp_edit_user_handler().
Note: See TracChangeset for help on using the changeset viewer.