public function testInsertDuplicateUser() { ob_start(); $myDb = DBMaker::create('botspacetest'); Database::clearDB(); $db = Database::getDB('botspacetest', 'C:\\xampp\\myConfig.ini'); $beforeCount = count(UsersDB::getUsersBy()); $duplicateTest = array("email" => "*****@*****.**", "password" => "whatever"); $s1 = new User($duplicateTest); $newUser = UsersDB::addUser($s1); $this->assertGreaterThan(0, $newUser->getErrorCount(), 'Duplicate attempt should return with an error'); $afterCount = count(UsersDB::getUsersBy()); $this->assertEquals($afterCount, $beforeCount, 'The database should have the same number of elements after trying to insert duplicate'); ob_get_clean(); }
public function testInsertDuplicateUser() { ob_start(); $myDb = DBMaker::create('sensordatarepotest'); Database::clearDB(); $db = Database::getDB('sensordatarepotest', 'C:\\xampp\\myConfig.ini'); $beforeCount = count(UsersDB::getUsersBy()); $duplicateTest = array('username' => 'mwatney', 'password' => 'validpassword'); $s1 = new User($duplicateTest); $newUser = UsersDB::addUser($s1); $this->assertGreaterThan(0, $newUser->getErrorCount(), 'Duplicate attempt should return with an error'); $afterCount = count(UsersDB::getUsersBy()); $this->assertEquals($afterCount, $beforeCount, 'The database should have no additional users after insertion'); ob_get_clean(); }
public static function run() { $user = null; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $formUser = new User($_POST); $user = UsersDB::addUser($formUser); if ($user->getErrorCount() == 0) { $_POST['user'] = $user; } } if (is_null($user) || $user->getErrorCount() != 0) { SignupView::show($user); } else { ProfileView::show(); } }
public static function run() { $userData = null; if ($_SERVER["REQUEST_METHOD"] == "POST") { $userData = new User($_POST); if (is_null($userData) || $userData->getErrorCount() != 0) { SignupView::show($userData); } else { $userData = UsersDB::addUser($userData); HomeView::show(); header('Location: /' . $_SESSION['base']); } } else { // Initial link SignupView::show(null); } }
public static function run() { $user = null; $userData = null; if ($_SERVER["REQUEST_METHOD"] == "POST") { $user = new User($_POST); //$dbUser = UsersDB::addUser($user); $userData = new UserData($_POST); //$_POST["userId"] = $user->getUserId(); $dbUserData = UsersDB::addUser($user, $userData); if ($user->getErrorCount() == 0 && $userData->getErrorCount() == 0) { ProfileView::show($user, $userData); } else { SignupView::show($user, $userData); } } else { SignupView::show(null, null); } }
public static function newUser() { $user = null; if ($_SERVER["REQUEST_METHOD"] == "POST") { $user = new User($_POST); } $_SESSION['user'] = $user; if (is_null($user) || $user->getErrorCount() != 0) { //$_SESSION['user'] = $user; UserView::showNew(); } else { $newUser = UsersDB::addUser($user); if ($newUser->getErrorCount() == 0) { $_SESSION['user'] = $newUser; } HomeView::show(); //header('Location: /'.$_SESSION['base']); } }
public static function run() { $userData = null; if ($_SERVER["REQUEST_METHOD"] == "POST") { $userData = new User($_POST); $userData = UsersDB::addUser($userData); } if (is_null($userData) || $userData->getErrorCount() != 0) { //SignupView::show($userData); $_SESSION['user'] = $userData; SignupView::show(); } else { $_SESSION['authenticatedUser'] = $userData; HomeView::show(); header('Location: /' . $_SESSION['base']); } // } else // Initial link // $_SESSION['user'] = null; // SignupView::show(); }
public static function run() { $user = null; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $formUser = new User($_POST); if ($formUser->getErrorCount() == 0) { $plaintextPassword = $formUser->getPassword(); $hashedPassword = password_hash($plaintextPassword, PASSWORD_DEFAULT); $formUser->setPassword($hashedPassword); $user = UsersDB::addUser($formUser); if ($user->getErrorCount() == 0) { $_SESSION['user'] = $user; } } else { $user = $formUser; } } if (is_null($user) || $user->getErrorCount() != 0) { SignupView::show($user); } else { ProfileView::show(); } }
public static function run() { $user = null; $userData = null; if ($_SERVER["REQUEST_METHOD"] == "POST") { //print_r($_POST); $formUser = new User($_POST); $user = UsersDB::addUser($formUser); if ($user->getErrorCount() == 0) { $_POST["userId"] = $user->getUserId(); $formUserData = new UserData($_POST); $userData = UserDataDB::addUserData($formUserData); if ($userData->getErrorCount() == 0) { $_SESSION['user'] = $user; $_SESSION['userData'] = $userData; } } } if (is_null($user) || is_null($userData) || $user->getErrorCount() != 0 || $userData->getErrorCount() != 0) { SignupView::show($user, $userData); } else { ProfileView::show(); } }
<h2>It should allow a user to be added</h2> <?php echo "Number of users in db before added is: " . count(UsersDB::getAllUsers()) . "<br>"; $validTest = array("userName" => "joan", "password" => "123"); $user = new User($validTest); $userId = UsersDB::addUser($user); echo "Number of users in db after added is: " . count(UsersDB::getAllUsers()) . "<br>"; echo "User ID of new user is: {$userId}<br>"; ?> <h2>It should not add an invalid user</h2> <?php echo "Number of users in db before added is: " . count(UsersDB::getAllUsers()) . "<br>"; $invalidUser = new User(array("userName" => "krobbins\$")); $userId = UsersDB::addUser($invalidUser); echo "Number of users in db after added is: " . count(UsersDB::getAllUsers()) . "<br>"; echo "User ID of new user is: {$userId}<br>"; ?> <h2>It should get a User by userName</h2> <?php $users = UsersDB::getUsersBy('userName', 'George'); echo "The value of User George is:<br>{$users['0']}<br>"; ?> <h2>It should get a User by userId</h2> <?php $users = UsersDB::getUsersBy('userId', '3'); echo "The value of User 3 is:<br>{$users['0']}<br>"; ?>
$db = Database::getDB('ptest'); echo "Number of users in db before added is: " . count(UsersDB::getUsersBy()) . "<br>"; $invalidUser = new User(array("userName" => "krobbins\$")); $newUser = UsersDB::addUser($invalidUser); echo "Number of users in db after added is: " . count(UsersDB::getUsersBy()) . "<br>"; echo "New user is: {$newUser}<br>"; ?> <h2>It should not add a duplicate user</h2> <?php DBMaker::create('ptest'); Database::clearDB(); $db = Database::getDB('ptest'); echo "Number of users in db before added is: " . count(UsersDB::getUsersBy()) . "<br>"; $duplicateUser = new User(array("userName" => "Kay", "password" => "XXX")); $userId = UsersDB::addUser($duplicateUser); echo "Number of users in db after added is: " . count(UsersDB::getUsersBy()) . "<br>"; echo "User ID of new user is: {$userId}<br>"; ?> <h2>It should get a User by userName</h2> <?php DBMaker::create('ptest'); Database::clearDB(); $db = Database::getDB('ptest'); $users = UsersDB::getUsersBy('userName', 'George'); echo "The value of User George is:<br>{$users['0']}<br>"; ?> <h2>It should get a User by userId</h2> <?php
$userDataCount = count($userData); echo "Number of user data in db is: {$userDataCount} <br>"; foreach ($userData as $userData) { echo "{$userData} <br>"; } ?> <h2>It should allow a new valid user data to be added for a new user</h2> <?php makeDB('botspacetest'); Database::clearDB(); $db = Database::getDB('botspacetest'); echo "Number of user data in db before adding is: " . count(UserDataDB::getUserDataBy()) . "<br>"; $validTestUser = array("email" => "*****@*****.**", "password" => "validpassword"); $user = new User($validTestUser); $userId = UsersDB::addUser($user); $validTestUserData = array("user_name" => "newbie-user", "skill_level" => "novice", "skill_areas" => array("computer-vision", "soldering", "circuit-design"), "profile_pic" => "no-picture.jpg", "started_hobby" => "2015-10", "fav_color" => "#ff8000", "url" => "http://www.wired.com", "phone" => "210-555-1234"); $userData = new UserData($validTestUserData); $userData->setUserId($userId); $userDataId = UserDataDB::addUserData($userData); echo "Number of user data in db after adding is: " . count(UserDataDB::getUserDataBy()) . "<br>"; echo "UserData ID of new user is: {$userDataId}"; ?> <h2>It should not allow invalid user data to be added</h2> <h2>It should allow user data to be edited for an existing user</h2> <h2>It should not allow user data to be added for a nonexistent user</h2>