/**
  * test updating an access that already exists
  *
  * @expectedException \PDOException
  */
 public function testUpdateInvalidAccess()
 {
     //create an access with a non null access id and watch it fail
     $access = new Access(null, $this->VALID_ACCESSNAME);
     $access->update($this->getPDO());
 }
Esempio n. 2
0
     if ($method === "PUT" || $method === "POST") {
         verifyXsrf();
         $requestContent = file_get_contents("php://input");
         $requestObject = json_decode($requestContent);
         //make sure all fields are present, in order to fix database issues
         if (empty($requestObject->accessName) === true) {
             throw new InvalidArgumentException("accessName cannot be null", 405);
         }
         //perform put or post
         if ($method === "PUT") {
             $access = Access::getAccessByAccessId($pdo, $id);
             if ($access === null) {
                 throw new RuntimeException("access does not exist", 404);
             }
             $access = new Access($id, $requestObject->accessName);
             $access->update($pdo);
             $reply->message = "Access updated ok";
             //check to make sure a non-admin is only attempting to edit themselves
             //if not, take their temp access and throw an exception
             // use the example from Slack to determine admins
         } else {
             if ($method === "POST") {
                 $access = new Access(null, $requestObject->accessName);
                 $access->insert($pdo);
                 $reply->message = "Access created OK";
             }
         }
     }
 } else {
     throw new RuntimeException("Must be an administrator to gain access.");
 }