/**
  * set up for dependent objects before running each test
  */
 public final function setUp()
 {
     //run default set-up method
     parent::setUp();
     //create a new organization for the test volunteers to belong
     $organization = new Organization(null, "123 Easy Street", '', "Albuquerque", "Feeding people since 1987", "9 - 5", "Food for Hungry People", "505-765-4321", "NM", "R", "87801");
     $organization->insert($this->getPDO());
     //create a new volunteer to use as an admin for the tests
     //don't need to insert them into the database: just need their info to create sessions
     //for testing purposes, allow them to create organizations they're not associated with
     $salt = bin2hex(openssl_random_pseudo_bytes(32));
     $hash = hash_pbkdf2("sha512", "password4321", $salt, 262144, 128);
     $this->admin = new Volunteer(null, $organization->getOrgId(), "*****@*****.**", null, "John", $hash, true, "Doe", "505-123-4567", $salt);
     $this->admin->insert($this->getPDO());
     //create a non-admin volunteer for the tests
     $salt = bin2hex(openssl_random_pseudo_bytes(32));
     $hash = hash_pbkdf2("sha512", "password1234", $salt, 262144, 128);
     $this->volunteer = new Volunteer(null, $organization->getOrgId(), "*****@*****.**", null, "Jane", $hash, false, "Doe", "505-555-5555", $salt);
     $this->volunteer->insert($this->getPDO());
     //create the guzzle client
     $this->guzzle = new \GuzzleHttp\Client(["cookies" => true]);
     //visit ourselves to get the xsrf-token
     $this->guzzle->get('https://bootcamp-coders.cnm.edu/~tfenstermaker/bread-basket/public_html/php/api/organization');
     $cookies = $this->guzzle->getConfig()["cookies"];
     $this->token = $cookies->getCookieByName("XSRF-TOKEN")->getValue();
     //send a request to the sign-in method
     $adminLogin = new stdClass();
     $adminLogin->email = "*****@*****.**";
     $adminLogin->password = "******";
     $login = $this->guzzle->post('https://bootcamp-coders.cnm.edu/~tfenstermaker/bread-basket/public_html/php/controllers/sign-in-controller.php', ['json' => $adminLogin, 'headers' => ['X-XSRF-TOKEN' => $this->token]]);
 }
예제 #2
0
 $volEmail = filter_var($requestObject->volEmail, FILTER_SANITIZE_EMAIL);
 $volunteer = Volunteer::getVolunteerByVolEmail($pdo, $volEmail);
 if ($volunteer !== null) {
     throw new RuntimeException("This email already has an account", 422);
 }
 // create a new salt and email activation
 $volSalt = bin2hex(openssl_random_pseudo_bytes(32));
 $volEmailActivation = bin2hex(openssl_random_pseudo_bytes(8));
 // create the hash
 $volHash = hash_pbkdf2("sha512", $requestObject->password, $volSalt, 262144, 128);
 //create a new organization and insert into mySQL
 $organization = new Organization(null, $requestObject->orgAddress1, $requestObject->orgAddress2, $requestObject->orgCity, $requestObject->orgDescription, $requestObject->orgHours, $requestObject->orgName, $requestObject->orgPhone, $requestObject->orgState, $requestObject->orgType, $requestObject->orgZip);
 $organization->insert($pdo);
 $reply->message = "New organization has been created";
 //create a new Volunteer and insert into mySQL
 $volunteer = new Volunteer(null, $organization->getOrgId(), $requestObject->volEmail, $volEmailActivation, $requestObject->volFirstName, $volHash, true, $requestObject->volLastName, $requestObject->volPhone, $volSalt);
 $volunteer->insert($pdo);
 $reply->message = "A new administrator has been created";
 if ($volunteer->getVolIsAdmin() === true) {
     $_SESSION["volunteer"] = $volunteer;
     $reply->status = 200;
     $reply->message = "Logged in as administrator";
 }
 // create Swift message
 $swiftMessage = Swift_Message::newInstance();
 // attach the sender to the message
 // this takes the form of an associative array where the Email is the key for the real name
 $swiftMessage->setFrom(["*****@*****.**" => "Bread Basket"]);
 /**
  * attach the recipients to the message
  * notice this an array that can include or omit the the recipient's real name
예제 #3
0
 /**
  * test inserting an organization and regrabbing it from mySQL
  */
 public function testGetValidOrganizationByOrgId()
 {
     //count the number of rows currently in the database
     $numRows = $this->getConnection()->getRowCount("organization");
     //create a new organization and insert into mySQL
     $organization = new Organization(null, $this->VALID_ADDRESS1, $this->VALID_ADDRESS2, $this->VALID_CITY, $this->VALID_DESCRIPTION, $this->VALID_HOURS, $this->VALID_NAME, $this->VALID_PHONE, $this->VALID_STATE, $this->VALID_TYPE, $this->VALID_ZIP);
     $organization->insert($this->getPDO());
     //grab data from mySQL and enforce that the fields match
     $pdoOrganization = Organization::getOrganizationByOrgId($this->getPDO(), $organization->getOrgId());
     $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("organization"));
     $this->assertSame($pdoOrganization->getOrgAddress1(), $this->VALID_ADDRESS1);
     $this->assertSame($pdoOrganization->getOrgAddress2(), $this->VALID_ADDRESS2);
     $this->assertSame($pdoOrganization->getOrgCity(), $this->VALID_CITY);
     $this->assertSame($pdoOrganization->getOrgDescription(), $this->VALID_DESCRIPTION);
     $this->assertSame($pdoOrganization->getOrgHours(), $this->VALID_HOURS);
     $this->assertSame($pdoOrganization->getOrgName(), $this->VALID_NAME);
     $this->assertSame($pdoOrganization->getOrgPhone(), $this->VALID_PHONE);
     $this->assertSame($pdoOrganization->getOrgState(), $this->VALID_STATE);
     $this->assertSame($pdoOrganization->getOrgType(), $this->VALID_TYPE);
     $this->assertSame($pdoOrganization->getOrgZip(), $this->VALID_ZIP);
 }
예제 #4
0
 /**
  * test putting a valid organization into the API
  */
 public function testValidPut()
 {
     //create a new organization, and insert into the database
     $organization = new Organization(null, $this->VALID_ADDRESS1, $this->VALID_ADDRESS2, $this->VALID_CITY, $this->VALID_DESCRIPTION, $this->VALID_HOURS, $this->VALID_NAME, $this->VALID_PHONE, $this->VALID_STATE, $this->VALID_TYPE, $this->VALID_ZIP);
     $organization->insert($this->getPDO());
     //update the organization
     $organization->setOrgName($this->VALID_NAME_ALT);
     //send the info to update to the API
     $response = $this->guzzle->put('https://bootcamp-coders.cnm.edu/~bbrown52/bread-basket/public_html/php/api/organization/' . $organization->getOrgId(), ['allow-redirects' => ['strict' => true], 'json' => $organization, 'headers' => ['X-XSRF-TOKEN' => $this->token]]);
     //ensure the response was sent, and the api returned a positive status
     $this->assertSame($response->getStatusCode(), 200);
     $body = $response->getBody();
     $retrievedOrg = json_decode($body);
     $this->assertSame(200, $retrievedOrg->status);
     //pull the value from the DB, and make sure it was properly updated
     $neworg = Organization::getOrganizationByOrgId($this->getPDO(), $organization->getOrgId());
     $this->assertSame($neworg->getOrgName(), $this->VALID_NAME_ALT);
 }