| | 138 | |
| | 139 | /** |
| | 140 | * @group friends_check_friendship_status |
| | 141 | */ |
| | 142 | public function test_friends_check_friendship_status_in_members_loop() { |
| | 143 | $now = time(); |
| | 144 | $u1 = $this->create_user( array( |
| | 145 | 'last_activity' => date( 'Y-m-d H:i:s', $now ), |
| | 146 | ) ); |
| | 147 | $u2 = $this->create_user( array( |
| | 148 | 'last_activity' => date( 'Y-m-d H:i:s', $now - 100 ), |
| | 149 | ) ); |
| | 150 | $u3 = $this->create_user( array( |
| | 151 | 'last_activity' => date( 'Y-m-d H:i:s', $now - 200 ), |
| | 152 | ) ); |
| | 153 | $u4 = $this->create_user( array( |
| | 154 | 'last_activity' => date( 'Y-m-d H:i:s', $now - 300 ), |
| | 155 | ) ); |
| | 156 | $u5 = $this->create_user( array( |
| | 157 | 'last_activity' => date( 'Y-m-d H:i:s', $now - 400 ), |
| | 158 | ) ); |
| | 159 | |
| | 160 | friends_add_friend( $u1, $u2, true ); |
| | 161 | friends_add_friend( $u1, $u3, false ); |
| | 162 | friends_add_friend( $u4, $u1, false ); |
| | 163 | |
| | 164 | $old_user = get_current_user_id(); |
| | 165 | $this->set_current_user( $u1 ); |
| | 166 | |
| | 167 | $found = array(); |
| | 168 | if ( bp_has_members() ) : while ( bp_members() ) : bp_the_member(); |
| | 169 | $found[ bp_get_member_user_id() ] = friends_check_friendship_status( $u1, bp_get_member_user_id() ); |
| | 170 | endwhile; endif; |
| | 171 | |
| | 172 | $expected = array( |
| | 173 | $u1 => 'not_friends', |
| | 174 | $u2 => 'is_friend', |
| | 175 | $u3 => 'pending', |
| | 176 | $u4 => 'awaiting_response', |
| | 177 | $u5 => 'not_friends', |
| | 178 | ); |
| | 179 | |
| | 180 | $this->assertSame( $expected, $found ); |
| | 181 | |
| | 182 | // clean up |
| | 183 | $GLOBALS['members_template'] = null; |
| | 184 | $this->set_current_user( $old_user ); |
| | 185 | } |
| | 186 | |
| | 187 | /** |
| | 188 | * @group friends_check_friendship_status |
| | 189 | */ |
| | 190 | public function test_friends_check_friendship_status_not_in_members_loop() { |
| | 191 | $now = time(); |
| | 192 | $u1 = $this->create_user( array( |
| | 193 | 'last_activity' => date( 'Y-m-d H:i:s', $now ), |
| | 194 | ) ); |
| | 195 | $u2 = $this->create_user( array( |
| | 196 | 'last_activity' => date( 'Y-m-d H:i:s', $now - 100 ), |
| | 197 | ) ); |
| | 198 | $u3 = $this->create_user( array( |
| | 199 | 'last_activity' => date( 'Y-m-d H:i:s', $now - 200 ), |
| | 200 | ) ); |
| | 201 | $u4 = $this->create_user( array( |
| | 202 | 'last_activity' => date( 'Y-m-d H:i:s', $now - 300 ), |
| | 203 | ) ); |
| | 204 | $u5 = $this->create_user( array( |
| | 205 | 'last_activity' => date( 'Y-m-d H:i:s', $now - 400 ), |
| | 206 | ) ); |
| | 207 | |
| | 208 | friends_add_friend( $u1, $u2, true ); |
| | 209 | friends_add_friend( $u1, $u3, false ); |
| | 210 | friends_add_friend( $u4, $u1, false ); |
| | 211 | |
| | 212 | $found = array( |
| | 213 | $u1 => friends_check_friendship_status( $u1, $u1 ), |
| | 214 | $u2 => friends_check_friendship_status( $u1, $u2 ), |
| | 215 | $u3 => friends_check_friendship_status( $u1, $u3 ), |
| | 216 | $u4 => friends_check_friendship_status( $u1, $u4 ), |
| | 217 | $u5 => friends_check_friendship_status( $u1, $u5 ), |
| | 218 | ); |
| | 219 | |
| | 220 | $expected = array( |
| | 221 | $u1 => 'not_friends', |
| | 222 | $u2 => 'is_friend', |
| | 223 | $u3 => 'pending', |
| | 224 | $u4 => 'awaiting_response', |
| | 225 | $u5 => 'not_friends', |
| | 226 | ); |
| | 227 | |
| | 228 | $this->assertSame( $expected, $found ); |
| | 229 | } |