Exemplo n.º 1
0
 /**
  * test grabbing a volunteer that does not exist
  **/
 public function testGetInvalidVolunteerByVolId()
 {
     //grab a volunteer id that exceeds the maximum allowable volunteer id
     $volunteer = Volunteer::getVolunteerByVolId($this->getPDO(), BreadBasketTest::INVALID_KEY);
     $this->assertNull($volunteer);
 }
Exemplo n.º 2
0
 public function testValidPut()
 {
     //create a new volunteer, and insert into the database
     $volunteer = new Volunteer(null, $this->valid_org_id, $this->VALID_EMAIL, $this->VALID_EMAIL_ACTIVATION, $this->VALID_FIRST_NAME, $this->VALID_HASH, $this->VALID_ADMIN, $this->VALID_LAST_NAME, $this->VALID_PHONE, $this->VALID_SALT);
     $volunteer->insert($this->getPDO());
     //update the volunteer
     $volunteer->setVolPhone($this->VALID_ALT_PHONE);
     //$volunteer->setVolEmail($this->VALID_ALT_EMAIL);
     //		var_dump($volunteer->getVolId());
     //send the info to update the API
     $response = $this->guzzle->put('https://bootcamp-coders.cnm.edu/~kkeller13/bread-basket/public_html/php/api/volunteer/' . $volunteer->getVolId(), ['allow-redirects' => ['strict' => true], 'json' => $volunteer, 'headers' => ['X-XSRF-TOKEN' => $this->token]]);
     //		var_dump($response);
     $newVolunteer = Volunteer::getVolunteerByVolId($this->getPDO(), $volunteer->getVolId());
     var_dump($newVolunteer);
     //ensure the response was sent, and the api returned a positive status
     $this->assertSame($response->getStatusCode(), 200);
     $body = $response->getBody();
     var_dump((string) $response->getBody());
     $retrievedVol = json_decode($body);
     //		var_dump($retrievedVol);
     $this->assertSame(200, $retrievedVol->status);
     //pull the value from the DB, and make sure it was properly updated
     $newvol = Volunteer::getVolunteerByVolId($this->getPDO(), $volunteer->getVolId());
     $this->assertSame($newvol->getVolPhone(), $this->VALID_ALT_PHONE);
 }
Exemplo n.º 3
0
         $listing = Listing::getListingByListingId($pdo, $id);
         if ($listing === null) {
             throw new RuntimeException("Listing does not exist", 404);
         }
         $listing = Listing::getListingByListingId($pdo, $id);
         $listing->setListingClaimedBy($requestObject->listingClaimedBy);
         $listing->setListingClosed($requestObject->listingClosed);
         $listing->setListingCost($requestObject->listingCost);
         $listing->setListingMemo($requestObject->listingMemo);
         $listing->setListingParentId($requestObject->listingParentId);
         $listing->setListingPostTime($requestObject->listingPostTime);
         $listing->setListingTypeId($requestObject->listingTypeId);
         $listing->update($pdo);
         $pusher->trigger("listing", "update", $listing);
         //if this isn't supposed to be an admin, take away the temporary admin access
         $security = Volunteer::getVolunteerByVolId($pdo, $_SESSION["volunteer"]->getVolId());
         if ($security->getVolIsAdmin() === false) {
             $_SESSION["volunteer"]->setVolIsAdmin(false);
         }
         $reply->message = "Listing updated OK";
     } elseif ($method === "POST") {
         //create new listing
         $listing = new Listing(null, $_SESSION["volunteer"]->getOrgId(), $requestObject->listingClaimedBy, $requestObject->listingClosed, $requestObject->listingCost, $requestObject->listingMemo, $requestObject->listingParentId, $requestObject->listingPostTime, $requestObject->listingTypeId);
         $listing->insert($pdo);
         $pusher->trigger("listing", "new", $listing);
         $reply->message = "Listing created OK";
     }
 } elseif ($method === "DELETE") {
     $listing = Listing::getListingByListingId($pdo, $id);
     if ($listing === null) {
         throw new RuntimeException("Listing does not exist", 404);
Exemplo n.º 4
0
              **/
             if ($numSent !== count($recipients)) {
                 // the $failedRecipients parameter passed in the send() method now contains contains an array of the Emails that failed
                 throw new RuntimeException("unable to send email", 404);
             }
         }
     } elseif ($method === "DELETE") {
         //verifyXsrf();
         //if they shouldn't have admin access to this method, kill the temp access and boot them
         //check by retrieving their original volunteer from the DB and checking
         $security = Volunteer::getVolunteerByVolId($pdo, $_SESSION["volunteer"]->getVolId());
         if ($security->getVolIsAdmin() === false) {
             $_SESSION["volunteer"]->setVolIsAdmin(false);
             throw new RunTimeException("Access Denied", 403);
         }
         $volunteer = Volunteer::getVolunteerByVolId($pdo, $id);
         if ($volunteer === null) {
             throw new RangeException("Volunteer does not exist", 404);
         }
         $volunteer->delete($pdo);
         $deletedObject = new stdClass();
         $deletedObject->volunteerId = $id;
         $reply->message = "Volunteer deleted OK";
     }
 } else {
     //if not an admin, and attempting a method other than get, throw an exception
     if (empty($method) === false && $method !== "GET") {
         throw new RuntimeException("Only administrators are allowed to modify entries", 401);
     }
 }
 //send exception back to the caller