Ejemplo n.º 1
0
 public function testAddMemberProfileWithValidParameter()
 {
     $input = array("firstName" => "Nathan", "middleName" => null, "lastName" => "Martin", "email" => "*****@*****.**", "gender" => "male", "phone" => "210-555-4917", "address" => "201 Sunset Ave, San Antonio, TX 78249", "dob" => "1983-11-26", "profileType" => "member");
     $profile = new Profile($input);
     $this->dbQuery("delete from Profiles where email = '*****@*****.**'");
     $rowsBeforeAdd = $this->dbSelect("select * from Profiles where email = '*****@*****.**'");
     $profileID = ProfilesDB::addProfile($profile);
     $rowsAfterAdd = $this->dbSelect("select * from Profiles where email = '*****@*****.**'");
     $this->assertEmpty($rowsBeforeAdd, 'It should not have the provided member profile until the profile has been added');
     $this->assertCount(1, $rowsAfterAdd, 'It should have a new row in the Profiles table of the database when the profile parameter is provided');
     $this->assertArrayHasKey('firstName', $rowsAfterAdd[0], 'It should have a new row in the Profiles table of the database when the profile parameter is provided');
     $this->assertEquals("*****@*****.**", $rowsAfterAdd[0]["email"], 'It should have a new row in the Profiles table of the database when the profile parameter is provided');
     $this->assertTrue(is_numeric($profileID), 'It should return the profile ID of the added member profile when the profile parameter is provided');
     $this->assertNotEquals(-1, $profileID, 'It should return a valid profile ID of the added member profile when the profile parameter is provided');
 }
Ejemplo n.º 2
0
 private static function createProfile($arguments)
 {
     // check arguments
     if (!array_key_exists(0, $arguments) || !isset($_GET['ssn']) || !isset($_GET['name']) || !isset($_GET['email'])) {
         self::outputMessage(self::CODE_BAD_REQUEST, 'Missing arguments', 'bankID, SSN, name, and email are required for registration.');
         return;
     }
     list($_GET['firstName'], $_GET['lastName']) = explode(' ', $_GET['name']);
     $bankID = $arguments[0];
     // make sure an account with the specified bankID (aka accountID) exists
     $matchingAccounts = AccountsDB::getAccountsBy('bankID', $bankID);
     if (empty($matchingAccounts)) {
         self::outputMessage(self::CODE_BAD_REQUEST, 'Member not found', 'A member with the specified bank ID does not exist.');
         return;
     }
     // make sure the profile has not already been created
     $existingProfile = ProfilesDB::getProfileBy('email', $_GET['email']);
     if (!is_null($existingProfile)) {
         self::outputMessage(self::CODE_BAD_REQUEST, 'Account already exists', 'An account with the specified bank ID already exists.');
         return;
     }
     // generate default password for account, and store bank ID
     $_GET['password'] = Email::sendEmail($_GET['email'], 1);
     $_GET['bankID'] = $bankID;
     // create the profile
     $profile = new Profile($_GET);
     if ($profile->getErrorCount() > 0) {
         self::outputMessage(self::CODE_BAD_REQUEST, 'Account creation failed', 'Errors occured while processing the arguments to create the account.');
         return;
     }
     // store the profile in the database
     $result = ProfilesDB::addProfile($profile);
     if ($profile->getErrorCount() > 0 || !is_numeric($result)) {
         self::outputMessage(self::CODE_INTERNAL_SERVER_ERROR, 'Account creation failed', 'Errors occured while attempting to store the new account information in the database.');
         return;
     }
     $profile->setProfileID($result);
     // success
     self::outputMessage(self::CODE_SUCCESS, 'Registration complete', 'An account for specified member was successfully created.', $profile);
 }