<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][13428] branches/10.0: Improve comparison consistency in `BP_Friends_Friendship`</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/13428">13428</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/13428","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>imath</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-02-23 00:18:50 +0000 (Thu, 23 Feb 2023)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Improve comparison consistency in `BP_Friends_Friendship`

- Fix a bug introduced in <a href="http://buddypress.trac.wordpress.org/changeset/13092">[13092]</a> making sure to cast IDs retrieved by `$wpdb->results()` as integers when comparing them to another integer (user ID).
- Use strong comparisons everywhere in the class.
- Add unit tests.

Props boonebgorges

Fixes <a href="http://buddypress.trac.wordpress.org/ticket/8844">#8844</a> (branch 11.0)</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branches100srcbpfriendsclassesclassbpfriendsfriendshipphp">branches/10.0/src/bp-friends/classes/class-bp-friends-friendship.php</a></li>
<li><a href="#branches100testsphpunittestcasesfriendsclassbpfriendsfriendshipphp">branches/10.0/tests/phpunit/testcases/friends/class-bp-friends-friendship.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branches100srcbpfriendsclassesclassbpfriendsfriendshipphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/10.0/src/bp-friends/classes/class-bp-friends-friendship.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/10.0/src/bp-friends/classes/class-bp-friends-friendship.php      2023-02-23 00:04:36 UTC (rev 13427)
+++ branches/10.0/src/bp-friends/classes/class-bp-friends-friendship.php        2023-02-23 00:18:50 UTC (rev 13428)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -269,6 +269,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $user_id = bp_loggedin_user_id();
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $friendships = array();
+               $operator    = strtoupper( $operator );
+
+               if ( ! in_array( $operator, array( 'AND', 'OR', 'NOT' ), true ) ) {
+                       return $friendships;
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $r = bp_parse_args(
</span><span class="cx" style="display: block; padding: 0 10px">                        $args,
</span><span class="cx" style="display: block; padding: 0 10px">                        array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -302,18 +309,22 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $int_keys  = array( 'id', 'initiator_user_id', 'friend_user_id' );
+               $bool_keys = array( 'is_confirmed', 'is_limited' );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // Assemble filter array.
</span><span class="cx" style="display: block; padding: 0 10px">                $filters = wp_array_slice_assoc( $r, array( 'id', 'initiator_user_id', 'friend_user_id', 'is_confirmed', 'is_limited' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                foreach ( $filters as $filter_name => $filter_value ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( is_null( $filter_value ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                unset( $filters[ $filter_name ] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        } elseif ( in_array( $filter_name, $int_keys, true ) ) {
+                               $filters[ $filter_name ] = (int) $filter_value;
+                       } else {
+                               $filters[ $filter_name ] = (bool) $filter_value;
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Populate friendship array from cache, and normalize.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $friendships = array();
-               $int_keys    = array( 'id', 'initiator_user_id', 'friend_user_id' );
-               $bool_keys   = array( 'is_confirmed', 'is_limited' );
</del><span class="cx" style="display: block; padding: 0 10px">                 foreach ( $friendship_ids as $friendship_id ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        // Create a limited BP_Friends_Friendship object (don't fetch the user details).
</span><span class="cx" style="display: block; padding: 0 10px">                        $friendship = new BP_Friends_Friendship( $friendship_id, false, false );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -334,17 +345,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // We need to support the same operators as wp_list_filter().
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( 'OR' == $operator || 'NOT' == $operator ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( 'OR' === $operator || 'NOT' === $operator ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $matched = 0;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                foreach ( $filters as $filter_name => $filter_value ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        if ( isset( $friendship->{$filter_name} ) && $filter_value == $friendship->{$filter_name} ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 if ( isset( $friendship->{$filter_name} ) && $filter_value === $friendship->{$filter_name} ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 $matched++;
</span><span class="cx" style="display: block; padding: 0 10px">                                        }
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( ( 'OR' == $operator && $matched > 0 )
-                                 || ( 'NOT' == $operator && 0 == $matched ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( ( 'OR' === $operator && $matched > 0 )
+                                 || ( 'NOT' === $operator && 0 === $matched ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                         $friendships[ $friendship->id ] = $friendship;
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -354,7 +365,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                 * If any of the filters miss, we move on.
</span><span class="cx" style="display: block; padding: 0 10px">                                 */
</span><span class="cx" style="display: block; padding: 0 10px">                                foreach ( $filters as $filter_name => $filter_value ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        if ( ! isset( $friendship->{$filter_name} ) || $filter_value != $friendship->{$filter_name} ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 if ( ! isset( $friendship->{$filter_name} ) || $filter_value !== $friendship->{$filter_name} ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 continue 2;
</span><span class="cx" style="display: block; padding: 0 10px">                                        }
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -431,13 +442,19 @@
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $friendships = self::get_friendships( $user_id, $args );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $user_id     = (int) $user_id;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $fids = array();
</span><span class="cx" style="display: block; padding: 0 10px">                foreach ( $friendships as $friendship ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $friend_id = $friendship->friend_user_id;
+                       if ( $friendship->friend_user_id === $user_id ) {
+                               $friend_id = $friendship->initiator_user_id;
+                       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         if ( ! empty( $assoc_arr ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $fids[] = array( 'user_id' => ( $friendship->friend_user_id == $user_id ) ? $friendship->initiator_user_id : $friendship->friend_user_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $fids[] = array( 'user_id' => $friend_id );
</ins><span class="cx" style="display: block; padding: 0 10px">                         } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $fids[] = ( $friendship->friend_user_id == $user_id ) ? $friendship->initiator_user_id : $friendship->friend_user_id;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $fids[] = $friend_id;
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -636,7 +653,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Can't friend yourself.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( $initiator_userid === $possible_friend_userid ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( (int) $initiator_userid === (int) $possible_friend_userid ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         return 'not_friends';
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -662,6 +679,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $bp                  = buddypress();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $user_id             = (int) $user_id;
</ins><span class="cx" style="display: block; padding: 0 10px">                 $possible_friend_ids = wp_parse_id_list( $possible_friend_ids );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $fetch = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -939,9 +957,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $fids    = array();
</span><span class="cx" style="display: block; padding: 0 10px">                $sql     = $wpdb->prepare( "SELECT friend_user_id, initiator_user_id FROM {$bp->friends->table_name} WHERE (friend_user_id = %d || initiator_user_id = %d) && is_confirmed = 1 ORDER BY rand() LIMIT %d", $user_id, $user_id, $total_friends );
</span><span class="cx" style="display: block; padding: 0 10px">                $results = $wpdb->get_results( $sql );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $user_id = (int) $user_id;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                for ( $i = 0, $count = count( $results ); $i < $count; ++$i ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $fids[] = ( $results[ $i ]->friend_user_id === $user_id ) ? $results[ $i ]->initiator_user_id : $results[ $i ]->friend_user_id;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $friend_user_id    = (int) $results[ $i ]->friend_user_id;
+                       $initiator_user_id = (int) $results[ $i ]->initiator_user_id;
+
+                       if ( $friend_user_id === $user_id ) {
+                               $fids[] = $initiator_user_id;
+                       } else {
+                               $fids[] = $friend_user_id;
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Remove duplicates.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1058,7 +1084,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public static function delete_all_for_user( $user_id ) {
</span><span class="cx" style="display: block; padding: 0 10px">                global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $bp = buddypress();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $bp      = buddypress();
+               $user_id = (int) $user_id;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Get all friendships, of any status, for the user.
</span><span class="cx" style="display: block; padding: 0 10px">                $friendships    = self::get_friendships( $user_id );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1067,7 +1094,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">                foreach ( $friendships as $friendship ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $friendship_ids[] = $friendship->id;
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( $friendship->is_confirmed ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $friend_ids[] = ( $friendship->friend_user_id == $user_id ) ? $friendship->initiator_user_id : $friendship->friend_user_id;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( $friendship->friend_user_id === $user_id ) {
+                                       $friend_ids[] = $friendship->initiator_user_id;
+                               } else {
+                                       $friend_ids[] = $friendship->friend_user_id;
+                               }
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="branches100testsphpunittestcasesfriendsclassbpfriendsfriendshipphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/10.0/tests/phpunit/testcases/friends/class-bp-friends-friendship.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/10.0/tests/phpunit/testcases/friends/class-bp-friends-friendship.php     2023-02-23 00:04:36 UTC (rev 13427)
+++ branches/10.0/tests/phpunit/testcases/friends/class-bp-friends-friendship.php       2023-02-23 00:18:50 UTC (rev 13428)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -191,4 +191,71 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $first_query_count, $wpdb->num_queries );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * @ticket BP8844
+        */
+       public function test_get_random_friends() {
+               $user_id = self::factory()->user->create();
+               $friends = self::factory()->user->create_many( 4 );
+
+               foreach ( $friends as $initiator_id ) {
+                       friends_add_friend( $initiator_id, $user_id, true );
+               }
+
+               $random = BP_Friends_Friendship::get_random_friends( $user_id, 4 );
+               $this->assertFalse( in_array( $user_id, $random, true ), 'The requested user id should not be listed into random friends' );
+               $this->assertTrue( 4 === count( $random ) );
+       }
+
+       /**
+        * @ticket BP8844
+        */
+       public function test_get_friend_user_ids() {
+               $user_id = self::factory()->user->create();
+               $friends = self::factory()->user->create_many( 4 );
+
+               foreach ( $friends as $initiator_id ) {
+                       friends_add_friend( $initiator_id, $user_id, true );
+               }
+
+               $friend_user_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id );
+               $this->assertFalse( in_array( $user_id, $friend_user_ids, true ), 'The requested user id should not be listed into random friends' );
+               $this->assertTrue( 4 === count( $friend_user_ids ) );
+       }
+
+       /**
+        * @ticket BP8844
+        */
+       public function test_delete_all_for_user() {
+               $user_id = self::factory()->user->create();
+               $friends = self::factory()->user->create_many( 4 );
+
+               foreach ( $friends as $initiator_id ) {
+                       friends_add_friend( $initiator_id, $user_id, true );
+               }
+
+               BP_Friends_Friendship::delete_all_for_user( $user_id );
+               $friend_user_ids = BP_Friends_Friendship::get_friendship_ids_for_user( $user_id );
+               $this->assertEmpty( $friend_user_ids );
+       }
+
+       /**
+        * @ticket BP8844
+        */
+       public function test_get_friendships() {
+               $u1 = self::factory()->user->create();
+               $u2 = self::factory()->user->create();
+               $u3 = self::factory()->user->create();
+
+               friends_add_friend( $u2, $u1, false );
+               friends_add_friend( $u3, $u1, true );
+
+               $friendships = BP_Friends_Friendship::get_friendships( $u1, array( 'initiator_user_id' => $u2 ), 'not' );
+               $friendship = reset( $friendships );
+               $this->assertTrue( $u3 === $friendship->initiator_user_id && 1 === count( $friendships ) );
+
+               $friendships = BP_Friends_Friendship::get_friendships( $u1, array( 'initiator_user_id' => $u3, 'is_confirmed' => 0 ), 'or' );
+               $this->assertTrue( 2 === count( $friendships ) );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>