/** * Prepares the environment before running a test. */ public static function setUpBeforeClass() { self::$pdo = new ForumServicePDO(); self::$userPDO = new UserServicePDO(); AppUtils::setTestMode(true); AppUtils::setLoginValid(SELF::USER_ID, "sysuser"); // Create a user for forum testing // Not sure how else to do this $newUser = array('id' => SELF::USER_ID, 'firstName' => 'forumUserFirstName', 'lastName' => 'forumUserLastName', 'organization' => 'testOrganization', 'email' => '*****@*****.**', 'password' => 'forumUser1234', 'sysuser' => 1, 'enabled' => 1); // Create Users for forum test $retUser = self::$userPDO->create($newUser); PHPUnit_Framework_Assert::assertEquals($retUser['id'], SELF::USER_ID); $newUser['id'] = SELF::USER_ID2; $retUser = self::$userPDO->create($newUser); PHPUnit_Framework_Assert::assertEquals($retUser['id'], SELF::USER_ID2); }
/** * Prepares the environment before running a test. */ public static function setUpBeforeClass() { // fwrite(STDOUT, __METHOD__ . "\n"); self::$forumPDO = new ForumServicePDO(); self::$postPDO = new ForumPostServicePDO(); self::$userPDO = new UserServicePDO(); AppUtils::setTestMode(true); AppUtils::setLoginValid(SELF::USER_ID, "sysuser"); // Create a user for forum testing // Not sure how else to do this $newUser = array('id' => SELF::USER_ID, 'firstName' => 'forumUserFirstName', 'lastName' => 'forumUserLastName', 'organization' => 'testOrganization', 'email' => '*****@*****.**', 'password' => 'forumUser1234', 'sysuser' => 1, 'enabled' => 1); // Create Users for forum test $retUser = self::$userPDO->create($newUser); PHPUnit_Framework_Assert::assertEquals($retUser['id'], SELF::USER_ID); // Create a Forum self::$forumId = self::$forumPDO->createForum('TestForum.1', 'TestForum.1 Description', SELF::USER_ID); PHPUnit_Framework_Assert::assertNotNull(self::$forumId); }
/** * Login the user with credentials past in POST */ public static function login() { $app = \Slim\Slim::getInstance(); AppUtils::logout(); try { // get and decode JSON request body $request = $app->request(); $response = $app->response(); $body = $request->getBody(); $login = (array) json_decode($body); $loginOK = false; // AppUtils::logDebug("attempting login // ".$login['userId'].'/'.$login['password']); if (!isset($login['userId'])) { AppUtils::sendError(0, "Login Error", "User ID was not specified.", 401); return; } if (!isset($login['password'])) { AppUtils::sendError(0, "Login Error", "Password was not specified.", 401); return; } $userService = new UserServicePDO(); if ($userService->validateUser($login['userId'], $login['password'])) { // AppUtils::logDebug($login['userId'].' Successfully logged in.'); $access = $userService->getAccess($login['userId']); AppUtils::setLoginValid($login['userId'], $access); $rsp = array('userId' => $login['userId'], 'accessLevel' => $access); AppUtils::sendResponse($rsp); } else { // AppUtils::logDebug($login['userId'].' Failed login!'); AppUtils::sendError(0, "Login Error", "User ID/Password combination is invalid.", 401); } } catch (Exception $e) { AppUtils::logError($e, __METHOD__); AppUtils::sendError($e->getCode(), "Error Authenticating User", $e->getMessage()); } }