/** * Create Authentication object * This function is overwritable from the custom helpers/auth_helper.php * * @param string $id PK value * @param object $data The user data object (optional). If it is not given, auth_create will load it from db * * @return object The authenticated user object or FALSE on failure */ function auth_create($id, $data = null) { $lc_auth = auth_prerequisite(); $auth = auth_get(); if (!$auth) { $table = db_prefix() . str_replace(db_prefix(), '', $lc_auth['table']); $fieldId = $lc_auth['fields']['id']; $fieldRole = $lc_auth['fields']['role']; if (is_object($data)) { $session = $data; } else { $sql = 'SELECT * FROM ' . $table . ' WHERE ' . $fieldId . ' = :id LIMIT 1'; if ($result = db_query($sql, array(':id' => $id))) { $session = db_fetchObject($result); } } if (isset($session)) { $session->sessId = session_id(); $session->timestamp = md5(time()); $session->permissions = auth_permissions($session->{$fieldRole}); $session->blocks = auth_blocks($session->{$fieldRole}); auth_set($session); return $session; } } else { return $auth; } return false; }
function testIs_milestone_possible() { $db_config = new mock_db_configure(2); $db_q = array(0 => $this->queries['is_milestone_possible']); $dat = $this->_generate_records(array("proid", "uname"), 3); $rows = $this->_generate_records(array("SUM(payment)"), 3); $rows[0]["SUM(payment)"] = 99; $rows[1]["SUM(payment)"] = 100; $db_config->add_query(sprintf($db_q[0], $dat[1]["proid"], $dat[1]["uname"]), 0); $db_config->add_query(sprintf($db_q[0], $dat[2]["proid"], $dat[2]["uname"]), 1); $db_config->add_record($rows[0], 0); $db_config->add_record($rows[1], 1); // first test: auth is not set auth_unset(); $this->assertEquals(0, is_milestone_possible($dat[0]["proid"]), "test 1"); // second test: auth is set, sum is less than 100 auth_set(); $GLOBALS['auth']->set_uname($dat[1]["uname"]); $this->assertEquals(1, is_milestone_possible($dat[1]["proid"]), "test 2"); // third test: auth is set, sum is 100 auth_set(); $GLOBALS['auth']->set_uname($dat[2]["uname"]); $this->assertEquals(0, is_milestone_possible($dat[2]["proid"]), "test 3"); $this->_check_db($db_config); }
function unset_perm() { $this->_unset_attribute('perm'); } function unset_uname() { $this->_unset_attribute('uname'); } function _set_attribute($att_name, $att_value) { $this->auth[$att_name] = $att_value; } function _unset_attribute($att_name = false) { if ($att_name) { unset($this->auth[$att_name]); } else { $this->auth = array(); } } } function auth_unset() { unset($GLOBALS['auth']); } function auth_set() { $GLOBALS['auth'] = new Auth(); } auth_set();