예제 #1
0
 /**
  * test favoriting a team and then deleting it.
  */
 public function testDeleteValidFavoriteTeam()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("favoriteTeam");
     // create a new favorite team, and insert it into the db
     $favoriteTeam = new FavoriteTeam($this->profile->getProfileId(), $this->team->getTeamId());
     $favoriteTeam->insert($this->getPDO());
     // delete the favorite team from profiles favorite teams
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("favoriteTeam"));
     $favoriteTeam->delete($this->getPDO());
     // grab the data from the db, and enforce that the favorite team doesn't exist
     $pdoFavoriteTeam = FavoriteTeam::getFavoriteTeamByFavoriteTeamProfileIdAndFavoriteTeamTeamId($this->getPDO(), $this->profile->getProfileId(), $this->team->getTeamId());
     $this->assertNull($pdoFavoriteTeam);
     $this->assertEquals($numRows, $this->getConnection()->getRowCount("favoriteTeam"));
 }
예제 #2
0
    // grab the MySQL connection
    $pdo = connectToEncryptedMySQL("/etc/apache2/capstone-mysql/sprots.ini");
    //determine which HTTP method was used
    $method = array_key_exists("HTTP_X_HTTP_METHOD", $_SERVER) ? $_SERVER["HTTP_X_HTTP_METHOD"] : $SERVER["REQUEST_METHOD"];
    //sanitize inputs
    $id = filter_input(INPUT_GET, "id", FILTER_VALIDATE_INT);
    //make sure the id is valid for methods that require it
    if (($method === "DELETE" || $method === "PUT") && (empty($id) === true || $id < 0)) {
        throw new InvalidArgumentException("id can not be empty or negative", 405);
    }
    //sanitize and trim other fields
    $favoriteTeamProfileId = filter_input(INPUT_GET, "profileId", FILTER_VALIDATE_INT);
    $favoriteTeamTeamId = filter_input(INPUT_GET, "teamId", FILTER_VALIDATE_INT);
    //get the team based on the given field
    if (empty($id) === false) {
        $favoriteTeam = FavoriteTeam::getFavoriteTeamByFavoriteTeamProfileIdAndFavoriteTeamTeamId($pdo, $id);
        $reply->data = $favoriteTeam;
    } elseif (empty($favoriteTeamTeamId) === false) {
        $favoriteTeam = FavoriteTeam::getFavoriteTeamsByFavoriteTeamProfileId($pdo, $teamId);
        $reply->date = $favoriteTeam;
    }
} catch (Exception $exception) {
    $reply->status = $exception->getCode();
    $reply->message = $exception->getMessage();
} catch (TypeError $typeError) {
    $reply->status = $typeError->getCode();
    $reply->message = $typeError->getMessage();
}
header("Content-type: application/json");
if ($reply->data === null) {
    unset($reply->data);