Exemplo n.º 1
0
 //Set an XSRF cookie on 'get' requests
 setXsrfCookie("/");
 //Get the listing based on the current field
 if (empty($followerFollowerId) === false && empty($followerFollowedId) === false) {
     $reply->data = Follower::getFollowerByFollowerIdAndFollowedId($pdo, $followerFollowerId, $followerFollowedId);
 } elseif (empty($followerFollowerId) === false) {
     $reply->data = Follower::getFollowerByFollowerId($pdo, $followerFollowerId)->toArray();
 } elseif (empty($followerFollowedId) === false) {
     $reply->data = Follower::getFollowerByFollowedId($pdo, $followerFollowedId)->toArray();
 }
 if (empty($_SESSION["profile"]) === false) {
     if ($method === "POST") {
         verifyXsrf();
         $requestContent = file_get_contents("php://input");
         $requestObject = json_decode($requestContent);
         $follow = new Follower($requestObject->followerFollowerId, $requestObject->followerFollowedId);
         $follow->insert($pdo);
         $tempName = Profile::getProfilebyProfileId($pdo, $requestObject->followerFollowedId)->getProfileHandle();
         $reply->message = "You are now following " . $tempName;
     } elseif ($method === "DELETE") {
         $follower = Follower::getFollowerByFollowerIdAndFollowedId($pdo, $followerFollowerId, $followerFollowedId);
         if ($follower === null) {
             throw new \RuntimeException("relationship does not exist", 404);
         }
         if ($_SESSION["profile"]->getProfileId() !== $follower->getFollowerFollowerId()) {
             throw new \RuntimeException("Only the follower can stop following.");
         }
         $tempName = Profile::getProfilebyProfileId($pdo, $follower->getFollowerFollowedId())->getProfileHandle();
         $follower->delete($pdo);
         $deletedObject = new stdClass();
         $deletedObject->followerFollowerId = $followerFollowerId;
Exemplo n.º 2
0
 /**
  * @expectedException \RangeException
  **/
 public function testSetInvalidFollowerByNegativeFollowedId()
 {
     $follow = new Follower($this->follower->getProfileId(), -1);
     $follow->insert($this->getPDO());
 }