/** * @group integration */ public function testFollowUser() { $this->clearDB(); $this->loadDB(); $username = '******'; $service = new UserService(); $suggestions = $service->friendSuggestions($username); $toFollow = $suggestions[0]; $service->followUser($username, $toFollow->username); $following = $service->following($username); $this->assertTrue($this->checkUserIsFollowed($toFollow->username, $following)); }
$app->put('/user/edit', function () use($app) { $params = json_decode($app->request->getBody()); $user = UserService::getByUsername($_SESSION['username']); $user->firstname = $params->firstname; $user->lastname = $params->lastname; UserService::save($user); $app->jsonResponse->build($user); })->name('user-edit'); /******************************** * Start Social Graph *******************************/ // social - friends - get list of friends and search for new ones $app->get('/friends', $isLoggedIn, function () use($app) { $user = UserService::getByUsername($_SESSION['username']); $following = UserService::following($_SESSION['username']); $suggestions = UserService::friendSuggestions($_SESSION['username']); $app->render('graphs/social/friends.mustache', array('user' => $user, 'following' => $following, 'suggestions' => $suggestions, 'unfollowUrl' => $app->urlFor('social-unfollow', array('userToUnfollow' => null)), 'followUrl' => $app->urlFor('social-follow', array('userToFollow' => null)))); })->name('social-friends'); // takes current user session and will follow :username, e.g. one way follow $app->get('/follow/:userToFollow', function ($userToFollow) use($app) { UserService::followUser($_SESSION['username'], $userToFollow); $following = UserService::following($_SESSION['username']); $unfollowUrl = $app->urlFor('social-unfollow', array('userToUnfollow' => null)); $return = array(); foreach ($following as $friend) { $content = array_merge(array('unfollowUrl' => $unfollowUrl), $friend->toArray()); $return[] = $app->view->getInstance()->render('graphs/social/friends-partial', $content); } $app->jsonResponse->build(array('following' => $return)); })->name('social-follow'); // takes current user session and will unfollow :username