예제 #1
0
 /**
  * create dependent objects before running each test
  */
 public final function setUp()
 {
     // run the default setUp() method first
     parent::setUp();
     $password = "******";
     $activation = bin2hex(random_bytes(16));
     $salt = bin2hex(random_bytes(32));
     $hash = hash_pbkdf2("sha512", $password, $salt, 262144);
     // creates and inserts Company to sql for User foreign key relations
     $this->company = new Company(null, "Taco B.", "404 Taco St.", "suite:666", "Attention!!", "NM", "Burque", "87106", "5055551111", "*****@*****.**", "www.tocobell.com");
     $this->company->insert($this->getPDO());
     $_SESSION["company"] = $this->company;
     // creates and inserts Crew to sql for User foreign key relations
     $this->crew = new Crew(null, $this->company->getCompanyId(), "the moon");
     $this->crew->insert($this->getPDO());
     // creates and inserts Access to sql for User foreign key relations
     $this->access = new Access(null, "requestor or admin");
     $this->access->insert($this->getPDO());
     // create and insert a User to own the test Request
     $this->requestor = new User(null, $this->company->getCompanyId(), $this->crew->getCrewId(), $this->access->getAccessId(), "5551212", "Johnny", "Requestorman", "*****@*****.**", $activation, $hash, $salt);
     $this->requestor->insert($this->getPDO());
     $this->admin = new User(null, $this->company->getCompanyId(), $this->crew->getCrewId(), $this->access->getAccessId(), "5552121", "Suzy", "Hughes", "*****@*****.**", $activation, $hash, $salt);
     $this->admin->insert($this->getPDO());
     // calculate the date (just use the time the unit test was setup...)
     $this->VALID_REQUESTTIMESTAMP = new \DateTime();
     $this->VALID_REQUESTACTIONTIMESTAMP = new \DateTime();
 }
예제 #2
0
 /**
  * test grabbing all Crews
  **/
 public function testGetAllValidCrews()
 {
     //count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowcount("crew");
     //create a new Crew and insert it into mySQL
     $crew = new Crew(null, $this->company->getCompanyId(), $this->VALID_CREWLOCATION);
     $crew->insert($this->getPDO());
     //grab the data from mySQL and enforce the fields match our expectations
     $pdoCrews = Crew::getAllCrews($this->getPDO());
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("crew"));
     foreach ($pdoCrews as $pdoCrew) {
         if ($pdoCrew->getCrewId() === $crew->getCrewId()) {
             $this->assertEquals($pdoCrew->getCrewId(), $crew->getCrewId());
             $this->assertEquals($pdoCrew->getCrewLocation(), $crew->getCrewLocation());
             $this->assertEquals($pdoCrew->getCrewCompanyId(), $crew->getCrewCompanyId());
         }
     }
 }
예제 #3
0
     if (empty($requestObject->crewLocation) === true) {
         throw new InvalidArgumentException("Crew Location cannot be empty", 405);
     }
     //perform the actual put or post
     if ($method === "PUT") {
         $crew = Crew::getCrewByCrewId($pdo, $id);
         if ($crew === null) {
             throw new RuntimeException("Crew does not exist", 404);
         }
         $crew->setCrewLocation($requestObject->crewLocation);
         $crew->update($pdo);
         $reply->message = "Crew updated OK";
     } else {
         if ($method === "POST") {
             $crew = new Crew(null, $requestObject->crewCompanyId, $requestObject->crewLocation);
             $crew->insert($pdo);
             $reply->message = "Crew created OK";
         }
     }
 } else {
     if ($method === "DELETE") {
         verifyXsrf();
         $crew = Crew::getCrewByCrewId($pdo, $id);
         if ($crew === null) {
             throw new RuntimeException("Crew does not exist", 404);
         }
         $crew->delete($pdo);
         $deletedObject = new stdClass();
         $deletedObject->crewId = $id;
         $reply->message = "Crew deleted OK";
     }